function getRadioValue(RadioName){
  var allNodes=document.getElementsByName(RadioName);
  for(var i=0; i<allNodes.length; i++)if(allNodes[i].checked)return(allNodes[i].value);
  return(null);
}
//============================================================================//
//																																						//
//			判斷 Login Page 頁面所有表單欄位是否有漏填。           							//
//																																						//
//============================================================================//
function checkContactForm(theForm){

	if ( document.getElementById(theForm).id101.value == "" ){
		alert("請輸入帳號!!!");
		document.getElementById(theForm).id101.focus();
		return false;
	}	
	if ( document.getElementById(theForm).id102.value == "" ){
		alert("請輸入密碼!!!");
		document.getElementById(theForm).id102.focus();
		return false;
	}	

	document.getElementById(theForm).action="admin.php";
}


//============================================================================//
//																																						//
//			判斷 contact.php 頁面所有表單欄位是否有漏填。           							//
//																																						//
//============================================================================//
function checkContactForm(theForm){

	if ( document.getElementById(theForm).contactName.value == "" ){
		alert("請填【姓名】欄位!");
		return false;
	}	
	if ( document.getElementById(theForm).contactEmail.value == "" ){
		alert("請填【E-mail】欄位!");
				document.getElementById(theForm).contactEmail.focus();
		return false;
	}	
	if (!checkEmail(document.getElementById(theForm).contactEmail)){
		document.getElementById(theForm).contactEmail.focus();
		return false;
	}	
	if ( document.getElementById(theForm).contactPhone.value == "" ){
		alert("請填【聯絡電話】欄位!");
		return false;
	}
	if ( document.getElementById(theForm).contactComment.value == "" ){
		alert("請填【諮詢意見】欄位!");
		return false;
	}
	if ((getRadioValue('contactSex')!=1)&&(getRadioValue('contactSex')!=0)){
		alert("請填【性別】欄位!");
		return false;
	}
	document.getElementById(theForm).action="cMailSend.php";
}

//============================================================================//
//																																						//
//			判斷 member_forget.php 頁面所有表單欄位是否有漏填。           				//
//																																						//
//============================================================================//

function checkForgetForm(theForm){

	if ( document.getElementById(theForm).emailApplied.value == "" ){
		alert("請填【E-mail】欄位!");
				document.getElementById(theForm).emailApplied.focus();
		return false;
	}
	if (!checkEmail(document.getElementById(theForm).emailApplied)){
		document.getElementById(theForm).emailApplied.focus();
		return false;
	}
	if ( document.getElementById(theForm).nameApplied.value == "" ){
		alert("請填【申請人姓名】欄位!");
		return false;
	}	
	document.getElementById(theForm).action="memberQuery.php";
}

//============================================================================//
//																																						//
//			判斷 cooperation_join.php 頁面所有表單欄位是否有漏填。           			//
//																																						//
//============================================================================//

function checkForm3(theForm){

	if ( document.getElementById(theForm).joinName.value == "" ){
		alert("請填【聯絡人】欄位!");
		return false;
	}	
	if ( document.getElementById(theForm).joinAddress.value == "" ){
		alert("請選擇【才藝教室地點】欄位!");
		return false;
	}
	if ( document.getElementById(theForm).joinPhone.value == "" ){
		alert("請填【聯絡電話】欄位!");
		return false;
	}
	if ( document.getElementById(theForm).joinReason.value == "" ){
		alert("請填【加盟原因】欄位!");
		return false;
	}
	if ((getRadioValue('joinSex')!=1)&&(getRadioValue('joinSex')!=0)){
//	if (!(document.getElementById(theForm).joinSex.value=='')/*&&!(document.getElementById(theForm).joinSex2.checked)*/){
//	if ((document.getElementById(theForm).joinSex.value !=1)&&(document.getElementById(theForm).joinSex.value !=0)){
			alert("請填【性別】欄位!");
//			alert(getRadioValue('joinSex'));
//		alert(document.getElementById(theForm).joinSex.value);
		return false;
	}
	if ( document.getElementById(theForm).joinEmail.value == "" ){
		alert("請填【E-mail】欄位!");
				document.getElementById(theForm).joinEmail.focus();
		return false;
	}
	if (!checkEmail(document.getElementById(theForm).joinEmail)){
		document.getElementById(theForm).joinEmail.focus();
		return false;
	}
	document.getElementById(theForm).action="jMailSend.php";
}

//============================================================================//
//																																						//
//			判斷 member_new.php 頁面所有表單欄位是否有漏填。           			      //
//																																						//
//============================================================================//

function checkForm1(theForm){

	var str = document.getElementById(theForm).id001.value;
	
	if ( str == "請輸入帳號" ){
		document.getElementById(theForm).id001.focus();
		alert("請輸入帳號");
		return false;
	}
	if ( str == "" || str.length < 4 ){
		document.getElementById(theForm).id001.focus();
		alert("帳號至少４碼!!!");
		return false;
	}
	if ( str.length > 15 ){
		document.getElementById(theForm).id001.focus();
		alert("帳號不得超過15碼!!!");
		return false;		
	}
	if (document.getElementById(theForm).id002.value == ""){
		alert("請輸入密碼!!!");
		document.getElementById(theForm).id002.focus();
		return false;
	}	
	var acco = document.getElementById(theForm).id001.value;
	var pass = document.getElementById(theForm).id002.value;	
	if ( pass == "" || pass.length < 6 ){
		alert("密碼至少６碼!!!");
		document.getElementById(theForm).id002.focus();
		return false;
	}
	if (document.getElementById(theForm).id002.value != document.getElementById(theForm).id003.value){
		alert("密碼不相符!!!");
		document.getElementById(theForm).id002.focus();
		return false;
	}

	var nameStr = document.getElementById(theForm).id004.value;
	
	if ( nameStr == "" || nameStr.length < 2 ){
		alert("請填【姓名】欄位!");
		document.getElementById(theForm).id004.focus();
		return false;
	}

	if ( nameStr.length > 30 ){
		alert("【姓名】字數目前為"+nameStr.length+"個字，不得超過３０個字！");
		document.getElementById(theForm).id004.focus();
		return false;
	}
	
	if ( document.getElementById(theForm).id005.value == "選擇" 
		|| document.getElementById(theForm).id006.value == "選擇" 
		|| document.getElementById(theForm).id007.value == "選擇" ){

		alert("請選擇完整的【生日】欄位!");
				document.getElementById(theForm).id005.focus();
		return false;
	}
	if ( document.getElementById(theForm).id008.value == "" ){
		alert("請填【E-mail】欄位!");
				document.getElementById(theForm).id008.focus();
		return false;
	}
	if (!checkEmail(document.getElementById(theForm).id008)){
		document.getElementById(theForm).id008.focus();
		return false;
	}
	if ( document.getElementById(theForm).id010.value == "" ){
		alert("請填【連絡電話】欄位!");
		return false;
	}	
	if ((getRadioValue('radioId1')!=1) && (getRadioValue('radioId1')!=2)
			&&(getRadioValue('radioId1')!=3)&&(getRadioValue('radioId1')!=4)&&(getRadioValue('radioId1')!=5)){
		document.getElementById(theForm).id009.focus();				
		alert("請選擇【職業別】欄位!");
		return false;		
	}
	if((getRadioValue('radioId1')==5)&&(document.getElementById(theForm).id009.value == "")){
		document.getElementById(theForm).id009.focus();				
		alert("請填寫您的【職業】資料!");
		return false;		
	}
/*	if (!(getRadioValue('radioId2')==1 || getRadioValue('radioId2')==2)){
				document.getElementById(theForm).id011.focus();
				alert("請選擇【身分】欄位!");
				return false;
	}
	if ((getRadioValue('radioId2')==1)&&(document.getElementById(theForm).id010.value == "")){
		document.getElementById(theForm).id010.focus();
		alert("請填寫您的【連絡電話】資料!");
		return false;		
	}
	if ((getRadioValue('radioId2')==2)&&(document.getElementById(theForm).id011.value == "")){
		document.getElementById(theForm).id011.focus();
		alert("請填寫【加盟業者教室名稱】資料!");
		return false;		
	}
	if ((getRadioValue('radioId2')==2)&&(document.getElementById(theForm).id012.value == "")){
		document.getElementById(theForm).id012.focus();
		alert("請填寫【加盟業者連絡電話】資料!");
		return false;		
	}
	if ((document.getElementById(theForm).id010.value=="")&&(document.getElementById(theForm).id012.value=="")){
		document.getElementById(theForm).id012.focus();
		alert("請確認資料填寫完整!");
		return false;		
	}
*/	
	document.getElementById(theForm).action="memberAdd.php";
}


function checkForm2(theForm){ 	

	if ( document.getElementById(theForm).id101.value == "選擇" ){
		alert("請選擇【縣市】!");
		return false;
	}

	if ( document.getElementById(theForm).id105.value == "" ){
		alert("請填【學校】欄位!");
		return false;
	}

	if ( document.getElementById(theForm).id106.value == "" ){
		alert("請填【隊名】欄位!");
		return false;
	}

	if ( document.getElementById(theForm).id107.value == "" ){
		alert("請填【教練姓名】欄位!");
		return false;
	}

	if ( document.getElementById(theForm).id108.value == "" ){
		alert("請填【教練身份證】欄位!");
		return false;
	}

	if ( document.getElementById(theForm).id109.value == "選擇" 
		|| document.getElementById(theForm).id110.value == "選擇" 
		|| document.getElementById(theForm).id111.value == "選擇" ){

		alert("請選擇完整的【教練生日】!");
		return false;
		}

	if ( document.getElementById(theForm).id112.value == "" ){
		alert("請填【教練電話】欄位!");
		return false;
	}

	if ( document.getElementById(theForm).id113.value == "" ){
		alert("請填【教練手機】欄位!");
		return false;
	}

	if ( document.getElementById(theForm).id114.value == "" ){
		alert("請填【教練通訊處】欄位!");
		return false;
	}
		
	if ( document.getElementById(theForm).id115.value == "" ){
		alert("請填【FLL報名費】欄位!");
		return false;
	}
	
	if ( document.getElementById(theForm).id116.value == "" ){
		alert("請填【教練E-mail】欄位!");
		return false;
	}

	document.getElementById(theForm).action="signUpDo.php?lastTable=<?php echo $_GET[lastTable];?>&memberOrder=<?php echo $_GET[memberOrder];?>";

}

//============================================================================//
//																																						//
//			先判斷所有表單欄位是否為空，最後一次列出未填的欄位名稱。							//
//																																						//
//============================================================================//

function check() {
  err = '';
  i = 0;
  reg = new RegExp("^[a-zA-Z0-9\-\.\_]+\@[a-zA-Z0-9\-\.]+(\\.)+([a-zA-Z]{2,4})$","gi");
  if(document.forms[0].name.value == '') {i++; err += i+'.姓名\n';}
  if(document.forms[0].tel.value == '') {i++; err += i+'.電話\n';}
  if(document.forms[0].addr.value == '') {i++; err += i+'.地址\n';}
  if((document.forms[0].email.value == '')||(!reg.test(document.forms[0].email.value))){i++; err += i+'.電子信箱\n';}
  if(document.forms[0].msg.value == '') {i++; err += i+'.訊息\n';}
  if(err) {alert('敬請填妥以下欄位:\n'+err); return false; }
}

//============================================================================//
//																																						//
//  							Ｃｈｅｃｋ　Ｅｍａｉｌ　Ｆｕｎｃｔｉｏｎ 										//
//																																						//
//============================================================================//
function checkEmail(emailObj){
 var emailType = /\b\w+[@]\w+\.{1}\w+\b/;
 strtxt = emailObj.value;
 if (strtxt==""){
	alert ("電子郵件信箱 請不要空白");
	emailObj.focus();
	return false;
 }else if(!strtxt=="" && (!checkMouse(emailObj) || !checkDot(emailObj))){
 	alert ("請輸入正確格式的電子郵件信箱");
	emailObj.focus();
	return false;
 }else if(strtxt.charAt(strtxt.length-1)=="@"){
 	alert ("電子郵件信箱的結尾不能為( @ )小老鼠");
	emailObj.focus();
	return false;
 }else if(strtxt.charAt(0)=="@"){
 	alert ("電子郵件信箱的開頭不能為( @ )小老鼠");
	emailObj.focus();
	return false;
 }else if(strtxt.charAt(strtxt.length-1)=="."){
 	alert ("電子郵件信箱的結尾不能為( . )小數點");
	emailObj.focus();
	return false;
 }else if(strtxt.charAt(0)=="."){
 	alert ("電子郵件信箱的開頭不能為( . )小數點");
	emailObj.focus();
	return false;
 }else if(!checkSemicolon(emailObj)){
	alert ("電子郵件信箱不可含有( ; )分號");
	emailObj.focus();
	return false;
 }else if(!checkSpace(emailObj)){
	alert ("電子郵件信箱不可含有空白");
	emailObj.focus();
	return false;
 }else if(!checkDoubleDot(emailObj)){
	alert ("電子郵件信箱不可含有連續小數點");
	emailObj.focus();
	return false;
 }else if(!checkMouseDotOrDotMouse(emailObj)){
	alert ("電子郵件信箱中小數點不可緊鄰( @ )小老鼠");
	emailObj.focus();
	return false;
 }
 return true;
}

function checkMouse(emailObj){
 idx=0;
 count = 0;
 exist = "false";
 strtxt = emailObj.value;
 while (idx < strtxt.length){
	if (strtxt.charAt(idx++) == "@"){
		exist = "true";
		count++
	}
 }
 if(exist == "true" && count == 1)
 	return true;
 else
 	return false;
}

function checkDot(emailObj){
 idx=0;
 exist = "false";
 strtxt = emailObj.value;
 while (idx < strtxt.length){
	if (strtxt.charAt(idx++) == "."){
		exist = "true";
	}
 }
 if(exist == "true")
 	return true;
 else
 	return false;
}

function checkSemicolon(emailObj){
 idx=0;
 strtxt = emailObj.value;
 while (idx < strtxt.length){
	if (strtxt.charAt(idx++) == ";")
		return false;
 }
 return true;
}

function checkSpace(emailObj){
 idx=0;
 strtxt = emailObj.value;
 while (idx < strtxt.length){
	if (strtxt.charAt(idx++) == " ")
		return false;
 }
 return true;
}
function checkDoubleDot(emailObj){
 idx=0;
 strtxt = emailObj.value;
 while (idx < strtxt.length){
	if (strtxt.charAt(idx) == "." && strtxt.charAt(idx+1) == "."){
		return false;
	}
	idx++;
 }
 return true;
}
function checkMouseDotOrDotMouse(emailObj){
 idx=0;
 strtxt = emailObj.value;
 while (idx < strtxt.length){
	if ((strtxt.charAt(idx) == "@" && strtxt.charAt(idx+1) == ".")||(strtxt.charAt(idx) == "." && strtxt.charAt(idx+1) == "@")){
		return false;
	}
	idx++;
 }
 return true;
}


