// JavaScript Document
// AJAX Connection script
var xmlHttp;
var element;
var callFunc;
var contentType = "application/x-www-form-urlencoded";

function ajaxConn(app, str, ele, action, method)
{ 
	
	xmlHttp=GetXmlHttpObject();
	element = ele;
	callFunc = action;
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	if(str){
		var checkVals = str.split("&");
		var checkOK = true;
		for (var x=0;x<checkVals.length;x++) {
			//checks to see if variable/value pairs are valid
			var val = checkVals[x].split("=");
			if (val[1] == ""){checkOK=false;}
		}
	}else{
		checkOK = true}
	if( checkOK == true ){
		var request = app+"?"+str;
		var dateVar = new Date();
		request = request+"&sid="+encodeURIComponent(dateVar);
		xmlHttp.onreadystatechange=stateChanged;
		if(method.toUpperCase()=='GET'){
			xmlHttp.open("GET",request,true);
			xmlHttp.send(null);
		}else if(method.toUpperCase()=='POST'){
			xmlHttp.open("POST", app, true);
			xmlHttp.setRequestHeader("Content-Type", contentType);
			xmlHttp.setRequestHeader("Content-length", str.length);
			xmlHttp.setRequestHeader("connection", "close");
			xmlHttp.send(str);
		}
		action("loading",null,element);
	}else{action("error","invalid query: "+str,element);}
	return false;
}

function stateChanged() 
{ 
	if (xmlHttp.readyState!=4)
	{
		callFunc("loading",null,element);
	}
	if (xmlHttp.readyState==4)
	{ 
		var response = xmlHttp.responseText;
		callFunc("ready",response,element);
	}
}
function GetXmlHttpObject() {
	var xmlHttp=null;
	/*@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') {
		try {
			xmlHttp = new XMLHttpRequest();
		} catch (e) {
			xmlHttp=null;
		}
	}
	if (!xmlHttp && window.createRequest) {
		try {
			xmlHttp = window.createRequest();
		} catch (e) {
			xmlHttp=null;
		}
	}
	return xmlHttp;
}