function Ajax() {
  //Eigenschaften deklarieren und initialisieren
  this.url="";
  this.params="";
  this.method="GET";
  this.onSuccess=null;
  this.xmlHttpRequest=null;
  this.onError=function (msg) {
//    alert("Ajax.js\n"+msg);
  }
}

Ajax.prototype.IsRunning = function() {
  if (this.xmlHttpRequest==null) {
    return false;
  } else {
    return (this.xmlHttpRequest.readyState<4);
  }
}

Ajax.prototype.Abort = function() {
  if (this.IsRunning()) {
    this.xmlHttpRequest.abort();
  }
}

Ajax.prototype.doRequest=function() {
  //Üeberpruefen der Angaben
  if (!this.url) {
    this.onError("Es wurde kein URL angegeben. Der Request wird abgebrochen.");
    return false;
  }

  if (!this.method) {
    this.method="GET";
  } else {
    this.method=this.method.toUpperCase();
  }

  //Zugriff auf Klasse für readyStateHandler ermöglichen
  var _this = this;

  //XMLHttpRequest-Objekt erstellen
  this.xmlHttpRequest=getXMLHttpRequest();
  if (!this.xmlHttpRequest) {
    this.onError("Es konnte kein XMLHttpRequest-Objekt erstellt werden.");
    return false;
  }

  //Fallunterscheidung nach Übertragungsmethode
  switch (this.method) {
    case "GET": this.xmlHttpRequest.open(this.method, this.url+"?"+this.params, true);
    this.xmlHttpRequest.onreadystatechange = readyStateHandler;
    this.xmlHttpRequest.send(null);
    break;
    case "POST": this.xmlHttpRequest.open(this.method, this.url, true);
    this.xmlHttpRequest.onreadystatechange = readyStateHandler;
    this.xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    this.xmlHttpRequest.send(this.params);
    break;
  }

  //Private Methode zur Verarbeitung der erhaltenen Daten
  function readyStateHandler() {
    try {
      if (_this.xmlHttpRequest.readyState < 4) {
        return false;
      }
      if (_this.xmlHttpRequest.status == 200 || _this.xmlHttpRequest.status==304) {
        if (_this.onSuccess) {
          _this.onSuccess(_this.xmlHttpRequest.responseText, _this.xmlHttpRequest.responseXML);
        }
      } else {
        if (_this.onError) {
          _this.onError("["+_this.xmlHttpRequest.status+" "+_this.xmlHttpRequest.statusText+"] Es trat ein Fehler bei der Datenbertragung auf.");
        }
      }
    } catch(e) {

    }
  }
}

//Gibt browserunabhängig ein XMLHttpRequest-Objekt zurück
function getXMLHttpRequest()
{
  if (window.XMLHttpRequest) {
    //XMLHttpRequest für Firefox, Opera, Safari, ...
    return new XMLHttpRequest();
  } else
  if (window.ActiveXObject) {
    try {
      //XMLHTTP (neu) für Internet Explorer
      return new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        //XMLHTTP (alt) für Internet Explorer
        return new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        return null;
      }
    }
  }
  return false;
}

