function checkAccounts ( me ){
	if( ! isPassword( me.value ) || !/[A-Za-z0-9]/.test( me.value )){ _( "chkaccounts" ).style.display = "";
		_( "chkaccountsval" ).style.display = "none";
	}
	else {
		_( "chkaccounts" ).style.display = "none";
		_( "chkaccountsval" ).style.display = "";
		//validate(me.value)
	
		}	
	}

var serverAddress = "yanzheng.asp";
var cache = new Array();

function getHttpObject() {
	var objType = false;
	try {
		objType = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch(e) {
        try {
            objType = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch(e) {
			objType = new XMLHttpRequest();
		}
	}
	return objType;
}


function getAJAX(postBody){
	var theHttpRequest = getHttpObject();
	theHttpRequest.onreadystatechange = function() {processAJAX();};
	theHttpRequest.open("GET", serverAddress, true);
	theHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	theHttpRequest.send(postBody);

	function processAJAX(){
		if (theHttpRequest.readyState == 4) {
			if (theHttpRequest.status != 200) {
				var msgid=theHttpRequest.responseText;
				var msgstr;
				//if (msgid==1)
				if(msgid!=1)
				{
					msgstr="恭喜,帐号格式可用&nbsp;&nbsp;";
					}
				else
				{
					msgstr="帐号不可用,请选择其它帐号";
					}	
				//msgstr = msgstr + "msgid:" + msgid;
				document.getElementById(messageID).innerHTML = msgstr;
				//setTimeout("validate();", 500);
                                 alert(msgstr);
			}
			else {
				alert("Error: status code is " + msgid);
				document.getElementById(messageID).innerHTML="<p>错误信息:&nbsp;" + theHttpRequest.statusText +"<\/p>";
			}
		}
	}
} 



function validate(inputValue){
	//if (fieldID){
		inputValue = encodeURIComponent(inputValue);
		//fieldID = encodeURIComponent(fieldID);
		cache.push("id=" + inputValue);
		alter(inputValue);
	//}
	//if (cache.length > 0){
		//var cacheEntry = cache.shift();
		//getAJAX(cacheEntry);
	//}
}

function checkPWD( me ){
	if( ! isPassword( me.value )) _( "chkPwd" ).style.display = "";
	else {
		_( "pwds" ).innerHTML = "<font color=black>密码安全程度：</font>"+checkStrong(me.value);
		_( "chkPwdStr" ).style.display = "";
	}
}
function isPassword( str ){
	if (str.length < 6 || str.length > 16) return false;
	var len;
	var i;
	len = 0;
	for (i=0;i<str.length;i++){
		if (str.charCodeAt(i)>255) return false;
	}
	return true;
}

function editpwd( me )

{
	if (( me.value.length > 16 || me.value.length < 6) && me.value.length!=0) {
		 _( "chkPwd" ).style.display = "";
	} else {
	var len;
	var i;
	len = 0;
	for (i=0;i<me.value.length;i++){
		if (me.value.charCodeAt(i)>255){
			_( "chkPwd" ).style.display = "";
			return false;
			}
	}
		}
}


function checkNumber( num ,max){
    if( /^[0-9]+$/.test( num ) && num <=max)
		return true;
	else return false;
}
function birthPress(){
	var k = window.event.keyCode;
	if (k < 48 || k > 57)
		window.event.keyCode = 0 ;
}
function confirmPwd( me ){
	var oPassword = _( "password" );
	if( ! ( me.value == oPassword.value ) ) _( "pwdConfirm" ).style.display = "";
}
function checkVerifyCode( me ){
	if( me.value == "" || !( /^\w{6}$/.test( me.value ) ) || me.value.length != 6 ) _( "verifyConfirm" ).style.display = "";
}
function checkBirthday() {
	if (_("year").value == "" || !checkNumber(_("month").value,12) || !checkNumber(_("date").value,31)){
		_( "birthdayConfirm" ).style.display = "";
	}
}
function isAnswer( answer ){
	return /^[^%&]{2,20}$/.test( answer );
}
function checkGender(){
	for( var i = 0; i < document.getElementsByName("gender").length; i++ )	{
		if(document.getElementsByName("gender")[i].checked) return true;
	}
	return false;
}


function checknickname( customquestion )
{
    var oCQ = _( 'nicknamestr' );
//    showCQChk( "yes" );
    if ( customquestion.value == null || customquestion.value == "" )
    {
    	oCQ.innerHTML = "请填写昵称";
    	return;
    }
    if ( customquestion.length > 20 )
    {
    	oCQ.innerHTML = "昵称应不超过20个字符";
    	return;
    }
    if(! /^[^%&]+$/.test( customquestion.value ) )
    {
    	oCQ.innerHTML = "昵称中不能包含'%'和'&'这两个字符";
   	return;
    }
	_( 'chknickname' ).style.display = 'none';
//    showCQChk( "no" );
}

function isMobile( mobile ){
    return /^13\d{9}$/.test( mobile ) | /^15\d{9}$/.test( mobile );
}
function isAlt_email( alt_email ){
    return ( /^[^@]+@[^@]+\.[^@]+$/.test( alt_email ) && alt_email.length<128 );
}
function checkAltEmail( me ){
	if( ! isAlt_email( me.value ) ) _( "altConfirm" ).style.display = "";
}
function checkMobile( me ){
	if( (me.value!="") && (! isMobile( me.value )) ) _( "mobileConfirm" ).style.display = "";

}
function checkAnswer( me ){
	if( ! isAnswer( me.value ) ) _( "answerConfirm" ).style.display = "";
}
function _(id) {
	return document.getElementById(id);
}



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){ 
	Modes=0; 
	for (i=0;i<sPW.length;i++){ 
		//测试每一个字符的类别并统计一共有多少种模式. 
		Modes|=CharMode(sPW.charCodeAt(i)); 
	} 
	switch(bitTotal(Modes)) {
		case 1:
			return "<font color='#FF0000'>弱</font>";
			break;
		case 2:
			return "<font color='#FF9900'>中</font>";
			break;
		case 3:
			return "<font color='#33CC00'>强</font>";
			break;
		default:
			return "<font color='#FF0000'>弱</font>";
	}
}


function fCheck(){
//	if( !_("readed").checked )	{
//		alert("您需要接受服务条款后才能注册！");
//		_("readed").focus();
//		return false;
//	}
	

//	if( ! isPassword( _("reg_accounts" ).value) || !/[A-Za-z0-9]/.test( _("reg_accounts" ).value))
//	{
//		alert("游戏帐号必须是6～16位的英文字母、数字或下划线的组合!");
//		_("reg_accounts").select();
///		_("reg_accounts").focus();
//	/	return false;
//	}

	var nickname = _("nickname").value;
	if ( nickname == null || nickname == "" ){
		alert("请填写昵称");
		_("nickname").select();
		_("nickname").focus();
		return false;
	}
	if ( nickname.length > 20 ){
		alert("昵称应不超过20个字符");
		_("nickname").select();
		_("nickname").focus();
		return false;
	}
	if(! /^[^%&]+$/.test( nickname ) ){
		alert("昵称中不能包含'%'和'&'这两个字符");
		_("nickname").select();
		_("nickname").focus();
		return false;
	}

	if (_("password").value != "")
	{
	if( ! isPassword( _("password").value ) || !/^[^%&]*$/.test( _("password").value )) {
		alert("\请重新输入密码,密码由至少6个英文字母、数字、特殊字符等组成(不能包含'%'和'&'这两个字符) !");
		_("password").select();
		_("password").focus();
		return false;
	}
	}
	if (_("mobile").value != "")
	{
	if(! isMobile(_("mobile").value )) {
		alert("请重新输入手机号码 !");
		_("mobile").select();
		_("mobile").focus();
		return false;
	}
    }

	if( _("password_cf").value != _("password").value ) {
		alert("\两次密码输入不一致 !");
		_("password_cf").select();
		_("password_cf").focus();
		return false;
	}
	

		
}