$(document).ready(function () {
    if (document.cookie.indexOf('tcwl_remember') >= 0) {
        var co = document.cookie.substring(document.cookie.indexOf('tcwl_remember')).split(";")[0];
        if (co != null) {
            var times = co.split("=")[4];
            if (times == "1") {
                var username = co.split("=")[2].split("&")[0];
                var password = co.split("=")[3].split("&")[0];
                $("#userName").val(username);
                $("#passWord").val(password);
                $("#rememberme").attr("checked", true);
            }
        }
    }

    $("#userName").on('input', function (e) {
        $("#passWord").val('');
    });

    $('#ft').height($(window).height() - 697);
    if ($(window).height() - 697 <= 60) {
        $('#ft').height(70);
    }
    $('html').bind('keydown', function (e) {
        var ev = document.all ? window.event : e;
        if (ev.keyCode == 13) {
            Login();
        }
    });

    $(window).resize(function () {
        if ($(window).height() - 697 <= 60) {
            $('#ft').height(70);
            return;
        }
        $('#ft').height($(window).height() - 697);

    });
    $('#userName').bind('focus', function (e) {
        $(this).parent().css({ 'z-index': 10 });
        $(this).parent().addClass('lg-txt-active');

    });
    $('#userName').bind('blur', function (e) {
        $(this).parent().removeAttr('style');
        $(this).parent().removeClass('lg-txt-active');

    });

    $('#passWord').bind('focus', function (e) {
        $(this).parent().css({ 'z-index': 10 });
        $(this).parent().addClass('lg-pwd-active');

    });
    $('#passWord').bind('blur', function (e) {
        $(this).parent().removeAttr('style');
        $(this).parent().removeClass('lg-pwd-active');

    });
    $('#checkword').bind('focus', function (e) {
        $(this).addClass('lg-chk-active');

    });
    $('#checkword').bind('blur', function (e) {

        $(this).removeClass('lg-chk-active');

    });

});

function LoadLog() {
    $.ajax({
        type: "post",
        url: "/Handlers/Login.aspx?Method=GetCopyright",
        cache: false,
        dataType: "json",
        success: function (data) {
            if (data == null) {
                $("#imglogo").attr("src", "../Scripts/Log/images/logo.png");
                $("#imgleft").attr("src", "Scripts/Log/images/lg-img.png");
            } else if (data == "f") {
                $("#imglogo").attr("src", "../Scripts/Log/images/logo.png");
                $("#imgleft").attr("src", "Scripts/Log/images/lg-img.png");
                layer.alert("经检测您可能尚未对本软件进行配置安装，请点击确定进行配置安装。", 5, " ", function () {
                    window.location.href = "install.htm";
                });
//                $("#Copyright").parent.next().childern().eq(0).remove();
//                $("#Copyright").parent().next().append('<a id="ydd" style="color: #666; float: left; margin-left: 450px; margin-top: 10px; font-size: 12px;" target="_blank" href="http://www.yundiandi.cn" >云点滴V2.1</a>');
                $("#Copyright").parent().next().append('<a id="ydd" style="color: #666; float: left; margin-left: 450px; margin-top: 10px; font-size: 12px;" target="_blank" href="http://www.yundiandi.cn" >YUNDIANDI  V2.4</a>');
                $("#Copyright").parent().next().children().first().remove();
            } else {
                $("#imglogo").attr("src", data.rows[0].Log_logo);
                $("#imgleft").attr("src", data.rows[0].Log_Img);
                getCopy();

            }
            $("#Copyright").parent().next().append('<a id="ydd" style="color: #666; float: left; margin-left: 450px; margin-top: 10px; font-size: 12px;" target="_blank" href="http://www.yundiandi.cn" >YUNDIANDI  V2.4</a>');
            $("#Copyright").parent().next().children().first().remove();
            //$("#Copyright").parent().append('<div><a id="ydd" target="_blank" href="http://www.yundiandi.cn">云点滴VerSion2.1</a></div>');
        },
        error: function () {
            $("#imglogo").attr("src", "../Scripts/Log/images/logo.png");
            $("#imgleft").attr("src", "Scripts/Log/images/lg-img.png");
            layer.alert("经检测您可能尚未对本软件进行配置安装，请点击确定进行配置安装。", 5, " ", function () {
                window.location.href = "install.htm";
            });
            $('.xubox_setwin').hide();
            //$("#Copyright").parent().append('<div><a id="ydd" target="_blank" href="http://www.yundiandi.cn">云点滴VerSion2.1</a></div>');
            //$("#Copyright").next().remove();
            // $("#Copyright").parent().append('<a id="ydd" style="color: #666; float: left; margin-left: 450px; margin-top: 10px; font-size: 12px;" target="_blank" href="http://www.yundiandi.cn" >云点滴V2.1</a>');
            //$("#Copyright").parent.next().empty();
            $("#Copyright").parent().next().append('<a id="ydd" style="color: #666; float: left; margin-left: 450px; margin-top: 10px; font-size: 12px;" target="_blank" href="http://www.yundiandi.cn" >YUNDIANDI  V2.4</a>');
            $("#Copyright").parent().next().children().first().remove();
        }
    });
}

function getCopy() {
    $.ajax({
        type: "post",
        url: "/Handlers/system/SetInfo.aspx?Method=GetCopy",
        cache: false,
        success: function (data) {
            if (data != "no") {
                $("#Copyright").html(data);
            } else {
                var d = '<div class="\&quot;copydh\&quot;" style="\&quot;font-family:" font-size:="" margin:="" padding:="" 13px="" 0px="" color:="" line-height:="" white-space:="" background-color:=""><div class="copydh" style="text-align: center; font-family: Arial; font-size: 12px; margin: 0px; padding: 13px 0px 0px 16px; color: #d7d7d7; line-height: normal; white-space: normal; "><a href="http://www.yundiandi.cn" target="_blank" title="关于云点滴">关于云点滴</a>&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp; &nbsp;<a href="http://www.yundiandi.com/Help/reg.htm" target="_blank" title="云点滴帮助">云点滴帮助</a>&nbsp; &nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.yundiandi.cn/jianjie.html" target="_blank" title="云点滴价格">云点滴价格&nbsp;</a> &nbsp;</div><div class="copycon" style="font-family: Arial; font-size: 12px; margin: 0px; padding: 8px 0px 0px 16px; color: rgb(51, 51, 51); text-align: center; line-height: 20px; white-space: normal; color:#d7d7d7;"><p style="margin-top: 0px; margin-bottom: 0px; padding-bottom: 1em; line-height: 18px;">Copyright @ 云点滴技术团队 (<a href="http://www.hntcwl.com/" style="color: rgb(51, 51, 51);">&nbsp;</a><a href="http://www.yundiandi.com/" target="_blank">www.yundiandi.com&nbsp;</a>), All Rights Reserved<br/></p></div>';
                $("#Copyright").text("");
                $("#Copyright").append(d);
            }
        },
        error: function () { }
    });
}


function ChangeRandImg() {
    $("#vcode_img").attr("src", "Registration/veryCode.aspx?" + Math.random() + "");
}

function KeyLogin(e) {
    var e = e || window.event;
    if (e.keyCode == 13) {
        $("#fm-login-submit").click();
    }
}

function Login() {
    if ($("#userName").val() == "") {
        $("#login-error").show();
        //$("#msg").text('用户名不可为空！');
        $("#userName").focus();

        return false;
    }
    if ($("#passWord").val() == "") {
        $("#login-error").show();
        //$("#msg").text('密码不可为空！');
        $("#passWord").focus();

        return false;
    }
    var l = layer.load('正在登陆......');
    var ydd = $("#ydd").text();
    if (ydd == null || ydd == "" || ydd == undefined) {
        layer.msg(" 系统登录异常，可能是程序有改动，请恢复程序后再尝试登录！", 4, 5);
        return;
    }
    $("#hidcopy").val(ydd);
    $.ajax({
        type: "post",
        url: "/Handlers/Login.aspx?Method=Login",
        cache: false,
        data: $('#fmlog').serialize(),
        success: function (data) {
            layer.close(l);
            if (data == "success") {
                window.location.href = "index.htm";
            } else if (data == "nocopy") {
                layer.msg("系统登录异常，请重新安装！如有问题请联系云点滴客服。", 4, 5);
                return;
            } else if (data == "noGG") {
                layer.msg("系统登录异常，请重新安装！如有问题请联系云点滴客服。", 4, 5);
                return;
            } else {
                if (data == "error") {
                    $("#login-error").show();
                    layer.msg("账户已过期,请及时联系管理员！", 1, 8);

                } else {
                    if (data == "error_N") {
                        $("#login-error").show();
                        //$("#msg").text('账号被禁用,请及时联系管理员！');
                        layer.msg("账号被禁用,请及时联系管理员！", 1, 8);

                    } else {
                        $("#login-error").show();
                        //$("#msg").text('登陆信息错误！');
                        layer.msg("用户名或者密码错误！", 1, 8);

                    }
                }
            }
        },
        error: function () {
            layer.msg("网络错误！请稍后重试！");
        }
    });
}

window.onresize = function () {
    var minh = 675;
    var minw = 960;
    $("#divPage").height(document.documentElement.offsetHeight < minh ? minh : '100%');
    $("#divPage").width(document.documentElement.offsetWidth < minw ? minw : "auto");
}
if ($("#userName").value == "") {
    $("#userName").focus();
} else {
    $("#passWord").focus();
}