var Ajax = function(){};

//取得组件
Ajax.prototype.GetHttpRequest = function()
{
    if (window.XMLHttpRequest)
    {
        return new XMLHttpRequest() ;
    }
    else if (window.ActiveXObject)
    {
        return new ActiveXObject("Microsoft.XMLHTTP") ;
    }
}
//提交数据
Ajax.prototype.PostURL = function(URL, PostData, FunctionName) {
    var TempAjax = this;
    var IsFunction = (typeof (FunctionName) == 'function');
    var TempXmlHttp = this.GetHttpRequest();
    if (URL.indexOf("?") > -1) {
        URL += "&t=" + new Date();
    }
    else {
        URL += "?t=" + new Date();
    }
    TempXmlHttp.open("POST", URL, IsFunction);
    if (IsFunction) {
        TempXmlHttp.onreadystatechange = function() {
            if (TempXmlHttp.readyState == 4) {
                var Result = TempXmlHttp.responseText;
                TempAjax.DOMDocument = TempXmlHttp.responseXML;
                FunctionName(Result);
            }
        }
    }
    if (this.debug == 1) {
        alert("Error");
    }
    TempXmlHttp.setRequestHeader("CONTENT-TYPE", "application/x-www-form-urlencoded");
    TempXmlHttp.send(PostData);
    if (!IsFunction) {
        this.DOMDocument = TempXmlHttp.responseXML;
    }
}
//请求数据
Ajax.prototype.RequestURL = function(URL, FunctionName) {
    var TempAjax = this;
    var IsFunction = (typeof (FunctionName) == 'function');
    var TempXmlHttp = this.GetHttpRequest();
    if (URL.indexOf("?") > -1) {
        URL += "&t=" + new Date();
    }
    else {
        URL += "?t=" + new Date();
    }
    TempXmlHttp.open("GET", URL, IsFunction);
    if (IsFunction) {
        TempXmlHttp.onreadystatechange = function() {
            if (TempXmlHttp.readyState == 4) {
                var Result = TempXmlHttp.responseText;
                TempAjax.DOMDocument = TempXmlHttp.responseXML;
                FunctionName(Result);
            }
        }
    }
    TempXmlHttp.send(null);
    if (!IsFunction) {
        this.DOMDocument = TempXmlHttp.responseXML;
    }
}
//读取XML节
Ajax.prototype.SelectNodes = function(Xpath)
{
    if (document.all)
    {
        return this.DOMDocument.selectNodes(Xpath) ;
    }
    else
    {
        var NodeArray = new Array();
        var PathResult = this.DOMDocument.evaluate(Xpath,this.DOMDocument,this.DOMDocument.createNSResolver(this.DOMDocument.documentElement),XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
        if (PathResult) 
        {
            var TempNode = PathResult.iterateNext() ;
            while(TempNode)
            {
                NodeArray[NodeArray.length] = TempNode ;
                TempNode = PathResult.iterateNext();
            }
        } 
        return NodeArray;
    }
}
//读取单个XML字内容
Ajax.prototype.SelectSingleNode = function(Xpath) 
{
    if (document.all)
    {
        return this.DOMDocument.selectSingleNode(Xpath);
    }
    else
    {
        var PathResult = this.DOMDocument.evaluate(Xpath,this.DOMDocument,this.DOMDocument.createNSResolver(this.DOMDocument.documentElement),9,null);
        if (PathResult && PathResult.singleNodeValue )
        {
            return PathResult.singleNodeValue;
        }
        else
        {
            return null ;
        }
    }
}