<script language="javascript">
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;
}

function do_close(){
	if (xmlHttp.readyState>0 && xmlHttp.readyState<4){
		xmlHttp.abort();
	}
}
// make asynchronous HTTP request using the XMLHttpRequest object 
function do_get_command(command)
{
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
	  command+="&t=" +new Date().getTime();
    xmlHttp.open("GET", command, true);  
    // define the method to handle server responses
    xmlHttp.onreadystatechange = handleServerResponse;
    // make the server request
    xmlHttp.send(null);
  }
}
function do_post_command(formname,command)
{
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
	  // form the send parameters
	frm=document.forms[formname];
	params="";
	for (icnt=0;icnt<frm.elements.length;icnt++){
		params+=frm.elements[icnt].name+"="+encodeURI(frm.elements[icnt].value)+"&";
	}
	params+=new Date().getTime();
	command+="&t=" + new Date().getTime();
    // define the method to handle server responses
    
    xmlHttp.open("POST", command, true);
	xmlHttp.onreadystatechange = handleServerResponse;
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	//xmlHttp.setRequestHeader("Content-length", params.length);
	//xmlHttp.setRequestHeader("Connection", "close");
    // make the server request
   xmlHttp.send(params);
  }
}
// executed automatically when a message is received from the server
function handleServerResponse() 
{
  // 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;
	  do_result(response);
    } 
    // a HTTP status different than 200 signals an error
    else if (xmlHttp.status != 0)
    {
      alert("There was a problem accessing the server: " + xmlHttp.status);
    }
  }
}
</script>
