<!--{assign var="menu_id" value=""}-->
<!--{include file="<!--{$oetplpath}-->block_header.tpl"}-->
<div class="oe_ntop">
  <i class="iconfont" onclick="goBack();">&#xe616;</i>
  <p>找回密码</p>
</div>
<div class="oe_reg">
  <h2>请输入您注册时填写的邮箱或者手机，我们将发送密码找回的验证码到您的邮箱或者手机上</h2>
  <div class="oe_regtype">
    <span class="current" f="forget_type" data-type="2">手机取回</span><span f="forget_type" data-type="1">邮箱取回</span>
  </div>
  <div class="oe_input">
    <div class="oe_regcn">
      <dl id="put_mobile">
        <dt>手 机</dt>
        <dd>
          <input type="text" name="mobile" id="mobile" placeholder="输入手机号码" maxlength="11" />
        </dd>
      </dl>
      <dl id="put_email" style="display:none;">
        <dt>邮 箱</dt>
        <dd>
          <input type="text" name="email" id="email" placeholder="输入注册邮箱" />
        </dd>
      </dl>
      <dl>
        <dt>验证码</dt>
        <dd>
          <input type="text" name="validcode" id="validcode" class="checkcode" placeholder="输入验证码" maxlength="6" />
          <em id="forget-sendbtn">获取验证码</em> </dd>
      </dl>
      <dl>
        <dt>新密码</dt>
        <dd>
          <input type="password" name="password" id="password" placeholder="设置6-16个字符的新密码" />
        </dd>
      </dl>
    </div>
    <div class="oe_button">
      <input type="hidden" name="gettype" id="gettype" value="2" />
      <p id="tips_post"></p>
      <span id="btn_setnew">取回密码</span>
	</div>
  </div>
</div>
<script type="text/javascript">
$(function(){
	$tips_obj = $("#tips_post");

    $max_widths = (WIN_WIDTH-120);
    $(".oe_input dl dd input").css({"width":$max_widths});
    $(".oe_reg dl dd input.checkcode").css({"width":$max_widths-120});
	
	//取回方式
	$("[f='forget_type']").bind("click", function(){
		$_type = $(this).attr("data-type");
		$("#gettype").val($_type);
		$(".oe_regtype span").removeClass("current");
		$(this).addClass("current");

		if ($_type == "2") {
			$("#put_mobile").show();
			$("#put_email").hide();
		}
		else {
			$("#put_mobile").hide();
			$("#put_email").show();
		}
	});

	//发送验证码
	$("#forget-sendbtn").click(function(){
		$type = $("#gettype").val();

		if ($type == "1") { //邮箱
			$name = $("#email").val();
			if ($name.length == 0) {
				$tips_obj.html("<font color='red'>请输入注册邮箱</font>");
				return false;
			}
		}
		else { //手机
			$name = $("#mobile").val();
			if ($name.length == 0) {
				$tips_obj.html("<font color='red'>请输入手机号码</font>");
				return false;
			}
		}
		$("#forget-sendbtn").html("发送中...");
		$tips_obj.html("");

		$.ajax({
			type: "POST",
			url: WAP_APPFILE + "&c=passport",
			cache: false,
			data: {a:"sendforget", type:$type, name:$name, r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
				    if ($type == 1) { //邮箱
						ToastShow("验证码已发送到您的邮箱，请查收。");
					}
					else { //手机
						ToastShow("验证码已发送您的手机，请查收。");
					}
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("发送失败，请检查输入是否正确。");
					}
				}
				$("#forget-sendbtn").html("获取验证码");

			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
				$("#forget-sendbtn").html("获取验证码");
			}
		});

	});


	$("#btn_setnew").click(function(){ //设置新密码
		$type = $("#gettype").val();
		if ($type == 1) { //邮箱
			$name = $("#email").val();
			if ($name.length == 0) {
				$tips_obj.html("<font color='red'>请输入注册邮箱</font>");
				return false;
			}
		}
		else { //手机
			$name = $("#mobile").val();
			if ($name.length == 0) {
				$tips_obj.html("<font color='red'>请输入手机号码</font>");
				return false;
			}
		}
		
		$validcode = $("#validcode").val();
		if ($validcode.length == 0) {
			$tips_obj.html("<font color='red'>请输入验证码</font>");
			return false;
		}
		$password = $("#password").val();
		if ($password.length < 6 || $password.length > 16) {
			$tips_obj.html("<font color='red'>请输入6-16位的新密码</font>");
			return false;
		}
		$tips_obj.html("");
		$.ajax({
			type: "POST",
			url: WAP_APPFILE + "&c=passport",
			cache: false,
			data: {a:"setpassword", type:$type, name:$name, validcode:$validcode, password:$password, r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					ToastShow("取回密码成功");
					setTimeout(function(){
						window.location.href = WAP_APPFILE + "&c=passport&a=login"
					}, 500);
				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("取回密码失败");
					}
				}

			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
			}
		});

	});


});
</script>
</body></html>