function ajax()
{
var oAjax = this;
this.req = 'qwe';

var READY_STATE_UNINITIALIZED=0;
var READY_STATE_LOADING=1;
var READY_STATE_LOADED=2;
var READY_STATE_INTERACTIVE=3;
var READY_STATE_COMPLETE=4;

this.onReadyStateLoading;
this.onReadyStateInteractive;
this.onReadyStateLoaded;
this.onReadyStateComplete;

this.setReadyState = function setReadyState (on_loading, on_loaded, on_interactive, on_complete) {
    this.onReadyStateLoading = on_loading ? on_loading : null;
    this.onReadyStateLoaded = on_loaded ? on_loaded : null;
    this.onReadyStateInteractive = on_interactive ? on_interactive : null;
    this.onReadyStateComplete = on_complete ? on_complete : null;
}

this.sendRequest = function sendRequest (func, url, params, method, contentType, async ) {
    if (!method) {
        method = 'GET';
    }
    if (!contentType && method=="POST"){
        contentType='application/x-www-form-urlencoded';
    }
    if (!async)
    {
    	async = false;
    }
    this.req = this.initXMLHTTPRequest();
    if (this.req != null) {
        if (!(/:\/\//.test(url)))
        {
        	url = 'http://' + location.host + url;
        }
        url += (url.indexOf('?') != -1 ? '&' : '?') + 'rand=' + Math.round(Math.random()*1000);
        this.req.open(method, url, async);
        this.req.onreadystatechange = func ? func : this.onLoadState;
        this.req.setRequestHeader("Accept-Language", "ru, en");
        this.req.setRequestHeader("Accept-Charset", "windows-1251");
        if(contentType)
                this.req.setRequestHeader('Content-Type', contentType);
        this.req.send(params);
        return this.req;
    }
    return false;
}

this.initXMLHTTPRequest = function initXMLHTTPRequest () {
    var xReq = null;
    if (window.XMLHttpRequest){
        xReq = new XMLHttpRequest();
    } else if (window.ActiveXObject){
      try {
        xReq = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
        try {
          xReq = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
          xReq = null;
        }
      }
    }
    return xReq;
}

this.onLoadState = function onLoadState() {
    if (oAjax.req == null)
    {
        return false;
    }
    var ready = oAjax.req.readyState;
    var data = null;
    if( ready == READY_STATE_LOADING ) {
        if(oAjax.onReadyStateLoading)
            oAjax.onReadyStateLoading(oAjax.req);
    } else if ( ready == READY_STATE_LOADED ) {
        if(oAjax.onReadyStateLoaded)
            oAjax.onReadyStateLoaded(oAjax.req);
    } else if ( ready == READY_STATE_INTERACTIVE ) {
        if(oAjax.onReadyStateInteractive)
            oAjax.onReadyStateInteractive(oAjax.req);
    } else if ( ready == READY_STATE_COMPLETE ) {
        if(oAjax.onReadyStateComplete)
            oAjax.onReadyStateComplete(oAjax.req);
    }
}
}
