<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Czou2012.UI.Manager.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <title>Czou  管理平台</title>
    <meta content="管理系统" name="keywords" />
    <meta content="管理系统" name="description" />
    <link type="text/css" rel="stylesheet" href="Styles/style.css" />
    <link type="text/css" rel="stylesheet" href="Scripts/Tips/tip-yellowsimple/tip-yellowsimple.css" />
    <script type="text/javascript" src="Scripts/jquery.min.js"></script>
    <script type="text/javascript" src="Scripts/jquery.cookie.js"></script>
    <script type="text/javascript" src="Scripts/jquery.validate.field.js"></script>
    <script type="text/javascript" src="Scripts/Tips/jquery.poshytip.js"></script>
    <script type="text/javascript">
     <!--
        //页面属性 Start
        $(document).ready(function () {

            //检查登录次数
            var loginTimes;
            if ($.cookie("LoginTimesCookie") != null) {
                loginTimes = parseInt($.cookie("LoginTimesCookie").toString());
                if (loginTimes >= 3) {
                    $(".row:eq(2)").css("display", "");
                }
                else {
                    $(".row:eq(2)").css("display", "none");
                }

            }
            else {
                $(".row:eq(2)").css("display", "none");
            }

            //检查是否记住用户名
            if ($.cookie("IsRememberCheckCookie") != null) {
                var ifRemUser = parseInt($.cookie("IsRememberCheckCookie").toString());

                if (ifRemUser == 1) {

                    var UserNameCookie;
                    if ($.cookie("UserNameCookie") != null) {

                        UserNameCookie = $.cookie("UserNameCookie").toString();
                        $("#loginUserName").attr("value", UserNameCookie);
                    }
                    else {

                        $("#loginUserName").attr("value", "");
                    }

                    $("#loginRemUser").attr("checked", true);
                    $("#loginPassword").focus();
                }
                else {
                    ifRemUser = 0;
                    $("#loginRemUser").attr("checked", false)
                    $("#loginUserName").focus();
                }
            }
            else {
                ifRemUser = 0;
                $("#loginRemUser").attr("checked", false)
                $("#loginUserName").focus();
            }

            //设置不要在公共场所使用记住用户名Tips
            $('#loginRemUser').poshytip({
                className: 'tip-yellowsimple',
                showOn: 'focus',
                alignTo: 'target',
                alignX: 'left',
                alignY: 'center',
                offsetX: 5
            });

            //初始设置输入框风格
            $("#loginUserName,#loginPassword,#loginValidateCode").addClass("input-t no-ime");
            $("#loginUserName,#loginPassword,#loginValidateCode").focus(function () { $(this).addClass("input-t-focus"); });
            $("#loginUserName,#loginPassword,#loginValidateCode").blur(function () { $(this).removeClass(); $(this).addClass("input-t no-ime"); });

            //更换验证码  Start          
            $("#loginValidateImage").click(function () {
                $.ajax({
                    type: "GET",
                    url: "Utility/ValidateCode.aspx",
                    beforeSend: Loading, //执行ajax前执行loading函数.直到success 
                    success: Response //成功时执行Response函数 
                });

                function Loading()
                { $("#loginValidateImage").attr('src', 'images/loading.gif'); };

                function Response(data)
                { $("#loginValidateImage").attr('src', "Utility/ValidateCode.aspx?number=" + Math.random()); }
            })
            //更换验证码 End


            //登录判断 Start
            $('#loginForm').bind('submit', function () {
                var username = $.trim($('#loginUserName').val());
                var password = $.trim($('#loginPassword').val());
                var validateCode = $.trim($('#loginValidateCode').val());
                var isRemember = $('#loginRemUser').attr('checked');

                if (isRemember != "checked" && isRemember != true) {
                    isRemember = "0";
                }
                else
                { isRemember = "1"; }



                var msg = $.ValidateField.ValidateUserName(username);
                if (msg != $.ValidateField.OK) {
                    $('#loginErr').html(msg);
                    $('#loginUserName').focus();
                    return false;
                } else { $('#loginErr').html(""); }
                msg = $.ValidateField.ValidatePassword(password);
                if (msg != $.ValidateField.OK) {
                    $('#loginErr').html(msg);
                    $('#loginPassword').focus();
                    return false;
                } else { $('#loginErr').html(""); }

                if (loginTimes >= 3) {
                    msg = $.ValidateField.ValidateCode(validateCode);
                    if (msg != $.ValidateField.OK) {
                        $('#loginErr').html(msg);
                        $('#loginValidateCode').focus();
                        return false;
                    } else
                    { $('#loginErr').html(""); }

                }

                $("#btnLogin").val("登录中...").attr("disabled", "true").removeClass().addClass("input input-b-hover");
                $('#loadingImg').html("<img src='images/loading.gif' style='width:16px;height:16px;margin-bottom:1px;margin-top:3px;'/>");

                //表单提交 Start
                $.ajax({
                    type: 'post',
                    url: 'Default.aspx',
                    data: 'userName=' + username + '&password=' + password + '&validateCode=' + validateCode + '&isRemember=' + isRemember + '&type=login',
                    success: function (msg) {

                        //alert(msg);
                        //检查登录次数
                        var ncookie = new $.cookie("LoginTimesCookie");
                        if (ncookie != null) {
                            loginTimes = parseInt($.cookie("LoginTimesCookie").toString());
                            if (loginTimes >= 3) {
                                $(".row:eq(2)").css("display", "");
                            }
                            else {
                                $(".row:eq(2)").css("display", "none");
                            }
                        }

                        if (msg == 'errorCode') {
                            // alert('验证码错误');
                            $('#loginErr').html("验证码错误");
                            $('#loadingImg').html("");
                            $('#loginValidateCode').focus();
                        }
                        if (msg == 'codeExpire') {
                            //alert('验证码过期');
                            $('#loginErr').html("验证码过期");
                            $('#loadingImg').html("");
                            $("#loginValidateImage").attr('src', "Utility/validateCode.aspx?number=" + Math.random());
                            $('#loginValidateCode').focus();
                        }
                        if (msg == 'loginError') {
                            //alert('错误用户名和密码，请确认Caps Lock是否打开。');
                            $('#loginErr').html("登录失败，请确认Caps Lock是否打开。");
                            $('#loadingImg').html("");
                            $("#loginValidateImage").attr('src', "Utility/validateCode.aspx?number=" + Math.random());
                            $('#loginUserName').focus();
                        }


                        if (msg == 'ok') {
                            $.ajax({
                                type: "get",
                                url: "mainFrame.aspx",
                                success: function () { window.location.href = 'mainFrame.aspx'; } //成功时跳转
                            });
                        }
                        else {
                            $("#btnLogin").val("登 录").removeAttr("disabled").removeClass().addClass("input input-b"); ;
                        }
                    },
                    error: function (msg) {
                        alert(msg.responseText);
                    }
                });

                //表单提交 End
                return false;
            });
            //登录判断 End
            $('#forgotUser,#forgotPassword').poshytip({
                className: 'tip-yellowsimple',
                showOn: 'mouseover',
                alignTo: 'target',
                alignX: 'center',
                alignY: 'top',
                offsetY: 3
            });

            $("#loginPassword").val("");
        });
        //页面属性 End


//-->
    </script>
</head>
<body>
    <div class="page">
        <div class="head">
            <div class="czour" style="display: none">
               </div>
        </div>
        <div class="loginLogo">
            <img alt="" src="Images/logo.png" /></div>
        <div class="loginWindow">
            <div class="login">
                <div class="divSpan">
                </div>
                <div class="marLeft loginForm">
                    <form action="" id="loginForm">
                    <div class="row">
                        <label class="row-lb-l">
                            用户名</label>
                        <input type="text" id="loginUserName" tabindex="1" />
                        <span class="row-lb-r hand underline" id="forgotUser" title="忘记请联系系统管理员">忘记用户？</span>
                    </div>
                    <div class="row">
                        <label class="row-lb-l">
                            密 码</label>
                        <input type="password" id="loginPassword" tabindex="2" maxlength="20" />
                        <span class="row-lb-r hand underline" id="forgotPassword" title="请联系系统管理员">忘记密码？</span>
                    </div>
                    <div class="row" id="rowValidate">
                        <label class="row-lb-l">
                            验证码</label>
                        <input id="loginValidateCode" style="width: 80px;" tabindex="3" maxlength="20" />
                        &nbsp;<img src="Utility/validateCode.aspx" id="loginValidateImage" alt="验证码" title="看不清，点击更改验证码"
                            runat="server" />&nbsp;&nbsp;
                        <label class="divCheck">
                            *验证码必填</label>
                    </div>
                    <div class="row secuLeft">
                        <input type="checkbox" id="loginRemUser" checked="checked" value="" title="请勿在网吧或公用电脑上使用此功能！" />
                        <label class="divCheck" for="loginRemUser">
                            记住用户名</label>
                    </div>
                    <div class="row row-btn">
                        <input type="submit" class="input input-b" id="btnLogin" value="登 录" onmouseover="$(this).removeClass().addClass('input input-b-hover')"
                            onmouseout="$(this).removeClass().addClass('input input-b')" tabindex="4" />&nbsp;&nbsp;<input
                                type="button" class="input input-b" value="注 册" onmouseover="$(this).removeClass().addClass('input input-b-hover')"
                                onmouseout="$(this).removeClass().addClass('input input-b')" tabindex="5" />&nbsp;&nbsp;<label
                                    id="loadingImg" style="vertical-align: middle; padding-top: 4px;"><img src='images/loading.gif'
                                        style='width: 0px; height: 0px; margin-bottom: 1px; margin-top: 3px;' /></label>
                        <br />
                        <label class="err" id="loginErr">
                        </label>
                    </div>
                    </form>
                </div>
                <div class="marLeft row-line">
                </div>
                 <div class="marLeft row">
                    <label class="row-lb">思想，用心，创造
                        </label>
                    <label style="float: right; width: 220px; text-align: left;">
                        [测试用户：demo，密码：demo]</label>
                </div>

            </div>
        </div>
    </div>
    <div class="footer">
        <div class="copyright">
            <span>&nbsp;Copyright 2011-2012 by Czou, All Rights Reserved .&nbsp;&nbsp如有需要请联系&nbsp;&nbsp<a href="http://www.czou.com/" target="_blank" style="text-decoration: underline;">[船长]</a></span>
            <span style="display:none">请保留以上版权信息，谢谢！</span>
        </div>
    </div>
    <!--Count Begin -->
    <!--Count End -->
</body>
</html>
