Ajax = function(id)
{
  this.id = id;
  this.rq = null;
  this.onresponce = null;
  this.ts = null;
  this.params = new Array();

  this.init = function()
  {
    var XMLHTTPtype = new Array(
      'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0',
      'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP',
      'Microsoft.XMLHTTP'); // divl
    if (window.XMLHttpRequest)
    {
      try { this.rq = new XMLHttpRequest(); } catch (e) {};
    }
    else if (window.ActiveXObject)
    {
      var i = 0;
      while ((i < XMLHTTPtype.length) && (this.rq == null))
      {
        try { this.rq = new ActiveXObject(XMLHTTPtype[i]); } catch (e) {};
        i++;
      }
    }
  }

  this.sendraw = function(method, url, data, func)
  {
    if (!this.rq) this.init();
    if (!this.rq) return;
  
    this.rq.onreadystatechange = (func)?func:function() {;}
    if ((method == "GET") && (data)) { url+='?'+data; data = null; }
    this.rq.open(method, url, true);
    if (method == "POST") this.rq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    this.rq.send(data);
  }

  this.send = function(method, url, data, func)
  {
    var d = new Date();
    this.ts = this.id+d.getTime();
    var d = 'aid='+this.ts;
    if (data) d+='&'+data;
    this.sendraw(method, url, d, func);
  }

  this.verify_responce = function()
  {
    if (!this.rq) return 0;
    if ((this.rq.readyState == 4) && (typeof(this.rq.responseText)!="unknown"))
    {
      var rt = this.rq.responseText; 
      if (!rt) return 0;
      if (this.ts)
      {
        var i = rt.indexOf(this.ts);
        if (i > 0) rt = rt.substr(i-1);
      }
      this.params = rt.split(rt.charAt(0));
      this.params.shift();
      if (this.params[0] != this.ts) return 0;
      this.params.shift();
      return 1;
    }
    return 0;
  }

  this.init();
}
