	function isEmail(x){		
		var pt=/^((\w|\W)+[@])((\w|\W)+)([.]\w{2,}){1,}$/;
		var result=x.match(pt)
		if (result==null)
			return false;
		else
			return true;
	}
	function isTEL1(x){		
		var pt=/^[0]\d{1,2}$/;
		var result=x.match(pt)
		if (result==null)
			return false;
		else
			return true;
	}
	
	function isTEL2(x){		
		var pt=/^\d{6,8}$/;		
		var result=x.match(pt)
		if (result==null)
			return false;
		else
			return true;
	}
	
	function isTEL3(x){		
		var pt=/^\d{0,5}$/;
		var result=x.match(pt)
		if (result==null)
			return false;
		else
			return true;
	}
	
	function isMobile(x){		
		var pt=/^\d{10,10}$/;		
		var result=x.match(pt)
		if (result==null)
			return false;
		else
			return true;
	}
	
	function isUID(x){		
		var pt=/^\w{4,16}$/;		
		var result=x.match(pt)
		if (result==null)
			return false;
		else
			return true;
	}
	
	function isNickname(x){		
		var pt=/^.{1,10}$/;		
		var result=x.match(pt)
		if (result==null)
			return false;
		else
			return true;
	}
	
	function isPWD(x){		
		var pt=/^\w{4,20}$/;		
		var result=x.match(pt)
		if (result==null)
			return false;
		else
			return true;
	}
	
	function isName(x){	
		var pt=/^\W{2,5}$/;	
		var result=x.match(pt)		
		if (result==null)
			return false;
		else
			return true;
	}	
	
	function pwdMatch(p1,p2){
		if(p1==p2)
			return true
		else			
			return false
	}
	
	function isSelectDOB(x,y,z){
		if(x=='' || y=='' || z=='')
			return false
		else
			return true
	}
	
	function isSelectSEX(x){		
		if(x[0].checked||x[1].checked)
			return true
		else
			return false
	}
	
	function isSchool(x){		
		var pt=/^\W{2,6}$/;	
		var result=x.match(pt)
		if (result==null)
			return false;
		else
			return true;
	}	
	
	function isSelectGrade(x){
		if(x=='')
			return false
		else
			return true	
	}
	function isSelectCity(x){
		if(x=='')
			return false
		else
			return true	
	}
	
	function isPostcode(x){
		var pt=/^\d{3,5}$/;
		var result=x.match(pt)
		if (result==null)
			return false;
		else
			return true;
	}
	
	function isAddress(x){
		var pt=/^.{5,40}$/;		
		var result=x.match(pt)
		if (result==null)
			return false;
		else
			return true;
	}
	
	function isDate(yy, mm,dd){
		if(isNaN(parseInt(yy)))
			return false;
		a=parseInt(DaysOfTheMonth (parseInt(yy), parseInt(mm)))		
		b=parseInt(dd)
		if (b>=1 && b<=a)
			return true;
		else
			return false;
	}
	
	function DaysOfTheMonth (yy, mm) {
		var monthday = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
		if ((yy % 4 == 0 && yy % 100 != 0) || yy % 400 == 0) {
			monthday[1] = 29;		}
		return monthday[mm-1];
	}
	
	function RecheckDate (theY,theM,theD) {
		var yy = theY.options[theY.selectedIndex].value;
		var mm = theM.options[theM.selectedIndex].value;
		var dd = theD.options[theD.selectedIndex].value;
		if(yy=='')	{
			theY.options[1].selected=true
			yy=theY.options[theY.selectedIndex].value;
		}
		if(mm=='')	{
			theM.options[1].selected=true
			mm=theM.options[theM.selectedIndex].value;
		}
		if(dd=='')	{
			theD.options[1].selected=true
			dd=theD.options[theD.selectedIndex].value;
		}
		//alert(yy)
		//alert(mm)
		yy=parseInt(yy)+1911;	
		days = DaysOfTheMonth (yy, mm);
		//alert(days)
		end = days -1;
		if ( dd > end ) {
			theD.options[end].selected = true;
		}
		olddays = theD.length;
		//alert(olddays)
		//alert(days)
		days=days+1
		if ( olddays > days ) {
			for (i=days; i<olddays+1; i++) {
				theD.options[i] = null;
			}
			theD.length = days;
			return 0;
		}

		if (olddays < days) {
			for (i=olddays; i<days; i++) {
				theD.options[i] = new Option (i, i);
			}
		}
	}
	
	function isReadyP(fm){
		if(!isUID(fm.uid.value)){
			alert('請輸入正確的[帳號]\n(英文或數字 4-16 位數)')
			fm.uid.focus();
			return false
		}
		if(!isPWD(fm.pwd.value)){
			alert('請輸入正確的[密碼]\n(英文或數字 4-20 位數)')
			fm.pwd.focus();
			return false;
		}
		if(!pwdMatch(fm.pwd.value,fm.pwd1.value)){
			alert('[密碼確認]錯誤，請再輸入一次密碼')
			fm.pwd1.focus();
			return false;
		}
		if(!isName(fm.realname.value)){
			alert('請輸入正確的[中文姓名]');
			fm.realname.focus();
			return false;
		}
		if(!isEmail(fm.email.value)){
			alert('請輸入正確的[電子信箱]');
			fm.email.focus();
			return false;
		}
		if(!isSelectSEX(fm.gender)){
			alert('請選擇[性別]!');			
			return false;
		}
		if (!isSelectDOB(fm.bY.value,fm.bM.value,fm.bD.value)){
			alert('請選擇[生日]');
			fm.bY.focus();
			return false;
		}
		if(!isTEL1(fm.tel1.value)){
			alert('請輸入正確的[電話區碼]');
			fm.tel1.focus();
			return false;
		}
		if(!isTEL2(fm.tel.value)){
			alert('請輸入正確的[電話號碼]');
			fm.tel.focus();
			return false;
		}
		if(!isTEL3(fm.tel2.value)){
			alert('請輸入正確的[電話分機]，如果沒有請空白');
			fm.tel2.focus();
			return false;
		}
		if((fm.mobilephone.value.length>0) && (!isMobile(fm.mobilephone.value))){
			alert('請輸入正確的[手機號碼]，如果沒有請空白');
			fm.mobilephone.focus();
			return false;
		}
		if(!isPostcode(fm.postcode.value)){
			alert('請輸入正確的[郵遞區號]');
			fm.postcode.focus();
			return false;
		}
		if(!isSelectCity(fm.city.value)){
			alert('請輸入正確的[縣市]');
			fm.city.focus();
			return false;
		}
		if(!isAddress(fm.address.value)){
			alert('請輸入正確的[地址]');
			fm.address.focus();
			return false;
		}
		if(!isName(fm.pname.value)){
			alert('請輸入正確的[家長中文姓名]');
			fm.pname.focus();
			return false;
		}
		if(!isEmail(fm.pemail.value)){
			alert('請輸入正確的[家長電子信箱]');
			fm.pemail.focus();
			return false;
		}
		return true;
	}
	
	function checkData(){	
		if (isReadyP(document.joinForm)){
			submitData()
		}			
	}
	
	function submitData(){
		document.joinForm.action='register05.aspx'
		document.joinForm.submit();
		document.joinForm.submitbutton.disable=true
	}
	
	function checkUID(uid){
		if(!isUID(uid.value)){
			alert('請輸入正確的[帳號]\n(英文或數字 4-16 位數)')
			document.joinForm.uid.focus();
			return false
		}else{
			window.open('checkuid.aspx?UID='+uid.value,'login','toolbar=no,location=no,directories=no,status=no,scrollbars=auto,resizable=no,copyhistory=no,widTH=400,height=230');
		}
	}
	
	//freetest 用
	function checkDatafree(){	
		if (isReadyfree(document.joinForm)){
			submitDatafree()
		}			
	}
	
	function submitDatafree(){
		document.joinForm.action='freeusersave.aspx'
		document.joinForm.submit();
		document.joinForm.submitbutton.disable=true
	}
	
	function isReadyfree(fm){
		if(!isName(fm.realname.value)){
			alert('請輸入正確的[中文姓名]');
			fm.realname.focus();
			return false;
		}
		if(!isEmail(fm.email.value)){
			alert('請輸入正確的[電子信箱]');
			fm.email.focus();
			return false;
		}
		if(!isSelectSEX(fm.gender)){
			alert('請選擇[性別]!');			
			return false;
		}
		if (!isSelectDOB(fm.bY.value,fm.bM.value,fm.bD.value)){
			alert('請選擇[生日]');
			fm.bY.focus();
			return false;
		}
		if(!isTEL1(fm.tel1.value)){
			alert('請輸入正確的[電話區碼]');
			fm.tel1.focus();
			return false;
		}
		if(!isTEL2(fm.tel.value)){
			alert('請輸入正確的[電話號碼]');
			fm.tel.focus();
			return false;
		}
		if(!isTEL3(fm.tel2.value)){
			alert('請輸入正確的[電話分機]，如果沒有請空白');
			fm.tel2.focus();
			return false;
		}
		if((fm.mobilephone.value.length>0) && (!isMobile(fm.mobilephone.value))){
			alert('請輸入正確的[手機號碼]，如果沒有請空白');
			fm.mobilephone.focus();
			return false;
		}
		if(!isPostcode(fm.postcode.value)){
			alert('請輸入正確的[郵遞區號]');
			fm.postcode.focus();
			return false;
		}
		if(!isSelectCity(fm.city.value)){
			alert('請輸入正確的[縣市]');
			fm.city.focus();
			return false;
		}
		if(!isAddress(fm.address.value)){
			alert('請輸入正確的[地址]');
			fm.address.focus();
			return false;
		}
		if(!isName(fm.pname.value)){
			alert('請輸入正確的[家長中文姓名]');
			fm.pname.focus();
			return false;
		}
		if(!isEmail(fm.pemail.value)){
			alert('請輸入正確的[家長電子信箱]');
			fm.pemail.focus();
			return false;
		}
		/*if(!fm.q1[0].checked && !fm.q1[1].checked && !fm.q1[2].checked){
			alert('請選擇問卷一');
			return false;
		}
		if(!fm.q2[0].checked && !fm.q2[1].checked){
			alert('請選擇問卷二');
			return false;
		}
		if(!fm.q3[0].checked && !fm.q3[1].checked && !fm.q3[2].checked && !fm.q3[3].checked && !fm.q3[4].checked && !fm.q3[5].checked){
			alert('請選擇問卷三');
			return false;
		}
		if(!fm.q4[0].checked && !fm.q4[1].checked && !fm.q4[2].checked && !fm.q4[3].checked){
			alert('請選擇問卷四');
			return false;
		}
		if(!fm.q5[0].checked && !fm.q5[1].checked && !fm.q5[2].checked){
			alert('請選擇問卷五');
			return false;
		}*/
		return true;
	}
	
	function checkDataedit(){	
		if (isReadyedit(document.joinForm)){
			submitDataedit()
		}			
	}
	
	function submitDataedit(){
		document.joinForm.action='edituserupdate.aspx'
		document.joinForm.submit();
		document.joinForm.submitbutton.disable=true
	}
	
	function isReadyedit(fm){
		if(!isName(fm.realname.value)){
			alert('請輸入正確的[中文姓名]');
			fm.realname.focus();
			return false;
		}
		if(!isEmail(fm.email.value)){
			alert('請輸入正確的[電子信箱]');
			fm.email.focus();
			return false;
		}
		if(!isSelectSEX(fm.gender)){
			alert('請選擇[性別]!');			
			return false;
		}
		if (!isSelectDOB(fm.bY.value,fm.bM.value,fm.bD.value)){
			alert('請選擇[生日]');
			fm.bY.focus();
			return false;
		}
		if(!isTEL1(fm.tel1.value)){
			alert('請輸入正確的[電話區碼]');
			fm.tel1.focus();
			return false;
		}
		if(!isTEL2(fm.tel.value)){
			alert('請輸入正確的[電話號碼]');
			fm.tel.focus();
			return false;
		}
		if(!isTEL3(fm.tel2.value)){
			alert('請輸入正確的[電話分機]，如果沒有請空白');
			fm.tel2.focus();
			return false;
		}
		if((fm.mobilephone.value.length>0) && (!isMobile(fm.mobilephone.value))){
			alert('請輸入正確的[手機號碼]，如果沒有請空白');
			fm.mobilephone.focus();
			return false;
		}
		if(!isPostcode(fm.postcode.value)){
			alert('請輸入正確的[郵遞區號]');
			fm.postcode.focus();
			return false;
		}
		if(!isSelectCity(fm.city.value)){
			alert('請輸入正確的[縣市]');
			fm.city.focus();
			return false;
		}
		if(!isAddress(fm.address.value)){
			alert('請輸入正確的[地址]');
			fm.address.focus();
			return false;
		}
		if(!isName(fm.pname.value)){
			alert('請輸入正確的[家長中文姓名]');
			fm.pname.focus();
			return false;
		}
		if(!isEmail(fm.pemail.value)){
			alert('請輸入正確的[家長電子信箱]');
			fm.pemail.focus();
			return false;
		}
		return true;
	}
	
	function checkDatapwd(){	
		if (isReadypwd(document.pwdform)){
			submitDatapwd()
		}			
	}
	
	function submitDatapwd(){
		document.pwdform.action='editpwdupdate.aspx'
		document.pwdform.submit();
		document.pwdform.submitbutton.disable=true
	}
	
	function isReadypwd(fm){
		if(!isPWD(fm.oldpwd.value)){
			alert('請輸入正確的[舊密碼]\n(英文或數字 4-20 位數)')
			fm.oldpwd.focus();
			return false;
		}
		if(!isPWD(fm.newpwd.value)){
			alert('請輸入正確的[新密碼]\n(英文或數字 4-20 位數)')
			fm.newpwd.focus();
			return false;
		}
		if(!pwdMatch(fm.newpwd.value,fm.newpwd1.value)){
			alert('[密碼確認]錯誤，請再輸入一次密碼')
			fm.newpwd1.focus();
			return false;
		}
		return true;
	}
	
	function checkDataCathay(){	
		if (isReadyCathay(document.joinForm)){
			submitDataCathay()
		}			
	}
	
	function submitDataCathay(){
		document.joinForm.action='userformsave.aspx'
		document.joinForm.submit();
		document.joinForm.submitbutton.disable=true
	}
	
	function isReadyCathay(fm){
		if(!isName(fm.realname.value)){
			alert('請輸入正確的[中文姓名]');
			fm.realname.focus();
			return false;
		}
		if(!isEmail(fm.email.value)){
			alert('請輸入正確的[電子信箱]');
			fm.email.focus();
			return false;
		}
		if(!isSelectSEX(fm.gender)){
			alert('請選擇[性別]!');			
			return false;
		}
		if (!isSelectDOB(fm.bY.value,fm.bM.value,fm.bD.value)){
			alert('請選擇[生日]');
			fm.bY.focus();
			return false;
		}
		if(!isTEL1(fm.tel1.value)){
			alert('請輸入正確的[電話區碼]');
			fm.tel1.focus();
			return false;
		}
		if(!isTEL2(fm.tel.value)){
			alert('請輸入正確的[電話號碼]');
			fm.tel.focus();
			return false;
		}
		if(!isTEL3(fm.tel2.value)){
			alert('請輸入正確的[電話分機]，如果沒有請空白');
			fm.tel2.focus();
			return false;
		}
		if((fm.mobilephone.value.length>0) && (!isMobile(fm.mobilephone.value))){
			alert('請輸入正確的[手機號碼]，如果沒有請空白');
			fm.mobilephone.focus();
			return false;
		}
		if(!isPostcode(fm.postcode.value)){
			alert('請輸入正確的[郵遞區號]');
			fm.postcode.focus();
			return false;
		}
		if(!isSelectCity(fm.city.value)){
			alert('請輸入正確的[縣市]');
			fm.city.focus();
			return false;
		}
		if(!isAddress(fm.address.value)){
			alert('請輸入正確的[地址]');
			fm.address.focus();
			return false;
		}
		return true;
	}