﻿function $(id) {
    return document.getElementById(id)
}
var isIE = (document.all) ? true: false;
function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        try {
            return new ActiveXObject("MSXML2.XMLHTTP.3.0")
        } catch(e) {}
    } else {
        try {
            return new XMLHttpRequest()
        } catch(e) {}
    }
    alert("XMLHTTP对象创建失败！")
}
function genSOAP(method, nameSpace, strAttributes) {
    var soapMessage;
    soapMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
    soapMessage += "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">";
    soapMessage += "<soap:Body>";
    soapMessage += "<" + method + " xmlns=\"" + nameSpace + "\">";
    soapMessage += strAttributes;
    soapMessage += "</" + method + ">";
    soapMessage += "</soap:Body>";
    soapMessage += "</soap:Envelope>";
    return soapMessage
}
function resolveXML(xml_str) {
    this.text = "";
    this.obj_xml = null;
    this.is_ie = true;
    this.createXmlObj = function() {
        if (window.ActiveXObject) {
            this.is_ie = true;
            var arr_signatures = ["MSXML2.DOMDocument.3.0"];
            for (var i = 0; i < arr_signatures.length; i++) {
                try {
                    this.obj_xml = new ActiveXObject(arr_signatures[i]);
                    return
                } catch(e) {}
            }
            alert("常见XML DOM对象失败！")
        } else if (document.implementation && document.implementation.createDocument) {
            this.is_ie = false;
            try {
                this.obj_xml = document.implementation.createDocument("", "", null);
                Document.prototype.loadXML = function(xml_str) {
                    var xml_parser = new DOMParser();
                    var xml_obj = xml_parser.parseFromString(xml_str, "text/xml");
                    while (this.firstChild) {
                        this.removeChild(this.firstChild)
                    }
                    for (var i = 0; i < xml_obj.childNodes.length; i++) {
                        var temp_node = this.importNode(xml_obj.childNodes[i], true);
                        this.appendChild(temp_node)
                    }
                }
                return
            } catch(e) {}
        } else {
            alert("常见XML DOM对象失败！")
        }
    }
    this.loadFromText = function(strXMLtext) {
        this.text = strXMLtext;
        this.obj_xml.loadXML(strXMLtext)
    }
    this.getRootValue = function() {
        var xml_node;
        xml_node = this.obj_xml.documentElement.firstChild.firstChild;
        return this.getNodeValue(xml_node)
    }
    this.getSingleValue = function(nodeName) {
        var xmlNode;
        xmlNode = this.obj_xml.getElementsByTagName(nodeName);
        return xmlNode[0].childNodes[0].nodeValue
    }
    this.getKeyValue = function(node_name) {
        try {
            var arr = [];
            var node = this.obj_xml.getElementsByTagName(node_name);
            if (node) {
                for (var i = 0; i < node.length; i++) {
                    arr.push([this.getNodeValue(node[i].firstChild), this.getNodeValue(node[i].lastChild)])
                }
            }
        } catch(e) {} finally {
            return arr;
            arr = null;
            node = null
        }
    }
    this.getListValue = function(node_name) {
        try {
            var arr = [];
            var node = this.obj_xml.getElementsByTagName(node_name)[0];
            for (var i = 0; i < node.childNodes.length; i++) {
                if (node.childNodes[i].nodeType == 1) {
                    arr.push(this.getNodeValue(node.childNodes[i]))
                }
            }
        } catch(e) {} finally {
            return arr;
            arr = null;
            node = null
        }
    }
    this.getNodeValue = function(node) {
        if (!node) return "";
        var b = "";
        if (node.nodeType == 3 || node.nodeType == 4 || node.nodeType == 2) b += node.nodeValue;
        else if (node.nodeType == 1 || node.nodeType == 9 || node.nodeType == 11) for (var c = 0; c < node.childNodes.length; ++c) b += arguments.callee(node.childNodes[c]);
        return b
    }
    this.getValueByTagName = function(tag_name) {
        var ele_arr = this.obj_xml.getElementsByTagName(tag_name);
        var ele_val = new Array();
        for (var i = 0; i < ele_arr.length; i++) {
            ele_val.push(this.getNodeValue(ele_arr[i]))
        }
        return ele_val
    }
    this.getSingleValueByTagName = function(tag_name) {
        var ele = this.obj_xml.getElementsByTagName(tag_name);
        if (ele) {
            return this.getNodeValue(ele[0])
        } else {
            alert(tag_name + "不存在")
        }
    }
    this.getObj = function() {
        return this.obj_xml
    }
    this.init = function() {
        this.createXmlObj();
        if (xml_str) {
            this.loadFromText(xml_str)
        }
    }
    this.init();
    if (typeof(this.obj_xml) != "object") {
        this.createXmlObj()
    }
}
function getCookie(name) {
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]);
    return null
}
var CookieObj = {
    getCookie: function(name) {
        var start = document.cookie.indexOf(name + "=");
        var len = start + name.length + 1;
        if ((!start) && (name != document.cookie.substring(0, name.length))) {
            return null
        }
        if (start == -1) return null;
        var end = document.cookie.indexOf(';', len);
        if (end == -1) end = document.cookie.length;
        return decodeURIComponent(document.cookie.substring(len, end))
    },
    setCookie: function(name, value, expires, path, domain, secure) {
        var today = new Date();
        today.setTime(today.getTime());
        if (expires) {
            expires = expires * 1000 * 60 * 60 * 24
        }
        var expires_date = new Date(today.getTime() + (expires));
        document.cookie = name + '=' + encodeURIComponent(value) + ((expires) ? ';expires=' + expires_date.toGMTString() : '') + ((path) ? ';path=' + path: '') + ((domain) ? ';domain=' + domain: '') + ((secure) ? ';secure': '')
    },
    delCookie: function(name, path, domain) {
        if (getCookie(name)) {
            document.cookie = name + '=' + ((path) ? ';path=' + path: '') + ((domain) ? ';domain=' + domain: '') + ';expires=Thu, 01-Jan-1970 00:00:01 GMT'
        }
    }
}
