// OPLS - Ajax Utilites

/*
 * Returns a new XMLHttpRequest object, or false if this browser
 * doesn't support it
 */
function newXMLHttpRequest() 
{
  var xmlreq = false;
  if (window.XMLHttpRequest) {
    xmlreq = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    try {
      xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e1) {
      try {
        xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
		// failure
      }
    }
  }
  if (!xmlreq)
  	alert("Unable to create required XMLHttpRequest object");
  return xmlreq;
}

/*
 * Returns a function that waits for the specified XMLHttpRequest
 * to complete, then passes its XML response to the given handler function.
 *  req - The XMLHttpRequest whose state is changing
 *  responseXmlHandler - Function to pass the XML response to
 */
function getReadyStateHandler(req, responseXmlHandler) 
{
  // Return an anonymous function that listens to the 
  // XMLHttpRequest instance
  return function () 
  {
    if (req.readyState == 4) {
      // Check that a successful server response was received
      if (req.status == 200) {
        responseXmlHandler(req.responseText);
      } else {
        //alert("ReadStateHandler Error: "+req.status+" - "+req.statusText);
      }
    }
  }
}