function checkRegistForm()
{
	 var passport    =  $('passport').value;
	 var superpass   =  $('superpass').value;
	 var resuperpass   =  $('resuperpass').value;
	 var passwords   =  $('password').value;
	 var repassword  =  $('repassword').value;
	 
	 var email          = $('email').value;
	 var uname			= $('uname').value;
	 var have_idcard    = $('have_idcard').get('checked');
	 var idcard			= $('idcard').value;
	 var verify         = $('verify').value;
	 var answer        = $('answer').value;
	 var agreement      = $('agreement');

	 if(passport.length<8 || passport.length>30)
	 {
	 		alert('通行证长度不正确！');
	 		setStyle('passport');
	 		return false;
	 }
	 if(!passport.test(/^[0-9a-zA-Z]+$/))
	 {
	 		alert('通行证包含非法字符！');
	 		setStyle('passport');
	 		return false;
	 }
	// var ishave=checkPassport(passport);
	//alert(ishave);
/*	 if(!ishave)
	 {
			alert('通行证已存在！');
			setStyle('passport');
			return false;
	 }*/
	 setBack('passport');
	 if(passwords.trim()=='')
	 {
	 		alert('密码不能为空！');
	 		setStyle('password');
	 		return false;
	 }
	 if(passwords.length<6 || passwords.length>16)
	 {
	 		alert('密码长度不正确！');
			$('password').value='';
			$('repassword').value='';
	 		setStyle('password');
	 		return false;
	 }
	 setBack('password');
	 if(repassword.trim()=='')
	 {
	 		alert('确认密码不能为空！');
			$('password').value='';
			$('repassword').value='';
	 		setStyle('repassword');
	 		return false;
	 }
	 if(passwords!=repassword)
	 {
	 		alert('两次输入的密码不相同！');
			$('password').value='';
			$('repassword').value='';
	 		setStyle('password');
	 		return false;
	 }
	  setBack('repassword');
	 if(passwords==passport){
	 		alert('密码不能和通行证相同！');
	 		setStyle('password');
			$('password').value='';
			$('repassword').value='';
	 		return false;
	 }
	 setBack('password');
	
	 if(superpass.length<8 || superpass.length >20)
	 {
	 		alert('超级密码长度不正确！');
	 		setStyle('superpass');
			$('superpass').value='';
			$('resuperpass').value='';
	 		return false;
	 }
	 setBack('superpass');
	 if(superpass != resuperpass)
	 {
	 		alert('两次输入的超级密码不相同！');
	 		setStyle('superpass');
			$('superpass').value='';
			$('resuperpass').value='';
	 		return false;
	 }
	 if(superpass == passport)
	 {
	 		alert('超级密码不能和通行证相同！');
	 		setStyle('superpass');
			$('superpass').value='';
			$('resuperpass').value='';
	 		return false;
	 }
	 if(superpass == passwords)
	 {
	 		alert('密码不能和超级密码相同！');
	 		setStyle('superpass');
			$('superpass').value='';
			$('resuperpass').value='';
	 		return false;
	 }
	 setBack('superpass');

	 if(!email.test(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/) || email=='')
	 {
	 		alert('邮箱格式不正确！');
	 		setStyle('email');
	 		return false;
	 }
	 if(!uname.test(/^[\u0391-\uFFE5]+$/) || uname.length<2 )
	 {
	 		alert('请填写真实姓名！');
	 		setStyle('uname');
	 		return false;
	 }

	 if( have_idcard==0 )
	 {
	     idcard = '';
	 }
	 
	 if( have_idcard==1 && !certIdValidator(idcard) )
	 {
	     	alert('身份证格式不正确！');
			setStyle('idcard');
			return false;
	 }

	 if(answer=='')
	 {
	 	 alert('答案不能为空！');
	 	 setStyle('answer');
	 	 return false;
	 }
	 
	 if(!verify.test(/^[0-9]{4}$/))
	 {
	 	  alert('验证码不正确！');
	 		setStyle('verify');
	 		return false;
	 }
	 if(agreement.checked!=true)
	 {
		 alert('请查看过并同意用户协议！');
		 return false;
	 }
	 return true;
}

function certIdValidator(certid) {
	var reg_15 = /\d{15}/;
	var reg_18 = /\d{17}([0-9]{1}|x|X)/;
	var monthPerDays = new Array("31","28","31","30","31","30","31","31","30","31","30","31");
	certid = certid.toLowerCase();
	if(certid == "" || certid=="111111111111111") {
		return false;
	}
	var ret = certid.length == 15?reg_15.test(certid):reg_18.test(certid);
	if(!ret) {
		return false;
	}
	birthDate = certid.length == 15?"19" + certid.substr(6,6):certid.substr(6,8);
	year = birthDate.substr(0,4);
	if(birthDate.substr(4,1) == '0')
		month = birthDate.substr(5,1);
	else
		month = birthDate.substr(4,2);
	if(birthDate.substr(6,1) == '0')
		day = birthDate.substr(7,1);
	else
		day = birthDate.substr(6,2);
	dd = parseInt(day);
	mm = parseInt(month);
	yy = parseInt(year);
	days = new Date();
	gdate = days.getDate();
	gmonth = days.getMonth();
	gyear18 = days.getFullYear()-18;
	if(mm>12 || mm<1 ||dd>31 || dd<1) {
		return false;
	}
	if(year % 100 != 0) {
		if(year % 4 ==0)
		monthPerDays[1] = 29;
	}
	else {
		if(year % 400 == 0)
		monthPerDays[1] = 29;
	}
	if(monthPerDays[mm - 1] < dd) {
		return false;
	}
	if(certid.length == 18) {
		var arTemp = new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2);
		var num = 0;
		var proof;
		for(var i=0; i < 17; i++) {
			num = num + certid.substr(i,1) * arTemp[i];
		}
		num = num % 11;
		switch(num) {
			case 0:proof='1';break;
			case 1:proof='0';break;
			case 2:proof='x';break;
			case 3:proof='9';break;
			case 4:proof='8';break;
			case 5:proof='7';break;
			case 6:proof='6';break;
			case 7:proof='5';break;
			case 8:proof='4';break;
			case 9:proof='3';break;
			case 10:proof='2';break;
		}
		if(certid.substr(17, 1) != proof) {
			return false;
		}
	}
	mm = mm - 1;
	var prevTS18 = new Date(gyear18, gmonth, gdate,0,0,0);
	var ageTs = new Date(yy,mm,dd,0,0,0)
	if((prevTS18 < ageTs)) {
		return false;
	}
	return true;
}



function setStyle(id)
{
	$(id).set('styles',{'background-color':'#FFAAB5'});
	$(id).focus();
}

function setBack(id)
{
	$(id).set('styles',{'background-color':''});
	$(id).focus();	
}


function changImg(id)
{
	var rand=Math.random();
	$(id).src="http://passport.ljlgame.com/index.php/Index/verify/"+rand;	
}

function checkLoginForm()
 {
	 var uid=$('uid').value;
	 var password=$('spassword').value;
	 var vcode=$('vcode').value;
	 var seeds= seed;
 	if(uid.trim()=='')
	{
		$('rs').set('text','通行证帐号不能为空！');
		$('uid').focus();
		return false;
	}
	if(password.trim()=='')
	{
		$('rs').set('text','通行证密码不能为空！');
		$('spassword').focus();
		return false;	
	}
	if(vcode.trim()=='')
	{
		$('rs').set('text','验证码不能为空！');
		$('vcode').focus();
		return false;
	}
	  $('spassword').value=hex_sha1(hex_sha1(password)+seeds); 
	///$('form1').submit();
	//return true;

}


function flashCode()
{
	$('vcodeImg').src="http://passport.ljlgame.com/index.php/Index/verify/"+Math.random()*1000;
}
function init()
{
    change_idcard($('have_idcard').get('checked'));
}
function change_idcard(id)
{
    if(id==0)
    {
        $('idcard').value = '';
        $('idcard').set('readonly','readonly');
        $('idcard_info').set('styles',{'display':'none'});
    }
    else
    {
        $('idcard').set('readonly','');
        $('idcard_info').set('styles',{'display':'block'});
    }
}

function checkPassport(spassport)
{
	$('passporterror').innerHTML='<img src="/Public/images/load.gif" />';
	var passport =  $('passport').value;
	 if(passport.length<8 || passport.length>30)
	 {
	 		$('passporterror').innerHTML='<span style="color:#F00;">通行证长度不正确</span>';
	 		return false;
	 }
	 if(!passport.test(/^[0-9a-zA-Z\.-@]+$/))
	 {
	 		$('passporterror').innerHTML='<span style="color:#F00;">通行证包含非法字符</span>';
	 		return false;
	 }
    var check = new Request({  
                      method: "post",  
                      url: "http://passport.ljlgame.com/index.php/Regist/checkPassport/passport/"+spassport, 
                      onSuccess:function(responseText){  
					  	if(responseText=='0')
						{
                        	$('passporterror').innerHTML='<span style="color:#0C0;">通行证可以使用</span>';
						}else{
							$('passporterror').innerHTML='<span style="color:#F00;">通行证已存在！</span>';
						}
                      }
                   });
      check.send(); 
}

function returnRs(state)
{
	if(state=='1')
	{
			return false;	
	}else{
	    	return true;	
	}		
}
