/**
 * Subsys_JsHttpRequest_Js
 * (C) 2005 Dmitry Koterov
 * @version 3.22
 */
function Subsys_JsHttpRequest_Js() { this._construct() }
(function() { 
var COUNT       = 0;
var PENDING     = {};
var CACHE       = {};
Subsys_JsHttpRequest_Js.dataReady = function(id, text, js) {
    var undef;
    var th = PENDING[id];
    delete PENDING[id];
    if (th) {
        delete th._xmlReq;
        if (th.caching) CACHE[th.hash] = [text, js];
        th._dataReady(text, js);
    } else if (typeof(th) != typeof(undef)) {
        alert("ScriptLoader: unknown pending id: "+id);
    }
}

Subsys_JsHttpRequest_Js.prototype = {
    onreadystatechange: null,
    readyState:         0,
    responseText:       null,
    responseXML:        null,
    status:             200,
    statusText:         'OK',
    session_name:       'vysh_6xrxj',
    responseJS:         null,
    caching:            false,
    _span:              null,
    _id:                null,
    _xmlReq:            null,
    _openArg:           null,
    _reqHeaders:        null,
    abort: function() {
        if (this._xmlReq) return this._xmlReq.abort();
        if (this._span) {
            this.readyState = 0;
            if (this.onreadystatechange) this.onreadystatechange();
            this._cleanupScript();
        }
    },
    open: function(method, url, asyncFlag, username, password) {
        this._openArg = {
            'method':    method,
            'url':       url,
            'asyncFlag': asyncFlag,
            'username':  username,
            'password':  password
        };
        this._id = null;
        this._xmlReq = null;
        this._reqHeaders = [];
        return true;
    },
    send: function(content) {
        var id = (new Date().getTime()) + "" + COUNT++;
        var query = this._hash2query(content);
        var url = this._openArg.url;
        var sid = this._getSid();
        if (sid) url += (url.indexOf('?')>=0? '&' : '?') + this.session_name + "=" + escape(sid);
        var hash = this.hash = url + '?' + query;
        if (this.caching && CACHE[hash]) {
            var c = CACHE[hash];
            this._dataReady(c[0], c[1]);
            return false;
        }
        this._xmlReq = this._obtainXmlReq(id, url);
        var hasSetHeader = this._xmlReq && (window.ActiveXObject || this._xmlReq.setRequestHeader); 
        var href, body;
        if (this._xmlReq && hasSetHeader && (""+this._openArg.method).toUpperCase() == "POST") {
            this._openArg.method = "POST";
            href = url;
            body = query;
        } else {
            this._openArg.method = "GET";
            href = url + (url.indexOf('?')>=0? '&' : '?') + query;
            body = null;
        }
        href = href + (href.indexOf('?')>=0? '&' : '?') + id;
        PENDING[id] = this;

        if (this._xmlReq) {
            var a = this._openArg;
            this._xmlReq.open(a.method, href+"&", a.asyncFlag, a.username, a.password);
            if (hasSetHeader) {
                for (var i=0; i<this._reqHeaders.length; i++)
                    this._xmlReq.setRequestHeader(this._reqHeaders[i][0], this._reqHeaders[i][1]);
                this._xmlReq.setRequestHeader('Content-Type', 'application/octet-stream');
            }
            return this._xmlReq.send(body);
        } else {
            this._obtainScript(id, href);
            return true;
        }
    },
    getAllResponseHeaders: function() {
        if (this._xmlReq) return this._xmlReq.getAllResponseHeaders();
        return '';
    },
    getResponseHeader: function(label) {
        if (this._xmlReq) return this._xmlReq.getResponseHeader(label);
        return '';
    },
    setRequestHeader: function(label, value) {
        this._reqHeaders[this._reqHeaders.length] = [label, value];
    },
    _construct: function() {},
    _dataReady: function(text, js) { with (this) {
        if (text !== null || js !== null) {
            readyState = 4;
            responseText = responseXML = text;
            responseJS = js;
        } else {
            readyState = 0;
            responseText = responseXML = responseJS = null;
        }
        if (onreadystatechange) onreadystatechange();
        _cleanupScript();
    }},
    _obtainXmlReq: function(id, url) {
        if (url.match(new RegExp('^[a-z]+://', 'i'))) return null;
        var req = null;
        if (window.XMLHttpRequest) {
            try { req = new XMLHttpRequest() } catch(e) {}
        } else if (window.ActiveXObject) {
            try { req = new ActiveXObject("Microsoft.XMLHTTP") } catch(e) {}
            if (!req) try { req = new ActiveXObject("Msxml2.XMLHTTP") } catch (e) {}
        }
        if (req) {
            var th = this;
            req.onreadystatechange = function() { 
                if (req.readyState == 4) {
                    // Call associated dataReady().
                    eval(req.responseText);
                } else {
                    th.readyState = req.readyState;
                    if (th.onreadystatechange) th.onreadystatechange() 
                }
            };
            this._id = id;
        }
        return req;
    },
    _obtainScript: function(id, href) { with (document) {
        var span = null;
        span = body.appendChild(createElement("SPAN"));
        span.style.display = 'none';
        span.innerHTML = 'Text for IE.<s'+'cript></' + 'script>';
        setTimeout(function() {
            var s = span.getElementsByTagName("script")[0];
            s.language = "JavaScript";
            if (s.setAttribute) s.setAttribute('src', href); else s.src = href;
        }, 10);
        this._id = id;
        this._span = span;
    }},

    _cleanupScript: function() {
        var span = this._span;
        if (span) {
            this._span = null;
            setTimeout(function() {
                // without setTimeout - crash in IE 5.0!
                span.parentNode.removeChild(span);
            }, 50);
        }
        return false;
    },
    _hash2query: function(content, prefix) {
        if (prefix == null) prefix = "";
        var query = [];
        if (content instanceof Object) {
            for (var k in content) {
                var curPrefix = prefix? prefix+'['+escape(k)+']' : escape(k);
                if (content[k] instanceof Object)
                    query[query.length] = this._hash2query(content[k], curPrefix);
                else
                    query[query.length] = curPrefix + "=" + escape(content[k]);
            }
        } else {
            query = [content];
        }
        return query.join('&');
    },
    _getSid: function() {
        var m = document.location.search.match(new RegExp('[&?]'+this.session_name+'=([^&?]*)'));
        var sid = null;
        if (m) {
            sid = m[1];
        } else {
            var m = document.cookie.match(new RegExp(s='(;|^)\\s*'+this.session_name+'=([^;]*)'));
            if (m) sid = m[2];
        }
        return sid;
    }
}
})();

