function getXMLHttpRequest() 
{
  if (window.XMLHttpRequest) {
    return new XMLHttpRequest();
  } else 
  if (window.ActiveXObject) {
    try {   
      return new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {        
        return new ActiveXObject("Microsoft.XMLHTTP");  
      } catch (e) {
        return null;
      }
    }
  }
  return false;
}

function Ajax()
{
  this.url="";
  this.params="";
  this.method="POST";
  this.onSuccess = null;
  this.onError = null;
  this.onAbort = null;
  this.aborted = false;
  this.httpReq = getXMLHttpRequest();
}


Ajax.prototype.doRequest=function()
{  
  var _this = this;
  switch (this.method)
  {
    
    case "GET": this.httpReq.open(this.method, this.url+"?"+this.params, true);
                this.httpReq.onreadystatechange = readyStateHandler;
                this.httpReq.send(null);
                break;
    case "POST": this.httpReq.open(this.method, this.url, true);
                 this.httpReq.onreadystatechange = readyStateHandler;
                 this.httpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                 this.httpReq.send(this.params);
                 break;
  } 
  
  function readyStateHandler()
  {
    switch (_this.httpReq.readyState)
    {
      case 0 : // UNINITIALIZED
      case 1 : // LOADING
      case 2 : // LOADED
      case 3 : // INTERACTIVE
        break;
      case 4 : // COMPLETED

        if (_this.httpReq.status == 200 || _this.httpReq.status == 304)
        {
          if (_this.onSuccess)
          {
            _this.onSuccess(_this.httpReq.responseText, _this.httpReq.responseXML);
          }
        }
        else if(_this.httpReq.status == 0)
        {
          _this.doAbort();
         // _this.doRequest();
        }
        else
        {
          if (_this.onError)
          {
            _this.onError("["+_this.httpReq.status+" "+_this.httpReq.statusText+"]");
          }
        }
      break;
      default : ; // fehlerhafter Status
    }
  }
}

Ajax.prototype.doAbort=function()
{
  if (this.onAbort)
  {
    this.onAbort();
  }
  this.httpReq.abort();
  this.aborted = true;
}




