<%@Page Language="C#" AutoEventWireup="true" Inherits="Web.inherits.ViewPage" %>
<!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>
    <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/client.validate.js"></script> 
    <script src="<%path:%>js/web.js" type="text/javascript"></script>
    <script src="<%path:%>js/user.js" type="text/javascript"></script>

</head>
<body>
    <!--head-->
    <%template:_head.html%>
    <!--body-->
    <div class="body main">
        <form id="form1">
            <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="txtAccount" maxlength="30" type="text" onfocus="checkInput(this,1)" onblur="checkInput(this,2)" />
                                </td>
                                <td id="txtAccountStatus" align="left">&nbsp;</td>
                            </tr>
                            <tr>
                                <td class="itemtitle">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码:</td>
                                <td class="itemcontent">
                                    <input id="txtPassword" maxlength="20" type="password" onfocus="checkInput(this,1)" onblur="checkInput(this,2)" />
                                </td>
                                <td id="txtPasswordStatus" align="left">&nbsp;</td>
                            </tr>
                            <tr>
                                <td class="itemtitle">重复密码:</td>
                                <td class="itemcontent">
                                    <input id="txtRepeatPassword" maxlength="20" type="password" onfocus="checkInput(this,1)" onblur="checkInput(this,2)" />
                                </td>
                                <td id="txtRepeatPasswordStatus" align="left">&nbsp;</td>
                            </tr> 
                            <tr>
                                <td class="itemtitle">验&nbsp;&nbsp;证&nbsp;&nbsp;码:</td>
                                <td class="itemcontent itemcontent2">
                                    <input id="VerificationCode" class="registervcode" type="text" size="6" onfocus="checkInput(this,1)" onblur="checkInput(this,2)" />
                                    <img id="imgVerification" src="/Images/common/loading1.gif" alt="验证码" title="刷新验证码" style="cursor:pointer;" />
                                </td>
                                <td id="VerificationCodeStatus" align="left">&nbsp;</td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                                <td>
                                    <input id="btnSubmitRegister" class="registerbutton" type="button" value="注    册" onclick="submitRegister(this);" />
                                    已有账号，<a href="/Login/default" style="color: blue;">从这里登录</a>
                                </td>
                                <td>&nbsp;</td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <!--foot-->
    <%template:_foot.html%>
</body>
</html>
<script type="text/javascript">
    function id(data) { return document.getElementById(data); }
    function checkResult(idvalue, isError, msg) {
        if (isError) {
            id(idvalue + "Status").innerHTML = "<img src=\"/images/login/redstatus.gif\"/>" + (msg == null ? "" : msg);
            return false;
        }
        else {
            if (id(idvalue).value != "")
                id(idvalue + "Status").innerHTML = "<img src=\"/images/login/greenstatus.gif\"/>";
            else
                id(idvalue + "Status").innerHTML = "";
            return true;
        }
    }
    function inputTips(idvalue, value) {
        id(idvalue + "Status").innerHTML = "<label style=\"color: blue\"><img src=\"/images/login/bluestatus.gif\"/>" + value + "</label>";
        return false;
    }
    function checkInput(obj, v) {
        if (obj.id == "txtAccount") {
            var txtaccount = obj.value;
            if (v == 1) {
                return inputTips(obj.id, "请输入有效账号");
            }
            else {
                if (!Validator.digitLetter(txtaccount)) {
                    return checkResult(obj.id, true, "请输入有效账号");
                }
                else {
                    var exists = false;
                    exists = checkResult(obj.id, false);
                    return exists;
                }
            }
        }
        else if (obj.id == "txtPassword") {
            var txtpassword = obj.value;
            if (v == 1) {
                return inputTips(obj.id, "密码大于6位，由英文字母和数字组成");
            } else {
                if (txtpassword.length < 6 || txtpassword.length > 20)
                    return checkResult(obj.id, true, "密码大于6位，由英文字母和数字组成");
                else
                    return checkResult(obj.id, false);
            }
        }
        else if (obj.id == "txtRepeatPassword") {
            var txtpassword = obj.value;
            if (v == 1) {
                return inputTips(obj.id, "请再次输入你的密码");
            } else {
                if (txtpassword.length < 6 || txtpassword.length > 20 || txtpassword != id("txtPassword").value)
                    return checkResult(obj.id, true, "请再次输入你的密码");
                else
                    return checkResult(obj.id, false);
            }
        }
        else if (obj.id == "VerificationCode") {
            var txtreferrals = obj.value;
            if (v == 1) {
                return inputTips(obj.id, "请填写验证码");
            } else {
                if (txtreferrals.length != 4)
                    return checkResult(obj.id, true, "请填写验证码");
                else
                    return checkResult(obj.id, false);
            }
        }
    }
    var isSubmit = false;
    function submitRegister(obj) {
        isSubmit = true;
        if (!checkInput(id("txtAccount")) || !checkInput(id("txtPassword")) || !checkInput(id("txtRepeatPassword"))) {
            isSubmit = false;
            return false;
        }
        var vaccount = id("txtAccount").value;
        var vpassword = id("txtPassword").value;
        var vvericode = id("VerificationCode").value;
        User.register({ "account": vaccount, "password": vpassword, "code": vvericode }, function (result) {
            if (result.status == "success") {
                Alert("注册成功", function () {
                    window.location.href = "/login/default";
                }); 
            }
            else if (result.error == "code") {
                isSubmit = false;
                Alert("注册失败,原因:验证码错误");
            } else if (result.error == "existsaccount") {
                Alert("注册失败,原因:邮箱已被注册");
            } else {
                isSubmit = false;
                Alert("注册失败,请检查!");
            }
        })
    }
    window.onload = function () {
        RefreshVerification();
    }
</script>
