//蓝色 00a2ff  红色 e1504a
//获得焦点**************************************************************************************
function ThisOnfocus(ObjID)
{
    $(".tc-msg").hide(); //隐藏顶部提示
    var objText = $("#" + ObjID).val();
    if (ObjID == "reg_username")
    {
        if ($("#reg_username").attr("vdata") == "2")
        {
            if (objText == "" || objText == null)
            {
                $("#reg_username").css("border", "1px solid #e1504a");
                $("#reg_username_mes").css("color", "#e1504a");
                $("#reg_username_mes").html("请输入手机号码");
                $("#reg_username_mes").animate({ lineHeight: "45px"  }, 300);
                return false;
            }
        }
        else
        {
            $("#reg_username").attr("vdata", "0");
            if (objText == "" || objText == null)
            {
                $("#reg_username").css("border", "1px solid #00a2ff");
                $("#reg_username_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;
            }
        }
    }
    
}
//失去焦点**************************************************************************************
function ThisOnblur(ObjID)
{
    var objText = $("#" + ObjID).val();
    if (ObjID == "reg_username")
    {
        checkusername();
    }
    //密码======================================
    else if (ObjID == "reg_password")
    {
        $("#reg_password").attr("vdata", "0");
        if (objText == "" || objText == null)
        {
            $("#reg_password").css("border", "1px solid #ddd");
            $("#reg_password_mes").hide();
            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").css("border", "1px solid #ddd");
            $("#reg_password_mes").hide();
        }
    }

}
//内容改变时**************************************************************************************
function ThisOnkeyup(ObjID)
{
    $(".tc-msg").hide(); //隐藏顶部提示
    var objText = $("#" + ObjID).val();
   if (ObjID == "reg_username")
    {
        $("#reg_username").css("border", "1px solid #00a2ff"); //蓝色
        $("#reg_username_mes").hide();
        return false;
    }
    //确认密码===================
    else if (ObjID == "reg_password")
    {
        $("#reg_password").css("border", "1px solid #00a2ff"); //蓝色
        $("#reg_password_mes").css("color", "#aaa");
        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 >= 1)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function checkusername(){
    var objText =$("#reg_username").val();
          $.ajax({
              data: {
                  username: $("#reg_username").val()
              },
              type: "post",
              dataType: "json",
              url: "/index.php?a=checkLoginName&c=member&m=member",
              success: function (data)
              {
                  if(data.code!= "100")
                  {
                      mui.toast(data.msg,{type:'div'}); 
                  }else{
                      $("#reg_username").css("border", "1px solid #ddd");
                      $("#reg_username_mes").hide();
                      $("#reg_username").attr("vdata", "1");
                  }
              }
        })
    }


//开始登录**************************************************************************************
function LoginCheck()
{
    checkusername();
    if ($("#reg_password").val() == "" || $("#reg_password").val() == 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);
    }
    else
    {
        $("#btnLogin").html("正在登录...").attr("disabled", "disabled").css({ "cursor": "not-allowed", "background": "url(/skin_mobile/images/loading_a.gif) 145px 6px #bbb no-repeat" });
        //开始注册
        $.ajax({ 
            data: {
                username: $("#reg_username").val(),
                pwd: $("#reg_password").val(),
				token: $("#safecode").val()
            },
            type: "post",
            dataType: "json",
            url: "/index.php?a=logincheck_ajax&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'});
                    $("#btnLogin").html("登录").removeAttr("disabled").css({ "cursor": "pointer", "background": "#3598dc" });
                }else{
                    mui.toast(data.msg,{type:'div'}); 
                    $("#btnLogin").html("登录").removeAttr("disabled").css({ "cursor": "pointer", "background": "#3598dc" });
                }
            }
        })
    }
}