/*AJAX对象*/
function AJAXObject()//异步xmlhttp通讯
{
}

//创建xmlhttp对象方法
AJAXObject.prototype.CreatXMLHttpObject=function(recontainer,saveto,waitingtext,waitingtextclass,method)//recontainer接受返回值的容器的id，saveto存储返回值的变量名，waitingtext等待时显示的内容，waitingtextclass:容器等待时的样式，method接收文件的格式。
{
    var objXmlHttp=null;
    if(navigator.userAgent.indexOf("Opera")>=0)//浏览器是否是Opera
    {
        alert("Opera浏览器不支持XMLHttp通讯!");
        return;
    }
    if(navigator.userAgent.indexOf("MSIE")>=0)//浏览器是否是ie
    { 
        var strName="Msxml2.XMLHTTP";//浏览器是ie6以上
        if(navigator.appVersion.indexOf("MSIE 5.5")>=0)//浏览器是否是ie5
        {
            strName="Microsoft.XMLHTTP";
        } 
        try
        { 
            objXmlHttp=new ActiveXObject(strName);
            objXmlHttp.onreadystatechange=function(){stateChanged(objXmlHttp,recontainer,saveto,waitingtext,waitingtextclass,method);};//将一个函数作为参数赋给函数
            return objXmlHttp;
        } 
        catch(e)
        {
            alert("创建XMLHttp通讯失败!");
            return;
        } 
    } 
    if(navigator.userAgent.indexOf("Mozilla")>=0)//浏览器是否非ie
    {
        objXmlHttp=new XMLHttpRequest();
        objXmlHttp.onreadystatechange=function(){stateChanged(objXmlHttp,recontainer,saveto,waitingtext,waitingtextclass,method);};
        return objXmlHttp;
    }
}

//xmlhttp状态处理函数，XMLHttp对象会多次单独调用
function stateChanged(xmlhttpobj,recontainer,saveto,waitingtext,waitingtextclass,method)//xmlhttpobj:xmlhttp对象，recontainer:返回值接受容器的id，saveto存储返回值的变量名，waitingtext:等待时的文字，waitingtextclass:容器等待时的样式，method:获取内容的方式。
{
    var objstatue=xmlhttpobj.readyState;//xmlhttp对象当前状态
    if(objstatue==0 || objstatue==1 || objstatue==2 || objstatue==3)//如果状态不为4
    {
        document.getElementById(recontainer).innerHTML=waitingtext;//显示等待时的内容
        document.getElementById(recontainer).className=waitingtextclass;//等待样式
    }
    else if(objstatue==4 || objstatue=="complete")//如果状态为4
    { 
        switch(method)
        {
            case "text":
            document.getElementById(recontainer).innerHTML=xmlhttpobj.responseText;
            document.getElementById(recontainer).className="";
            contextsave(saveto);
            break;
            case "xml":
            var xmlDom=new ActiveXObject("MSXML2.DOMDocument");
            xmlDom.loadXML(xmlhttpobj.responseText);
            var root=xmlDom.selectSingleNode("//options");
            var optionnodes=root.childNodes;
            for(var i=0;i<optionnodes.length;i++)
            {
                var newOption = document.createElement("OPTION"); 
                newOption.text=optionnodes[i].text;
                newOption.value=optionnodes[i].attributes[0].value;
                document.getElementById(recontainer).options.add(newOption);
            }
            break;
            case "stream":
            break;
            default:
            document.getElementById(recontainer).innerHTML="";
            document.getElementById(recontainer).className="";
            break;
        }
    } 
}
/*AJAX对象*/