function ajax (){
  this._makeClient();
  this._makeHandler();
  return this;
}

ajax.prototype._makeClient = function()
{
  var client;
  try{
    client=new XMLHttpRequest();
  }catch (e){
    try{
        client=new ActiveXObject("Msxml2.XMLHTTP");
    }catch (e){
      try {
          client=new ActiveXObject("Microsoft.XMLHTTP");
      }catch (e){
          alert("Your browser does not support AJAX!");
          return false;
      }
    }
  }
  this.client = client;
};

ajax.prototype.send = function(url, method) {
    if (method == "GET") {
      this.client.open("GET",url+"&rnd="+new Date().getTime(),true);
      this.client.send(null);
    } else {
      var target = url.split('?') [0];
      var params = url.split('?') [1];
      this.client.open("POST",target+"?rnd="+new Date().getTime(),true);
      this.client.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      this.client.setRequestHeader("Content-length", params.length);
      this.client.setRequestHeader("Connection", "close");
      this.client.send(params);
    }
};

ajax.prototype._makeHandler = function() {
  var _self = this;
  this.client.onreadystatechange=function() {
    if(_self.client.readyState==4) {
      if (_self.getResponse().substr (0, 2) == "OK") {
                typeof (_self.onSuccess) == "function" ? _self.onSuccess () : eval (_self.onSuccess);
      } else {
                typeof (_self.onFailure) == "function" ? _self.onFailure () : eval (_self.onFailure);
      }
    }
  }
};

ajax.prototype.onSuccessHandler = function(func) {
    this.onSuccess = func;
    this._makeHandler ();
};

ajax.prototype.onFailureHandler = function (func) {
  this.onFailure = func;
  this._makeHandler ();
};

ajax.prototype.getResponse = function () {
   return this.client.responseText || "";
};
