if (document.implementation.hasFeature("XPath", "3.0")) {
    XMLDocument.prototype.selectNodes = function(a, b) {
        if (!b) b = this;
        var c = this.createNSResolver(this.documentElement);
        var d = this.evaluate(a, b, c, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
        var e = [];
        for (var i = 0; i < d.snapshotLength; i++) e[i] = d.snapshotItem(i); return e
    }; Element.prototype.selectNodes = function(a) {
        if (this.ownerDocument.selectNodes) return this.ownerDocument.selectNodes(a, this);
        else throw "For XML Elements Only";
    };
    XMLDocument.prototype.selectSingleNode = function(a, b) {
        if (!b) b = this;
        var c = this.selectNodes(a, b);
        if (c.length > 0) return c[0];
        else return null
    };
    Element.prototype.selectSingleNode = function(a) {
        if (this.ownerDocument.selectSingleNode) return this.ownerDocument.selectSingleNode(a, this);
        else throw "For XML Elements Only";
    };
    HTMLElement.prototype.insertAdjacentElement = function(a, b) {
        switch (a) {
            case "beforeBegin": this.parentNode.insertBefore(b, this);
                break;
            case "afterBegin": this.insertBefore(b, this.firstChild);
                break;
            case "beforeEnd": this.appendChild(b);
                break;
            case "afterEnd": if (this.nextSibling) this.parentNode.insertBefore(b, this.nextSibling);
                else this.parentNode.appendChild(b);
                break
        }
    };
    HTMLElement.prototype.insertAdjacentHTML = function(a, b) {
        var r = this.ownerDocument.createRange();
        r.setStartBefore(this);
        var c = r.createContextualFragment(b);
        this.insertAdjacentElement(a, c)
    }
};
if (/msie/i.test(navigator.userAgent)) {
    window.XMLHttpRequest = function() {
        var msxmls = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'MICROSOFT.XMLHTTP.1.0', 'MICROSOFT.XMLHTTP.1', 'MICROSOFT.XMLHTTP'];
        for (var i = 0; i < msxmls.length; i++) {
            try {
                return new ActiveXObject(msxmls[i]);
            } catch (e) { }
        }
        return null;
    };
}
Object.extend = function(destination, source) {
    for (var property in source)
        destination[property] = source[property];
    return destination;
};
var ajax = {
    send: function (arg) {
        var req = new XMLHttpRequest();
        if (req == null) {
            alert("浏览器不支持xmlhttp");
            return;
        }
        if (req.overrideMimeTyp) req.overrideMimeType('text/xml');
        var dataType = { text: 'responseText', xml: 'responseXML', json: 'responseText' };
        var options = {
            url: '',
            type: 'POST',
            async: true,
            data: null,
            timeout: 0,
            contentType: 'application/x-www-form-urlencoded',
            encoding: 'UTF-8',
            dataType: 'text',
            State: ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'],
            ErrorState: { "400": "Bad Request 请求出现语法错误",
                "404": "无法找到指定位置的资源",
                "405": "type Not Allowed 请求方法（GET、POST、HEAD、DELETE、PUT、TRACE等）对指定的资源不适用"
            },
            //这里自己定义吧
            create: function () { },
            success: function () { },
            doing: function () { }, //从开始到结束，0-4状态
            timeout: function () { },
            error: function (status, ErrorMsg, eMsg) { alert("Status: " + status + "\nErrors: " + ErrorMsg + "\n        " + eMsg); }
        }
        Object.extend(options, arg || {});
        options.url += ((options.url.indexOf("?") > 0) ? "&" : "?") + "randnum=" + Math.random();
        options.type = options.type.toUpperCase();
        if (options.async) {
            options.doing(0, options.State[0]);
            req.onreadystatechange = function () {
                var _state = req.readyState;
                options.doing(_state, options.State[_state]);
                switch (_state) {
                    case 0:
                        options.create(_state, options.State[_state]);
                        break;
                    case 4:
                        if (req.status == 200)
                            options.success(options.dataType == "json" ? eval("(" + req[dataType[options.dataType]] + ")") : req[dataType[options.dataType]], _state, options.State[_state]);
                        else if (req.status > 200)
                            options.error(req.status, options.ErrorState[req.status], "");
                        req.onreadystatechange = function () { };
                        req = null;
                        break;
                }
            };
        }
        try {
            req.open(options.type, options.url, options.async);
            if (options.type == "POST")
                req.setRequestHeader('Content-Type', options.contentType + '; charset=' + options.encoding);
            if (options.async && options.timeout > 0) {
                setTimeout(function () {
                    try {
                        if (req != null && req.readyState != 4) options.timeout(); req.abort(); req = null;
                    }
                    catch (e) { }
                }, options.timeout);
            }
            req.send(options.data);
            //只要不是status=200,都算有错误
            if (!options.async) {
                options.success(req[dataType[options.dataType]]);
                req = null;
            }
        }
        catch (e) {
            try { options.error(req.status, options.ErrorState[req.status], e); }
            catch (e) { options.error(0, "", e); }
            finally { req.abort(); req = null; }
        }
    }
}