var HD = HD || {};
(function() {
    HD.dom = HD.dom || {};
    var ua = navigator.userAgent.toLowerCase(),
    ie = /msie/.test(ua) && !/opera/.test(ua),
    ie6 = /msie 6/.test(ua),
    chrome = /chrome/i.test(ua) && /webkit/i.test(ua) && /mozilla/i.test(ua),
    get = function(id) {
        return typeof(id) !== "string" ? id: document.getElementById(id)
    };
    if (!Array.prototype.forEach) {
        Array.prototype.forEach = function(fun) {
            var len = this.length;
            if (typeof fun != "function") {
                throw new TypeError()
            }
            var thisp = arguments[1];
            for (var i = 0; i < len; i++) {
                if (i in this) {
                    fun.call(thisp, this[i], i, this)
                }
            }
        }
    }
    HD.dom.Util = {
        getCookie: function(a) {
            return (a = document.cookie.match("(?:^|;)\\s*" + a + "=([^;]*)")) && a[1] ? decodeURIComponent(a[1]) : ""
        },
		getElementsByClassName: function(className, tag, root) {
            var ret = [],
            els = (get(root) || document).getElementsByTagName(tag || "*"),
            reg = new RegExp("(^| )" + className + "( |$)", "i");
            for (var i = 0,
            l = els.length; i < l; i++) {
                if (reg.test(els[i].className)) {
                    ret.push(els[i])
                }
            }
            return ret
        },
		 parseQueryParams: function(a) {
            var b = {};
            a = a.split("&");
            for (var c = 0,
            f = a.length; c < f; ++c) {
                var e = a[c],
                h = e.search("="),
                m = e.substring(0, h);
                e = e.substring(h + 1, e.length);
                b[decodeURIComponent(m)] = decodeURIComponent(e)
            }
            return b
        },
        trim: function(a) {
            return a.replace(/^\s+|\s+$/g, "")
        },
        hasClass: function(el, className) {
            el = get(el);
            if (!className || !el.className) {
                return false
            }
            return (" " + el.className + " ").indexOf(" " + className + " ") > -1
        },
        addClass: function(el, className) {
            if (!className) {
                return
            }
            el = get(el);
            if (this.hasClass(el, className)) {
                return
            }
            el.className += " " + className
        },
        removeClass: function(el, className) {
            el = get(el);
            if (!this.hasClass(el, className)) {
                return
            }
            el.className = (" " + el.className + " ").replace(" " + className + " ", " ");
            if (this.hasClass(el, className)) {
                this.removeClass(el, className)
            }
        },
        addEvent: function() {
            if (window.addEventListener) {
                return function(el, type, fn, capture) {
                    get(el).addEventListener(type, fn, !!capture)
                }
            } else {
                if (window.attachEvent) {
                    return function(el, type, fn) {
                        if (el === null) {
                            return
                        }
                        var obj = typeof(el) === "string" ? get(el) : el;
                        obj.attachEvent("on" + type, fn)
                    }
                }
            }
        } (),
        removeEvent: function() {
            if (window.removeEventListener) {
                return function(el, type, fn, capture) {
                    el.removeEventListener(type, fn, !!capture)
                }
            } else {
                if (window.detachEvent) {
                    return function(el, type, fn) {
                        el.detachEvent("on" + type, fn)
                    }
                }
            }
        } (),
        preventEvent: function(ev) {
            if (ev.preventDefault) {
                ev.preventDefault()
            } else {
                ev.returnValue = false
            }
        },
        onReady: function(callback) {
            if (ie) {
                var timer = setInterval(function() {
                    try {
                        document.documentElement.doScroll("left");
                        clearInterval(timer);
                        callback()
                    } catch(ex) {}
                },
                50)
            } else {
                window.addEventListener("load", callback, false)
            }
        },
        toParamString: function(obj) {
            var result = [];
            for (var key in obj) {
                result.push(encodeURIComponent(key) + "=" + encodeURIComponent(obj[key]))
            }
            return result.join("&")
        },
        merge: function() {
            var o = {},
            a = arguments,
            l = a.length,
            i;
            for (i = 0; i < l; i = i + 1) {
                for (var p in a[i]) {
                    o[p] = a[i][p]
                }
            }
            return o
        },
        asyncRequest: function(method, url, callback, data) {
            var xmlhttp;
            if (window.XMLHttpRequest) {
                xmlhttp = new XMLHttpRequest()
            } else {//"MSXML2.XMLHTTP.5.0",
                var MSXML = ["MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
                for (var i = 0; i < MSXML.length; i++) {
                    try {
                        xmlhttp = new ActiveXObject(MSXML[i]);
                        break
                    } catch(ex) {}
                }
            }
            if (!xmlhttp) {
                return
            }
            xmlhttp.onreadystatechange = function() {
                if (xmlhttp.readyState == 4) {
                    if (xmlhttp.status == 200 || xmlhttp.status == 0) {
                        if (callback && callback.success) {
                            callback.success(xmlhttp)
                        }
                    } else {
                        if (callback && callback.failure) {
                            callback.failure(xmlhttp)
                        }
                    }
                }
            };
            method = method.toUpperCase();
            if (method.toUpperCase() == "GET" && data && data.length > 0) {
                url += ((url.indexOf("?") == -1) ? "?": "&") + data
            }
            if (callback && callback.cache === false) {
                url += ((url.indexOf("?") == -1) ? "?": "&") + "rnd=" + new Date().valueOf().toString()
            }
            xmlhttp.open(method, url);
            if (method == "POST") {
                xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                xmlhttp.send(data)
            } else {
                xmlhttp.send(null)
            }
        },
		escapeHTML: function(a) {
            var b = document.createElement("div");
            a = document.createTextNode(a);
            b.appendChild(a);
            return b.innerHTML
        }
    };
    var setStyle = function(el, property, value) {
        el = get(el);
        if (!el) {
            return
        }
        el.style[property] = value
    };	
})();

/*  Í·²¿µÇÂ½ÏÔÊ¾  */
(function() {
	var d = HD.dom.Util,
    G = d.getCookie("ch_nick"),
    w = d.getCookie("ch_uinfo"),
    w = d.parseQueryParams(w);
    var W = d.getCookie("ch_hdUser") && G || d.getCookie("ck1") && d.getCookie("ch_hdUser"),
    H = parseInt(w._msg_) || 0,
    I = (new Date).getTime(),
    x = document.location.href.indexOf("https://") === 0;
	HD.Header = {
        isLogin: function(a) {
            a = a || {};
            var b = a.memberServer || "http://www.585.com.cn",
            c = a.loginServer || b,
            f = a.loginUrl || c + "/member/login.php",
            e = location.href;
            if (/^http.*(\/member\/login\.php)$/i.test(e)) e = "";
            if (e = a.redirectUrl || e) f += "?reUrl=" + encodeURIComponent(e);
            a = a.logoutUrl || c + "/member/logout.php";
            c = b + "/member/select.php";
            b = b + "/member/message.php?t=" + I;
            e = "http://www.585.com.cn/member/home.php?t=" + I;
            var h = "";
            if (W) {
                h = '\u60a8\u597d\uff0c<a class="user-nick" href="' + e + '" target="_top">' + d.escapeHTML(unescape(G.replace(/\\u/g, "%u"))) + "</a>\uff01";
                h += '<a id="logout" href="' + a + '" target="_top">\u9000\u51fa</a>';
                h += '<a href="' + b + '" target="_top">\u7ad9\u5185\u4fe1';
                if (H) h += "(" + H + ")";
                h += "</a>"
            } else {
                h = '\u60A8\u597D\uFF0C\u6B22\u8FCE\u6765585\uff01<a href="' + f + '" target="_top">\u8bf7\u767b\u5f55</a>';
                h += '<a href="' + c + '" target="_top">\u514d\u8d39\u6ce8\u518c</a>'
            }
            document.write(h)
        }
	} 
})();


