<%@Page Language="C#" AutoEventWireup="true" Inherits="Web.inherits.ViewPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>找回密码-<%=WebSiteConfig.SiteTitle%></title>
    <link href="<%path:%>Css/common.css" rel="stylesheet" />
    <link href="<%path:%>Css/web.css" rel="stylesheet" />
    <link href="<%path:%>Css/user.css" rel="stylesheet" />
    <script src="/Js/jquery-1.8.2.min.js" type="text/javascript"></script>
    <script src="/Js/bx.library.js"></script>
    <script src="/Js/data.js"></script>
    <script src="/Js/form.js"></script>
    <link href="/Css/form.css" rel="stylesheet" />
    <script src="<%path:%>js/web.js" type="text/javascript"></script>
    <script src="<%path:%>js/user.js" type="text/javascript"></script>
    <style type="text/css">
        .seconditemtitle{word-break:keep-all;word-wrap:normal;}
    </style>
</head>
<body>
    <!--head-->
    <%template:_head.html%>
    <!--body-->
    <div class="body main">
        <form id="form2">
            <div class="register bordershadow">
                <div class="content">
                    <div class="righttitle">找回密码</div>
                    <div class="left">
                        <table>
                            <tr>
                                <td class="itemtitle">
                                    注册账号
                                </td>
                                <td class="itemcontent">
                                    <input id="Account" type="text" />
                                </td>
                                <td></td>
                            </tr>
                            <tr>
                                <td class="itemtitle">
                                    <input id="rdlOptionEmail" value="email" name="ForgetPasswordOption" type="radio" checked="checked" />
                                    <label for="rdlOptionEmail">通过邮箱找回</label>
                                </td>
                                <td>
                                    <table>
                                        <tr>
                                            <td class="seconditemtitle">注册邮箱</td>
                                            <td class="itemcontent">
                                                <input id="Email" type="text" />
                                                <a href="javascript:" onclick="emailAuth();">发送验证</a>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="seconditemtitle">邮箱验证码</td>
                                            <td class="itemcontent">
                                                <input id="EmailCode" type="text" />
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                                <td></td>
                            </tr>
                            <tr>
                                <td class="itemtitle">
                                    <input id="rdlOptionQuetion" value="question" name="ForgetPasswordOption" type="radio" />
                                    <label for="rdlOptionQuetion">通过问题找回</label>
                                </td>
                                <td>
                                    <table>
                                        <tr>
                                            <td class="seconditemtitle">密保问题</td>
                                            <td class="itemcontent">
                                                <input id="Question" type="text" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="seconditemtitle">密保答案</td>
                                            <td class="itemcontent">
                                                <input id="Answer" type="text" />
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                                <td></td>
                            </tr>
                            <tr>
                                <td colspan="3">&nbsp;</td>
                            </tr>
                            <tr>
                                <td class="itemtitle">
                                    新密码
                                </td>
                                <td class="itemcontent">
                                    <input id="NewPassword" type="password" />
                                </td>
                                <td>
                                    如果验证成功则重设原来的密码
                                </td>
                            </tr>
                            <tr>
                                <td class="itemtitle">
                                    图片验证码
                                </td>
                                <td class="itemcontent itemcontent2">
                                    <input id="Code" name="Code" class="registervcode" type="text" size="6" />
                                    <img id="imgVerification" src="/Images/common/loading1.gif" alt="验证码" title="刷新验证码" />
                                </td>
                                <td></td>
                            </tr>
                            <tr>
                                <td colspan="3">
                                    <input id="Button1" type="button" onclick="submitData();" value="提交" />
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <!--foot-->
    <%template:_foot.html%>

    <script type="text/javascript">
        var rule = '[{"Name": "Account", "Type": "text", "Null": "0","Error":"账号不能为空" }';
        rule += ',{ "Name": "NewPassword", "Type": "password", "Null":"0","Error":"新密码不能为空"}';
        rule += ',{ "Name": "Code", "Type": "text", "Null": "0","Error":"图片验证码不能为空"}';
        rule += ']';
        window.onload = function () {
            form.init(eval(rule));
        }
        function submitData() {
            var ck = form.check();
            if (ck == "") {
                User.forgotPassword(form.getJson(), function (result) {
                    if (result.status == "success") {
                        Alert("操作成功");
                        window.location.href = "/login/default";
                    } else if (result.error == "code") {
                        Alert("验证码错误");
                    }
                    else {
                        Alert(result.message);
                    }
                });
            }
            else {

            }
        }
        function emailAuth() {
            if (document.getElementById("rdlOptionEmail").checked) {
                var account = document.getElementById("Account").value;
                var email = document.getElementById("Email").value;
                if (account == "" || email == "") {
                    Alert("账号和邮箱都不能为空");
                }
                User.emailAuth({ action: "forgetpassword", account: account, email: email }, function (result) {
                    if (result.status == "success") {
                        Alert("验证邮件已发送");
                    } else if (result.error == "limit") {
                        Alert("验证邮件已达到最大限制次数,请稍后再试");
                    }
                    else if (result.error == "noemail") {
                        Alert("输入的Email或账号不存在");
                    }
                    else {
                        Alert("验证邮件发送失败");
                    }
                })
            } else {
                Alert("请先选择找回密码的方式");
            }
        }
        function RefreshVerification() {
            var imgid = "imgVerification", textid = "Code";
            if (document.getElementById(imgid).onclick == null) { document.getElementById(imgid).onclick = function () { RandomVerification(textid, imgid); document.getElementById(textid).focus(); } }
            RandomVerification(textid, imgid);
        }
        function RandomVerification(inputid, imgid) { if (inputid == null || imgid == null) { return; } else { document.getElementById(inputid).value = ""; document.getElementById(imgid).src = "/Ashx/VerificationCode.ashx?r=" + new Date().getTime(); } }
        window.onload = function () {
            RefreshVerification();
        }
    </script>

</body>
</html>
