<#-- 找回密码第二步 -->
<!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>
	<base href="${baseURL}">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>找回密码 - ${title}</title>
	<meta name="keywords" content="${keywords}"/>
	<meta name="description" content="${description}"/>
	<link rel="shortcut icon" type="image/x-icon" href="${baseURL}${commonPath}images/favicon.ico" media="screen" />
	<link href="${commonPath}css/common.css" type="text/css" rel="stylesheet" >
	<link href="${commonPath}css/themify-icons/style.css" type="text/css" rel="stylesheet">
	<script language="javascript" src="${commonPath}js/tool.js" type="text/javascript"></script>
	<script language="javascript" src="${commonPath}js/ajax.js" type="text/javascript"></script>
	<script language="javascript" src="${commonPath}js/json2.js" type="text/javascript"></script>
	<script src="${commonPath}js/cryptoJS/core.js" language="javascript" type="text/javascript"></script>
	<script src="${commonPath}js/cryptoJS/sha256.js" language="javascript" type="text/javascript"></script>
	<script type="text/javascript" src="${commonPath}js/jquery/jquery.min.js" language="javascript"></script>
	<link href="${commonPath}js/layer/skin/default/layer.css"  type="text/css" rel="stylesheet"/>
	<script type="text/javascript" src="${commonPath}js/layer/layer.js" language="javascript"></script>
</head>

<body>
<#-- 引入页头 -->
<@include action="${newPublic_2}"/>
<div class="skeleton">
	<div class="main wrap backgroundModule" >
		<div style="background: #fff; height: 1px;"></div>
		<div class="findPassWordModule" >
			<!-- 令牌标记 -->
			<input type="hidden" id="token" name="token" value="${token}">
        	<div class="title">
        		<#if user.type == 10>
	        		<span id="local_tab">校验密码提示答案</span>
	        	</#if>
	        	<#if user.type == 20>
	        		<span id="mobile_tab">校验手机号码</span>
	        	</#if>
        	</div>
        	
        	<div class="box">
        		<div class="form">
	        		<div class="form-field" >
		        		<div id="account_field_error" class="form-field-container">
			        		<div class="form-field-radio">
			        			<div class="form-field-radio-container">
				        			<div class="form-field-radio-input">
				        				<div>${user.account}</div>
				        				<label class="form-field-label form-field-active">账号</label>
				        			</div>
			        			</div>
			        		</div>
		        		</div>
		        	</div>
		        	<div class="form-field" >
		        		<div id="mobile_field_error" class="form-field-container">
			        		<div class="form-field-radio">
			        			<div class="form-field-radio-container">
				        			<div class="form-field-radio-input">
				        				<div>${url_mobile}</div>
				        				<label class="form-field-label form-field-active">手机号</label>
				        			</div>
			        			</div>
			        		</div>
		        		</div>
		        	</div>
		        	<div class="form-field" >
		        		<div id="issue_field_error" class="form-field-container">
			        		<div class="form-field-radio">
			        			<div class="form-field-radio-container">
				        			<div class="form-field-radio-input">
				        				<div>${user.issue}</div>
				        				<label class="form-field-label form-field-active">密码提示问题</label>
				        			</div>
			        			</div>
			        		</div>
		        		</div>
		        	</div>
	        		<div class="form-field" >
		        		<div id="answer_field_error" class="form-field-container">
			        		<div class="form-field-text">
			        			<div class="form-field-input-container">
				        			<input id="answer" maxLength="30" class="form-field-text-input" type="text" value="" onfocus="inputBoxClickTip(this);" onblur="inputBoxOutTip(this);">
				        			<label class="form-field-label">密码提示答案</label>
			        			</div>
			        		</div>
		        			<div id="answer_prompt_error" class="form-field-prompt-error"></div>
		        		</div>
		        	</div>
		        	<div class="form-field" >
		        		<div id="password_field_error" class="form-field-container">
			        		<div class="form-field-text">
			        			<div class="form-field-input-container">
				        			<input id="password" maxLength="20" class="form-field-text-input" type="password" value="" onfocus="inputBoxClickTip(this);" onblur="inputBoxOutTip(this);">
				        			<label class="form-field-label">新密码</label>
			        			</div>
			        		</div>
		        			<div id="password_prompt_error" class="form-field-prompt-error"></div>
		        		</div>
		        	</div>
		        	<div class="form-field" >
		        		<div id="confirmPassword_field_error" class="form-field-container">
			        		<div class="form-field-text">
			        			<div class="form-field-input-container">
				        			<input id="confirmPassword" maxLength="20" class="form-field-text-input" type="password" value="" onfocus="inputBoxClickTip(this);" onblur="inputBoxOutTip(this);">
				        			<label class="form-field-label">确认密码</label>
			        			</div>
			        		</div>
		        			<div id="confirmPassword_prompt_error" class="form-field-prompt-error"></div>
		        		</div>
		        	</div>
		        	<div class="form-field" >
		        		<div id="smsCode_field_error" class="form-field-container">
			        		<div class="form-field-text">
			        			<div class="form-field-input-container">
				        			<input id="smsCode" maxLength="6" class="form-field-text-input" type="text" value="" onfocus="inputBoxClickTip(this);" onblur="inputBoxOutTip(this);">
				        			<label class="form-field-label">短信验证码</label>
			        			</div>
			        			<div class="form-field-button-container">
							    	<button type="button" class="btn btn-link" tabindex="-1" onClick="getSmsCode();">获取验证码</button>
							    </div>
			        		</div>
		        			<div id="smsCode_prompt_error" class="form-field-prompt-error"></div>
		        			<div id="smsCode_prompt_successInfo" class="form-field-prompt-success"></div>
		        		</div>
		        	</div>
		        	<div id="captchaValue_field" class="form-field">
			        	<div id="captchaValue_field_error" class="form-field-container">
			        		<div class="form-field-text">
					        	<div class="form-field-input-container">
						        	<input type="hidden" id="captchaKey" name="captchaKey" value="${captchaKey}">
						        	<input id="captchaValue" class="form-field-text-input" type="text" maxlength="4" value="" onfocus="inputBoxClickTip(this);" onblur="inputBoxOutTip(this);">
						        	<label class="form-field-label">验证码</label>
								</div>
						        <div class="form-field-image-container">
									<img id="captcha" src="captcha/${captchaKey!}.jpg" onClick="replaceCaptcha();" tabindex="4" />
									
						        </div>
						        <div class="form-field-button-container" style="background: #fff;">
						        	<button type="button" class="btn btn-link" tabindex="-1" onClick="replaceCaptcha();">换一幅</button>
						        </div>
						    </div>
						    <div id="captchaValue_prompt_error" class="form-field-prompt-error"></div>
						</div>
		        	</div>
	        	</div>
        	</div>
        	<div id="token_prompt_error" style="color: red;">${(error['token'])!}</div>
        	<div id="user_prompt_error" style="color: red;">${(error['user'])!}</div>
			<div id="account_prompt_error" style="color: red;">${(error['account'])!}</div>
       		<div class="submitButton-box">
				<a href="javascript:void(0);" onClick="javascript:ajaxSubmit()" tabindex="6">提&nbsp;交</a>
			</div>
		</div>
	
	</div>
</div>
<#--引入页脚-->
<@include action="${newPublic_3}"/>

<script language="javascript" type="text/javascript">
	$(".form-field").find(".form-field-input-container").bind("mousedown",function(e) {
		$(this).find(".form-field-text-input").focus();
		
		if($(this).find(".form-field-label").hasClass("form-field-active")){
			return;
		
		}
		$(this).find(".form-field-label").addClass("form-field-active");
	});
	
	$(document).mousedown(function (e) {
        var target = $(e.target);
        if (target.closest(".form-field-input-container").length == 0) {
            $(".form-field-input-container").each(function(){
			    if($(this).find(".form-field-label").hasClass("form-field-active")){
					if($(this).find('input[type="text"]').val() == "" || $(this).find('input[type="password"]').val() == ""){
						$(this).find(".form-field-label").removeClass("form-field-active");
					}
					
				}
			});
        }
    });
    //文本框含有默认值时字段名称缩小
	$(document).ready(function(){
		$(".form-field-input-container").each(function(){
		    if(!$(this).find(".form-field-label").hasClass("form-field-active")){
				if(($(this).find('input[type="text"]').val() != undefined && $(this).find('input[type="text"]').val() != '') 
					|| $(this).find('input[type="password"]').val() != undefined && $(this).find('input[type="password"]').val() != ''){
					$(this).find(".form-field-label").addClass("form-field-active");
				}
				
			}
		});
	});
	
	
	//监听Tab键
    $(document).on('keyup',function (e) {
	    if(e.keyCode == 9){
	    	var input = $(this).find('input:focus');
	    	if (input.length) {
		    	if(!input.parent().parent().find(".form-field-label").hasClass("form-field-active")){
					input.parent().parent().find(".form-field-label").addClass("form-field-active");
				}
		    }
		}
	});
    //解决提交按钮的click和blur事件冲突
	$(document).ready(function(){
		$("input[type='button']").mousedown(function(e){
	    	e.preventDefault();
		});
		$("a[href='javascript:void(0);']").mousedown(function(e){
	    	e.preventDefault();
		});
		
	});

</script>

<script language="javascript" type="text/javascript">
	//选择账号类型
	$(document).ready(function(){
		//选择
		$(".title").each(function(){
			selectAccountType($(this).find("span").attr("id"));
		});
	});

	function selectAccountType(id){
		if(id == "local_tab"){//本地账号密码用户
			$("#account_field_error").parent().show();
			$("#mobile_field_error").parent().hide();
			$("#issue_field_error").parent().show();
			$("#answer_field_error").parent().show();
			$("#smsCode_field_error").parent().hide();
		}
		if(id == "mobile_tab"){//手机用户
			$("#account_field_error").parent().hide();
			$("#mobile_field_error").parent().show();
			$("#issue_field_error").parent().hide();
			$("#answer_field_error").parent().hide();
			$("#smsCode_field_error").parent().show();
		}
	}
	
	//点击输入框提示
	function inputBoxClickTip(obj){
	
	
	}
	//离开输入框提示
	function inputBoxOutTip(obj){
		verification(obj.id);
	}
	
	//验证参数
	function verification(field){
		$("#"+field+"_prompt_error").hide();
		$("#"+field+"_field_error").removeClass("form-field-error");
		
		if(field == "password"){//密码
			var password = $("#"+field).val().trim();
			if(password == ""){
				$("#"+field+"_prompt_error").html("密码不能为空");
				$("#"+field+"_prompt_error").show();
				$("#"+field+"_field_error").addClass("form-field-error");
				return false;
			}
			if(getStringLeng(password) < 6){
				$("#"+field+"_prompt_error").html("密码长度不能小于6位");
				$("#"+field+"_prompt_error").show();
				$("#"+field+"_field_error").addClass("form-field-error");
				return false;
			}
			if(getStringLeng(password) > 20){
				$("#"+field+"_prompt_error").html("密码长度不能大于20位");
				$("#"+field+"_prompt_error").show();
				$("#"+field+"_field_error").addClass("form-field-error");
				return false;
			}
		}
		if(field == "confirmPassword"){//确认密码
			var confirmPassword = $("#"+field).val().trim();
			if(confirmPassword == ""){
				$("#"+field+"_prompt_error").html("确认密码不能为空");
				$("#"+field+"_prompt_error").show();
				$("#"+field+"_field_error").addClass("form-field-error");
				return false;
			}
			
			var password = $("#password").val().trim();
			if(confirmPassword != password){
				$("#"+field+"_prompt_error").html("两次密码不相等");
				$("#"+field+"_prompt_error").show();
				$("#"+field+"_field_error").addClass("form-field-error");
				return false;
			}
		}
		if(field == "answer"){//密码提示答案
			var answer = $("#"+field).val().trim();
			if(answer == ""){
				$("#"+field+"_prompt_error").html("提示答案不能为空");
				$("#"+field+"_prompt_error").show();
				$("#"+field+"_field_error").addClass("form-field-error");
				return false;
			}
			if(getStringLeng(answer) < 6){
				$("#"+field+"_prompt_error").html("提示答案长度不能小于6位");
				$("#"+field+"_prompt_error").show();
				$("#"+field+"_field_error").addClass("form-field-error");
				return false;
			}
			if(getStringLeng(answer) > 30){
				$("#"+field+"_prompt_error").html("提示答案长度不能大于30位");
				$("#"+field+"_prompt_error").show();
				$("#"+field+"_field_error").addClass("form-field-error");
				return false;
			}
		}

		if(field == "smsCode"){//手机验证码
			var smsCode = $("#"+field).val().trim();
			if(smsCode == ""){
				$("#"+field+"_prompt_error").html("手机验证码不能为空");
				$("#"+field+"_prompt_error").show();
				$("#"+field+"_field_error").addClass("form-field-error");
			}
		}
		if(field == "captchaValue"){//验证码
			if(!$("#captchaValue_field").is(":hidden")){//如果验证码框显示
				var captchaKey = $("#captchaKey").val().trim();
				var captchaValue = $("#"+field).val().trim();
				if(captchaValue == ""){
					$("#"+field+"_prompt_error").html("验证码不能为空");
					$("#"+field+"_prompt_error").show();
					$("#"+field+"_field_error").addClass("form-field-error");
					return false;
				}
				
				get_request(function(value){
	            	if(value == "false"){
	            		$("#"+field+"_prompt_error").html("验证码错误");
						$("#"+field+"_prompt_error").show();
						$("#"+field+"_field_error").addClass("form-field-error");
	            	}
	            },
			 		"userVerification?captchaKey="+captchaKey+"&captchaValue="+captchaValue+"&timestamp=" + new Date().getTime(), true);
	            	
			}
		}
	}
	//更换验证码
	function replaceCaptcha(){
		var captchaKey = document.getElementById("captchaKey").value;
		document.getElementById("captcha").src = "captcha/"+captchaKey+".jpg?" + Math.random(); 
	}
	
	//组装参数
	function getParameter(){
		var parameter = "";
		
		//令牌标记
		var token = $("#token").val();
		parameter += "&token="+token;
		
		//验证码Key
		parameter += "&captchaKey="+encodeURIComponent($("#captchaKey").val());
		
		//验证码值
		parameter += "&captchaValue="+encodeURIComponent($("#captchaValue").val());

		//用户类型
		if($(".title").find("span").attr("id") =="local_tab"){
			parameter += "&type=10";
			
		}
		if($(".title").find("span").attr("id") =="mobile_tab"){
			parameter += "&type=20";
		}
		
		//用户名
		parameter += "&userName="+encodeURIComponent(getUrlParam("userName"));
			
		//密码需SHA256加密
		var password = $("#password").val().trim();
		if(password != ""){
			parameter += "&password="+ CryptoJS.SHA256(password);
		}
		
		//密码提示答案需SHA256加密
		var answer = $("#answer").val().trim();
		if(answer != ""){
			parameter += "&answer="+ CryptoJS.SHA256(answer);
		}
		
		//手机验证码
		var smsCode = $("#smsCode").val().trim();
		if(smsCode != ""){
			parameter += "&smsCode="+encodeURIComponent(smsCode);
		}

		
		return parameter;
	}
	
	//验证全部参数
	function allVerification(){
		var isVerification = true;
		
		if($(".title").find("span").attr("id") =="local_tab"){
			if(verification("password") == false){
				isVerification = false;
			}
			if(verification("confirmPassword") == false){
				isVerification = false;
			}
			if(verification("answer") == false){
				isVerification = false;
			}
			if(verification("captchaValue") == false){
				isVerification = false;
			}
		}
		if($(".title").find("span").attr("id") =="mobile_tab"){
			if(verification("password") == false){
				isVerification = false;
			}
			if(verification("confirmPassword") == false){
				isVerification = false;
			}
		}
		return isVerification;
	}
	//ajax提交
	function ajaxSubmit(){
		if(allVerification() == false){
			//需引入layer
     		layer.msg('请填好资料再提交', {
				time: 3000 //3秒关闭（如果不配置，默认是3秒）
				},function(){//关闭后的操作
						
				}
			);
			return;
		}
		
		var parameter = getParameter();
		if(parameter.indexOf("&") == 0){
			parameter = parameter.substring(1,parameter.length);
		}
		post_request(function(value){
			if(value != ""){
				var returnValue = JSON.parse(value);//JSON转为对象
				for(var key in returnValue){
					if(key == "success"){	
						var success = returnValue[key];	
						if(success == "true"){
							layer.msg('找回密码成功，3秒后自动跳转', {
								time: 3000 //3秒关闭（如果不配置，默认是3秒）
								},function(){//关闭后的操作
									//跳转到登录页
									window.location.href = getBasePath()+"login";
								}
							);
							
						}
					}else if(key == "error"){
						var errorValue = returnValue[key];
						for(var error in errorValue){
							if(error != ""){
								$("#"+error+"_prompt_error").html(errorValue[error]);
								$("#"+error+"_prompt_error").show();
								$("#"+error+"_field_error").addClass("form-field-error");	
							}
						}
					}else if(key == "captchaKey"){//显示验证码	
						var captchaKey = returnValue[key];
						if(captchaKey != ""){
							$("#captchaValue_field").show();
							//设置验证码Key
							$("#captchaKey").val(captchaKey);
							
							//设置验证码图片
							replaceCaptcha();
						}
					}
				}
				
			}	
		},
			"findPassWord/step2?&timestamp=" + new Date().getTime(), true,parameter);
	}
	//获取短信验证码
	function getSmsCode(){
	
		if($("#smsCode_field_error").find("button").hasClass("btn-link-disabled")){
			return;
		}
	
		var parameter = "";
		//令牌标记
		var token = $("#token").val();
		parameter += "&token="+token;
		
		//模块
		parameter += "&module=300";
		
		parameter += "&mobile="+encodeURIComponent(getUrlParam("mobile"));
		
		
		//验证码Key
		parameter += "&captchaKey="+encodeURIComponent($("#captchaKey").val());
		
		//验证码值
		parameter += "&captchaValue="+encodeURIComponent($("#captchaValue").val());
		
		if(parameter.indexOf("&") == 0){
			parameter = parameter.substring(1,parameter.length);
		}
		
		//清除错误信息
		$("#smsCode_prompt_error").html("");
		$("#smsCode_prompt_error").hide();
		$("#smsCode_field_error").removeClass("form-field-error");
		
		$("#smsCode_prompt_successInfo").html("");
		$("#smsCode_prompt_successInfo").hide();
		

		
		post_request(function(value){
			if(value != ""){
				var returnValue = JSON.parse(value);//JSON转为对象
				var success = "false";
				
				for(var key in returnValue){
					if(key == "success"){	
						var success = returnValue[key];
						if(success == "true"){
							$("#smsCode_prompt_successInfo").html("短信验证码已发送");
							$("#smsCode_prompt_successInfo").show();
							//隐藏提交按钮60秒
							var number = 60;//秒
							var countdown = function(){
								if (number == 0) {
									$("#smsCode_field_error").find("button").removeClass("btn-link-disabled");
									$("#smsCode_field_error").find("button").addClass("btn-link");
									$("#smsCode_field_error").find("button").text("获取验证码");
						            number = 60;
						            return;
						        } else {
						        	if($("#smsCode_field_error").find("button").hasClass("btn-link")){
										$("#smsCode_field_error").find("button").removeClass("btn-link");
										$("#smsCode_field_error").find("button").addClass("btn-link-disabled");
									}
									$("#smsCode_field_error").find("button").text(number + "秒后没收到可重新获取");
						        	number--;
						        }
								setTimeout(countdown,1000);
							}
							setTimeout(countdown,0);
								
						}		
					}else if(key == "error"){
						var errorValue = returnValue[key];
						for(var error in errorValue){
							if(error != ""){
								$("#"+error+"_prompt_error").html(errorValue[error]);
								$("#"+error+"_prompt_error").show();
								$("#"+error+"_field_error").addClass("form-field-error");
									
							}
						}
					}else if(key == "captchaKey"){//显示验证码	
						var captchaKey = returnValue[key];
						if(captchaKey != ""){
							//设置验证码Key
							$("#captchaValue_field").show();
							//设置验证码Key
							$("#captchaKey").val(captchaKey);
							//设置验证码图片
							replaceCaptcha();
						}
					}
				}
			}	
		},
			"smsCode?&timestamp=" + new Date().getTime(), true,parameter);
	}
</script>	





</body></html>