//-----------------------------------------------------------
// Message handler
//  - Sends message to script and waits for completion
//  - On completion, updates page with script output
//-----------------------------------------------------------
// url = url to call server-side script
// resultID = ID of DIV or SPAN element to receive the output
//-----------------------------------------------------------
function handleMessages (url, resultID) {

   // Create xmlhttp request object

   var xmlhttp=false;
   try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } 
   catch (e) {
               try { xmlhtttp = new ActiveXObject("Microsoft.XMLHTTP"); } 
               catch (E) { xmlhttp = false; }
             }

   if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); }

   if (xmlhttp) {
       var obj;
       xmlhttp.open("GET", url, true);
       xmlhttp.onreadystatechange=function() {
         if (xmlhttp.readyState==4) {
             obj = document.getElementById(resultID);
             obj.innerHTML = xmlhttp.responseText;
         }
       }
       xmlhttp.send(""); 
       return 0;
   }
}

//-------------------------------------------------
function handleForm (url, params, resultID) 
  {
   // Create xmlhttp request object
   var xmlhttp=false;
   try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } 
   catch (e) {
               try { xmlhtttp = new ActiveXObject("Microsoft.XMLHTTP"); } 
               catch (E) { xmlhttp = false; }
             }
   if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); }
   if (xmlhttp) 
      {
       var obj;
       xmlhttp.open("POST", url, true);
       //Send the proper header information along with the request
       xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=unicode");
       xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
	    if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
              {
               obj = document.getElementById(resultID);
               obj.innerHTML = xmlhttp.responseText;
              }
       } // end inline function
       xmlhttp.send(params);
      } // end if (xmlhttp)
  } // end function

//------------------------------------------------
//Function to create an XMLHttp Object.
//------------------------------------------------
function getXmlhttp ()
  {//Create a boolean variable to check for a valid microsoft active X instance.
   var xmlhttp = false;
   //Check if we are using internet explorer.
   try  //If the javascript version is greater than 5.
        { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } 
   catch (e) 
         { //If not, then use the older active x object.
           try  //If we are using internet explorer.
               { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } 
           catch (e)  //Else we must be using a non-internet explorer browser. 
                 { xmlhttp = false; }
	 }
   //If we are using a non-internet explorer browser, create a javascript instance of the object.
   if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {	xmlhttp = new XMLHttpRequest();	}
   return xmlhttp;
  }
	
//------------------------------------------------
//Function to process an XMLHttpRequest.
//------------------------------------------------
function processAjax (serverPage, obj, getOrPost, str)
  { //Get an XMLHttpRequest object for use.
    xmlhttp = getXmlhttp ();
    if (getOrPost == "get")
       { xmlhttp.open("GET", serverPage);
         xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { obj.innerHTML = xmlhttp.responseText; } }
         xmlhttp.send(null);
       }
    else
       { xmlhttp.open("POST", serverPage, true);
         xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
         xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { obj.innerHTML = xmlhttp.responseText; } }
         xmlhttp.send(str);
       }
  }
