﻿document.write('<div class="Heartop">');
document.write('   <div class="gbar fl">');
document.write('     <span><a href="#">设为首页</a></span>');
document.write('	 <span><a href="#">加入收藏</a></span>');
document.write('	 <span><a href="#">网站地图</a></span>');
document.write('   </div>');

if (getCookie("l_t") == null || getCookie("l_t") == "" || getCookie("l_t") == "undefined") {
    document.write('   <div class="reg fr">');
    document.write('    <div class="form_reg">');
    document.write('	  用户名:<input type="text" id="username" name="username" class="text1" maxlength="20" />');
    document.write('	  密  码:<input type="password" id="password" name="password" class="pas1" maxlength="20" />');
    document.write('      <input type="hidden" id="returnurl" name="returnurl" />');
    document.write('    </div>');
    //document.write('      <span class="btn_top"><input type="image" alt="登陆按钮" src="../images/baseimg/btn.jpg" style="width:61px; height:23px;" onclick="userLogin()"/></span>');
    document.write('      <span class="btn_top"><img alt="登陆按钮" src="/images/baseimg/btn.jpg" style="width:61px; height:23px; cursor:pointer;" onclick="userLogin()"/></span>');
    document.write('      <span class="orage"><a href="member_reg.html">[免费注册]</a></span>');
    //document.write('	  <span class="orage"><a href="user/index.aspx">[管理中心]</a></span>');
    document.write('   </div>');
} else {
    var userinfo = stringToJson(decodeCookie(getCookie("l_u")));
    document.write('   <div class="reg fr">');
    document.write('    <div class="form_reg">');
    document.write('	<span>  用户名: '+userinfo.UserName + '</span>');
    document.write('	<span  style="margin-left:20px;">  昵  称: ' + userinfo.NickName + '</span>');
    document.write('    </div>');
    document.write('      <span class="orage" style="margin-left:20px;"><a href="javascript:void(0)" onclick="userLogout()">[注销]</a></span>');
    document.write('	  <span class="orage"><a href="user/index.aspx" target="_blank">[管理中心]</a></span>');
    document.write('   </div>');
}

document.write('</div>');
function userLogout() {
    var postJson = { dt: "logout" };
    $.post("/Login/LoginHandler.ashx",
            postJson,
            function(text) {
                var json = stringToJson(text);
                if (json.result == "ok") {
                    window.location.reload();
                } else {
                    alert(json.msg);
                }
            }
    );
}
function userLogin() {
    var username = document.getElementById("username").value;
    var password = document.getElementById("password").value;
    var postJson = { dt: "login", username:encodeURIComponent(username), password: password };
    $.post("/Login/LoginHandler.ashx",
            postJson,
            function(text) {
                //alert(text);
                var json = stringToJson(text);
                if (json.result == "ok") {
                    window.location.reload();
                    //alert(json.msg);
                } else {
                    alert(json.msg);
                }
            }
    );
}
function whenKeyDown(ev){
    var e = ev || event;
    var currKey = e.keyCode||e.which||e.charCode;
    if(currKey==13){userLogin();}
}
document.onkeypress = whenKeyDown;
