function checkreg(){
var testid;
var testid_bk;
var testvalue;
var testvalue_bk;
validate("username",document.getElementById("a1").value,"chkuser",0)
testid="username";
testid_bk="a1";
testvalue=strtrim(document.getElementById(testid).innerHTML);
testvalue_bk=strtrim(document.getElementById(testid_bk).value);
innum=testvalue.indexOf("可以使用")
if (innum==-1)
{
	if(testvalue_bk.length<6)
	alert("用户名不能少于6位!");
	else
	alert("用户名已被注册,请重新选择!");
	document.getElementById(testid_bk).select();
	return false;
}


testid="a2";
testvalue=strtrim(document.getElementById(testid).value);
if(testvalue.length>4){
	testid_bk="a2k";
	testvalue_bk=strtrim(document.getElementById(testid_bk).value);
	if(testvalue!=testvalue_bk){
	alert("密码与确认密码不一致,请重新输入!");
	document.getElementById(testid).value="";
	document.getElementById(testid_bk).value="";
	document.getElementById(testid).select();
	return false;
	}
}
else{
	alert("登陆密码不能少于5位!");
	document.getElementById(testid).value="";
	document.getElementById(testid).select();
	return false;
}
testid="a13";
testvalue=strtrim(document.getElementById(testid).value);
if(testvalue.length<3){
alert("请正确填写公司名称!");
document.getElementById(testid).select();
return false
}
testid="a5";
testvalue=strtrim(document.getElementById(testid).value);
if(testvalue.length>=1){
	if(!IsEmail(testvalue)){
	alert("电子邮件格式不正确!");
	document.getElementById(testid).select();
	return false
	}
}
testid="a8";
testvalue=strtrim(document.getElementById(testid).value);
if(testvalue.length<3){
alert("请正确填写您的联系地址!");
document.getElementById(testid).select();
return false
}
testid="a6";
testvalue=strtrim(document.getElementById(testid).value);
testid_bk="a7";
testvalue_bk=strtrim(document.getElementById(testid_bk).value);
if(testvalue.length<1){
//return false;
	if(testvalue_bk.length<1){
		alert("电话号码和手机至少填写一个!");
		document.getElementById(testid).select();
		return false;}
	else{
		if(!IsMobile(testvalue_bk)){
			alert("手机号码格式不正确!");
			document.getElementById(testid_bk).select();
			return false;
			}
	}
}
else{
if(!IsTel(testvalue)){
alert("电话号码格式不正确!");
document.getElementById(testid).select();
return false
	}
}
testid="a9";
testvalue=strtrim(document.getElementById(testid).value);
if(!IsPostCode(testvalue)&&testvalue.length>0){
alert("邮政编码格式不正确!");
document.getElementById(testid).select();
return false
}
return true;
}

//手机检查
function IsMobile(tel){
if(!(/^13\d{9}$/g.test(tel)||(/^15[0,8,9]\d{8}$/g.test(tel)))) 
{
return false;
}
return true;
}
//邮件检查
function IsEmail(email) {
		//if(! IsEnglish(email))
			//return false; 
		var i = email.indexOf("@"); 
		var j = email.lastIndexOf("@");
		if((i <= 0) || (i != j) || (i >= email.length-3)) 
			return false;		
		return true;
	}
//整数检查
function IsInteger(number)	{	
		if(number.length == 0)
			return false;
		for(i = 0; i < number.length; i++) {
			if(number.charAt(i) < '0' || number.charAt(i) > '9')
				return false;
		}
		return true;
	}
//数值检测    (包括浮点数)
function IsNumber(number)	{	
		if(number.length == 0)
			return false;
		for(i = 0; i < number.length; i++) {
			if(number.charAt(i) < '0' || number.charAt(i) > '9') {
				if(number.charAt(i) != '.')					
					return false;
			}
		}
		return true;
	}
//电话检查
function IsTel(tel) {
		if(tel.length < 7 || tel.length > 20)
			return false;
		for(i = 0;i<tel.length;i++)
		{
			if((tel.charAt(i)>='0' && tel.charAt(i)<='9') || tel.charAt(i) == '-') {
				if(tel.charAt(i) == '-' && (i <=2 || i >= (tel.length -1)))
					return false;
			}
			else			
				return false;			
		}
		return true;	
	} 
//邮编检查
function IsPostCode(postCode)	{	
		if(postCode.length != 6 || !IsNumber(postCode))
			return false;		
		return true;
	}
//去除空格
function strtrim(str){
str=str.replace(/^\s+|\s+$/g,"");
return str
}
//日期检查
function IsDate(dateValue) {
		var firstSplim = dateValue.indexOf("-");
		var secondSplim = dateValue.indexOf("-",firstSplim+1);
		year = dateValue.substring(0,firstSplim);
		month = dateValue.substring(firstSplim+1,secondSplim);
		day = dateValue.substring(secondSplim+1);

		if(year < 1900 || year > 2500)
			return false;
		if(month < 1 || month > 12)
			return false;
		if(day < 1 || day > 31)
			return false;		
		if(month == 4 || month == 6 || month == 9 || month == 11) {
			if(day > 30)				
				return false;
	    }
		if(month == 2) {
			if(year%4 == 0 && year%100 != 0 && day > 29)
				return false;
			if(year%4 == 0 && year%100 == 0 && year%400 == 0 && day > 29)
				return false;
			if(year%4 == 0 && year%100 == 0 && year%400 != 0 && day > 28)
				return false;
			if(year%4 != 0 && day > 28)
				return false;
		}
		return true;
	}
//密码强度
//测试某个字符是属于哪一类.  
function CharMode(iN){  
if (iN>=48 && iN <=57) //数字  
return 1;  
if (iN>=65 && iN <=90) //大写字母  
return 2;  
if (iN>=97 && iN <=122) //小写  
return 4;  
else  
return 8; //特殊字符  
}  
//bitTotal函数  
//计算出当前密码当中一共有多少种模式  
function bitTotal(num){  
modes=0;  
for (i=0;i<4;i++){  
if (num & 1) modes++;  
num>>>=1;  
}  
return modes;  
}  
//checkStrong函数  
//返回密码的强度级别  
function checkStrong(sPW){  
if (sPW.length<=4)  
return 0; //密码太短  
Modes=0;  
for (i=0;i<sPW.length;i++){  
//测试每一个字符的类别并统计一共有多少种模式.  
Modes|=CharMode(sPW.charCodeAt(i));  
}  
return bitTotal(Modes);  
}  
//pwStrength函数  
//当用户放开键盘或密码输入框失去焦点时,根据不同的级别显示不同的颜色  
function pwStrength(pwd){  
O_color="#eeeeee";  
L_color="#FF0000";  
M_color="#FF9900";  
H_color="#33CC00";  
if (pwd==null||pwd==''){  
Lcolor=Mcolor=Hcolor=O_color;  
}  
else{  
S_level=checkStrong(pwd);  
switch(S_level) {  
case 0:  
Lcolor=Mcolor=Hcolor=O_color;  
case 1:  
Lcolor=L_color;  
Mcolor=Hcolor=O_color;  
break;  
case 2:  
Lcolor=Mcolor=M_color;  
Hcolor=O_color;  
break;  
default:  
Lcolor=Mcolor=Hcolor=H_color;  
}  
}
document.getElementById("strength_L").style.background=Lcolor;  
document.getElementById("strength_M").style.background=Mcolor;  
document.getElementById("strength_H").style.background=Hcolor;  
return;  
}
// JavaScript Document
