function checkUserExist(){
	var passportName = $("#passportName").val();

	if(passportName == "") {
		$("#zh").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');
		$("#zw").html('游戏帐号不能为空');		
		//alert(error[5]);
		//passportName.focus();
		return false;
	}
	var PNstate = regexPassportName(passportName);	//判断是否合法 ？  提交 / 返回	//帐号名
	if(PNstate == -1){
		$("#zh").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');
		$("#zw").html('游戏帐号不能以“SD”开头');
		return false;
	}
	if(PNstate == -2){
		$("#zh").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');
		$("#zw").html('游戏帐号不能以“SD”开头');
		return false;
	}
	if(PNstate == -4){
		$("#zh").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');
		$("#zw").html('游戏帐号必须以字母开头');
		return false;
	}
	if(PNstate == -5){
		$("#zh").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');
		$("#zw").html('您的游戏帐号含非法字符');
		return false;
	}
	if(PNstate == -6){
		$("#zh").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');
		$("#zw").html('游戏帐号至少6个字符');
		return false;
	}
	if(PNstate == -7){
		$("#zh").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');	
		$("#zw").html('游戏帐号不能多于16个字符');
		return false;
	}

	$.ajax({
	   type: "POST",
	   url: "userExist.php",
	   data: 'userName='+passportName,
	   success: function(text){
			var errors={'0':'账号可以注册','-100':'非法调用中间件或传入的参数不符合规则','992':"对不起，暂时不能提供注册服务。",'-200':'系统错误','-1407':'帐号已存在','-999':'账号不能以LK,SD开头','-998':'两次输入的密码不一致!','-997':'密码中不能有汉字和空格,必须包含字母数字!','-996':'玩家名称长度不合法 目前限制为最多4个汉字!','-994':'邮件地址不合法!','-995':'验证码错误!','-995':'验证码错误!','-993':'用户名格式不正确！'};
			if(parseInt(text)==0){
				$("#zh").html('<img src="http://res.condorgame.com/20101008/img/r.gif" />');
				$("#zw").html('');
				return true;
			}else{
				$("#zh").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');
				$("#zw").html('帐号已存在');
				return false;
			}
	   }
	 });
		
	$("#zh").html('<img src="http://res.condorgame.com/20101008/img/r.gif" />');
	$("#zw").html('');
	return true;
}

function checkRealName(){
	var realName = $("#realName").val();

	var RNstate=regexrealName(realName) ;
	if(RNstate == -1){
		$("#xm").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');
		$("#zw").html('真实姓名格式不对,请输入2-4位的汉字');
		return false;
	}
	if(RNstate == -2){
		$("#xm").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');
		$("#zw").html('真实姓名格式不对,请输入2-4位的汉字');
		return false;
	}
	if(RNstate == -3){
		$("#xm").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');
		$("#zw").html('真实姓名格式不对,请输入2-4位的汉字');		
		return false;
	}
	$("#xm").html('<img src="http://res.condorgame.com/20101008/img/r.gif" />');
	$("#zw").html('');
	return true;
}

function checkPassword(){

	var passportPswd = $("#passportPswd").val();
	/*-=================================================================================================-*/
	if(passportPswd == "") {
		$("#pwd").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');	
		$("#zw").html('游戏密码不能为空');		
		//passportPswd.focus();
		return false;
	}
	
	var PDstate = VALPassword(passportPswd);
	//密码
	if(PDstate == -1){
		$("#pwd").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');		
		return false;
	}
	if(PDstate == -2){
		$("#pwd").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');	
		$("#zw").html('密码含有非法字符');		
		return false;
	}
	if(PDstate == -3){
		$("#pwd").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');	
		$("#zw").html='确认密码不能少于6位';		
		return false;
	}
	if(PDstate == -4){
	    $("#pwd").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');	
		$("#zw").html('确认密码不能大于12位');		
		return false;
	}
	if(PDstate == -5){
		$("#pwd").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');		
		$("#zw").html('游戏密码不能为空');		
		return false;
	}
	
	$("#pwd").html('<img src="http://res.condorgame.com/20101008/img/r.gif" />');
	$("#zw").html('');
	return true;
}

function checkIDCardInfo(){
	var IDCard = $("#IDCard").val();
		
	if(IDCard == "") {
		$("#sfz").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');
		$("#zw").html('身份证号码不能为空');		
		//IDCard.focus();
		return false;
	}
    var ICstate = regexIDCard(IDCard)	
	if(ICstate == -1){
		$("#sfz").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');;
		$("#zw").html('身份证号码输入错误,请检查!');		
		return false;
	}
	
		$("#sfz").html('<img src="http://res.condorgame.com/20101008/img/r.gif" />');
		$("#zw").html('');
		return true;
}

/*function checkRePassword(){
	var passportPswd1 = $("#passportPswd1").val();
	var passportPswd  = $("#passportPswd").val();
	if(passportPswd1 == "") {
		$("#pwd1").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');
		$("#zw").html('确认密码不能为空');		
		return false;
	}
	if(passportPswd1!=passportPswd){
		$("#pwd1").html('<img src="http://res.condorgame.com/20101008/img/w.gif" />');
		$("#zw").html('两次密码输入不一致');		
		return false;
	}
	$("#pwd1").html('<img src="http://res.condorgame.com/20101008/img/r.gif" />');
	$("#zw").html('');
	return true;
}*/


function onSubmit() {
	var validate = $("#validate").val();
	var protocol = document.getElementById("protocol");

	if(!checkUserExist())return checkUserExist();
	if(!checkPassword())return checkPassword();
	//if(!checkRePassword())return checkRePassword();

	if(!checkRealName())return checkRealName();
	if(!checkIDCardInfo())return checkIDCardInfo();


	//return checkUserExist();
	//return checkRealName();
	//return checkPassword();
	//return checkIDCardInfo();
	//return checkRePassword();
	//return checkmobile();

	/*if(validate == "") {
		alert("对不起，请您输入验证码!");
		//validate.focus();
		return false;
	}*/
	
	if(!protocol.checked){
		alert("您还没有同意《神雕游戏服务条款》!");
		return false;
	}
	/*-=================================================================================================-*/
	$("#zw").html("");
	reg();
}

/*-=================================================================================================-*/

function regexPassportName(passportName) {

	if(passportName == ""){
		//document.getElementById('dd1')html = "<font color=red>游戏帐号不能为空</font>";
		return false;
	 }

	var pn = passportName.toLowerCase();
	var regex = /^sd/;
	if(regex.test(pn)) {
		//document.getElementById('dd1')html = "<font color=red>游戏帐号不能以“SD”开头</font>";
		return -1;
	}
	
	var regex = /^[A-Za-z]/;
	if(!regex.test(pn)) {
		//document.getElementById('dd1')html = "<font color=red>游戏帐号必须以字母或数字开头</font>";
		return -4;
	}
	var regex = /^[A-Za-z0-9_]*$/;
	if(!regex.test(pn)) {
		//document.getElementById('dd1')html = "<font color=red>您的游戏帐号含非法字符</font>";
		return -5;
	}
	if(passportName.length < 6){
		//document.getElementById('dd1')html = "<font color=red>游戏帐号至少6个字符!</font>";
		return -6;
	}
	if(passportName.length > 16){
		//document.getElementById('dd1')html = "<font color=red>游戏帐号不能多于16个字符!</font>";
		return -7;
	}

	//getthis('/reg.php','nameback','name','passportName');
	return PNstate = 1;		
	
}
/*-=================================================================================================-*/
//验证密码是否匹配

function VALPassword(password) {
	
	var regex = /^[\x00-\x19\x21-\x7f]*$/;
	if(!regex.test(password)) {
		//document.getElementById('dd2')html = "<font color=red>确认密码含有非法字符</font>";
		return -2;
	}
	if(password.length<6){
		//document.getElementById('dd2')html = "<font color=red>确认密码不能少于6位!</font>";
		return -3;
	}
	if(password.length>12){
		//document.getElementById('dd2')html = "<font color=red>确认密码不能大于12位!</font>";
		return -4;
	}
	
	var regex1 = /^[a-zA-Z0-9]{6,12}$/;
	if(!regex1.test(password)) {
		//document.getElementById('dd2')html = "<font color=red>确认密码必须含有字母和数字</font>";
		return -5;
	}	
}

//验证密码
function regexPassword(password) {
	
	var regex = /^[\x00-\x19\x21-\x7f]*$/;
	if(!regex.test(password)) {
		//document.getElementById('dd2')html = "<font color=red>密码含有非法字符</font>";
		return -2;
	}
	if(password.length<6){
		//document.getElementById('dd2')html = "<font color=red>密码不能小于6位!</font>";
		return -3;
	}
	if(password.length>12){
		//document.getElementById('dd2')html = "<font color=red>密码不能大于12位!</font>";
		return -4;
	}
	
	var regex1 = /^[a-zA-Z0-9]{6,12}$/;
	if(!regex1.test(password)) {
		//document.getElementById('dd2')html = "<font color=red>密码必须含有字母和数字</font>";
		return PDstate = -5;
	}

}

/*-=================================================================================================-*/

//验证真实姓名
function regexrealName(realname) {	
	//真实姓名验证
	if (realname != ""){
		var reg = /^[\u4e00-\u9fa5]*$/;
		var pattern= /^[A-Za-z]+$/; 
		if(!(reg.test(realname))||realname.length<2||realname.length>4){
			return -1;
		}else{
			return true;
		}
	}
	else
	{
		return -1;
	}
	return true;
}




//验证身份证号码
function regexIDCard(strID) {
	
	//验证各位字符是否合法的正则表达式
	ReDigital15 = /\d{15}/;
	ReDigital18 = /\d{17}[0-9xX]{1}/;
	//提取日期和校验的正则表达式
	ReDate15 = /\d{6}(\d{6})\d{3}/;
	ReDate18 = /\d{6}(\d{8})\d{3}/;
	switch (strID.length) {
	  case 15:
			if (ReDigital15.test(strID) == false) {
				//return "对不起，您输入的身份证号码无效！";
				//alert("对不起，您输入的身份证号码无效！");
				return -1;
			}
			Arr = ReDate15.exec(strID);
			strDate = "19" + Arr[1];
			if (CheckDate(strDate, new Date(1900, 0, 1), new Date()) == false) {
				//return "对不起，您输入的身份证号码无效！";
				//alert("对不起，您输入的身份证号码无效！");
				return -1;
			}
			return 1;
	  break;
	  case 18:
			if (ReDigital18.test(strID) == false) {
				//return "对不起，您输入的身份证号码无效！";
				//alert("对不起，您输入的身份证号码无效！");
				return -1;
			}
			Arr = ReDate18.exec(strID);
			strDate = Arr[1];
			if (CheckDate(strDate, new Date(1900, 0, 1), new Date()) == false) {
				//return "对不起，您输入的身份证号码无效！";
				//alert("对不起，您输入的身份证号码无效！");
				return -1;
			}
			if (CheckSum(strID) == false) {
				//return "对不起，您输入的身份证号码无效！";
				//alert("对不起，您输入的身份证号码无效！");
				return -1;
			}
			return 1;
	  break;
	  default:
			//return "对不起，您输入的身份证号码无效！";
			//alert("对不起，您输入的身份证号码无效！");
			return -1;
	   break;
	}
	return "";
	
}

//对身份证的校验位进行验证

function CheckSum(strID) {
	//debugger;
	//18位数字提取正则表达式
	Re18Digital = /(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})(\d{1})([0-9xX]{1})/;
	Arr = Re18Digital.exec(strID);
	var Wi = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
	Sum = 0;
	for (i = 0; i <= 16; i++) {
		Sum += Arr[i + 1] * Wi[i];
	}
	ArrCheckSum = new Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2");
	strCheckSum = ArrCheckSum[Sum % 11];
	if (strCheckSum == Arr[18].toUpperCase()) {
		return true;
	}else{
		return false;
	}
}
//检查在指定范围之内的日期，支持选择框自动生成格式和手动连打格式。返回bool，true表示日期有效，false表示日期无效。
function CheckDate(strDate, DateFrom, DateTo) {
	//手动日期验证正则表达式
	ReDigital8 = /\d{8}/;
	//自动日期验证正则表达式
	ReAutoDate = /\d{4}-{1}\d{1,2}-\d{1,2}/;
	//自动日期提取正则表达式
	//ReGetDate = /(d{4})-{1}(d{1,2})-(d{1,2})/;
	//debugger;
	if (strDate.indexOf("-") > -1) {
		if (ReAutoDate.test(strDate) == false) {
			return false;
		}
		//Arr = ReGetDate.exec( strDate );
		Arr = strDate.split("-");
		strDate = (Arr[0]) + "" + (Arr[1].length < 2 ? "0" : "") + Arr[1] + (Arr[2].length < 2 ? "0" : "") + (Arr[2]);
	}
	if (strDate.length != 8) {
		return false;
	}
	if (ReDigital8.test(strDate) == false) {
		return false;
	}
	MyDate = eval(strDate.replace(/^(\d{4})(\d{2})(\d{2})$/, "new Date($1,$2-1,$3)"));
	strMyDate = MyDate.getFullYear() + (MyDate.getMonth() < 9 ? "0" : "") + (MyDate.getMonth() + 1) + "" + (MyDate.getDate() <= 9 ? "0" : "") + MyDate.getDate();
	//日期有效性验证
	if (strMyDate != strDate) {
		return false;
	}
	//日期范围验证
	if (MyDate >= DateFrom && MyDate <= DateTo) {
		return true;
	}else{
		return false;
	}
}


//验证邮箱
var EMstate = 1;
function regexEmail(Email) {
	
	 if(Email == ""){
		return false;
	 }
	var regex = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/;
	if(!regex.test(Email)) {
		return EMstate = -1;
	}
	return EMstate = 1;	
}


    function changeImg() {
	    var img = document.getElementById("imgVerify");
	    img.src = "./img.php?" + Math.random();
    }
    function InitAjax() {
        var http_request = false;

        if (window.XMLHttpRequest) {
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
            }
        } else if (window.ActiveXObject) {
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        } if (!http_request) {
            alert('Cannot create an XMLHTTP instance');
            return false;
        }
        return http_request;
    }
    
function reg() {
  
		var passportName = $('#passportName').val();
		var passportPswd = $('#passportPswd').val();
		var realName	 = $('#realName').val();
		var IDCard       = $('#IDCard').val();
		var validate	 = $('#validate').val();
		var spreadCode   = $('#spreadCode').val();
		
		//var mobileTel    = document.getElementById('mobileTel').value;
		//if(mobileTel=='填写手机得尊贵卡'){mobileTel=""}
		if(spreadCode=='如果没有请留空'){spreadCode = ""}
		mobileTel=""
		
		var url = "./reg.poxy.php"; 
        var str = 'passportName='+passportName+'&passportPswd='+passportPswd+'&mobileTel='+mobileTel+'&spreadCode='+spreadCode+'&realName='+realName+'&IDCard='+IDCard+'&validate='+validate;

        var ajax = InitAjax();  //创建XMLHttprequest对象
		
    　  ajax.open("POST", url, true);
    　  ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        ajax.send(str);
        ajax.onreadystatechange = function() 
        {
        　　if (ajax.readyState == 4 && ajax.status == 200) 
            {
        　　　  var status = parseInt(ajax.responseText); 
                if (!isNaN(status)) 
                {
                    switch (status) 
                    {                       
                        case 0:
							count('reg',passportName);
                            //alert('注册成功！');
							regSuccessfull();
				            $('#passportName').val("");
				            $('#passportPswd').val("");
				            $('#passportPswd1').val("");
				            $('#realName').val("");
				            $('#IDCard').val("");
				            $('#validate').val("");
							//document.getElementById('mobileTel').value = '';
				            document.getElementById('protocol').checked = true;
				    
                            break;
                        /*case 2002:
							showAuth(1); 
                            alert('验证码错误！');
                            break; */                      
                        case 1009:
                            alert('用户已存在');
                            break;                     
                        case -999:
                            alert('对不起，服务器响应超时，请重试！');
                            break; 
                        default:
                            alert('注册失败！');
                            break; 
                    }
                }                
        　　}
      }
	return false;
}
function checkAuthcode(){return true;}

function regSuccessfull()
{

		try{
			tb_remove();
		}catch(e){}
		tb_show('','#TB_inline?height=400px&width=400px&inlineId=reg_ok&modal=true');
		$('#TB_ajaxContent').css('height','0');
		$('#TB_ajaxContent').css('width','0');
	
		$('#TB_window').css('width','0px'); 
		$('#TB_window').css('height','0px');
		$('#TB_window').css('border','0px');
		$('#TB_ajaxContent').css('margin-left','180px'); 
		$('#TB_ajaxContent').css('margin-top','30px');

		if($.browser.msie&&($.browser.version == "6.0")){
			$('#TB_ajaxContent').css('height','auto').css('width','auto');
			$('#TB_window').css('height','auto').css('padding','0').css('width','auto').css('background','none');
		}
		return false;



	/*  var w, h,wd;
      if (self.innerHeight) {
    	w = self.innerWidth;
    	h = self.innerHeight;
      }else if(document.documentElement && document.documentElement.clientHeight) {
        w = document.documentElement.clientWidth;
        h = document.documentElement.clientHeight;
      }else if (document.body){
        w = document.body.clientWidth;
        h = document.body.clientHeight;
      }
      sh = document.body.scrollTop;
      sh = sh ? sh : document.documentElement.scrollTop;
	  wh = document.body.scrollLeft;

      wh = wh ? wh : document.documentElement.scrollLeft;
	  wd = document.documentElement.clientWidth;


	obj=document.getElementById("forbid");
	var width=document.body.clientWidth;    //网页可见区域宽
	var height=document.body.clientHeight;  //网页可见区域高
	obj.style.width=width+"px";        
	obj.style.height=height+"px";  
	obj.style.visibility = "visible";
	var okobj=document.getElementById("reg_ok");
	okobj.style.display = "block";	
	okobj.style.top = ((h - $('#reg_ok').height())/2+sh) +'px';
	okobj.style.left = ((wd - 357)/2) +'px';
*/
}

function closeAppDiv(){	
	var obj=document.getElementById("forbid");	
	var okobj=document.getElementById("reg_ok");
	okobj.style.display = "none";
	obj.style.visibility = "hidden";
}


//   检查手机号码是否符合标准
function checkMobileTel(mobileTel){
	if(mobileTel != "填写手机得尊贵卡"){
		var partten = /^1[3,5,8]\d{9}$/;
		if(mobileTel.length != 11){
			//msghtml = "&times; 手机号码必须为11位";
			return -1;
		} else if(checkNum(mobileTel)){
			//msghtml = "&times; 手机号码必须为数字";
			return -2;
		} else if(!partten.test(mobileTel)){
			//msghtml = "&times; 请输入有效的手机号码";
			return -3;
		} else {
			//msghtml = "&radic; 手机号码可以使用";
			return 1;
		}
	}
}

function checkNum(str){
   var numExp=/^[0-9]+$/;
   var numReg=new RegExp(numExp);
   if(!numReg.test(str)){
	  return true; 
	} 
	return false;
}

function show_msg(id,val){
	if (id == 'spreadCode' && val =='')
	{
		document.getElementById("spreadCode").value="如果没有请留空";
		document.getElementById("spreadCode").className="noinput";
	}
	
		if (id == 'mobileTel' && val =='')
	{
		document.getElementById("mobileTel").value="填写手机得尊贵卡";
		document.getElementById("mobileTel").className="noinput";
	}
}

function hidd_msg(id,val){
	
	if (id == 'spreadCode' && val !='')
	{
		document.getElementById("spreadCode").value="";
		document.getElementById("spreadCode").className="input";
	}

		if (id == 'mobileTel' && val !='')
	{
		document.getElementById("mobileTel").value="";
		document.getElementById("mobileTel").className="input";

	}
}


