//蓝色 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;
            }
        }
    }
    if (ObjID == "reg_email")
    {
        if ($("#reg_email").attr("vdata") == "2")
        {
            if (objText == "" || objText == null)
            {
                $("#reg_email").css("border", "1px solid #e1504a");
                $("#reg_email_mes").css("color", "#e1504a");
                $("#reg_email_mes").html("请输入手机号码");
                $("#reg_email_mes").animate({ lineHeight: "45px"  }, 300);
                return false;
            }
        }
        else
        {
            $("#reg_email").attr("vdata", "0");
            if (objText == "" || objText == null)
            {
                $("#reg_email").css("border", "1px solid #00a2ff");
                $("#reg_email_mes").hide(); 
                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]\d{9}$/; //手机号码验证规则
    //手机======================================
    if (ObjID == "reg_phone")
    {
        checkmobile();
    }
    if (ObjID == "reg_email")
    {
        checkemail();
    }
    //手机验证码======================================
    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").hide();
        return false;
    }else if (ObjID == "reg_email")
    {
        $("#reg_email").css("border", "1px solid #00a2ff"); //蓝色
        $("#reg_email_mes").hide();
        return false;
    }
    //验证码===================
    else if (ObjID == "reg_yzm")
    {
        $("#reg_yzm").css("border", "1px solid #00a2ff"); //蓝色
        $("#reg_yzm_mes").animate({ height: "0px" }, 100);
        return false;
    }
}

function checkmobile(){
	  var objText =$("#reg_phone").val();
      var isMobile = /^1[3|4|5|6|7|8|9]\d{9}$/; //手机号码验证规则
	   if (objText == "" || objText == null)
        {
            $("#reg_phone").css("border", "1px solid #e1504a");
            mui.toast("手机号码为空",{type:'div'}); 
            return false;
        }
        else if (!isMobile.test(objText))
        {
            $("#reg_phone").css("border", "1px solid #e1504a");
            mui.toast("手机号码格式有误，请修改",{type:'div'}); 
            return false;
        }
        else
        {
            $("#reg_phone").css("border", "1px solid #ddd");
            $("#reg_phone_mes").hide();
            $("#reg_phone").attr("vdata", "1");
        }
}


function checkemail(){
    var objText =$("#reg_email").val();
    var isEmail = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
     if (objText == "" || objText == null)
      {
          $("#reg_email").css("border", "1px solid #e1504a");
          mui.toast("邮箱号码为空",{type:'div'}); 
          return false;
      }
      else if (!isEmail.test(objText))
      {
          $("#reg_email").css("border", "1px solid #e1504a");
          mui.toast("邮箱号码格式有误，请修改",{type:'div'}); 
          return false;
      }
      else
      {
        $("#reg_email").css("border", "1px solid #ddd");
        $("#reg_email_mes").hide();
        $("#reg_email").attr("vdata", "1");
      }
}



//获取手机验证码**************************************************************************************
function GetCode(mobile,smstype,posturl,buttonid)
{
    var buttonid = arguments[3] ? arguments[3] : "ButtonCode";
    if(mobile == "" || mobile == null){
        mui.toast("手机号码错误",{type:'div'}); 
    }
    if(checkmobile()!=false){
	    $("#"+buttonid).html("正在获取...").attr("disabled", "disabled").css("cursor", "not-allowed").css("background", "#3598dc");
        $.ajax({
            data: {
                mobile:mobile,
                smstype: smstype
            },
            type: "post",
            dataType: "json",
            url:posturl,
            success: function (data)
              {
                   console.log(data.code);
                    if(data.code==100){
                        seconds = 60; //60秒后重新获取
                        objTimer = window.setInterval(redirection, 1000);
                    }
                    else if(data.code!=100){
                        mui.toast(data.msg,{type:'div'});
                        $("#"+buttonid).html("重新发送验证码").removeAttr("disabled").css("cursor", "pointer").css("background", "#3598dc").css("color", "#fff");
                    }else{
                        mui.toast(data.msg,{type:'div'}); 
                        $("#"+buttonid).html("重新发送验证码").removeAttr("disabled").css("cursor", "pointer").css("background", "#3598dc").css("color", "#fff");
                    }
              }
           })		
	}
}

//获取邮箱验证码**************************************************************************************
function GetEmailCode(email,smstype,posturl,buttonid)
{
    var buttonid = arguments[3] ? arguments[3] : "ButtonCode";
    if(email == "" || email == null){
         mui.toast("用户Email输入错误",{type:'div'}); 
    }
    if(checkemail(email)!=false){  
	    $("#"+buttonid).html("正在获取...").attr("disabled", "disabled").css("cursor", "not-allowed").css("background", "#3598dc");
        $.ajax({
            data: {
                email:email,
                emailtype: smstype
             },
            type: "post",
            dataType: "json",
            url:posturl,
            success: function (data)
              {
                    console.log(data.code);
                    if(data.code==100){
                        seconds = 60; //60秒后重新获取
                        objTimer = window.setInterval(redirection, 1000);
                    }else if(data.code!=100){ 
                        mui.toast(data.msg,{type:'div'});
                        $("#"+buttonid).html("重新发送验证码").removeAttr("disabled").css("cursor", "pointer").css("background", "#3598dc").css("color", "#fff");
                    }else{
                        mui.toast(data.msg,{type:'div'}); 
                        $("#"+buttonid).html("重新发送验证码").removeAttr("disabled").css("cursor", "pointer").css("background", "#3598dc").css("color", "#fff");
                    }
              }
           })		
	}
}


//计时器**************************************************************************************
function redirection()
{
    seconds--;
    buttonid="ButtonCode"
    $("#"+buttonid).html(seconds + "秒后重新获取");
    $("#"+buttonid).css("color", "#fff");
    if (seconds == 0)
    {
        window.clearInterval(objTimer);
        $("#"+buttonid).html("重新发送验证码").removeAttr("disabled").css("cursor", "pointer").css("background", "#3598dc").css("color", "#fff");
    }
}
//开始注册**************************************************************************************
function quicklogin()
{
    var regtype=$("#regtype").val();
    if(regtype==1){
        if ($("#reg_phone").attr("vdata") != "1")
        {
            $("#reg_phone").attr("vdata", "2");
            $("#reg_phone").focus();
            return false;
        }
    }
    if(regtype==2){
        if($("#reg_email").attr("vdata") != "1")
        {
            $("#reg_email").attr("vdata", "2");
            $("#reg_email").focus();
            return false;
        }
    }   
    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(),
                email: $("#reg_email").val(),
                code: $("#reg_yzm").val(),
                regtype: $("#regtype").val(),
				token: $("#safecode").val()
            }, 
            type: "post", 
            dataType: "json",
            url: "/index.php?a=quicklogin_check&c=member&m=member",
            success: function (data)
            {
                if(data.code==100){
                    window.location.href="/index.php?m=member&c=member&a=index";
                }
                else if(data.code!=100){
                    mui.toast(data.msg,{type:'div'});
                    $("#btnRegister").html("登录").removeAttr("disabled").css({ "cursor": "pointer", "background": "#3598dc" });
                }else{
                    mui.toast(data.msg,{type:'div'}); 
                    $("#btnRegister").html("登录").removeAttr("disabled").css({ "cursor": "pointer", "background": "#3598dc" });
                }             
            }
        })
    }
}