// JavaScript Document
function ajaxObject() {
    //private variables
    var _XmlHttpRequest = null;
    var _This = null;
    var isLoading = false;
   
    //public properties
    this.GetResponseXML = function() {
        return (_XmlHttpRequest) ? _XmlHttpRequest.responseXML : null;
    }
   
    this.GetResponseText = function() {
        return (_XmlHttpRequest) ? _XmlHttpRequest.responseText : null;
    }
   
    this.GetXMLHttpRequestObj = function() {
        return _XmlHttpRequest;
    }
   
    //public methods
    this.InitXmlHttpRequest = function(Method, CallUri, GetHaveCach) {
        _InitXmlHttpRequest();
        _This = this;
        if (GetHaveCach != "haveCache")
        {
            var sep = (-1 < CallUri.indexOf("?")) ? "&" : "?"
            //CallUri = CallUri + sep + "__=" + encodeURIComponent((new Date()).getTime());
            CallUri = CallUri + "&__=" + encodeURIComponent((new Date()).getTime());
            //alert(CallUri.length);
        }
        switch( arguments.length ) {
            case 2:
                _XmlHttpRequest.open(Method, CallUri);   
                break;
            case 3:
                _XmlHttpRequest.open(Method, CallUri, arguments[2]);
                break;
        }
       if (Method=='POST') {_XmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');}
        if( arguments.length >= 4) {
            _XmlHttpRequest.open(Method, CallUri, arguments[2], arguments[3]);
        }
    }
   
    this.Commit = function(Data) {
        if( _XmlHttpRequest ) {
            _XmlHttpRequest.send(Data);
        }
    }
   
    this.Close    = function() {
        if( _XmlHttpRequest ) {
            _XmlHttpRequest.abort();
        }
    }
   
    //public events
    this.OnUninit         = function() {};
    this.OnLoading         = function() {};
    this.OnLoaded         = function() {};
    this.OnInteractive     = function() {};
    this.OnSuccess        = function() {};
    this.OnFailure         = function() {};
   
    //private events
    function _OnUninit()         { _This.OnUninit(); };
    function _OnLoading()         {_This.OnLoading(); };
    function _OnLoaded()         { _This.OnLoaded(); };
    function _OnInteractive()     { _This.OnInteractive(); };
    function _OnSuccess()         { _This.OnSuccess();isLoading=false;};
    function _OnFailure()         { _This.OnFailure();isLoading=false;};
   
    //private methods
    function _InitXmlHttpRequest() {
        _XmlHttpRequest = _GetXmlHttpRequest();
        _XmlHttpRequest.onreadystatechange = _StateHandler;
    }
   
    function _StateHandler() {
        switch(_XmlHttpRequest.readyState) {
            case 0:
                window.setTimeout("void(0)", 100);
                _OnUninit();
                break;
            case 1:
                window.setTimeout("void(0)", 100);
                if (!(isLoading)){_OnLoading();isLoading=true;}
                break;
            case 2:
                window.setTimeout("void(0)", 100);
                _OnLoaded();
                break;
            case 3:
                window.setTimeout("void(0)", 100);
                _OnInteractive();
                break;
            case 4:
                if (_XmlHttpRequest.status == 200) {
                    _OnSuccess();
                } else {
                    _OnFailure();
                }
                return;
                break;
        }
    }
   
    function _GetXmlHttpRequest() {
        var requester
        try {
            requester = new XMLHttpRequest();
        } catch (error) {
            try {
                requester = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (error) {
                return null;
            }
        }
        return requester;
    }
}