var http = getHTTPObject(); // We create the HTTP Object
var isWorking = false;


function handleHttpResponse() {
//   	alert(http.readyState + ": " + http.responseText);
	if (http.readyState ==4) {
		if (http.responseText.indexOf('invalid') == -1) {
			if (http.responseText != '') {

				// The returned XML string should include a "returnFunction" value. We'll
				// execute that function using eval, and pass the remainder of the XML (the data node) to
				// that function as a Hash object. If there is no returnFunction value,
				// then we will ignore any response from the server.

				var xmlDoc = http.responseXML ;

				if ( xmlDoc && xmlDoc.getElementsByTagName( '_returnFunction' ).item(0) ) {
					var returnFunction = xmlDoc.getElementsByTagName( '_returnFunction' ).item(0).firstChild.nodeValue ;
				}

				if ( returnFunction != null && returnFunction != '' ) {
					// pull out data...

					eval( returnFunction + '( xmlDoc );' ) ;
				}

			}
			isWorking = false;
		}
	}
}


function sendAjaxRequest( reqMethod, reqAddress, argHash, async, returnFunction ) {
	if (!isWorking && http) {

		if ( argHash == null ) argHash = new Hash() ;

		if ( returnFunction != null && returnFunction != '' ) argHash.addItem( 'returnFunction', returnFunction ) ;

		http.open(reqMethod, reqAddress + hashToGetQuery( argHash ), async);
		http.onreadystatechange = handleHttpResponse;
		isWorking = true;
		http.send(null);
	}

}


function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}





