/* Creating the XMLHttpRequest same as above */
var xmlHttp = false;
var outputDiv = "";
var cnt=0;

 try {
  /* try the first version of JavaScript in IE */
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
 } 
 catch (e) {
  try {
   /* try the second version of JavaScript in IE */
   xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } 
  catch (e2) {
   xmlHttp = false;
  }
 }

 /* else create the object the non-Microsoft way */
 if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
 }


/* 1. retrieving the entered data and issuing the request */
function callServer(page,args,output) {
 //alert ("function call is good. "+args);
 outputDiv = output;
 //check whether the element has value
 //if((page==null) || (args=="")){ return;}
//alert ("testing 123");
 //make the URL that will process the request
 var url="";
 if (args==""){
  url=page;
 }
 else{
  argArr=args.split("$$");
  args=argArr.join("=");
  url = page + "?" + args;
 }
//alert("doing call for "+url);
 
 // Setup a function for the server to run when it's done
 xmlHttp.onreadystatechange = updatePage();

 //make a connection to the server
 xmlHttp.open("GET",url,true);

 // Send the request
 xmlHttp.send(null);
//alert ("testing 12");
}

/* 2. handling the server response */
function updatePage() {
//alert("res func called");
 if (xmlHttp.readyState == 4) {
  setTimeout("continueLoad()",2000);//to give server-side scripts time to load.
 }
 else{
  if (cnt<5){
   cnt++;
   setTimeout("updatePage()",2000);
  }
 }
}

function continueLoad(){
//alert("response initiated properly");
  var response = xmlHttp.responseText;
//alert(response);
  document.getElementById(outputDiv).innerHTML = response;
  response="";
}
