﻿ function report_js_error(msg, url, linenumber) {
  stuff=" URL: "+url+" - "+msg+"; line: "+linenumber;
  tmp = new Image();
  tmp.src = "write_error.php?error="+stuff;
  return true;
 }

window.onerror=report_js_error


var bV=parseInt(navigator.appVersion);
NS4=(document.layers) ? true : false;
IE4=((document.all)&&(bV>=4))?true:false;

//[#if ("1"=="<#DEBUG_TEMPLATES#>")#]
//[#inc debug_templates.js#]
//[#endif#]

// <AJAX>

var Letters=new Array('%C0','%C1','%C2','%C3','%C4','%C5','%C6','%C7','%C8','%C9','%CA','%CB','%CC','%CD','%CE','%CF','%D0','%D1','%D2','%D3','%D4','%D5','%D6','%D7','%D8','%D9','%DA','%DB','%DC','%DD','%DE','%DF','%E0','%E1','%E2','%E3','%E4','%E5','%E6','%E7','%E8','%E9','%EA','%EB','%EC','%ED','%EE','%EF','%F0','%F1','%F2','%F3','%F4','%F5','%F6','%F7','%F8','%F9','%FA','%FB','%FC','%FD','%FE','%FF','%A8','%B8');
var flashing=0;

// -------------------------------------------------------------

function Win2Escape(AStr){
	return escape(AStr);
}//Win2Escape

// -------------------------------------------------------------

function URLencode(sStr) {
    return (Win2Escape(sStr)).replace(/\+/g, '%2C').replace(/\"/g,'%22').replace(/\'/g, '%27');
}

// -------------------------------------------------------------

function startFlashing(block_id) {

 layer = document.getElementById(block_id);
 if (flashing==1) {
  layer.style.borderWidth='1px';
  layer.style.borderColor='#000000';
  if (layer.style.borderStyle.indexOf('none') == -1) {
   //alert(layer.style.borderStyle);
   layer.style.borderStyle='none';
  } else {
   layer.style.borderStyle='dotted';
  }
  window.setTimeout("startFlashing('"+block_id+"');", 100);

 } else {
  layer.style.borderStyle='none';
  layer.style.borderWidth='0px';
 }

}

// -------------------------------------------------------------

 function AJAXRequest(url, ready_function, first_param, proc_function) {

  proc_function = proc_function || '';
  first_param = first_param || '';

 var xmlhttp=false;

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/

  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
   xmlhttp = new XMLHttpRequest();
  }
  xmlhttp.open("GET", url,true);
  xmlhttp.onreadystatechange=function() {
   if (xmlhttp.readyState==4) {
    eval(ready_function+'(\''+first_param+'\', xmlhttp.responseText);');
   }
  }
  if (proc_function) {
   eval(proc_function+'();');
  }
  xmlhttp.send(null);

  return false;
 }

// -------------------------------------------------------------

 function getBlockDataForm(block_id, form) {
  params='';
  for(i=0;i<form.elements.length;i++) {
   if ((form.elements[i].type!='radio' && form.elements[i].type!='checkbox') || form.elements[i].checked) {
    params+='&'+form.elements[i].name+'='+URLencode(form.elements[i].value);
   }
  }
  //alert(params);
  url=form.action;

 layer = document.getElementById(block_id);
 old_data=layer.innerHTML;

 flashing=1;
 startFlashing(block_id);

// layer.innerHTML='<b>Loading please wait...</b>';


 var xmlhttp=false;

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/

  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
   xmlhttp = new XMLHttpRequest();
  }

  xmlhttp.onreadystatechange=function() {
   if (xmlhttp.readyState==4) {
    flashing=0;
    layer.innerHTML=xmlhttp.responseText;
    layer.style.borderStyle='none';
   }
  }

  if (form.method=='post') {
   xmlhttp.open("POST", url, true);
   xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
   xmlhttp.send(params+'&filterblock='+block_id);
  } else {
   xmlhttp.open("GET", url+params+'&filterblock='+block_id,true);
   xmlhttp.send(null);
  }

  return false;

 }

// ------------------------------------------------------------

 function getBlockData(block_id, url) {
  layer = document.getElementById(block_id);
  old_data=layer.innerHTML;

  flashing=1;
  startFlashing(block_id);
//  return false;
  //layer.innerHTML='<b>Loading please wait...</b>';


 var xmlhttp=false;

/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/

  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
   xmlhttp = new XMLHttpRequest();
  }
  xmlhttp.open("GET", url+'&filterblock='+block_id,true);
  xmlhttp.onreadystatechange=function() {
   if (xmlhttp.readyState==4) {
    flashing=0;
    layer.style.borderStyle='none';
    layer.innerHTML=xmlhttp.responseText;
   }
  }
  xmlhttp.send(null);
  return false;
 }


 function returnURLParams(formId){
		var params='';
		var tmp = document.getElementById(formId);
		if(tmp) {
			if(tmp.elements.length>0)  for(i=0; i<tmp.elements.length; i++) {
				if(tmp.elements[i].name == 'param3') {
					//alert(document.getElementById(formId).elements[i].value);
					//alert(tmp.elements[i].value)
				}
				switch(tmp.elements[i].type) {
					case "radio": case "checkbox": 
						if(tmp.elements[i].checked) {
							if(tmp.elements[i].value=='') params += "&" + tmp.elements[i].name + "=1";
							else params += "&" + tmp.elements[i].name + "=" + encodeURIComponent(tmp.elements[i].value);
						}
					break;
					case "select-multiple": 
						if(tmp.elements[i].options.length>0) for(y=0; y<tmp.elements[i].options.length; y++) {
							if(tmp.elements[i].options[y].selected) {
								params += "&" + tmp.elements[i].name + encodeURIComponent("[") + y + encodeURIComponent("]") + "=" + encodeURIComponent(tmp.elements[i].options[y].value);
							}
						}
					break;
					default: params += "&" + tmp.elements[i].name + "=" + encodeURIComponent(tmp.elements[i].value);
				}
			}
		}
		return params;
	}
 
 
 function create_http_handle(TYPE){
		var http_handle = false;
		if (window.XMLHttpRequest){
			http_handle = new XMLHttpRequest();
			if (http_handle.overrideMimeType){
				if (TYPE == "XML"){
					http_handle.overrideMimeType('text/xml');
				} else {
					http_handle.overrideMimeType('text/html');
				}
			}
		} else if (window.ActiveXObject){
			try {
				http_handle = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					http_handle = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		if (!http_handle){
			alert("We are sorry but you are using an outdated browser.  To view this site you must update your browser.");
			return false;
		} else {
			return http_handle;
		}
 }
 
 function AJAXPostRequest(url, params, ready_function, first_param, proc_function) {
		proc_function = proc_function || '';
		first_param = first_param || '';
		xmlhttp = create_http_handle();
		var now = "&upid=" + new Date().getTime();
		url += (url.indexOf("?")+1) ? "&" : "?";
		url += now;
		//params += now;
		//xmlhttp.open("POST",url+params,true);
		xmlhttp.open("POST",url,true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {eval(ready_function+'(\''+first_param+'\', xmlhttp.responseText);');}
		}
		if (proc_function) { eval(proc_function+'(\''+first_param+'\');');	}
		xmlhttp.send(params);
		return false;
	} 
// </AJAX>
