String.prototype.Trim = function(){ 
	return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 

String.prototype.LTrim = function(){ 
	return this.replace(/(^\s*)/g, ""); 
} 

String.prototype.RTrim = function(){ 
	return this.replace(/(\s*$)/g, ""); 
} 
function countlength(schar){
	return schar.replace(/[^\x00-\xff]/g,'**').length;
}

function fucCheckNUM(NUM) 
{ 
var i,j,strTemp; 
strTemp="0123456789-"; 
if ( NUM.length== 0) 
return 0 
for (i=0;i<NUM.length;i++) 
{ 
j=strTemp.indexOf(NUM.charAt(i)); 
if (j==-1) 
{ 
//说明有字符不是数字 
return 0; 
} 
} 
//说明是数字 
return 1; 
} 

function chkUserEmail( str ){
	if( str.Trim() == '' ){
		window.alert( "请输入您的E-mail地址 ！" );
		return false;
	}
	return chkUserEmailFormat( str );
}

function chkUserEmailFormat( str ){
	if( str.Trim().length > 40 ){
		window.alert( "email地址长度不能超过40位!" );
		return false;
	}
	str = str.toLowerCase()
	var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT|name|NAME)$";
	var re = new RegExp( regu );
	if( str.search( re ) != -1 ){
	return true;
	}else{
		window.alert ( "请输入有效合法的E-mail地址！" );
		return false;
	}
}

function chkSignUp(){

            if( chkUserEmail( document.getElementById( 'email' ).value )){
	        }else{
		        document.getElementById( 'email' ).focus();
		        return false;
	        }
        	
	        if( chkUserPwd( document.getElementById( 'userpwd' ).value , document.getElementById( 'userpwdcfm' ).value ) ){
	        }else{
	        return false;
	        }
        	
	        if( document.getElementById( 'username' ).value=='' ){
		        window.alert( "请输入联系人 ！" );
		        document.getElementById( 'username' ).focus();
		        return false;
	        }else if(countlength(document.getElementById( 'username' ).value)>24){
		        window.alert( "联系人不能大于24个字符 ！" );
		        document.getElementById( 'username' ).focus();
		        return false;	
	        }else if(countlength(document.getElementById( 'username' ).value)<4){
			    window.alert( "联系人不能小于4个字符 ！" );
		        document.getElementById( 'username' ).focus();
		        return false;					
			}
			if (document.getElementById( 'userpwd' ).value==document.getElementById( 'username' ).value){
			    window.alert( "联系人不能与密码相同 ！" );
		        document.getElementById( 'username' ).focus();
		        return false;								
			}
	        sexobj=document.getElementsByName("sex"); 
	        if(sexobj[0].checked==false && sexobj[1].checked==false ){
		        window.alert( "请选择您的性别 ！" );
		        document.getElementById( 'sex' ).focus();
		        return false;
	        }
        	
	        if( document.getElementById( 'phone' ).value!=='' ){
		        if(fucCheckNUM(document.getElementById( 'phone' ).value.Trim())==0){
			        window.alert( "电话号码中含有非数字字符！" );
			        document.getElementById( 'phone' ).focus();
			        return false;
		        }else if(document.getElementById( 'phone' ).value.Trim().length<8 || document.getElementById( 'phone' ).value.Trim().length>20){
			        window.alert( "电话号码长度不能小于8个或大于20个字符 ！" );
			        document.getElementById( 'phone' ).focus();
			        return false;
		        }
	        }

			
	        if( document.getElementById( 'mob' ).value!=='' ){
		        if(fucCheckNUM(document.getElementById( 'mob' ).value)==0){
			        window.alert( "手机号码中含有非数字字符！" );
			        document.getElementById( 'mob' ).focus();
			        return false;
		        }else if(document.getElementById( 'mob' ).value.Trim().length<11 || document.getElementById( 'mob' ).value.Trim().length>20){
			        window.alert( "手机号码长度不能小于11个或大于20个字符 ！" );
			        document.getElementById( 'mob' ).focus();
			        return false;
		        }
	        }
	        if( document.getElementById( 'QQ' ).value!=='' ){
		        if(countlength(document.getElementById( 'QQ' ).value.Trim())>15){
			        window.alert( "QQ长度不能大于15个字符 ！" );
			        document.getElementById( 'QQ' ).focus();
			        return false;
		        }
	        }
	        if( document.getElementById( 'MSN' ).value!=='' ){
		        if(countlength(document.getElementById( 'MSN' ).value.Trim())>40){
			        window.alert( "MSN长度不能大于40个字符 ！" );
			        document.getElementById( 'MSN' ).focus();
			        return false;
		        }
	        }
	        if( document.getElementById( 'address' ).value!=='' ){
		        if(countlength(document.getElementById( 'address' ).value.Trim())>100){
			        window.alert( "通信地址长度不能大于100个字符 ！" );
			        document.getElementById( 'address' ).focus();
			        return false;
		        }
	        }

			if(document.getElementById( 'firemail' ).value!=""){
				if( chkUserEmail( document.getElementById( 'firemail' ).value )){
				}else{
					document.getElementById( 'firemail' ).focus();
					return false;
				}
				if (document.getElementById( 'firemail' ).value==document.getElementById( 'email' ).value){
			        window.alert( "不能自己推荐自己！" );
			        document.getElementById( 'firemail' ).focus();
			        return false;		
				}
			}
			
			var testform=document.getElementById("signup");
	        for(var i=0;i<testform.elements.length;i++){
		        if(testform.elements[i].type=="checkbox"){
			        e=testform.elements[i];
			        if(e.checked==false){
				        window.alert( "请阅读并同意服务条款！" );
				        window.document.getElementById( 'agree' ).focus();
				        return false;	
			        }
		        }
	        }

}

function chkUserPwd( userpwd , userpwdcfm ){
	if( userpwd.Trim() == '' ){
		window.alert( "请输入您的密码！" );	
		document.getElementById( 'userpwd' ).focus();
		return false;
	}
	if( userpwdcfm.Trim() == '' ){
		window.alert( "请输入您的重复密码！" );	
		document.getElementById( 'userpwdcfm' ).focus();
		return false;
	}
	if( userpwd.Trim().length < 6 || userpwdcfm.Trim().length < 6 ){
		window.alert( "您的密码数必须大于5位！" );	
		document.getElementById( 'userpwd' ).focus();
		return false;
	}
	if( userpwd.Trim().length > 16 || userpwdcfm.Trim().length > 16 ){
		window.alert( '您的密码数超过了16位！' );	
		return false;
	}
	if( userpwd != userpwdcfm ){
		window.alert( "您的密码不一致！" );	
		document.getElementById( 'userpwd' ).focus();
		return false;
	}
	return true;
}

function checkid(){

		var gg
		var inputemail=document.getElementById( 'email' ).value
	if( chkUserEmail(inputemail)){
   		gg="/users/user_chkemail.asp?username="+inputemail;
  		 newwin = window.open(unescape(gg) ,"aa",		"width=340,height=30,top=350,left=600,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,cannelmode=no,fullscreen=no");
	}else{
		document.getElementById( 'email' ).focus();
		return false;
	}
}
