var xmlHttp = createXmlHttpRequestObject(); 

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() 
{  
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
	if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

var ajax={busy:false,divAnim:''}
ajax.onSuccess=function (){};
ajax.close=function (){
	if (xmlHttp.readyState>0 && xmlHttp.readyState<4){
		xmlHttp.abort();
	}
}
// make asynchronous HTTP request using the XMLHttpRequest object 
ajax.get=function(command,callback)
{
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
	ajax.onSuccess=callback;
	if (ajax.divAnim!=''){
		document.getElementById(ajax.divAnim).innerHTML='<div style="height:600px;padding-top:100px;text-align:center;"><img src="'+page.imgPath+'ajload.gif" class="ajxAnimation"></div>';
	}
	command+="&" +new Date().getTime();
	if(typeof(openURL)!='undefined'){
		if(command.indexOf('http:')<0)command = openURL+command;
	}
	
	xmlHttp.open("GET", command, true);

	if(typeof(slide_up)=='function')slide_up();
	
	xmlHttp.onreadystatechange = ajax._handleResponse;
	xmlHttp.send(null);
	ajax.busy=true;
  }
}
ajax.post=function(formname,command,callback)
{
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
  	ajax.onSuccess=callback;
	if (ajax.divAnim!=''){
		document.getElementById(ajax.divAnim).innerHTML='<img src="'+page.imgPath+'ajload.gif" class="ajxAnimation">';
	}


	frm=document.forms[formname];
	params="";
	for (icnt=0;icnt<frm.elements.length;icnt++){
		if(frm.elements[icnt].type.toLowerCase() == "radio"){
			if(frm.elements[icnt].checked){
				params+=frm.elements[icnt].name+"="+encodeURIComponent(frm.elements[icnt].value)+"&";
			}
		}else
			params+=frm.elements[icnt].name+"="+encodeURI(frm.elements[icnt].value)+"&";
	}

	params+=new Date().getTime();
	command+="&" + new Date().getTime();
	if(typeof(openURL)!='undefined'){
		if(command.indexOf('http:')<0)command = openURL+command;
	}
    
    xmlHttp.open("POST", command, true);
	xmlHttp.onreadystatechange = ajax._handleResponse;
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.send(params);
	ajax.busy=true;
  }
}
// executed automatically when a message is received from the server
ajax._handleResponse=function () 
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      // extract the XML retrieved from the server
      response = xmlHttp.responseText;
      ajax.busy=false;
	  ajax.onSuccess(response);
    } 
    // a HTTP status different than 200 signals an error
    else if (xmlHttp.status != 0)
    {
     ajax.busy=false;
      alert("There was a problem accessing the server: " + xmlHttp.status);
    }
	ajax.divAnim='';
  }
}

function URLEncode(string){
	//alert (string);
	var sEncode;
	var result="";
	var charCode
	if (string=="" || !string) return "";
	
	for (icnt=0,n=string.length;icnt<n;icnt++){
		charCode=string.charCodeAt(icnt);
		//alert (charCode);
		if ((charCode>=48 && charCode<=57) || (charCode>=65 && charCode<=92) || ((charCode>=95 && charCode<=122))) {
			result+=string.substr(icnt,1);
			continue;
		}
		sEncode =charCode.toString(16);
		
		if (sEncode.length==1) sEncode = "0"+sEncode;
		result+="%"+sEncode;
	}
	return result;
}