//蓝色 00a2ff  红色 e1504a
//获得焦点**************************************************************************************
function ThisOnfocus(ObjID)
{
    $(".tc-msg").hide(); //隐藏顶部提示
    var objText = $("#" + ObjID).val();
    //手机号码
    if (ObjID == "reg_phone")
    {
        if ($("#reg_phone").attr("vdata") == "2")
        {
            if (objText == "" || objText == null)
            {
                $("#reg_phone").css("border", "1px solid #e1504a");
                $("#reg_phone_mes").css("color", "#e1504a");
                $("#reg_phone_mes").html("请输入手机号码");
                $("#reg_phone_mes").animate({  lineHeight: "45px"  }, 300);
                return false;
            }
        }
        else
        {
            $("#reg_phone").attr("vdata", "0");
            if (objText == "" || objText == null)
            {
                $("#reg_phone").css("border", "1px solid #00a2ff");
                $("#reg_phone_mes").hide();
                return false;
            }
        }
    }
    //密码
    else if (ObjID == "reg_password")
    {
        if ($("#reg_password").attr("vdata") == "2")
        {
            if (objText == "" || objText == null)
            {
                $("#reg_password").css("border", "1px solid #e1504a");
                $("#reg_password_mes").css("color", "#e1504a");
                $("#reg_password_mes").html("请输入密码");
                $("#reg_password_mes").animate({ lineHeight: "45px" }, 300);
                return false;
            }
        }
        else
        {
            $("#reg_password").attr("vdata", "0");
            if (objText == "" || objText == null)
            {
                $("#reg_password").css("border", "1px solid #00a2ff");
                $("#reg_password_mes").css("color", "#aaa");
                $("#reg_password_mes").html("密码6-20个字符");
                $("#reg_password_mes").animate({  lineHeight: "45px"  }, 300);
                return false;
            }
        }
    }

    //验证码
    else if (ObjID == "reg_yzm")
    {
        if ($("#reg_yzm").attr("vdata") == "2")
        {
            if (objText == "" || objText == null)
            {
                $("#reg_yzm").css("border", "1px solid #e1504a");
                $("#reg_yzm_mes").css("color", "#e1504a");
                $("#reg_yzm_mes").html("请输入手机短信验证码");
                $("#reg_yzm_mes").animate({  lineHeight: "45px"  }, 300);
                return false;
            }
        }
        else
        {
            $("#reg_yzm").attr("vdata", "0");
            if (objText == "" || objText == null)
            {
                $("#reg_yzm").css("border", "1px solid #00a2ff");
                $("#reg_yzm_mes").animate({ height: "0px" }, 100);
                return false;
            }
        }
    }
}
//失去焦点**************************************************************************************
function ThisOnblur(ObjID)
{
    $(".tc-msg").hide(); //隐藏顶部提示
    var objText = $("#" + ObjID).val();
    var isMobile = /^1[3|4|5|7|8|9]\d{9}$/; //手机号码验证规则
    //手机======================================
    if (ObjID == "reg_phone")
    {
        checkmobile();
    }
    //密码======================================
    else if (ObjID == "reg_password")
    {
        $("#reg_password").attr("vdata", "0");
        if (objText == "" || objText == null)
        {
            $("#reg_password").css("border", "1px solid #ddd");
            $("#reg_password_mes").animate({ height: "0px" }, 100);
            return false;
        }
        else if (objText.length < 6 || objText.length > 20)
        {
            $("#reg_password").css("border", "1px solid #e1504a");
            $("#reg_password_mes").css("color", "#e1504a");
            $("#reg_password_mes").html("密码应该为6-20个字符");
            $("#reg_password_mes").animate({  lineHeight: "45px"  }, 300);
            return false;
        }
        else if (!checkRule())
        {
            $("#reg_password").css("border", "1px solid #e1504a");
            $("#reg_password_mes").css("color", "#e1504a");
            $("#reg_password_mes").html("密码至少包含字母、数字、符号中两种");
            $("#reg_password_mes").animate({  lineHeight: "45px"  }, 300);
            return false;
        }
        else
        {
            $("#reg_password_mes").hide();
            $("#reg_password").css("border", "1px solid #ddd");
            $("#reg_password").attr("vdata", "1");
            $("#reg_password_mes").hide();
        }
    }

    //手机验证码======================================
    else if (ObjID == "reg_yzm")
    {
        $("#reg_yzm").attr("vdata", "0");
        if (objText == "" || objText == null)
        {
            $("#reg_yzm").css("border", "1px solid #ddd");
            $("#reg_yzm_mes").animate({ height: "0px" }, 100);
            return false;
        }
        else
        {
            var myReg = /^[0-9]{6,6}$/;
            if (!myReg.test(objText))
            {
                $("#reg_yzm").css("border", "1px solid #e1504a");
                $("#reg_yzm_mes").css("color", "#e1504a");
                $("#reg_yzm_mes").html("请正确输入6位数字验证码");
                $("#reg_yzm_mes").animate({  lineHeight: "45px"  }, 300);
                return false;
            }
            else
            {
                $("#reg_yzm").css("border", "1px solid #ddd");
                $("#reg_yzm").attr("vdata", "1");
                $("#reg_yzm_mes").animate({ height: "0px" }, 100);
            }
        }
    }
}
//内容改变时**************************************************************************************
function ThisOnkeyup(ObjID)
{
    $(".tc-msg").hide(); //隐藏顶部提示
    var objText = $("#" + ObjID).val();
    //手机号码===================
    if (ObjID == "reg_phone")
    {
        $("#reg_phone").css("border", "1px solid #00a2ff"); //蓝色
        $("#reg_phone_mes").animate({ height: "0px" }, 100);
        return false;
    }
    //确认密码===================
    else if (ObjID == "reg_password")
    {
        $("#reg_password").css("border", "1px solid #00a2ff"); //蓝色
        $("#reg_password_mes").css("color", "#aaa");

       
        return false;
    }

    //验证码===================
    else if (ObjID == "reg_yzm")
    {
        $("#reg_yzm").css("border", "1px solid #00a2ff"); //蓝色
        $("#reg_yzm_mes").animate({ height: "0px" }, 100);
        return false;
    }
}

//密码规则**************************************************************************************
function checkRule()
{
    var len = 1;
    var Aq = 0;
    var objpsw = $("#reg_password").val();
    len = objpsw.length;
    if (/[a-zA-Z]/.test(objpsw))
    {
        Aq = Aq + 1;
    }
    if (/[0-9]/.test(objpsw))
    {
        Aq = Aq + 1;
    }
    if (/[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/.test(objpsw))
    {
        Aq = Aq + 1;
    }
    if (Aq > 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function checkmobile(){
	  var objText =$("#reg_phone").val();
      var isMobile = /^1[3|4|5|7|8]\d{9}$/; //手机号码验证规则
	   if (objText == "" || objText == null)
        {
            $("#reg_phone").css("border", "1px solid #ddd");
            $("#reg_phone_mes").hide();
            return false;
        }
        else if (!isMobile.test(objText))
        {
            $("#reg_phone").css("border", "1px solid #e1504a");
            $("#reg_phone_mes").show();
            $("#reg_phone_mes").html("手机号码格式有误，请修改");
            $("#reg_phone_mes").animate({ lineHeight: "45px" }, 300);
            return false;
        }
        else
        {
            $.ajax({
                data: {
                    Mobile: $("#reg_phone").val()
                },
                type: "post",
                dataType: "text",
                url: "/index.php?a=checkphone&c=member&m=member",
                success: function (msg)
                {
                    if (msg == "false")
                    {
						$("#reg_phone").css("border", "1px solid #e1504a");
                        $("#reg_phone_mes").show();
                        $("#reg_phone_mes").html("手机号不存在，请重新输入");
                        $("#reg_phone_mes").animate({ lineHeight:'45px' }, 300);
                        return false;
                    }
                    else
                    {
                        $("#reg_phone").css("border", "1px solid #ddd");
                        $("#reg_phone_mes").hide();
                        $("#reg_phone").attr("vdata", "1"); 
                    }
                }
            })
        }
}

//获取验证码**************************************************************************************
function GetYanzhengma()
{
	if(checkmobile()!=false){
	 $("#buttonYanzhengma").html("正在获取...").attr("disabled", "disabled").css("cursor", "not-allowed").css("background", "#f3a813");
        $.ajax({
            data: {
                Mobile: $("#reg_phone").val() 
            },
            type: "post",
            dataType: "text",
            url: "/index.php?a=editpwdcode&c=sendsms&m=member",
            success: function (msg)
            {
                if (msg == "OK")
                {
                    seconds = 60; //99秒后重新获取
                    objTimer = window.setInterval(redirection, 1000);
                }
				else if (msg == "phonenull")
                { 
                    $("#reg_phone").css("border", "1px solid #e1504a");
                    $("#reg_phone_mes").css("color", "#e1504a");
                    $("#reg_phone_mes").html("获取短信验证码失败：手机号码为空");
                    $("#reg_phone_mes").animate({  lineHeight: "45px"  }, 300);
                    return false;
                }
				 else if (msg == "phoneerror")
                {
                    $("#reg_phone").css("border", "1px solid #e1504a");
                    $("#reg_phone_mes").css("color", "#e1504a");
                    $("#reg_phone_mes").html("获取短信验证码失败：手机号码不正确");
                    $("#reg_phone_mes").animate({  lineHeight: "45px"  }, 300);
                    return false;
                }
             /* else if (msg == "out-of-date")
                {
                    $(".tip-info").html("获取短信验证码失败：安全验证码过期，请刷新当前网页重试");
                    $(".tc-msg").show();
                    return false;
                }
                else if (msg == "phone_exist")
                {
                    $(".tip-info").html("获取短信验证码失败：手机号码已存在");
                    $(".tc-msg").show();
                    return false;
                }
                else if(msg == "phone_notformat")
                {
                    $(".tip-info").html("获取短信验证码失败：手机号码格式不对");
                    $(".tc-msg").show();
                    return false;
                }
                else if (msg == "false")
                {
                    $(".tip-info").html("获取短信验证码失败：安全验证不存在");
                    $(".tc-msg").show();
                    return false;
                }*/
                else
                {
                    $(".tip-info").html("获取短信验证码失败：请刷新当前网页重试");
                    $(".tc-msg").show();
                    return false;
                }
            }
        })
			
			
		}else{

            $("#reg_phone").css("border", "1px solid #e1504a");
            $("#reg_phone_mes").css("color", "#e1504a");
            $("#reg_phone_mes").html("获取短信验证码失败：手机号码不正确");
            $("#reg_phone_mes").animate({  lineHeight: "45px"  }, 300);
            return false;


        }

}

//计时器**************************************************************************************
function redirection()
{
    seconds--;
    $("#buttonYanzhengma").html(seconds + "秒后重新获取");
    $("#buttonYanzhengma").css("color", "#fff");
    if (seconds == 0)
    {
        window.clearInterval(objTimer);
        $("#buttonYanzhengma").html("重新发送验证码").removeAttr("disabled").css("cursor", "pointer").css("background", "#f3a813").css("color", "#fff");
    }
}
//开始注册**************************************************************************************
function findpassword()
{
    if ($("#reg_phone").attr("vdata") != "1")
    {
        $("#reg_phone").attr("vdata", "2");
        $("#reg_phone").focus();
        return false;
    }
    else if ($("#reg_password").attr("vdata") != "1")
    {
        $("#reg_password").attr("vdata", "2");
        $("#reg_password").focus();
        return false;
    }
    else if ($("#reg_yzm").attr("vdata") != "1")
    {
        $("#reg_yzm").attr("vdata", "2");
        $("#reg_yzm").focus();
        return false;
    }
    else
    {
        $("#btnRegister").html("正在修改密码...").attr("disabled", "disabled").css({ "cursor": "not-allowed", "background": "url(/skin_mobile/images/loading_a.gif) 145px 6px #bbb no-repeat" });
        //开始注册
        $.ajax({
            data: {
                mobile: $("#reg_phone").val(),
                pwd: $("#reg_password").val(),
                code: $("#reg_yzm").val(),
				token: $("#safecode").val()
            },
            type: "post",
            dataType: "text",
            url: "/index.php?a=editpwd&c=member&m=member",
            success: function (msg)
            {
                if (msg == "true")
                {
                    window.open('/index.php?a=editpwdok&c=member&m=member', '_self');
                    return false; 
                }
				else if (msg == "phonenull")
                {
                    $("#btnRegister").html("修改密码").removeAttr("disabled").css({ "cursor": "pointer", "background": "#f3a813" }); 
                    $("#reg_phone").css("border", "1px solid #e1504a");
                    $("#reg_phone_mes").css("color", "#e1504a");
                    $("#reg_phone_mes").html("密码找回失败：手机号为空");
                    $("#reg_phone_mes").animate({  lineHeight: "45px"  }, 300);
                    $("#btnRegister").html("找回密码").removeAttr("disabled").css({ "cursor": "pointer", "background": "#f3a813" });    
                    return false;
                }
				else if (msg == "pwdnull")
                {
                    $("#btnRegister").html("找回密码").removeAttr("disabled").css({ "cursor": "pointer", "background": "#f3a813" });
                    $("#reg_password").css("border", "1px solid #e1504a");
                    $("#reg_password_mes").css("color", "#e1504a");
                    $("#reg_password_mes").html("密码找回失败：密码为空");
                    $("#reg_password_mes").animate({  lineHeight: "45px"  }, 300);
                    $("#btnRegister").html("找回密码").removeAttr("disabled").css({ "cursor": "pointer", "background": "#f3a813" });    
                    return false;
                }
                else if (msg == "fail_phone_not_exist")
                {
                    $("#btnRegister").html("找回密码").removeAttr("disabled").css({ "cursor": "pointer", "background": "#f3a813" });
                    $("#reg_phone").css("border", "1px solid #e1504a");
                    $("#reg_phone_mes").css("color", "#e1504a");
                    $("#reg_phone_mes").html("密码找回失败：手机号码不存在");
                    $("#reg_phone_mes").animate({  lineHeight: "45px"  }, 300);
                    $("#btnRegister").html("找回密码").removeAttr("disabled").css({ "cursor": "pointer", "background": "#f3a813" });    
                    return false;
                }
				else if (msg == "token_error")
                {
                    $("#btnRegister").html("找回密码").removeAttr("disabled").css({ "cursor": "pointer", "background": "#f3a813" });
                    $(".tip-info").html("密码找回失败：安全码不正确");
                    $(".tc-msg").show();
                    return false;
                }
                else if (msg == "fail_code_overtime")
                {
                    $("#reg_yzm").css("border", "1px solid #e1504a");
                    $("#reg_yzm_mes").css("color", "#e1504a");
                    $("#reg_yzm_mes").html("验证码已过期，请重新获取");
                    $("#reg_yzm_mes").animate({  lineHeight: "45px"  }, 300);
                    $("#btnRegister").html("找回密码").removeAttr("disabled").css({ "cursor": "pointer", "background": "#f3a813" });
                    return false;
                }
                else if (msg == "fail_verification_code")
                {
                    $("#reg_yzm").css("border", "1px solid #e1504a");
                    $("#reg_yzm_mes").css("color", "#e1504a");
                    $("#reg_yzm_mes").html("验证码错误");
                    $("#reg_yzm_mes").animate({ lineHeight: "45px"  }, 300);
                    $("#btnRegister").html("找回密码").removeAttr("disabled").css({ "cursor": "pointer", "background": "#f3a813" });
                    return false;
                }
                else
                {
                    $("#btnRegister").html("找回密码").removeAttr("disabled").css({ "cursor": "pointer", "background": "#f3a813" });
                    $(".tip-info").html("密码找回失败：出错了，请重试");
                    $(".tc-msg").show();
                    return false;
                }
            }
        })
    }
}