﻿function isMoreShow()
{
    var oshow=document.getElementById("amoreshow");
    if(oshow.style.display=="none")
    {
        oshow.style.display="";
    }
    else
    {
        oshow.style.display="none";
    }

}

function isValidUserName() 
{
    var sUserName = document.getElementById("txUserName").value
    var valid = /^[a-zA-Z0-9_]{5,20}$/ 
    //var valid = /^[a-zA-Z][a-zA-Z0-9_]{4,19}$/
    //汉字\u4e00-\u9fa5
    if (sUserName.search(valid) == -1)
    {
        if(sUserName == "")
        {
            document.getElementById("lerror").innerHTML = "请输入通行证名称";   
//            document.getElementById("txUserName").focus(); 
            document.getElementById("txUserName").style.background = "Yellow";
        }
        else
        {
            document.getElementById("lerror").innerHTML = "通行证名称不合法 6-20字";
            document.getElementById("txUserName").style.background = "Yellow";
        }
        return false;
    }
    else
    {
        document.getElementById("lerror").innerHTML = "";
        document.getElementById("txUserName").style.background = "#ffecd6";
    }
}

function checkPassWord()
{
    if(!isValidPassWord(document.getElementById("txPassWord").value,6,16))
    {        
        document.getElementById("lerror").innerHTML = "密码不合法";
        document.getElementById("txPassWord").style.background = "Yellow";
        return false;
    }
    else
    {
        document.getElementById("lerror").innerHTML = "";
        document.getElementById("txPassWord").style.background = "#ffecd6";
    }
}

function PasswordConfirm(id1,id2,lblErr)
{
    if(document.getElementById(id1).value != document.getElementById(id2).value )
    {
        document.getElementById(lblErr).innerHTML = "两次输入的密码不相符";
        document.getElementById(id1).style.background = "Yellow";        
        document.getElementById(id2).style.background = "Yellow";
        return false;
    }
    else
    {
        if(document.getElementById(id2).value == "")
        {
            document.getElementById(lblErr).innerHTML = "请输入的密码";
            document.getElementById(id1).style.background = "Yellow";        
            document.getElementById(id2).style.background = "Yellow";
            return false;
        }
        else
        {
            document.getElementById(lblErr).innerHTML = "";
            document.getElementById(id1).style.background = "#ffecd6";
            document.getElementById(id2).style.background = "#ffecd6";
        }
    }
}

function isValidPassWord(PWD,sLength,toLength)
{
    if(PWD.toString().length >= sLength && PWD.toString().length <= toLength)
    {
        return true;
    }
    else
    {
        return false;
    }    
}

function isEmail(strEmail) 
{    
    if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)    
        return true;    
    else    
        return false;   
}

function CheckEmail()
{
    
    if(!isEmail(document.getElementById("txEmail").value))
    {
        document.getElementById("lerror").innerHTML = "邮箱地址不合法";
        document.getElementById("txEmail").style.background = "Yellow";
        return false;
    }
    else
    {
        document.getElementById("lerror").innerHTML = "";
        document.getElementById("txEmail").style.background = "#ffecd6";
    }
}


function isValidVerificationCode()
{
    var valid=/^[0-9.]{4,4}$/;
    if(document.getElementById("txVerificationCode").value == "" || !valid.exec(document.getElementById("txVerificationCode").value))
    {
        document.getElementById("lerror").innerHTML = "请输入正确验证码";
        document.getElementById("txVerificationCode").style.background = "Yellow";
        return false;
    }
    else
    {
        document.getElementById("lerror").innerHTML = "";
        document.getElementById("txVerificationCode").style.background = "#ffecd6";
    }
}

function Register()
{
    var Mark = true;
    
    document.getElementById("lerror").innerHTML = "";

    if(isValidUserName() == false)
    {//用户名合法性
        Mark = false;
        document.getElementById("txUserName").focus(); 
    }
    else
    {
        if(checkPassWord() == false)
        {//密码合法性
            Mark = false;
            document.getElementById("txPassWord").focus(); 
        }
        else
        {
            if(PasswordConfirm("txPassWord","txPassWordConfirm","lerror") == false)
            {//两次密码是否一致
                Mark = false;
                document.getElementById("txPassWord").focus(); 
            }
            else
            {
                if(CheckEmail() == false)
                {//邮箱合法性
                    Mark = false;
                    document.getElementById("txEmail").focus(); 
                }
                else
                {
                    if(isValidVerificationCode() == false)
                    {//验证码
                        Mark = false;
                        document.getElementById("txVerificationCode").focus(); 
                    }
                    else
                    {
                       
                    }
                 }
            }
        }
    }
    
    if(Mark)
    {
        document.getElementById("IbRegisterchaoshou").click();
    }
}

