jQuery.noConflict();
function forgetPwd(){
    var params = {};
    var step = $('#step').val();
    params.modes = modes;
    params.step = step;
    params.loginName = $.trim($('#loginName').val());
    params.Checkcode = $('#checkCode').val();
    if(params.loginName=='' && step==1){
    	WST.msg('请输入用户名','info');
    	WST.getVerify("#verifyImg1")
    	return;
    }
    params.verifyCode = $('#loginVerfy').val();

    $.post(WST.U('mobile/users/findPass'),params,function(data,textStatus){
      var json = WST.toJson(data);
      if(json.status=='1'){
	        	if(step==1){
		        	location.href=WST.U('mobile/users/forgetPasst');
	        	}else if(step==2){
	        		if(modes==1){
	        			location.href=json.url;
	        		}else{
	        			disabledBtn();
	        		}
	        	}
      }else{
            WST.msg(json.msg,'info');
            WST.getVerify("#verifyImg1")
      }
    });
}

$(function(){
	// 弹出层
   $("#frame").css('top',0);
});

//弹框
function dataShow(type){
	if(type=="email"){
		modes = 0;
		$('#contentTitle').html('通过邮箱找回密码');
		$('.emailBox').show();
		$('.phoneBox').hide();
	}else if(type=="phone"){
		modes = 1;
		$('#contentTitle').html('通过手机找回密码');
		$('.emailBox').hide();
		$('.phoneBox').show();
	}else{
		return;
	}
    jQuery('#cover').attr("onclick","javascript:dataHide();").show();
    jQuery('#frame').animate({"right": 0}, 500);
}
function dataHide(){
    var dataHeight = $("#frame").css('height');
    var dataWidth = $("#frame").css('width');
    jQuery('#frame').animate({'right': '-'+dataWidth}, 500);
    jQuery('#cover').hide();
}



/* 手机找回 */
function forgetPhone(){
	var code = $.trim($('#checkCode').val());
	if(code!=''){
		forgetPwd()
	}else{
		WST.msg('请输入手机校验码','info');
		return false;
	}
}
/* 发送邮箱校验码 */
function forgetEmail(){
	modes = 0;
	var code = $.trim($('#loginVerfy').val());
	if(code != ''){
		forgetPwd();
	}else{
		WST.msg('请输入验证码','info');
		return false;
	}	
}
/* 提交邮箱验证码-重置密码 */
function resetByEmail(){
	var code = $.trim($('#emailCode').val());
	if(code == ''){
		WST.msg('请输入校验码','info');
		return false;
	}else{
		$.post(WST.U('mobile/users/forgetPasss'),{secretCode:code},function(data){
			var json = WST.toJson(data);
			if(json.status==-1){
				WST.msg('校验码错误','info');
				WST.getVerify("#verifyImg1")
				return false;
			}else{
				location.href=WST.U('mobile/users/resetPass');
			}
		})
	}	
}

/*重置密码*/
function resetPwd(){
	var params = {};
	params.step = $('#step').val();
	params.loginPwd = $('#loginPwd').val();
	params.repassword = $('#repassword').val();
	$.post(WST.U('mobile/users/findPass'),params,function(data){
		var json = WST.toJson(data);
		if(json.status==1){
			WST.msg('重置成功');
			setTimeout(function(){
				location.href=WST.U('mobile/users/index');
			},1000)
		}else{
			WST.msg(json.msg,'info');
			return false;
		}
	})
}



var modes = '';

/** 校验码 **/
function phoneVerify2(){
	if(!$('#smsVerify').val()){
		WST.msg('请输入验证码','info');
		return false;
	}

	modes = $('#modes').val();
	var time = 0;
	var isSend = false;
	var smsVerfy = $('#smsVerify').val();
	$.post(WST.U('mobile/users/getfindPhone'),{smsVerfy:smsVerfy},function(data,textStatus){
		var json = WST.toJson(data);
		if(isSend )return;
		isSend = true;
		if(json.status!=1){
			WST.msg(json.msg, 'info');
			WST.getVerify('#verifyImg2');
			time = 0;
			isSend = false;
		}if(json.status==1){
			WST.msg('短信已发送，请注册查收');
			time = 120;
			$('#timeObtain').attr('disabled', 'disabled');
			$('#timeObtain').html('重新发送(120)');
			var task = setInterval(function(){
				time--;
				$('#timeObtain').html('重新发送('+time+")");
				if(time==0){
					isSend = false;						
					clearInterval(task);
					$('#timeObtain').html("重新获取");
					$('#timeObtain').removeAttr('disabled');
				}
			},1000);
		}
	});
}
function disabledBtn(){
	time = 120;
	$('#emailBtn').attr('disabled', 'disabled');
	$('#emailBtn').html('发送验证邮件(120)');
	var task = setInterval(function(){
		time--;
		$('#emailBtn').html('重新发送('+time+")");
		if(time==0){
			isSend = false;						
			clearInterval(task);
			$('#emailBtn').html("发送验证邮件");
			$('#emailBtn').removeAttr('disabled');
		}
	},1000);
}