﻿/******************************************************
        XmlDoc类
******************************************************/
    function XmlDoc()
    {
        this.doc;
        this.isIE;
        this.onreadystatechange;
        if(typeof(ActiveXObject) != "undefined")
        {
            var e;
            try
            {
                this.doc = new ActiveXObject("Msxml2.DOMDocument");
            }
            catch(e)
            {
                try
                {
                    this.doc = new ActiveXObject("Msxml.DOMDocument");
                }
                catch(e){}
            }
            isIE = true;
        }
        else
            isIE = false;
    }
    
    XmlDoc.prototype=
    {
        loadXml:function(xmlString)
        {
            if(isIE)
            {
                var docObject = this;
                this.doc.onreadystatechange = function(){docObject.loadXmlComplete()};
                this.doc.loadXML(xmlString);
            }
            else
            {
                Element.prototype.__defineGetter__("text",function(){if(this.firstChild == null)return ""; return this.firstChild.nodeValue;})
                var parser = new DOMParser();
                this.doc = parser.parseFromString(xmlString,"text/xml");
                this.returnDoc();
                delete parser;
                this.parser = null;
            }
        },
        
        loadXmlComplete: function()
        {
            if(this.doc.readyState == 4)
                this.returnDoc();
        },
        
        returnDoc:function()
        {
            if(typeof(this.onreadystatechange) == "function")
            {
                this.onreadystatechange(this.doc);
                delete this.doc;
                this.doc = null;    
            }
        }

    }

/************************************************
    XmlRequest类
**************************************************/
    function XmlRequest()
    {
        this.request;
        this.action;
        this.returnContent;
        this.onCallbackComplete;
        var e;
        try
        {
            this.request = new XMLHttpRequest();
        }
        catch(e)
        {
            try
            {
                this.request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e){}
        }   
    }
 
    XmlRequest.prototype={
        send : function(data)
        {
            var thisObject = this;
            this.request.onreadystatechange = function(){thisObject.getData();};
            this.request.open("post",this.action==""?document.forms[0].action:this.action,true);
            this.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            this.request.send(data == null?"":data);
        },
        
        getData : function()
        {
            if(this.request.readyState == 4)
            {
                this.returnContent = this.request.responseText;
                if(typeof(this.onCallbackComplete) == "function")
                {
                    this.onCallbackComplete(this.returnContent);
                    delete this.request;
                    this.request = null;
                }
            }
        }
    }
 /***********************************************/
	function requestPage(url,callfunction,sendData)
	{
		var xmlRequest = new XmlRequest();
		xmlRequest.action = url;
		//xmlRequest.onCallbackComplete = function(callbackContent){callbackComplete(callbackContent,callfunction);};
		xmlRequest.onCallbackComplete = callfunction;
		xmlRequest.send(sendData);
	}
	
	function requestDom(url,callfunction,sendData)
	{
		requestPage(url,function(callbackContent){callbackComplete(callbackContent,callfunction);},sendData);
	}

	function callbackComplete(callbackContent,docOnReadyFunction)
	{
		var doc = new XmlDoc();
		doc.onreadystatechange = docOnReadyFunction;
		doc.loadXml(callbackContent);
    } 