﻿ function checkuser()
    {
        var username=document.getElementById('TextUser');
        var p=/^[A-Za-z0-9\u4e00-\u9fa5]+$/ ;
        if(username.value.length<2 || username.value.length>16)
        {//长度验证
            document.getElementById("usrInfoDiv").innerHTML='<img src="img/info.gif" width="9" height="9" alt="" /> Minimum of 2 --16 characters in length';
            return(false);
        }
        else if(!p.test(username.value))
        {//用户名格式验证
            document.getElementById("usrInfoDiv").innerHTML='<img src="img/info.gif" width="9" height="9" alt="" /> Invalid username format';
            return(false);
        }
        else
        {
            document.getElementById("usrInfoDiv").innerHTML='<img src="img/info.gif" width="9" height="9" alt="" /> Valid username';
            return(true);
        }
    }
    //邮箱验证
    function checkEmail()
    {
        var email=document.getElementById('TextMail');
        var p=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/ ;
        if(!p.test(email.value))
        {//邮件格式验证
            document.getElementById("emlInfoDiv").innerHTML='<img src="img/info.gif" width="9" height="9" alt="" /> Invalid E-mail address';
            return(false);
        }
        var result = login.IsEmail(email.value)
        if(result.value==0)
        {
            document.getElementById("emlInfoDiv").innerHTML='<img src="img/info.gif" width="9" height="9" alt="" /> Mailbox is available';
            return(true);
        }
        else
        {
            document.getElementById("emlInfoDiv").innerHTML='<img src="img/info.gif" width="9" height="9" alt="" /> Registered Mailbox';
            return(false);
        }
    }
    //密码验证
    function checkPassword()
    {
        var password = document.getElementById('TextPwd');
        if(password.value.length<6)
        {
            document.getElementById("pwdInfoDiv").innerHTML='<img src="img/info.gif" width="9" height="9" alt="" /> Must have at least 6 characters';
            return(false);              
        }
        else
        {
            document.getElementById("pwdInfoDiv").innerHTML='<img src="img/info.gif" width="9" height="9" alt="" /> Correct password';
            return(true);
        }
    }
    //确认密码
    function checkPassword2()
    {
        var password=document.getElementById('TextPwd');
        var password2=document.getElementById('TextRepwd');
        if(password.value!=password2.value||password.value.length<6)
        {
            document.getElementById("repwdInfoDiv").innerHTML='<img src="img/info.gif" width="9" height="9" alt="" /> The retype password and set passwords do not match.Please check, and enter the password again.';
            return(false);
        }
        else
        {
            document.getElementById("repwdInfoDiv").innerHTML='<img src="img/info.gif" width="9" height="9" alt="" /> Password confirmed';
            return(true);
        }
    }
	//邮政编码验证
	function checkzip()
	{
		var zip =document.getElementById('Textzip');
		if(zip.value!="")
		{
			var pattern = /^[0-9]{6}$/;
                flag = pattern.test(zip.value);
                if (!flag) {
					document.getElementById("zipInfoDiv").innerHTML='<img src="img/info.gif" width="9" height="9" alt="" /> Zip code does not correspond to address';
                    //document.getElementById("Textzip").focus();
                    return false;
				}

		}
	}
	
//注册表单验证
function SubmitOK_onclick() {
    if(document.form1.TextUser.value==""||document.form1.TextMail.value==""||document.form1.TextPwd.value==""||document.form1.TextRepwd.value=="")
    { 
        alert("Please complete your login information!");
        return(false);
    }
    if(!checkuser()||!checkEmail()||!checkPassword()||!checkPassword2())
    {
        alert("Login failure!")
        return(false); 
    }
    else
    {
       document.form1.submit(); 
　　}
}

function ButtonCancel_onclick() {
    document.getElementById('TextUser').value = "";
    document.getElementById('TextMail').value = "";
    document.getElementById('TextPwd').value = "";
    document.getElementById('TextRepwd').value = "";
}
function ButtonCheck_onclick() {
    var username=document.getElementById('TextUser');
    var result = login.IsUserName(username.value);
        if(result.value==0)
        {
            document.getElementById("usrInfoDiv").innerHTML='<img src="img/info.gif" width="9" height="9" alt="" /> To login';
            return(true);
        }
        else
        {
            document.getElementById("usrInfoDiv").innerHTML='<img src="img/info.gif" width="9" height="9" alt="" /> Username name already exists';
            return(false);
        }
    
}
function ButtonLogin_onclick() {
    if(document.form1.TextUserName.value==""||document.form1.TextPassWord.value=="")
    {
        alert('Username and password cannot be left blank');
        return(false);
    }
}
function killErrors() {//
return true;
}
window.onerror = killErrors;
//-->