<%@ page language="C#" masterpagefile="~/MasterPage/MyspaceMasterPage.master" autoeventwireup="true" inherits="User_Member_MemberQuestion, DoodiiShop" title="Untitled Page" enableEventValidation="false" viewStateEncryptionMode="Never" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <script type="text/javascript">
 $(document).ready( function(){ init() });
    var init = function() {
        bindEvents();
        reset1();
    }
    var bindEvents = function() {
        $("#tbOldPwd").bind("blur", function(){ validatePassword(this) });
        $("#tbQuestion").bind("blur", function(){ validateQuestion(this) });
        $("#tbKey").bind("blur", function(){ validateKey(this) });
    }
    var validatePassword = function(objDom) {
        var txt = objDom.value;
        if ( txt.length < 6 || txt.length > 17 ) {
            $(objDom).next().attr("class", "MessageError");
            $(objDom).next().html("密码长度不符，请重新输入。");
            return false;
        } else {
            $(objDom).next().attr("class", "MessageRight");
            $(objDom).next().html("√");
            return true;
        }
    }
     var validateQuestion= function(objDom) {
        var txt = objDom.value;
        if (txt.length>30 || txt.length<1)
        {
            $(objDom).next().attr("class", "MessageError");
            $(objDom).next().html("您的问题长度不符！");
            return false;
        }
        else
        {
            $(objDom).next().attr("class", "MessageRight");
            $(objDom).next().html("√");
            return true;
        }
       
    }
      var validateKey= function(objDom) {
        var txt = objDom.value;
        if (txt.length>30 || txt.length<1)
        {
            $(objDom).next().attr("class", "MessageError");
            $(objDom).next().html("您的答案长度不符！");
            return false;
        }
        else
        {
            $(objDom).next().attr("class", "MessageRight");
            $(objDom).next().html("√");
            return true;
        }
       
    }
    var validateForm = function() {
        if ( !validateQuestion( document.getElementById("tbQuestion") ) ) return false;
        if ( !validateKey( document.getElementById("tbKey") ) ) return false;
        return true;
    }
    function saveForm() {
        if ( !validateForm() ) {
            return;
        }
        var OldPwd = $("#tbOldPwd").val();
        var Question= $("#tbQuestion").val();
        var Key = $("#tbKey").val();
        var ret = User_Member_MemberQuestion.ChangeQuestion(OldPwd,Question,Key).value;
        if ( ret == "0" )
            alert("修改成功！");
        else
            alert("发生错误:" + ret);
    }
    function next()
    {
        if ( !validatePassword( document.getElementById("tbOldPwd") ) ) return;
        var OldPwd = $("#tbOldPwd").val();
        var ret=User_Member_MemberQuestion.validatePwd(OldPwd).value;
        if ( ret == "0" )
           { $("#divP").hide();
            $("#divQ").show();}
        else
            alert("原密码不正确！");
    }
    function reset1()
    {
        var ret=User_Member_MemberQuestion.GetInfo().value;
        $("#tbQuestion").val(ret.Question);
        $("#tbKey").val(ret.Key);
    }
    </script>

    <style type="text/css">
    .MessageError {
        color:#f00;
    }
    .MessageRight {
        color:#090;
    }
     #PasswordCenter {
        width:400px;
        margin:0px auto;
    }</style>
    <div id="divP">
        <table>
            <tr>
                <td>输入原密码：</td>
                <td><input id="tbOldPwd" type="password" maxlength="17" onpaste="return false" />
        <span class="KcAttentionFont">6-17位字符。</span>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <a id="btnNext" class="Style_Input2" href="javascript:next()">下一步</a>
                </td>
            </tr>
        </table>
    </div>
    <div id="divQ" style="display:none;">
        <table class="MyTable" width="100%" border="0" cellpadding="1" cellspacing="1">
            <tr>
                <td class="htd">
                    问题：
                </td>
                <td class="rtd">
                    <input id="tbQuestion" type="text" maxlength="50" /><span class="KcAttentionFont">您可以自定义一个问题。</span>
                </td>
            </tr>
            <tr>
                <td class="htd">
                    回答：
                </td>
                <td class="rtd">
                    <input id="tbKey" type="text" maxlength="50" /><span class="KcAttentionFont">自定义问题的答案。</span>
                </td>
            </tr>
            <tr>
                <td style="padding:10px 0px;" colspan="2">
                    <a class="Style_Input2" id="btnSubmit" href="javascript:saveForm()" style="float:left; margin-left:190px; display:inline;">提&nbsp;交</a>
                    <a class="Style_Input3" id="Button1" href="javascript:reset1()" style="float:left; margin-left:20px; display:inline;">还&nbsp;原</a>
                </td>
            </tr>
        </table>
    </div>
</asp:Content>
