//$(function(){
//	var _widht = document.documentElement.clientWidth;  //屏幕宽
	var _height = document.documentElement.clientHeight; //屏幕高
//	var boxWidth = $(".phone-find1").width();
	var boxHeight = $(".phone-find1").height();
	$(".phone-find1").css({ top: (_height - boxHeight) / 2 +"px"});
//
//		 
//	});
	var phonePass = false;
	function valPhone(){
		var phoneVal = $("#phone").val();
		if(phoneVal.length == 0){
	        $(".msg1").text("请输入您的手机号码");
	    }else{
        	var hunPhone=/^1[3|4|5|7|8]\d{9}$/;
			if(hunPhone.test(phoneVal.trim())){
				$(".msg1").text("");
				phonePass = true;
			}else{
				phonePass = false;
				$(".msg1").text("手机格式正确,请输入正确的手机号码");
			}
	    }
	}
	var phoneState;
	function sendPhoneCode(){
		valPhone();
		if(phonePass == true){
			$.ajax("/ajax/vcWithRP",{
					type:"GET",
					 async: false,
					success:function(data){ 
						if(data.success){
							if(data.data == null){
								$(".msg2").text("验证码发送失败,请确认手机号码正确!");
							}else{
								phoneState = data.data;
								userRegisterOk();
							}
						}else{

							$(".msg2").text("服务器链接超时!");
							// alert("系统异常!");
						}
					},
					error:function(){$.MsgBox.Alert('message','fail')},
					data:{"mobilePhone":$("#phone").val()},
				 	dataType: 'json'
				});
		}else{
			$.MsgBox.Alert('消息',"请输入正确的手机号码");
		}
	}
	
	//
	function doClick(){
		$('.gain').hide();
	    $('.gainon').show();
	    var clickTime = new Date().getTime();
	    var Timer = setInterval(function(){
	        var nowTime = new Date().getTime();
	        var second  = Math.ceil(60-(nowTime-clickTime)/1000);
	        if(second>0){
	        	$('.gainon').val(second+"s后重新获取");
	        }else{
	            clearInterval(Timer);
	            $('.gain').show();
	    	    $('.gainon').hide();
	        }
	    },1000);
	}
	

	//校验手机验证码
	var codePass = false;
	function valCode(){
		var phoneCode = $("#phoneCode").val();
		if(phoneCode.length==0){
	        $(".msg2").text("请输入验证码");
	    }else{
		    if(!isNaN(phoneCode)){
				codePass = true;
				 $(".msg2").text("");
			}else{
				codePass=false;
				 $(".msg2").text("请填写数字");
			}
	    }
	}

	function submitCodeVal(){
		valPhone();
		valCode();
		if(phonePass == true && codePass == true){
			$.ajax("/ajax/validCode",{
					type:"POST",
					 async: false,
					success:function(data){ 
						if(data.success){
							if(data.data == true){
								location.href="login-phone-find02.html?mobilePhone="+$("#phone").val()+"&vc="+$("#phoneCode").val()+"&state="+phoneState;
							}else{
								$.MsgBox.Alert('消息',"验证码错误!");
								$(".msg3").text("验证码错误");
							}
						}else{

							$(".msg2").text("服务器链接超时!");
							// alert("系统异常!");
						}
					},
					error:function(){$.MsgBox.Alert('message','fail')},
					data:{"vc":$("#phoneCode").val(),"state":phoneState},
				 	dataType: 'json'
				});
		}
	}
	
	//判断账号是否注册
	function userRegisterOk(){
		var loginName= $("#phone").val();
		//console.log(loginName);
		$.ajax("/ajax/isReg?key="+loginName,{
			type:"GET",
			async: true,
			success:function($data){ 
				//console.log($data);
			    if($data.data==true){
			    	 $(".msg1").text("该手机号码未绑定科袖账户");
			    	 return false; 
			    }else{
			    	$.MsgBox.Alert("消息","发送成功,请查看手机验证码!");
					$(".msg2").text("");
			    	doClick();
			    }
			},
			error:function(){
				$.MsgBox.Alert('消息','服务器链接超时')},
			}
		);
	}
	