function checkForm()
{ 	
	var str = document.getElementById('registerForm').id101.value;

	if ( str == "" || str.length < 4 ){
		document.getElementById('registerForm').id101.focus();
		alert("帳號至少4碼!!!");
//		document.getElementById('registerForm').action="registration.php?;
		return false;
	}

	if (str.charAt(0) > '0' && str.charAt(0) < '9'){
		alert("帳號第一個字元必須為英文字母!!!");
		return false;
	}

	for (var i=1;i < str.length;i++ )
	{  
		// if ( 不在0到9 && 不在 a到z && 不在A到Z )
		if ( (str.charAt(i) < '0' || str.charAt(i) > '9') && (str.charAt(i) < 'a' || str.charAt(i) > 'z') 
			&& (str.charAt(i) < 'A' || str.charAt(i) > 'Z') ){
			alert("帳號只能由英數字組合!!!");
			return false;
		}
	}


	if (document.getElementById('registerForm').id102.value == ""){
		alert("請輸入密碼!!!");
		document.getElementById('registerForm').id102.focus();
		return;
	}
	
	var pass = document.getElementById('registerForm').id102.value;
	var acco = document.getElementById('registerForm').id101.value;

	if (pass == acco){

		alert("密碼不可與帳號相同!!!");
//		document.getElementById('registerForm').id102.focus();
		return;
	}

	if (pass.indexOf(acco)!=-1){
		alert("密碼不可有帳號資訊!!!");
		document.getElementById('registerForm').id102.focus();
		return;
	}
	
	if (document.getElementById('registerForm').id102.value != document.getElementById('registerForm').id103.value){
		alert("密碼不相符!!!");
		document.getElementById('registerForm').action="registration.php";
//		document.getElementById('registerForm').id103.focus();
		document.getElementById('registerForm').submit();
		return;
	}

	if (!checkEmail(document.getElementById('registerForm').id104)){
		document.getElementById('registerForm').id104.focus();
		return;
	}

	document.getElementById('registerForm').submit();
}

function checkQForm(theForm){ 	
	if ( document.getElementById(theForm).qSubject.value == "" ){
		alert("問題主旨未填寫！");
		document.getElementById(theForm).qSubject.focus();
		return false;
	}
	if ( document.getElementById(theForm).qContent.value == "" ){
		alert("問題內容未填寫！!!!");
		document.getElementById(theForm).qContent.focus();
		return false;
	}
	if (!checkEmail(document.getElementById(theForm).qEmail)){
		document.getElementById(theForm).qEmail.focus();
		return false;
	}
	if (!checkChr()){
		document.getElementById(theForm).qContent.focus();
		return false;
	}

	return true;
		
}
function checkChr(){

	var maxChr = 2000;
	var nowChr = 0;
	
	var value = document.getElementById('qContent').value;

	for(var i=0;i<value.length;i++){
		value.charCodeAt(i)<256?nowChr++:nowChr+=2;
	}

	if(nowChr>maxChr){ 
		alert("你多輸入了"+(nowChr-maxChr)+"個字元。");
		return false;
	}else{
		return true;		
	}
}

function modifyTeamMember(memberOrder){
	document.getElementById("teamForm").action="signUp.php?action=modify&memberOrder="+memberOrder+"&lastTable=memberTable";
	document.getElementById("teamForm").submit();
}

function deleteTeamMember(memberOrder){
	document.getElementById("teamForm").action="deleteMemberData.php?memberOrder="+memberOrder;
	document.getElementById("teamForm").submit();	
}

function initial(table){
	document.getElementById("teamForm").action="signUp.php?lastTable="+table;
	document.getElementById("teamForm").submit();	
}

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;
}
