/*
 * This is a file that pads AJAX to make it easier to use.  It makes asyncronous requests.
 * This file declares a global AJAX variable named ajaxHttp.  In order to make a request,
 * call one of the following methods:
 *
 * ajaxHttp.getRequest(script_url);
 * ajaxHttp.postRequest(script_url, post_string);
 *
 * getRequest just makes a get request to the server.
 * postRequest takes a get string and turns the get variables in to post variables when the request is submited.
 *    (i.e. post_string = "var1=sometext&var2=othertext&...")
 * In order to access the string that comes back from the request, overwrite the method ajaxHttp.onRequestComplete with custom code.
 * This is the method that is called after the message is deliverd successfully.
 */

var ajaxHttp = new Object();

ajaxHttp.onRequestComplete=function() { }

initializeAjaxHttpRequest();


function initializeAjaxHttpRequest(){
  try{
    // Firefox, Opera 8.0+, Safari
    ajaxHttp.request = new XMLHttpRequest();
  } catch (e) {
    // Internet Explorer
    try {
      ajaxHttp.request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
      ajaxHttp.request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        alert("Your browser does not support AJAX!");
        ajaxHttp.request = null;
      }
    }
  }
  
  if( ajaxHttp.request != null ){    

    ajaxHttp.getRequest=function(script){
      initializeAjaxHttpRequest();
      ajaxHttp.request.open("GET", script, true);
      ajaxHttp.request.send(null);
      //return ajaxHttp.request.responseText;
    }
    
    ajaxHttp.postRequest=function(script, header){
      initializeAjaxHttpRequest();
      ajaxHttp.request.open("POST", script, true);
      ajaxHttp.request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    
      ajaxHttp.request.send(header);
      //return ajaxHttp.request.responseText;
    }
        
    ajaxHttp.request.onreadystatechange=function(){
      if(ajaxHttp.request.readyState == 4){
        ajaxHttp.onRequestComplete();
      }
    }
    
    ajaxHttp.getResponseText=function(){
      return ajaxHttp.request.responseText;
    }
    
  }

}

