﻿//判断是否为数字
function isNumber( str ){
 	if( str.length == 0 ) return false;
 	for( var loc=0; loc<str.length; loc++ )
 		if( (str.charAt(loc) < '0') || (str.charAt(loc) > '9') ) return false;
 	return true;	
}
//删除两端的空格
function trim(strText){ 
  while (strText.substring(0,1) == ' ') 
    strText = strText.substring(1, strText.length);
  while (strText.substring(strText.length-1,strText.length) == ' ')
    strText = strText.substring(0, strText.length-1);
  return strText;
} 

	function checkUser()////检测用户名是否存在
	{
	    if(trim( window.newUserForm.account.value ) == ""){
		   alert( "请填写用户名" );window.newUserForm.account.focus();
		}else if( fIsNumber(window.newUserForm.account.value,"1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_")!=1 ){
		   alert("您的用户名应该是数字、字母、下划线,不允许出现汉字等其他字符!");window.newUserForm.account.focus();
		}else if(isNumber( trim( window.newUserForm.account.value ) ) ){
		   alert( "用户名不能全为数字" );window.newUserForm.account.focus();
		}else{
		window.open("about:blank","check", 'menubar=0,width=350,height=240,left=230,top=200,resizable=0,scrollbars=auto');
		window.newUserForm.target = "check";
		window.newUserForm.action = "checkId.jsp";
		window.newUserForm.submit();		
		}
	}

   function check_utilInfo(){
		var isRight=false;
		with( document.newUserForm ){
            if(trim( password.value ) == ""){alert( "请填写密码" );password.focus();}
			else if(trim( password2.value ) == ""){alert( "请再次填写密码" );password2.focus();}
			//else if(trim( name.value ) == ""){alert( "请填写您的姓名" );name.focus();}
			//else if(!sex[0].checked&&!sex[1].checked){alert( "请选择性别" );}
			else if(trim( mobile.value ) == ""){alert( "请填写手机号码" );mobile.focus();}
			else if(trim( areaCode.value ) == ""){alert( "请填写区号" );areaCode.focus();}
			else if(trim( phone.value ) == ""){alert( "请填写电话号码" );phone.focus();}
			else if(extension.value.length>0&&!isNumber( trim( extension.value ) )){alert( "分机号码有非数字" );extension.focus();}
			//else if(trim( txdz.value ) == ""){alert( "请填写通讯地址" );txdz.focus();}
			//else if(trim( yb.value ) == ""){alert( "请填写邮编" );yb.focus();}
			//else if(trim( email.value ) == ""||!isEmail( email.value )){alert( "请填写电子邮箱并确定格式是否正确" );email.focus();}
			else if( password.value.length<5||password.value.length>16) {alert("\您的密码长度应该在5－16个字符之间!");password.focus();}
			else if(password.value != password2.value) {alert("两次密码输入不一致 !");password2.focus();}
			else if( !isNumber( trim( mobile.value ) ) ){alert( "手机号码有非数字" );mobile.focus();} 
			else if(trim( mobile.value ).length<11 ){alert( "手机号码位数不够" );mobile.focus();}
			else if(!isNumber(trim( areaCode.value ) ) ){alert( "区号有非数字" );areaCode.focus();}
			else if(trim( areaCode.value ).length<3 ){alert( "区号位数不够" );areaCode.focus();}
			else if( !isNumber( trim( phone.value ) ) ){alert( "电话号码有非数字" );phone.focus();}
			else if(trim( phone.value ).length<7 ){alert( "电话号码位数不够" );phone.focus();}
			//else if( !service.checked){alert( "您必须同意[湖南美发美容协会网络服务使用协议]才能完成注册" );service.focus();}
			else {isRight=true;}
		    }
			return isRight;
   }
   
   function regInfUpdateSubmit(){
		with( document.newUserForm ){
			if(!check_utilInfo()){}
			else if(trim( name.value ) == ""){alert( "请填写您的姓名" );name.focus(); }
			else {
                 return true;
			}
		}
	   		 return false;
	}
   
   function userInfSubmit(){
	   var isRight=false;
		with( document.newUserForm ){
			if(trim( account.value ) == ""){alert( "请填写用户名" );account.focus();}
			else if(isNumber( trim( account.value ) ) ){alert("您的用户名应该是字母或字母与数字组合");account.focus();} 
			//else if(trim( account.value ).length<5 ){alert("您的用户名不能小于五位");account.focus();} 
			else if( fIsNumber(account.value,"1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_")!=1 ){alert("您的用户名应该是字母、字母数字组合、下划线,不允许出现汉字等其他字符!");account.focus();}
			else if(!check_utilInfo()){}
			else if(trim( name.value ) == ""){alert( "请填写您的姓名" );name.focus();}
			else if( !service.checked){alert( "您必须同意[湖南美发美容协会网络服务使用协议]才能完成注册" );service.focus();}
			else {		
				 //window.newUserForm.target = "";	
			    // window.newUserForm.action = "addUser.jsp";
			     //document.newUserForm.submit();	
				 isRight=true;
			}
		}
		return isRight;
	}

	
 function baseSubmit(){
	 var isRight=false;
	 
		with( document.newUserForm ){
			//if(trim( account.value ) == ""){alert( "请填写用户名" );account.focus();}
			//else if(isNumber( trim( account.value ) ) ){alert("您的用户名应该是字母或字母与数字组合");account.focus();} 
			//else if( fIsNumber(account.value,"1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_")!=1 ){alert("您的用户名应该是字母、字母数字组合、下划线,不允许出现汉字等其他字符!");account.focus();}
           /////////////////////////////////////////
			 if(!check_utilInfo()){}
			/////////////////////////////////////////
			else if(trim( name.value ) == ""){alert( "请填写机构名称" );name.focus(); }
			else if(trim( contact.value ) == ""){alert( "请填写联系人" );contact.focus();}
			else {
				 //window.newUserForm.target = "";	
			     //window.newUserForm.action = "addBase.jsp";
			     //document.newUserForm.submit();		
				 isRight=true;
			}
		}
		
		return isRight;
	}
	
  function userInfUpdateSubmit(){
		with( document.newUserForm ){
			if(!baseSubmit()){ return false;}
			else {
                 return true;
			}
		}
	   		 return false;
	}
	
function base3Submit(){
		with( document.newUserForm ){
			if( profile.value.length>1000) {alert("其它项目内容不能超过1000字");profile.focus();}
			else if( service_misc.value.length>1000) {alert("其它项目内容不能超过1000字");service_misc.focus();}
            else {		
				 window.newUserForm.target = "";	
			     window.newUserForm.action = "addBase3.jsp";
			     document.newUserForm.submit();			
			}
		}
		 return false;
	}

function isTel (s){
var sTmp;
if(s.length==0){ return (false);}
for (var i=0; i < s.length; i++){
  sTmp= s.substring (i, i+1);
  if(i==0){if(sTmp!=1)return (false);}
  if(i==1){if(sTmp!=3)return (false);}
}
return (true);
}

//****判断是否是Number.
function fIsNumber (sV,sR){
var sTmp;
if(sV.length==0){ return (false);}
for (var i=0; i < sV.length; i++){
sTmp= sV.substring (i, i+1);
if (sR.indexOf (sTmp, 0)==-1) {return (false);}
}
return (true);
}

//检验电子邮件地址是否合法
function isEmail(email) {
	var endvalue,allowstrlist;
	endvalue=true;
	if (email.lastIndexOf("@")==-1 || email.lastIndexOf(".")==-1) {
		endvalue=false;
	}
	if (email.indexOf("@",email.indexOf("@")+1)!=-1 || email.indexOf(".",email.indexOf("@"))==-1) {
		endvalue=false;
	}
	if (email.substr(0,1)=="@" || email.substr(0,1)=="." || email.substr(email.length-1,1)=="@" || email.substr(email.length-1,1)==".") {
		endvalue=false;
	}
	allowstrlist="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-.@";
	for (i=0;i<email.length;i++) {
		if (allowstrlist.indexOf(email.substr(i,1))==-1) {
			endvalue=false;
			break;
		}
	}

	return(endvalue);
}

function register()
{
   window.newUserForm.target = "";	
   window.newUserForm.action = "";
   window.newUserForm.submit();
}

function CloseMe()
{
   window.close();
}
function iframeResize(obj){ 
   document.all.left.height = document.left.document.body.scrollHeight; 
} 