function Ajax() {
  this.ajaxObject;
  this.url="";
  this.params="";
  this.method="GET";
  this.onSuccess=null;
  this.onError=function (msg) {
    alert(msg)
  }
  this.getAjaxObject = function () {
      return ajaxObject;
  }
}

Ajax.prototype.prepareRequest=function () {
    ajaxObj=getXMLHttpRequest();
    return ajaxObj;
}

Ajax.prototype.doRequest = function(ajaxObj) {

    if (!this.url) {
        this.onError("no url defined!");
        return false;
    }

    if (!this.method) {
        this.method="GET";
    } else {
        this.method=this.method.toUpperCase();
    }

    var xmlHttpRequest
    if (!ajaxObj) {
        //XMLHttpRequest-Objekt erstellen
        xmlHttpRequest=getXMLHttpRequest();
    } else {
        xmlHttpRequest=ajaxObj
    }

    //make this class for readyStateHandler visible
    var _this = this;


  var xmlHttpRequest=getXMLHttpRequest();
  if (!xmlHttpRequest) {
    this.onError("Create of XMLHttpRequest-object failed.");
    return false;
  }

  switch (this.method) {
    case "GET": xmlHttpRequest.open(this.method, this.url+"?"+this.params, true);
                xmlHttpRequest.onreadystatechange = readyStateHandler;
                xmlHttpRequest.send(null);
                break;
    case "POST": xmlHttpRequest.open(this.method, this.url, true);
                   xmlHttpRequest.onreadystatechange = readyStateHandler;
                 xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                 xmlHttpRequest.send(this.params);
                 break;
  }

  function readyStateHandler() {
    if (xmlHttpRequest.readyState < 4) {
      //xmlHttpRequest.abort();
      return false;
    }
    try {
        if (xmlHttpRequest.status == 200 || xmlHttpRequest.status==304) {
          if (_this.onSuccess) {
            _this.onSuccess(xmlHttpRequest.responseText, xmlHttpRequest.responseXML);
          }
        } else {
          if (_this.onError) {
            _this.onError("["+xmlHttpRequest.status+" "+xmlHttpRequest.statusText+"]. Error in process of data.");
          }
        }
    } catch(ff) {
	   _this.onError("xmlHttpRequest.status not available");
    }
  }
}

function getXMLHttpRequest()
{
  if (window.XMLHttpRequest) {
    //Firefox, Opera, Safari, ...
    return new XMLHttpRequest();
  } else
  if (window.ActiveXObject) {
    try {
      //XMLHTTP (new) doe Internet Explorer
      return new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        //XMLHTTP (old) for Internet Explorer
        return new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        return null;
      }
    }
  }
  return false;
}
