// Обертка для Аякса
function XS2AJAX () { this._construct(); }

(function() {

  XS2AJAX.prototype = {

    onreadystatechange: null,
    responseJS: null,
    jshttprequest: null,
    caching: false,
    loader: null,
    method: "POST",

    _construct: function() {
      this.jshttprequest = new JsHttpRequest();
    },

    send: function(param,url) {
      var th = this;
      var req = this.jshttprequest;

      if (param.elements) {
          param = {"form":param};
      }

      req.onreadystatechange = function() {
        if(4==req.readyState && "undefined"!=typeof(req.responseJS)) {
          th.responseText = req.responseText;
          th.responseJS = req.responseJS;
          th.onready();
        }
      };

      req.caching = this.caching;
      if (this.loader!=null) {
        req.loader = this.loader;
      }
      req.open(this.method, url, true);
      req.send(param);
    },

    sendForm: function(f,url) {
      if (f.elements) {
        var param = new Object();
        for (var i=0; i<f.elements.length; i++) {
          param[f.elements[i].name] = f.elements[i].value;
        }
        this.send(param,url);
      }
    }

  };

})();
