var ajax = new Object();
ajax.sendRequest = function(url,onload,onerror,method,params,contentType) {
   this.url = url;
   this.req = null;
   this.onload = onload;
   this.onerror = onerror ? onerror : this.defaultError;
   this.loadXML(url,method,params,contentType);
}
ajax.sendRequest.prototype = {
   
   loadXML: function(url,method,params,contentType) {
      if (!method) {
         method = "GET";
      }
      if (!contentType && method == "POST") {
         contentType = "application/x-www-form-urlencoded";
      }
      if (window.XMLHttpRequest) {
         this.req = new XMLHttpRequest();
      } else if (window.ActiveXObject) {
         this.req = new ActiveXObject("Microsoft.XMLHTTP");
      }
      if (this.req) {
         try {
            var loader = this;
            this.req.onreadystatechange = function() { loader.onReadyState.call(loader); }
            this.req.open(method,url,true);
            this.req.setRequestHeader("Cache-Control", "no-cache");
            if (contentType) {
               this.req.setRequestHeader("Content-Type", contentType);
            }
            this.req.send(params);
         } catch (err) {
            this.onerror.call(this);
         }
      }
   },
   
   onReadyState: function() {
      if (this.req.readyState == 4) {
         if (this.req.status == 200 || this.req.status == 0) {
            this.onload.call(this);
         } else {
            this.onerror.call(this);
         }
      }
   },
   
   defaultError: function() {
      debug("ERROR:<br />readyState: "+this.req.readyState+"<br />status: "+this.req.status+"<br />headers: "+this.req.getAllResponseHeaders());
   }
}
