// JavaScript Document
function check_form()
{
	//检查用户名
	var username = document.getElementById('username').value;
	if(!username)
	{
		alert("请输入用户名！");
		document.getElementById('username').focus();
		return false;
	}
	if(username.length<6||username.length>18)
	{
		alert("用户名应大于6位，小于18位！");
		document.getElementById('username').focus();
		return false;
	}
	//检查密码
	var password = document.getElementById('password').value;
	if(!password)
	{
		alert("请输入密码！");
		document.getElementById('password').focus();
		return false;
	}
	if(password.length<6||password.length>18)
	{
		alert("密码应大于6位，小于18位！");
		document.getElementById('password').focus();
		return false;
	}
	//检查密码验证
	var r_password = document.getElementById('r_password').value;
	if(!r_password)
	{
		alert("请输入密码验证！");
		document.getElementById('r_password').focus();
		return false;
	}
	if(r_password != password)
	{
		alert("两次密码输入不一致！");
		document.getElementById('r_password').focus();
		return false;
	}
	//检查密码保护答案
	var pwd_a = document.getElementById('pwd_a').value;
	if(!pwd_a)
	{
		alert("请输入密码保护答案！");
		document.getElementById('pwd_a').focus();
		return false;
	}
	if(pwd_a.length<4||pwd_a.length>30)
	{
		alert("密码保护答案应大于4位，小于30位！");
		document.getElementById('pwd_a').focus();
		return false;
	}
	//检查验证码
	var yzm = document.getElementById('yzm').value;
	if(!yzm)
	{
		alert("请输入验证码！");
		document.getElementById('yzm').focus();
		return false;
	}
	if(yzm.length!=4)
	{
		alert("验证码应是4位字母或数字！");
		document.getElementById('yzm').focus();
		return false;
	}
	return true;
}
function check_pwd_level()
{
	var password = document.getElementById('password').value;
	switch(check_strong(password))
	{
		case 1:
			document.getElementById('pwd_level').innerHTML = "弱";
			document.getElementById('pwd_level').className = "pwd_b_1";
			break;
		case 2:
			document.getElementById('pwd_level').innerHTML = "中";
			document.getElementById('pwd_level').className = "pwd_b_2";
			break;
		case 3:
			document.getElementById('pwd_level').innerHTML = "强";
			document.getElementById('pwd_level').className = "pwd_b_3";
			break;
	}

	document.getElementById('pwd_level_box').style.display = "block";
	return true;
}
function char_mode(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; //特殊字符 
} 
function bit_total(num){
	modes=0; 
	for (i=0;i<4;i++){ 
		if (num & 1) modes++; 
		num>>>=1; 
	} 
	return modes; 
} 

//checkStrong函数 
//返回密码的强度级别 
function check_strong(sPW){
	Modes=0; 
	for (i=0;i<sPW.length;i++){ 
		//测试每一个字符的类别并统计一共有多少种模式. 
		Modes|=char_mode(sPW.charCodeAt(i)); 
	} 
	return bit_total(Modes);
}
