﻿$(function () {
    bindLogin();
    $("#loginForm").submit(function () {
        validateCookie();
        if (!$("#userName").val()) {
            $("#status").show().html("用户名不能为空！");
            $("#userName").get(0).focus();
            return false;
        }
        if (!$("#pwd").val()) {
            $("#status").show().html("密码不能为空！");
            $("#pwd").get(0).focus();
            return false;
        }
        if (!$("#checkCode").val()) {
            $("#status").show().html("验证码不能为空！");
            $("#checkCode").get(0).focus();
            return false;
        }
        $.getScript("http://resource.3gsc.com.cn/user/IndexLogin.ashx?t=4&code=" + $("#checkCode").val().toUpperCase(), function () {
            if (checkCode && checkCode == $.cookie("checkCode")) {
                $("#status").show().html("正在登录。。。");
                $.getScript("http://resource.3gsc.com.cn/user/IndexLogin.ashx?t=2&un=" + encodeURIComponent($("#userName").val()) + "&pd=" + encodeURIComponent($("#pwd").val()) + "&rem=" + ($("#rem").get(0).checked ? 1 : 0), function () {
                    if (jsloginData.code && jsloginData.code < 0) {
                        $("#status").show();
                        $("#status").html(jsloginData.msg ? jsloginData.msg : "意外错误！");
                        change();
                        return;
                    }
                    else {
                        bindLogin();
                        $("#status").hide();
                    }
                });
            }
            else {
                $("#status").show().html("验证码不正确！");
                $("#checkCode").get(0).focus();
                change();
            }
        });
        return false;
    });
});
function bindLogin() {
    if (!jsisLogin) {
        $("#loginForm").get(0).reset();
        $("#Login").show();
        $("#User").hide();
        change();

        $("#LoginDiv").hide();
        $("#NoLogin").show();
    }
    else {
        $("#Login").hide();
        $("#User").show();
        if (jsloginData) {
            // 登录框loin状态
            $("#uName").html(jsloginData.userName);
            $("#nComment").html(jsloginData.newCommentCount);
            $("#nReadMsg").html(jsloginData.notReadMsg);
            $("#guli").html(jsloginData.guli);
            $("#brick").html(jsloginData.brick);

            //header头login状态。
            $("#LoginDiv").show();
            $("#NoLogin").hide();
            $("#h_name").html(jsloginData.userName);
            $("#h_msgcount").html(jsloginData.notReadMsg);
        }
    }
}
function isCookieOn() {
    return window.navigator.cookieEnabled;
}
function change() {
    $("#checkImg").attr("src", "http://resource.3gsc.com.cn/user/checkcode.aspx?m=" + Math.random(100));
    return false;
}
