var $=function(o){
    return document.getElementById(o);
};
var Authority = {
    init: function() {
        $("TopBar1_loginState").innerHTML = "正在载入用户信息...";
        Authority.checkLogin();
    },
    checkLogin: function() {
        var _name = this.getCookies("dcuser_name");
        var _value = this.getCookies("dcuser_mingchen");
        if (_name == "undefined" || _name == null || _name.length == 0) {
            $("TopBar1_loginState").innerHTML = this.initloginForm();
        } else {
            if (_value == "undefined" || _value == null || _value.length == 0) {
                _value = _name;
            }
            $("TopBar1_loginState").innerHTML = "欢迎您，<span style=\"color:#ff0000\">" + _value + "</span>&nbsp;&nbsp;<a href=\"http://chepass.eastmoney.com/UserInfo.EmUser\">修改个人信息</a>&nbsp;&nbsp;<a href=\"javascript:;\" onclick=\"Authority.exit()\" target=\"_top\">退出</a>";
        }
    },
    exit: function() {
        this.deleteCookies("dcuser_mingchen");
        this.deleteCookies("dcuser_name");
        window.location.reload();
    },
    getCookies: function(sName) {
        var aCookie = document.cookie.split("; ");
        for (var i = 0; i < aCookie.length; i++) {
            var aCrumb = aCookie[i].split("=");
            if (sName == aCrumb[0])
                return decodeURIComponent(aCrumb[1]);
        }
        return null;

    },
    deleteCookies: function(sName) {
        var date = new Date();
        document.cookie = sName + "=;path=/;domain=eastmoney.com;expires=" + date.toGMTString();
    },
    initloginForm: function() {
        var _value = "";
        _value += "<form method=\"post\" action=\"http://chepass.eastmoney.com/Blogin.EmUser\">";
        _value += "            <div class=\"lr\">用户名&nbsp;<input type=\"text\" name=\"loginuname\" id=\"loginuname\" value=\"\" class=\"inp\" />&nbsp;&nbsp;";
        _value += "            密 码&nbsp;<input type=\"password\" name=\"loginpass\" id=\"loginpass\" value=\"\" class=\"inp\" /></div>";
        _value += "            <div class=\"btn\"><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"\" class=\"frmBtn sub\" />";
        _value += "            <a href=\"http://chepass.eastmoney.com/Register.EmUser\" target=\"_blank\"><b class=\"frmBtn reg\"></b></a></div>";
        _value += "</form>";
        return _value;
    }
}
Authority.init();