function XHRObject (url, handler)
{
  // Constant value indicating that the request is complete.
  var ajax_REQUEST_COMPLETE = 4;

   //Constant value indicating that the request is well-formed.
  var ajax_REQUEST_OKAY = 200;

  // Clear previous requests:
  var xhr = false;

  //var xhr = null;
  var url = url;
  var handler = handler;
  var errorHandler = function(status)
  {
    //alert ("An XmlHttpRequest() Failed.\n\nURL: " + url+  "\n\nStatus: " + status);
  }

   // Depending on the browser, create the object:
  if( window.XMLHttpRequest ) {
    // Mozilla, Safari
    xhr = new XMLHttpRequest();
    if( xhr.overrideMimeType ) {
      xhr.overrideMimeType( 'text/xml' );
    }//if we need to override the mime-type
  } else if( window.ActiveXObject ) {
    // Internet Explorer
    try {      xhr = new ActiveXObject( 'Microsoft.XMLHTTP' );
    } catch( e ) {
      try {    xhr = new ActiveXObject( 'Msxml2.XMLHTTP' );
      } catch( e ) { // Do nothing; we failed.
      }//try again
    }//try to make the object
  }//if we have the right browser

  if( !xhr ) {
    ajax_error_code += 'Failed to create XMLHttpRequest Object.<br />';
    return false;
  }//if we could not make the object

// The body of the AJAX handler function:
  var function_body = function( http_request ) {
		if (http_request == null )
			return false;
    try {
      if( ajax_REQUEST_COMPLETE == http_request.readyState ) {
        if(ajax_REQUEST_OKAY == http_request.status ) {
          if (http_request.responseXML != null)
          {
            allMessages = http_request.responseXML.getElementsByTagName('message');
            if (allMessages.length > 0)
            {
              for (var messageNum = 0; messageNum < allMessages.length; messageNum++)
              {
                if (allMessages[messageNum].getAttribute('type') == 'debug')
                {
                  alert (allMessages[messageNum].firstChild.nodeValue);
                }

              }
            }
          }

          handler(http_request.responseText, http_request.status, http_request.responseXML);
          //acceptFunction( xmldoc ); // User-supplied function has been called.
        } else {
          errorHandler('Status: '+ http_request.status + "\n" + http_request.responseText);
          return false;
        }//if there were no errors
      }//end if: we either have a completed request or are pending with a different readyState
    } catch( e ) {
     	//errorHandler(e.description);
      return false;
    }
  }//end anonymous function: BODY

  // On ready state change function:
  var function_onreadystatechange = function () {
    function_body(xhr);
  }//End anonymous onreadystatechange function
  this.request = function(data, method, async)
  {
    if (async==null) { async = true;}
	     try {
        // Firefox uses onload, but only when you have multiple AJAX requests going.
        // Usually you can bind to onreadystatechange, but only if you are not doing too many requests at once.
				if (!xhr.onload && async) {
					xhr.onreadystatechange = function_onreadystatechange;
				} else {
					xhr.onload = function( e ) {
						var evt = window.event ? window.event : e;
						var targ = evt.target ? evt.target : evt.srcElement;
						function_body( targ );
					}
				}
               if (xhr.onreadystatechange == null) xhr.onreadystatechange = function_onreadystatechange;
      } catch( e ) {
        // IE does not have an onload handler, so bind the onreadystatechange
        xhr.onreadystatechange = function_onreadystatechange;
      }//end try: correct function handler is bound

    if (/post/i.test(method))
    {
      xhr.open("POST", url, async);
      xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      if (data==null) data='';
      xhr.send(data);
    }
    else
    {
      xhr.open("GET", url, async);
      xhr.send('');
    }

    // FIX FOR FIREFOX SYNCHRONOUS CALL WITH JAVASCRIPT FUCKUP
   var isGecko = (document.addEventListener) ? true : false;

		try {
      if (!async && isGecko && xhr.onreadystatechange == null) {
      function_onreadystatechange(xhr);
        return true;
      }
    }
		catch (e) { return false; }
  }
}