(function() {
    var undefined;
    var DXCMS = window.$ = function(o, father) { return DXCMS.fn.init(o, father); };
    DXCMS.fn = DXCMS.prototype =
    {
        obj: null,
        objs: null,
        length: 0,
        init: function(o, father) {
            if ('string' == typeof (o)) {
                if (o.indexOf("name:") > -1) {
                    this.objs = (father || document).getElementsByName(o.substring(5));
                }
                else if (o.indexOf("tag:") > -1) {
                    this.objs = (father || document).getElementsByTagName(o.substring(4));
                }
                else {
                    this.obj = (father || document).getElementById(o);
                }
            }
            else if (o) {
                if (o.length > 0) {
                    this.objs = o;
                }
                else {
                    this.obj = o;
                }
            }
            if (this.objs != null) {
                this.length = this.objs.length;
            }
            else if (this.obj != null) {
                this.length = 1;
            }
            return this;
        },
        html: function(value) {
            if (value != undefined) {
                this.obj.innerHTML = value;
                return this;
            }
            else {
                return this.obj.innerHTML;
            }
        },
        value: function(v) {
            if (v != undefined) {
                this.obj.value = v;
                return this;
            }
            else {
                return this.obj.value;
            }
        },
        radioValue: function(v) {
            if (v) {
                if (this.objs != null && this.objs.length > 0) {
                    for (var i = 0; i < this.objs.length; i++) {
                        if (this.objs[i].value == v) {
                            this.objs[i].checked = true;
                            break;
                        }
                    }
                }
                return this;
            }
            else {
                var result = "";
                if (this.objs != null && this.objs.length > 0) {
                    for (var i = 0; i < this.objs.length; i++) {
                        if (this.objs[i].checked == true) {
                            result = this.objs[i].value;
                            break;
                        }
                    }
                }
                return result;
            }
        },
        checkboxValue: function(v) {
            if (v) {
                if (this.objs != null && this.objs.length > 0) {
                    for (var i = 0; i < this.objs.length; i++) {
                        if (v.indexOf("|" + this.objs[i].value + "|") > -1) {
                            this.objs[i].checked = true;
                        }
                    }
                }
                return this;
            }
            else {
                var result = [];
                if (this.objs != null && this.objs.length > 0) {
                    for (var i = 0; i < this.objs.length; i++) {
                        if (this.objs[i].checked == true) {
                            result.push(this.objs[i].value);
                        }
                    }
                }
                return result;
            }
        },
        selectValue: function(v) {
            if (v) {
                if (this.objs != null && this.objs.length > 0) {
                    for (var i = 0; i < this.objs.length; i++) {
                        if (v.indexOf("|" + this.objs[i].value + "|") > -1) {
                            this.objs[i].selected = true;
                        }
                    }
                }
                return this;
            }
            else {
                var result = []; //¶¨ÒåÊý×é
                if (this.objs != null && this.objs.length > 0) {
                    for (var i = 0; i < this.objs.length; i++) {
                        if (this.objs[i].selected == true) {
                            result.push(this.objs[i].value);
                        }
                    }
                }
                return result;
            }
        },
        css: function(param, value) {
            if (typeof (param) == 'object') {
                for (var p in param) {
                    this.obj.style[p] = param[p];
                }
                return this;
            }
            else {
                this.obj.style[param] = value;
            }
        },
        focus: function() {
            this.obj.focus();
        },
        createElement: function(e) {
            return this.obj.createElement(e);
        },
        appendChild: function(c) {
            return this.obj.appendChild(c);
        },
        removeSelf: function() {
            this.obj.parentNode.removeChild(this.obj);
        },
        removeChild: function(c) {
            this.obj.removeChild(c);
        },
        attr: function(param, value) {
            if (typeof (param) == 'object') {
                for (var p in param)
                    this.obj[p] = param[p];
                return this;
            }
            if (value != undefined) {
                this.obj.setAttribute(param, value, 0);
                return this;
            }
            else {
                var a = this.obj.attributes[param];
                if (a == null) {
                    return "";
                }
                else {
                    return this.obj.getAttribute(param, 2);
                }
            }
        },
        className: function(value) {
            if (value != undefined) {
                this.obj.className = value;
                return this;
            }
            else {
                return this.obj.className;
            }
        },
        bind: function(n, f) {
            if (!f) {
                alert(n);
            }
            if (DXCMS.isIE) {
                this.obj.attachEvent('on' + n, f);
            }
            else {
                this.obj.addEventListener(n, f, false);
            }
            return this;
        },
        unbind: function(n, f) {
            if (DXCMS.isIE) {
                this.obj.detachEvent('on' + n, f);
            }
            else {
                this.obj.removeEventListener(n, f, false);
            }
            return this;
        },
        filter: function(o) {
            if (DXCMS.isIE) {
                o = Math.round(o * 100);
                this.obj.style.filter = (o > 100 ? '' : 'alpha(opacity=' + o + ')');
            }
            else {
                this.obj.style.opacity = o;
            }
        },
        click: function(f) {
            return DXCMS.fn.bind("click", f);
        },
        mousedown: function(f) {
            return DXCMS.fn.bind("mousedown", f);
        },
        mouseover: function(f) {
            return DXCMS.fn.bind("mouseover", f);
        },
        mouseout: function(f) {
            return DXCMS.fn.bind("mouseout", f);
        },
        contextmenu: function(f) {
            return DXCMS.fn.bind("contextmenu", f);
        },
        each: function(callback) {
            if (this.objs != null && this.objs.length > 0) {
                for (var i = 0; i < this.objs.length; i++) {
                    callback(this.objs[i]);
                }
            }
            else {
                if (this.obj != null) {
                    callback(this.obj);
                }
            }
        },
        load: function(url) {
            $.request(url, function(data) {
                DXCMS.fn.html(data);
            });
            return this;
        }
    };
    DXCMS.getXmlHttp = function() {
        return window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
    };
    DXCMS.post = function(url, postData, callBack) {
        var isFunction = (typeof (callBack) == 'function');
        var xmlHttp = this.getXmlHttp();
        xmlHttp.open("POST", url, isFunction);
        if (isFunction) {
            xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState == 4) {
                    var data = xmlHttp.responseText;
                    callBack(data);
                }
            }
        }
        xmlHttp.setRequestHeader("CONTENT-TYPE", "application/x-www-form-urlencoded");
        xmlHttp.send(this.param(postData));
    };
    DXCMS.request = function(url, callBack) {
        var isFunction = (typeof (callBack) == 'function');
        var xmlHttp = this.getXmlHttp();
        xmlHttp.open("GET", url, isFunction);
        xmlHttp.onreadystatechange = function() {
            if (xmlHttp.readyState == 4) {
                var data = xmlHttp.responseText;
                callBack(data);
            }
        }
        xmlHttp.send(null);
        this.DOMDocument = xmlHttp.responseXML;
    };
    DXCMS.param = function(param) {
        var s = [];
        function add(key, value) {
            s[s.length] = encodeURIComponent(key) + '=' + encodeURIComponent(value);
        };
        for (p in param) {
            add(p, param[p]);
        }
        return s.join("&").replace(/%20/g, "+");
    };
    DXCMS.getQueryString = function(parmName) {
        var result = '';
        var url = document.location.search;
        if (url != "undefined") {
            if (url.substr(0, 1) == "?") {
                url = url.substr(1);
            }
            var arrParam = url.split("&");
            for (var i = 0; i < arrParam.length; i++) {
                if (arrParam[i].split("=")[0] == parmName) {
                    result = arrParam[i].replace(parmName + "=", "");
                    break;
                }

            }
        }
        return result;
    };
    DXCMS.fn.init.prototype = DXCMS.fn;
    DXCMS.extend = DXCMS.fn.extend = function() {
        var a = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
        if (a.constructor == Boolean) {
            deep = a;
            a = arguments[1] || {};
            i = 2;
        }
        if (typeof a != 'object' && typeof a != 'function') a = {};
        if (length == i) {
            a = this;
            --i;
        }
        for (; i < length; i++)
            if ((options = arguments[i]) != null)
            for (var b in options) {
            var c = a[b], copy = options[b];
            if (a === copy)
                continue;
            if (deep && copy && typeof copy == 'object' && !copy.nodeType) {
                a[b] = DXCMS.extend(deep, c || (copy.length != null ? [] : {}), copy);
            }
            else if (copy !== undefined) {
                a[b] = copy;
            }
        }
        return a;
    };
    var j = navigator.userAgent.toLowerCase();
    DXCMS.extend(
    {
        isIE: /msie/.test(j) && !/opera/.test(j),
        isIE7: (j.match(/msie (\d+)/) || [])[1] >= 7 && !/opera/.test(j)
    });
})();
