document.onkeydown=function(event){
    var e = event || window.event || arguments.callee.caller.arguments[0];
    if (e && e.keyCode == 13) {
        getpassword();
    } 
}
/**
 * 找回密码验证
 */
function getpassword(){
	var phone=$("#phone").val();
	if(!phone){$.showErr('请输入手机号',0,'hc');return false;}
	
    var regverify=$("#regverify").val();
	if(!regverify){$.showErr('请输入验证码',0,'hc');return false;}
	
    var validPhoneCode=$("#validPhoneCode").val();
	if(!validPhoneCode){$.showErr('请输入短信验证码',0,'hc');return false;}
	
    var query= new Object();
    query = $("form[name='form_getpwd']").serialize();
    $.ajax({
        type: "POST",
        url: APP+"Shop/Register/get_shop",
        data: query,
        success: function(data){
            if(data.status == 1){
				$("#findpwd").hide();
				$("#repwd").show();
				$("input[name='uid']").val(data.uid);
            }else{
				$("#verify_img").click();
                $.showErr(data.info,0,'hc');
            }
        }
    });
}
/**
 * 设置新密码
 */
function resetpwd(){
	var psw=$("input[name='password']").val();
	if(!psw.match(/^[\w]{6,12}$/)){$.showErr('密码格式不正确',0,'hc');return false;}
	
	var repassword=$("input[name='repassword']").val();
	if(psw != repassword){$.showErr('两次密码不一致',0,'hc');return false;}
	
    var query= new Object();
    query = $("form[name='form_repwd']").serialize();
    $.ajax({
        type: "POST",
        url: APP+"Shop/Register/getpwd",
        data: query,
        success: function(data){
            if(data.status == 1){
               $.showSuccess(data.info,0,'hc');
			   window.location.href=data.url;
            }else{
                $.showErr(data.info,0,'hc');
            }
        }
    });
}

var InterValObj; //timer变量，控制时间
var curCount;//当前剩余秒数
function sendMessage() {
	var time = $("#true_time").val();
	var count = parseInt(time); //间隔函数，1秒执行
    curCount = count;
	//设置button效果，开始计时
    var mobile=$('#phone').val();
	if(mobile == ''){$.showErr('手机号不能为空',0,'hc');return false;}
    if(!mobile.match(/^0?1[3|4|5|8][0-9]\d{8}$/)){$.showErr('手机号格式不正确',0,'hc');return false;}
	
    var param="mobile=" + mobile + "&unique= 3" + "&type=" + 2;
	
	//开启注册短信验证
    var sms_reg_verify=$('#sms_reg_verify').val();
    if(sms_reg_verify) {
		var regverify = $('#regverify').val();
		param += "&regverify=" + regverify;
    }
    $.ajax({
        type: "POST",
        dataType: "JSON",
        url: APP+"Home/Ajax/sendsms",
        data:param,
        success:function (data){
        if(data.status==0){
			$("#verify_img").click();
            $.showErr(data.msg,0,'hc');return false;
        }else{
            $("#btnSendCode").removeAttr('onclick');
			$("#btnSendCode").attr('style',"cursor:not-allowed");
            $("#btnSendCode").html(curCount + "s后重新获取");
            InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器，1秒执行一次
        }
    }
});
}
//timer处理函数
function SetRemainTime() {
    if (curCount == 0) {
        window.clearInterval(InterValObj);//停止计时器
		$("#btnSendCode").attr('style',"cursor:pointer;");
		$("#btnSendCode").attr('onclick',"return sendMessage()");
        $("#btnSendCode").removeAttr("disabled");//启用按钮
        $("#btnSendCode").html("获取验证码");
    }else {
        curCount--;
        $("#btnSendCode").html(curCount + "s后重新获取");
    }
}
/**
 * 刷新验证码
 */
function change_img(){
    $("#verify_img").click();
}