function Ajax(URL, method, action) {
  this.URL = URL;

  method = method.toUpperCase();
  if(method!='GET')
    method = 'POST';
  this.method = method;

  this.action = action;

  if (window.XMLHttpRequest)
    this.obj = new XMLHttpRequest();
  else if (window.ActiveXObject)
    this.obj = new ActiveXObject("Microsoft.XMLHTTP");

  this._state = 0;
}

Ajax.prototype.abort = function() {
  this.obj.abort();
  this._state = 0;
}

Ajax.prototype.status = {
  'free'  : 0,
  'busy'  : 1,
  'error' : 2
}

Ajax.prototype.statusMessage = {
  0 : 'free',
  1 : 'busy',
  2 : 'error'
}

Ajax.prototype.setStatus = function (val) {
  this._state = val;
}

Ajax.prototype.getStatus = function () {
  return this._state;
}

Ajax.prototype.getStatusMessage = function () {
  return this.statusMessage[this._state];
}

Ajax.prototype.sendData = function (arrDatas, bolAbort) {
  if(bolAbort)
    this.abort();

  if(this.getStatus() == this.status.busy)
    return false;

  if(typeof(arrDatas) != 'object')
    return this.setStatus(this.status.error) && false;

  this.setStatus(this.status.busy);

  var arr = new Array();
  for(k in arrDatas)
    arr[arr.length] = k + "=" + escape(arrDatas[k]);
  var params = arr.join('&');

  if(this.method == 'GET')
    this.obj.open("GET", this.URL + "?" + params);
  else //POST
    this.obj.open("POST", this.URL);

  var self = this;

  this.obj.onreadystatechange = function() {
    self.onreadystatechange = emptyFunction;
    if (self.obj.readyState == 4) {
      if(self.obj.status == 200) {
        self.result = self.obj.responseText;
        self.setStatus(self.status.free);
      } else {
        self.result = null;
        self.setStatus(self.status.error);
      }
      eval(self.action+"(self);");
    }
  }

  if(this.method == 'GET') {
    this.obj.send(null);
  } else { //POST
    this.obj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    this.obj.send(params);
  }

  return true;
}

function emptyFunction() {
}
