var Br = new BrCheck()

function BrCheck() {
    this.VER = navigator.appVersion;
    this.AGENT = navigator.userAgent.replace(/[\/]/g, ' ');
    this.DOM = document.getElementById ? true : false;

    this.OP5 = this.AGENT.indexOf("Opera 5") > -1 ? true : false;
    this.OP6 = this.AGENT.indexOf("Opera 6") > -1 ? true : false;
    this.OP7 = this.AGENT.indexOf("Opera 7") > -1 ? true : false;
    this.OP8 = this.AGENT.indexOf("Opera 8") > -1 ? true : false;
    this.OP = (this.OP5 || this.OP6 || this.OP7 || this.OP8);

    this.IE4 = (document.all && !this.DOM && !this.OP) ? true : false;
    this.IE5 = (this.VER.indexOf("MSIE 5") > -1 && this.DOM && !this.OP) ? true : false;
    this.IE6 = (this.VER.indexOf("MSIE 6") > -1 && this.DOM && !this.OP) ? true : false;
    this.IE7 = (this.VER.indexOf("MSIE 7") > -1 && this.DOM && !this.OP) ? true : false;
    this.IE8 = (this.VER.indexOf("MSIE 8") > -1 && this.DOM && !this.OP) ? true : false;
    this.IE = (this.IE4 || this.IE5 || this.IE6 || this.IE7 || this.IE8);

    this.NS4 = (document.layers && !this.DOM) ? true : false;
    this.NS7 = (this.DOM && parseInt(this.VER) >= 5 && this.AGENT.lastIndexOf('Netscape') < this.AGENT.lastIndexOf('7')) ? true : false;
    this.NS6 = (this.DOM && parseInt(this.VER) >= 5 && !this.NS7) ? true : false;
    this.NS = (this.NS4 || this.NS6 || this.NS7);

    return this;
}

function Ajax(url, method, cbf) {
    this.ajax = this; this.act = false; this.xml = null; this.cbf = cbf; this.url = url; this.method = method;
    this.init();
}
Ajax.prototype.init = function() {
    this.xml = (window.XMLHttpRequest ? new XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : null));
    if (!this.xml) { this.act = false; }
    else { this.act = true; }
    this.encFunc = encodeURIComponent ? encodeURIComponent : escape;
}
Ajax.prototype.sendRQ = function(parameters) {
    if (!this.act) { return; }
    if (this.xml.readyState != 0) { this.xml.abort(); }

    if (Br.IE) { this.xml.onreadystatechange = function() { ajax.handleResponse(ajax); } }
    else { this.xml.onload = function() { ajax.handleResponse(ajax); } }

    var sParams = this.ParseParams(parameters);

    if (this.method.toUpperCase() == "GET") { this.xml.open("GET", this.url + "?" + sParams); this.xml.send(null); }
    else { this.xml.open("POST", this.url); this.xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); this.xml.setRequestHeader("Content-length", sParams.length); this.xml.send(sParams); }
}

Ajax.prototype.ParseParams = function(parameters) {
    var sParams = '';
    for (var i = 0; i < parameters.length; i++) {
        sParams += (sParams.length > 0 ? "&" : "") + parameters[i][0] + "=" + this.encFunc(parameters[i][1]);
    }
    return sParams;
}
Ajax.prototype.send = function(parameters) {
    if (!this.act) { return; }
    if (this.xml.readyState != 0) { this.xml.abort(); }

    if (Br.IE) { this.xml.onreadystatechange = function() { ajax.handleResponse(ajax); } }
    else { this.xml.onload = function() { ajax.handleResponse(ajax); } }

    if (this.method.toUpperCase() == "GET") {
        this.xml.open("GET", this.url + "?" + parameters);
        this.xml.send(null);
    } else {
        this.xml.open("POST", this.url);
        this.xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        this.xml.setRequestHeader("Content-length", sParams.length);
        this.xml.send(parameters);
    }
}
Ajax.prototype.handleResponse = function(ajax) {
    switch (ajax.xml.readyState) {
        case 0:
            break;
        case 1:
            break;
        case 2:
            break;
        case 3:
            break;
        case 4:
            if (ajax.xml.status == 200) {
                if (typeof (ajax.cbf) == 'function') {
                    ajax.cbf(ajax.xml.responseText)
                }
            } else {
                ajax.cbf('WriteMessage(\'' + ajax.xml.responseText + '\');');
            }
    }
}


