var flag ;
function user()
{
	var userName = $("#userName").val();
	$.get("/user.do?method=judgeUserName&userName="+userName+"&stam="+new Date(),function(text){
		var k = 0;
	var tmp = false;
	while (k < userName.length){  
		if (userName.charAt(k)  ==  " "){
			tmp = true;
			break;
		}else{
			k  =  k + 1;  
		}
	}  
		if(text==0){
		$("#unmsg").html("<img src='/images/wrong.gif' width=16 height=16/><font color='red'> 请输入用户名</font>");
		  flag = false;
		}else if(text==1){
		  $("#unmsg").html("<img src='/images/wrong.gif' width=16 height=16/><font color='red'> 用户名已存在</font>");
		  flag = false;
		}else if(tmp){
			$("#unmsg").html("<img src='/images/wrong.gif' width=16 height=16/><font color='red'> 用户名中不能含有空格</font>");
			flag = false;
		}else{
		  $("#unmsg").html("<img src='/images/true.gif' width=16 height=16>");
		  flag = true;
		}
    });
    return flag;
}

function confirmpass()
{
	var pass = $("#passWord").val();
	var confirmpass = $("#rpWord").val();
	if (confirmpass.length==0||confirmpass==""){ 
		$("#againmsg").html("<img src='/images/wrong.gif' width=16 height=16/><font color='red'> 请输入确认密码</font>");
		return false;
	}
	if(pass!=confirmpass){
		$("#againmsg").html("<img src='/images/wrong.gif' width=16 height=16/><font color='red'> 密码不一致</font>");
		return false;
	}else{
		$("#againmsg").html("<img src='/images/true.gif' width=16 height=16>");
		return true;
	}
}
function ruser()
{
	var realName = $("#realName").val();
	if (realName.length==0||realName==""){ 
		$("#runmsg").html("<img src='/images/wrong.gif' width=16 height=16/><font color='red'> 请输入真实姓名</font>");
		return false;
	}
	if(realName.length>4||realName.length<2){
		$("#runmsg").html("<img src='/images/wrong.gif' width=16 height=16/><font color='red'> 请输入正确的真实姓名</font>");
		return false;
	}else{
		$("#runmsg").html("<img src='/images/true.gif' width=16 height=16>");
		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(){ 
var pwd = $("#passWord").val();
O_color="#eeeeee"; 
L_color="#FF0000"; 
M_color="#FF9900"; 
H_color="#33CC00"; 
if (pwd==null||pwd==''){ 
   $("#pwmsg").html("<img src='/images/wrong.gif' width=16 height=16/><font color='red'> 请输入密码</font>");
   Lcolor=Mcolor=Hcolor=O_color; 
   return false;
} 
if (pwd.length>20){ 
   $("#pwmsg").html("<img src='/images/wrong.gif' width=16 height=16/><font color='red'> 密码不能超过20位</font>");
   Lcolor=Mcolor=Hcolor=O_color; 
   return false;
}
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; 
$("#pwmsg").html("<img src='/images/true.gif' width=16 height=16>");
return true;
} 
} 


var t;
function checktele()
{  
	var a = /^1[3,5,8]{1}[0-9]{1}[0-9]{8}$/;
	var tele = $("#tele").val();
	if(tele.length==0||tele==""){ 
		$("#tmsg").html("<img src='/images/wrong.gif' width=16 height=16/><font color='red'> 请输入固定电话或手机</font>");
		t = false;
		return t;
	}else{
		if(tele.length<11||tele.length>12){ 
			$("#tmsg").html("<img src='/images/wrong.gif' width=16 height=16/><font color='red'> 请输入正确的固定电话或手机</font>");
			t = false;
			return t;
		}else{
			$.get("/user.do?method=judgeTele&telephone="+tele+"&stam="+new Date(),function(text){
				if(text==1){
		 			 $("#tmsg").html("<img src='/images/wrong.gif' width=16 height=16/><font color='red'> 该电话已存在</font>");
		 			 t = false;
				}
				if(text==2){
		  			 $("#tmsg").html("<img src='/images/true.gif' width=16 height=16>");
		  		   	 t = true;
				}
   			 });
		}
	}
	
    return t;
}

function checkregist(){
     if(user()&&pwStrength()&&confirmpass()&&checktele()&&ruser())
     {
	    document.registForm.submit();
	  }
}
function reset(){
	var userName = document.getElementById("userName");
	var pass = document.getElementById("passWord");
	var confirmpass = document.getElementById("rpWord");
	var tele = document.getElementById("tele");
	var realName = document.getElementById("realName");
	userName.value="";
	pass.value="";
	confirmpass.value="";
	tele.value="";
	realName.value="";
}