if (typeof (EIS) == 'undefined') EIS = {};
EIS.LoadXml = function(url, params, method, contentType, async) {

//    var _this = this;
    
    this._req = null;
    this._method = (method) ? method : "POST";
    this._url = (url) ? url : "Proxy.ashx";
    this._contentType = (contentType) ? contentType : "application/x-www-form-urlencoded";
    this._params = (params) ? params : null;
    this._async = (async == null || async) ? true : false;    
    
    this.Callback = null;

    this.initilize();
    
};

EIS.LoadXml.prototype = {
    initilize: function() {
        if (window.XMLHttpRequest) {
            this._req = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            //this._req = new ActiveXObject("Msxml2.DOMDocument.4.0");
            // Use below for IE6 compatibility
            this._req = new ActiveXObject("Microsoft.XMLHTTP");
        }
        this.loading();
        this._req.open(this._method, this._url, this._async);
        this._req.setRequestHeader("Content-Type", this._contentType);
    },

    loading: function() {
        var loading = document.createElement("div");
        loading.id = "Loading";
        loading.style.position = "absolute";
        loading.style.top = "0px";
        loading.style.right = "0px";
        loading.style.padding = "2px";
        loading.style.backgroundColor = "red";
        loading.style.color = "white";
    },

    getRequest: function() {
        return this._req;
    },

    getXmlResponse: function() {
        //alert("getXmlResponse execution");
        return this._req.responseXML;
    },

    getTextResponse: function() {
        return this._req.responseText;
    },

    getResponseStatus: function() {
        return this._req.status;
    },

    getResponseStatusText: function() {
        return this._req.statusText;
    },

    getAllResponseHeaders: function() {
        return this._req.getAllResponseHeaders();
    },

    load: function() {
        if (this.Callback && this._async) {
            var loader = this;
            this._req.onreadystatechange = function() { LoadXml.onReadyState.call(loader); }

            this._req.send(this._params);
            return true;    // dummy for consistency
        }
        else {
            this._req.send(this._params);
            return;
        }

    },

    toString: function() {
        return this._method + "\n" + this._url + "\n" + this._async;
    }
};
    

EIS.LoadXml.onReadyState = function()
    {
        var req = this.getRequest();
        var ready = req.readyState;
        alert(ready);
        var loading = document.getElementById("Loading");
        
        if (ready == 4) {
            var httpStatus = req.status;
            //if (status==200 || httpStatus==0){        
                 
            //var resFilter = (parent.responseFilter) ? parent.responseFilter : responseFilter;
            //var xml = this.getXmlResponse();
            //var isOk = resFilter.processResponse(xml);
                
            //if (!this.filterResponse())
            //    return;

            if (loading)
                document.body.removeChild(loading);
            
            this.Callback.call(this, httpStatus);
            
            /*if (httpStatus == 200 || httpStatus == 0) {
                this.Callback.call(this, status);
            } else {
                this.Callback.call(this, status);
            }*/
        }
        else
        {
            if (!loading)
            {
                loading = document.createElement("div");
                loading.id = "Loading";
                loading.style.position = "absolute";
                loading.style.top = document.documentElement.scrollTop + "px";
                loading.style.right = "0px";
                loading.style.padding = "2px";
                loading.style.backgroundColor = "red";
                loading.style.color = "white";
                loading.style.fontSize = "12px";
                loading.style.fontWeight = "bold";
                loading.innerHTML = "Loading...";
                
                document.body.appendChild(loading);
            }
        }
    };

