// JScript 文件(Ajax)通过传递参数回调服务器
/*
    XmlHttpRequest 属性

    readyState:0 未初始化 1 正在加载 2 已加载 3 交互中 4 完成
    reponseText 服务器的响应，字符串
    reponseXML 服务器的响应，XML 该对象可以解析为一个DOM对象
    status 服务器返回的HTTP状态码
    statusText HTTP状态码相映的文本

    
    方法
    abort() 停止当前请求
    getAllRequestHeaders() 将HTTP请求的所有响应首部作为键/值对返回
    getResponseHeader("headerLabel") 返回指定的首部字符串
    open("method","URL"[,asyncFlag[,"userName"[,"password"]]])
    send(content) 向服务器发送请求

    setRequestHeader("label","value") 把指定首部设置为所提供的值，在调用该方法之前必须小调用open方法
*/

function CallBackObject()
{
    this.XmlHttp = this.GetHttpObject();
}

//返回XmlHttp字符串

CallBackObject.prototype.GetHttpObject = function ()
{
    var xmlhttp;
    /*@cc_on
    @if(@_jscript_version >= 5)
    try
    {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(ce)
        {
            xmlhttp = false;
        }
    }
    @else
    {
        xmlhttp = false;
    }
    @end @*/
    
    if(!xmlhttp && typeof XMLHttpRequest != 'undefined')
    {
        try
        {
            xmlhttp = new XMLHttpRequest();
        }
        catch(e)
        {
            xmlhttp = false;
        }
    }
    return xmlhttp;
}

//执行回调操作
CallBackObject.prototype.DoCallBack = function (URL)
{  
    if(this.XmlHttp)
    {
        if(this.XmlHttp.readyState == 4 || this.XmlHttp.readyState == 0)
        {
            var oThis = this;
            this.XmlHttp.open("POST",URL);
            this.XmlHttp.onreadystatechange = function ()
            {
                oThis.ReadyStateChange();
            }
            this.XmlHttp.send(null);
        }
    }
}

CallBackObject.prototype.AbortCallBack = function()
{
    if(this.XmlHttp)
    {
        this.XmlHttp.abort();
    }
}

CallBackObject.prototype.OnLoading = function()
{

}

CallBackObject.prototype.OnLoaded = function()
{

}

CallBackObject.prototype.OnInteractive = function()
{

}

CallBackObject.prototype.OnComplete = function(reponseText,responseXml)
{

}

CallBackObject.prototype.OnAbort = function()
{
    
}

CallBackObject.prototype.OnError = function(status,statusText)
{

}

CallBackObject.prototype.ReadyStateChange = function()
{
    if(this.XmlHttp.readyState == 1)
    {
        this.OnLoading();
    }
    else if(this.XmlHttp.readyState == 2)
    {
        this.OnLoaded();
    }
    else if(this.XmlHttp.readyState == 3)
    {
        this.OnInteractive();
    }
    else if(this.XmlHttp.readyState == 4)
    {
        if(this.XmlHttp.readyState == 0)
        {
            this.OnAbort();        
        }
        else if(this.XmlHttp.status == 200 && this.XmlHttp.statusText == "OK")
        {
            this.OnComplete(this.XmlHttp.responseText,this.XmlHttp.reponseXML);
        }
        else 
        {
            this.OnError(this.XmlHttp.status,this.XmlHttp.statusText,this.XmlHttp.responseText);
        }
    }
}