// JScript File
function CreateXmlDoc() {
    var XmlDoc = null;
    var documentCreated = false;
    try {
        if (document.implementation && document.implementation.createDocument) {
            XmlDoc = document.implementation.createDocument("","",null);
        } else if (window.ActiveXObject) {
            XmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        }
    } catch (e) {
        StatusCode = 0x0001;
    }
    
    return XmlDoc;
} 

function CreateXmlHttpRequest() {
    var XmlHttp = null;
    var XmlHttpCreated = false;
    try {
        if (window.XMLHttpRequest) {
            XmlHttp=new XMLHttpRequest() 
        } else if (window.ActiveXObject) {
            try {
                XmlHttp=new ActiveXObject("MSXML2.XMLHTTP.3.0");
            } catch(e2) {
                XmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
        XmlHttpCreated = true;
    } catch(e) {
        alert (e.description);
        StatusCode = 0x0003;
    }  
    return XmlHttp; 
}

function XmlDocument(cmd) {
    var self = this;
    
    cmd = cmd ? cmd : "NoCommand";
    
    var XmlDoc = CreateXmlDoc();
    var root = XmlDoc.createElement("Demonz");
    var request = XmlDoc.createElement("Request");
    var data = XmlDoc.createElement("Data");
    var command = XmlDoc.createElement("Command");
    var timestamp = XmlDoc.createElement("TimeStamp");
    
    var commandText = XmlDoc.createTextNode(cmd);
    var timestampText = XmlDoc.createTextNode((new Date()).toString());
    
    command.appendChild(commandText);
    timestamp.appendChild(timestampText);
    
    XmlDoc.appendChild(root);
    root.appendChild(request);
    root.appendChild(data);
    request.appendChild(command);
    request.appendChild(timestamp);
    
    this.Document = XmlDoc;
    this.Root = root;
    this.Data = data;
    
    this.AddData = function(tagName, tagValue, tagAttributeName, tagAttributeValue) {
        var node = XmlDoc.createElement(tagName);
        
        if (tagAttributeName) {
            tagAttributeValue = tagAttributeValue || "";
            node.setAttribute(tagAttributeName, tagAttributeValue);
        }
        
        node.appendChild(CDataNode(tagValue));
        data.appendChild(node);
        
        return node;
    };
    
    this.ClearData = function() {
        while (this.Data.firstChild) {
            this.Data.removeChild(this.Data.firstChild);
        }            
    };

    function TextNode(text) { return XmlDoc.createTextNode(text); }    
    function CDataNode(text) { 
        if (text==null) { text = ""; }
        return XmlDoc.createCDATASection(text); 
    }    
}


