/* Put all A.J.a.x. related code here */
var request = null;

function getHttpRequest(sRequestType, sURL, bSendAsynchronously, sResponseHandler){
  /* Returns a request object based on browser type 
   * MJA 20070105
   */

  if(window.XMLHttpRequest){
    /* Mozilla */
    request = new XMLHttpRequest();
  }else if(window.ActiveXObject){
    request = new ActiveXObject("Msxml2.XMLHTTP");
    //try a different version if needed
    if(!request){
      request = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }

  //Make sure the the request was created
  if(request){
    //The request type requires different handling for POSTs
    if(sRequestType.toLowerCase() != "post"){
      initializeRequest(sRequestType, sURL, bSendAsynchronously, sResponseHandler);
    }else{
      //Gotta get the posted data
      var otherArguments = arguments[4];
      if(otherArguments != null && otherArguments.length > 0){
        initializeRequest(sRequestType, sURL, bSendAsynchronously, sResponseHandler, otherArguments);
      }
    }
  }
}
function initializeRequest(sRequestType, sURL, bSendAsynchronously, sResponseHandler){
  /*
   * Initializes a request object (that already exists)
   * MJA 20070105 
   */
   try{
     /* set which function to call when we get stuff back */
     request.onreadystatechange = sResponseHandler;
     request.open(sRequestType, sURL, bSendAsynchronously);
     
     /* POSTs have more stuff to send */
     if(sRequestType.toLowerCase() == "post"){
       request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
       request.send(arguments[4]);
     }else{
       request.send(null);
     }
   }catch(errv){
     alert("An error has occurred." + errv.message);
   }

}