﻿ 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){
var Result='';
for(var i=0;i<AStr.length;i++)
if(AStr.charAt(i)>='А' && AStr.charAt(i)<='я')
Result+=Letters[AStr.charCodeAt(i)-0x0410];
else if(AStr.charAt(i)=='Ё')
Result+=Letters[64];
else if(AStr.charAt(i)=='ё')
Result+=Letters[65];
else if(AStr.charAt(i)=='=')
Result+='%3D';
else if(AStr.charAt(i)=='&')
Result+='%26';
else
Result+=AStr.charAt(i);
return Result;
}//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;
 }


// </AJAX>


function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {  
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
    if (self.innerHeight) { // all except Explorer
            if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
			} else {
					windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
	}
    contentHeight = document.getElementById("content").offsetHeight;
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
			pageHeight = windowHeight;
	} else { 
			pageHeight = yScroll;
	}
    if(pageHeight < contentHeight){
        pageHeight = contentHeight;
    }
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){      
			pageWidth = xScroll;            
	} else {
			pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight, document.body.scrollLeft, document.body.scrollTop) 
	return arrayPageSize;
}

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 selectCitiesByState(state) {
	var ar = document.getElementById("table_city");
	if(ar) ar.style.display = 'none' ;
	var ar = document.getElementById("table_school");
	if(ar) ar.style.display = 'none' ;
	var state = state || "";
	if(state != "") {
		var xmlhttp=create_http_handle();
		if(xmlhttp) {
			var params = 'name="schools" ajax="1" view_mode="cities-by-state" state="'+state+'"';
			var url_param = roothtml + '/index.php?ajt=messages&params='+params; 
			xmlhttp.open("GET", url_param, true);
			xmlhttp.setRequestHeader("Content-type", "text/html; charset=utf-8");
			xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
			xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
			xmlhttp.setRequestHeader("Pragma", "no-cache");
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
					var ar = document.getElementById("CitiesByState");
					if(ar) ar.innerHTML = xmlhttp.responseText;
					var ar = document.getElementById("table_city");
					if(ar) ar.style.display = '' ;
					reslights();
				}
			}
			xmlhttp.send(null);
		}
	}
}


function selectSchoolsByState(state, zip, city) {
	var state = state || "";
	var city = city || "";
	var zip = zip || "";

	if(city == '-') {
		return;
	}

	if(city == 0) {
		var ar = document.getElementById("other_school_city");
		if(ar) ar.style.display = '';
		var ar = document.getElementById("CitiesByState");
		if(ar) ar.style.display = 'none';
		var ar = document.getElementById("other_school_name");
		if(ar) ar.style.display = '';
		var ar = document.getElementById("SchoolsByState");
		if(ar) ar.style.display = 'none';
		var ar = document.getElementById("table_zip");
		if(ar) ar.style.display = 'block' ;
		var ar = document.getElementById("table_address");
		if(ar) ar.style.display = 'block' ;
		var ar = document.getElementById("table_email");
		if(ar) ar.style.display = 'block' ;
		var ar = document.getElementById("table_phone");
		if(ar) ar.style.display = 'block' ;
		var ar = document.getElementById("school_zip_code");
		if(ar) ar.value = "";
		var ar = document.getElementById("school_street");
		if(ar) ar.value = "";
		var ar = document.getElementById("school_email");
		if(ar) ar.value = "";
		var ar = document.getElementById("school_phone");
		if(ar) ar.value = "";

		reslights();
		return;
	}

	if(state != "") {
		var xmlhttp=create_http_handle();
		if(xmlhttp) {
			var ar = document.getElementById("SchoolsByState");
			if(ar) ar.innerHTML = "Please Wait...";
			var params = 'name="schools" ajax="1" view_mode="schools-by-state" state="'+state+'" city="'+city+'" zip="'+zip+'" ';
			var url_param = roothtml + '/index.php?ajt=messages&params='+params; 
			xmlhttp.open("GET", url_param, true);
			xmlhttp.setRequestHeader("Content-type", "text/html; charset=utf-8");
			xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
			xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
			xmlhttp.setRequestHeader("Pragma", "no-cache");
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
					var ar = document.getElementById("SchoolsByState");
					if(ar) {
						ar.innerHTML = xmlhttp.responseText;
						ar.style.display = '';
					}
					var ar = document.getElementById("other_school_name");
					if(ar) ar.style.display = 'none';
					var ar = document.getElementById("table_school");
					if(ar) ar.style.display = '' ;
					reslights();
				}
			}
			xmlhttp.send(null);
		}
	}
}

function loadSchoolData(id) {
	var id = id || 0;
	var ar = document.getElementById("other_school_name");
	if(ar) ar.style.display = 'none';
	var ar = document.getElementById("SchoolsByState");
	if(ar) ar.style.display = '';
	var ar = document.getElementById("school_zip_code");
	if(ar) ar.value = "";
	var ar = document.getElementById("school_street");
	if(ar) ar.value = "";
	var ar = document.getElementById("school_email");
	if(ar) ar.value = "";
	var ar = document.getElementById("school_phone");
	if(ar) ar.value = "";
	if(id == '-' ) return;
	if(id == 0) {
		var ar = document.getElementById("other_school_name");
		if(ar) ar.style.display = '';
		var ar = document.getElementById("SchoolsByState");
		if(ar) ar.style.display = 'none';
		var ar = document.getElementById("table_zip");
		if(ar) ar.style.display = 'block' ;
		var ar = document.getElementById("table_address");
		if(ar) ar.style.display = 'block' ;
		var ar = document.getElementById("table_email");
		if(ar) ar.style.display = 'block' ;
		var ar = document.getElementById("table_phone");
		if(ar) ar.style.display = 'block' ;
		reslights();
	} else {
		var xmlhttp=create_http_handle();
		if(xmlhttp) {
			var params = 'name="schools" ajax="1" view_mode="schools-data" id="'+id+'" ';
			var url_param = roothtml + '/index.php?ajt=messages&params='+params; 
			xmlhttp.open("GET", url_param, true);
			xmlhttp.setRequestHeader("Content-type", "text/html; charset=utf-8");
			xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
			xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
			xmlhttp.setRequestHeader("Pragma", "no-cache");
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
					xmlhttp.responseText.type = "text/javascript";
					xmlhttp.responseText.onload = new function() {
						eval(xmlhttp.responseText);
						var school = school || {};
						if(parseInt(school.ID) > 0) {
							var ar = document.getElementById("SchoolsByState");
							if(ar) ar.style.display = '';
							var ar = document.getElementById("school_zip_code");
							if(ar) ar.value = school.ZIP_CODE;
							var ar = document.getElementById("table_zip");
							if(ar) ar.style.display = 'block' ;
							var ar = document.getElementById("school_street");
							if(ar) ar.value = school.STREET;
							var ar = document.getElementById("table_address");
							if(ar) ar.style.display = 'block' ;
							var ar = document.getElementById("school_email");
							if(ar) ar.value = school.EMAIL;
							var ar = document.getElementById("table_email");
							if(ar) ar.style.display = 'block' ;
							var ar = document.getElementById("school_phone");
							if(ar) ar.value = school.PHONE;
							var ar = document.getElementById("table_phone");
							if(ar) ar.style.display = 'block' ;
							reslights();
						}
					}
				}
			}
			xmlhttp.send(null);
		}
	}
}

var roothtml = "";
/*
if(!/\.dev$/.test(window.location.host)) {
	roothtml = '/~bobbyboo';
}
*/
