cover_enable = false; 
//function addit(){
//	alert(document.TutorForm.innerHTML);
//	document.TutorForm.innerHTML = "<div id=message name=message> . </div>" + document.TutorForm.innerHTML;
//}
//	addit();

		function save_value(name, value){
				value = value + "";
				value = value.split("|");
				value = value.join("");
				value = value.split("~");
				value = value.join("");
				if (value.length > 50){
						return null;
				}
				
				//alert(name + "/" + value);
				var temp = Get_Cookie("all");
//				if (temp.length > 2000){
//					return null;
//				}
				//alert(temp);
				Delete_Cookie("all", '/', '' ) ;
				if (temp == null){
					temp = "";
				}
			
				temp = temp.split("|");
				temp_name = Array();
				flag = false;
				for (g = 0 ; g < temp.length; g++){
					temp_2 = temp[g].split("~");
					if (temp_2.length == 2){
						if (temp_2[0] == name){
							temp_2[1] = value;
							flag = true;
						} 
						temp2 = temp_2.join("~");
						temp_name.push(temp2);
					}
				}
			
				if (!flag){
					temp_name.push(name+"~"+value);
				}
				temp = temp_name.join("|");
				Set_Cookie("all", temp, 10, '/', '', '' );
//				alert('Saving: '+temp);
//				alert('result: '+Get_Cookie("all"));
			
		}
		function load_value(name){
				var temp = Get_Cookie("all");
				if (temp == null){
					temp = "";
				}
				
				temp = temp.split("|");
				for (g = 0 ; g < temp.length; g++){
					temp_2 = temp[g].split("~");
					if (temp_2.length == 2){
						if (temp_2[0] == name){
								return temp_2[1];
						} 
					}
				}
				return "";
		}




function isNan(input){
 if ( (input == 0 && (input == "0" || input == "")) || input > 0 || input < 0)
   return true;
 else 
   return false;
}

function CheckAll(x, y){
	var x, y;    
	var len = x.length;
	//alert(document.TutorForm.elements.length);
	if (cover_enable == false){
		for (var i=0;i < document.TutorForm.elements.length;i++)
		{
	   		var total = document.TutorForm.elements[i];
	   		var text = total.name
	   		text = text.substring(0, len); 
	    	if (text == x)
	      		total.checked = y;
	
		}
	} else {
	}
}	

function del(link){
		if (confirm("你真的想刪除這個表格嗎？"))
			location = "./index.php?" + link;
		else 
			alert("已經取消!");
}
function approve_form(link){
		if (confirm("你真的想批准這個表格嗎？"))
			location = "./index.php?" + link;
		else 
			alert("已經取消!");
}

function allowuser(link){
		if (confirm("你真的想批准這個用戶嗎？"))
			location = "./index.php?" + link;
		else 
			alert("已經取消!");
}

function delete_form(id){
		if (confirm("你真的想刪除這個表格嗎？"))
			location = "./index.php?" + id;
		else 
			alert("已經取消!");
}
function Match(id){
		if (confirm("你真的想刪除這個表格嗎？"))
			location = "./index.php?" + id;
		else 
			alert("已經取消!");
}

function del_user(link){
		if (confirm("你真的想刪除這個用戶嗎？"))
			location = "./index.php?" + link;
		else 
			alert("已經取消!");
}

function disable_form(name_){
	tempor.innerHTML = document.TutorForm.innerHTML;
	tempor.style.display = "none";
	var item_ = eval("document."+name_);
	for (var i=0;i < item_.elements.length;i++){
		var total = item_.elements[i];
		if (total.type != "text" && total.type != "select-one" && total.type != "button" && total.type != "textarea"  && total.type != "checkbox")
			total.disabled = true;
		else 
			total.readOnly = true;
	}
}

function disable_this(obj){
	if (obj.type == "text" || obj.type == "textarea" )
		obj.readOnly = true;
	else	
		obj.disabled = true;
}

function enable_this(obj){
	if (obj.type == "text" || obj.type == "textarea" )
		obj.readOnly = false;
	else	
		obj.disabled = false;
}

function enable_form(name_){
	var item_ = eval("document."+name_);
	for (var i=0;i < item_.elements.length;i++){
		var total = item_.elements[i];
			total.disabled = false;
			total.readOnly = false;
	}
	item_.readOnly = false;
	item_.disabled = false;

}

function allow_change(){
	
	cover_enable = false; 
	enable_form("TutorForm");
}
function update_score(obj){
				if (is_search == true)
					return true;
				var temp = Array(0, 0, 0, 0, 0, 0, 0, 0);
				var start = 1;
				var end = 31;
				var tempname = "hkcee["+start+"]";
				for (var i=0;i < document.TutorForm.elements.length;i++){
					var item = document.TutorForm.elements[i];
					
						if (item.name == tempname){
							temp[item.value] = temp[item.value]+1;
							
							if (start < end){
								start++;
								tempname = "hkcee["+start+"]";
							}
						}
						
				}
				
				var counter=0;
				score = 0;
				for (var i = temp.length - 1 ; i >= 3  ; i--){
							
							if (temp[i]+ counter > 6){
								temp[i]= 6 - counter;
							}
							
							counter += temp[i];
							if (  i - 2 > 0)
								score += temp[i]*(i - 2);
				}
				
				var item = document.TutorForm.elements["hkcee_total"];
				item.value = score;
}


function fill_form(name_, values){
	
	
	var G = 0;
	var item_ = eval("document."+name_);
	var values_length = values.length;
	
	for (var i=0;i < item_.elements.length;i++){
			var total = item_.elements[i];
			var size = values.length;
			if (total.type == 'text')
				total.value = "";
			
			for (var j=0; j < size && values_length > 0; j++){
						
						if (total.type == "radio"){
				   		if (total.value == values[j][1] && total.name == "apply["+values[j][0]+"]"){
				   			total.checked = true;
			   				values.splice(j, 1);
								values_length--;
								break;
			   			}
			   		} else if (total.type == "checkbox"){
			   			var i0 = values[j][0];
			   			var i1 = values[j][1];
						  if (total.name == "apply["+i0+"]["+i1+"]"){
			   				total.checked = true;
			   				values.splice(j, 1);
								values_length--;
								break;
			   			}
			   		} else if (total.type == "hidden"){
			   		
			   		} else if (total.type == "submit"){
			   			total.disabled = true;
			   		} else {
				   		if (total.name == "apply["+values[j][0]+"]"){
								total.value = values[j][1];
								values.splice(j, 1);
								values_length--;
								break;
				  		}
			   		}



				
				
						G++;

			}
		}
}

function editform(name_){
	var item_ = eval("document."+name_);
	for (var i=0;i < item_.elements.length;i++)
		{
		var total = item_.elements[i];
		if (total.name != "")
		total.disabled = false;
		total.readOnly = false;
		}
	item_.disabled = false;
	item_.readOnly = false;
}


function tutor_val(){
app = Array(
	Array("usrverify", "m", "請輸入驗證碼！"),
	Array("contact[identification][0]", "lid", "身份證號碼不正確"),
	Array("contact[ename]", "lmax", "英文名字不能超過40個字！", 40),
	Array("contact[cname]", "lmax", "中文名字不能超過40個字！", 40),
	Array("user_id", "m", "用戶ID不能為空！"),
	Array("user_id", "b", "用戶ID中不能有空格！"),
	Array("my_pass", "m", "用戶密碼不能為空！"),
	Array("re_pass", "m", "請確認您的密碼！"),
	Array("my_pass", "lmin", "用戶密碼不能少於4位！",4),
	Array("re_pass", "lmin", "請確認您的密碼不能少於4位！",4),	
	Array("re_pass", "eq", "兩次密碼輸入不符！","my_pass"),
	Array("contact[ename]", "m", "中文名不能為空！"),
	Array("contact[cname]", "m", "英文名不能為空！"),
 	Array("contact[dob]", "age", "你的出生日期載入不正確！"),
	Array("contact[sex]", "m", "請填好你的性別！"),
	Array("email", "@", "請填好你的電子郵件地址！"),
	Array("hk_area", "ze", "請選擇好你的居住地區！"),
	Array("hk_location", "ze", "請選擇好你的居住地區！"),
	Array("contact[t_location]", "ze", "請選擇好你想的教學地方！"),
	Array("contact[cphone]", "g", "請填好你的手機！ "),
	Array("contact[hphone]", "g", "請填好你的住家電話！"),
	Array("contact[wphone]", "g", "請填好你的工作電話！"),
	Array("contact[cphone]", "isNan", "手機只能輸入數字"),
	Array("contact[hphone]", "isNan", "住家電話只能輸入數字"),
	Array("contact[wphone]", "isNan", "工作電話只能輸入數字"),
	Array("howtoknowus", "ze", "請選擇好你從何處得知本站！")
);
		
	//var _ret=true; /* false means not validated */
	//var _m="Your input number must be provided by equal number of items";
	$flag = true;
	var len = app.length;
	var $message = "";
	var counter = 1;
	var g_count = 0;
	var namecounter = 0;



	for (var i = 0 ; i < len; i++)	{
				var error = false;
				
				var value_ = findvalue(app[i][0]);
				$ggg = "";
				if (value_ != "NULL"){
					if (app[i][0] != ""){
						$temp_message = "\n "+counter+": \t";
						if (app[i][1] == "@"){
							if (!emailCheck(value_)){
										error = true;
										$flag = false;
										$temp_message += app[i][2];
							}
						} else if (app[i][1] == "m"){
							// alert(value_);
							if (value_.length == 0){
								error = true;
								$flag = false;
								$temp_message += app[i][2];
							}
						} else if (app[i][1] == "b"){
							// alert(value_);
							if (value_.indexOf(" ") !=-1){
								error = true;
								$flag = false;
								$temp_message += app[i][2];
							}
						} else if (app[i][1] == "lmax"){
								if (value_.length > app[i][3]){
									error = true;
									$flag = false;
									$temp_message += app[i][2];
								}
						} else if (app[i][1] == "lmin"){
								if (value_.length < app[i][3]){
									error = true;
									$flag = false;
									$temp_message += app[i][2];
								}
								
						} else if (app[i][1] == "lid"){
							id_1 = document.getElementById("contact[identification][0]").value;
							
							id_2 = document.getElementById("contact[identification][1]").value;
								if ( id_1.length > 10 || (id_1.length != 0 || id_2.length != 0 ) && ((id_1.length < 7) || id_2.length != 1)    ){
									error = true;
									$flag = false;
									$temp_message += app[i][2];
								}
						} else if (app[i][1] == "g"){
								if (value_ == ""){
									g_count++;
								}
						} else if (app[i][1] == "n"){
							// n = number
							if (value_ < 1 || value_.length > 20){
								error = true;
								$flag = false;
								$temp_message += app[i][2];
							}
						} else if (app[i][1] == "to"){
							if (value_.length == 0)
								namecounter++;
							
						} else if (app[i][1] == "age"){
								if (!callvalid(11)){
									error = true;
									$flag = false;
									$temp_message += app[i][2];
								}
						} else if (app[i][1] == "isNan"){

								if (!isNan(value_)){
									error = true;
									$flag = false;
									$temp_message += app[i][2];
								}
						} else if (app[i][1] == "eq"){
						        
								if (value_ != findvalue(app[i][3])) {
									error = true;
									$flag = false;
									$temp_message += app[i][2];
								}

					    } else if (app[i][1] == "ze"){

								if (value_ == 0) {
									error = true;
									$flag = false;
									$temp_message += app[i][2];
								}
					    }
					}
				}

				if (error){
					$message += $temp_message;
					counter++;
				}
	}
	
	
	if (namecounter == 2){
		$flag = false;
		$temp_message = "\n "+counter+": \t";
		$message += $temp_message + "請填好你的中文名字 或 英文名字 ！";
		error = true;
		counter++;
		
	}

	if (g_count == 3){
		$temp_message = "\n "+counter+": \t";
		$flag = false;
		$message += $temp_message + "請填好你的電話號碼!";
		error = true;
		counter++;		
	}	
	if ($flag == false){
		alert($message);
		//temp = $message.split("\n");
		//err_msg.innerHTML = "<table> <tr><td>";
		//for (i=0; i < temp.length; i++)
		//	err_msg.innerHTML += "<font color=red>"+temp[i]+"</font><BR>";
			
		//err_msg.innerHTML += " </td></tr></table>";
			
	}

if ($flag)
	saveco();
enable_form("TutorForm");
//return false;
return $flag;
}


function advuser_val(){
app = Array(
	Array("usrverify", "m", "請輸入驗證碼！"),
	Array("contact[identification][0]", "lid", "身份證號碼不正確"),
	Array("name", "lmax", "名字不能超過40個字！", 40),
	Array("user_id", "m", "用戶ID不能為空！"),
	Array("user_id", "b", "用戶ID中不能有空格！"),
	Array("my_pass", "m", "用戶密碼不能為空！"),
	Array("re_pass", "m", "請確認您的密碼！"),
	Array("my_pass", "lmin", "用戶密碼不能少於4位！",4),
	Array("re_pass", "lmin", "請確認您的密碼不能少於4位！",4),	
	Array("re_pass", "eq", "兩次密碼輸入不符！","my_pass"),
	Array("name", "m", "姓名不能為空！"),
	Array("email", "@", "請填好你的電子郵件地址！"),
	Array("contact[cphone]", "g", "請填好你的手機！ "),
	Array("contact[hphone]", "g", "請填好你的住家電話！"),
	Array("contact[wphone]", "g", "請填好你的工作電話！"),
	Array("contact[cphone]", "isNan", "手機只能輸入數字"),
	Array("contact[hphone]", "isNan", "住家電話只能輸入數字"),
	Array("contact[wphone]", "isNan", "工作電話只能輸入數字")
	
);
		
	//var _ret=true; /* false means not validated */
	//var _m="Your input number must be provided by equal number of items";
	$flag = true;
	var len = app.length;
	var $message = "";
	var counter = 1;
	var g_count = 0;
	var namecounter = 0;



	for (var i = 0 ; i < len; i++)	{
				var error = false;
				
				var value_ = findvalue(app[i][0]);
				$ggg = "";
				if (value_ != "NULL"){
					if (app[i][0] != ""){
						$temp_message = "\n "+counter+": \t";
						if (app[i][1] == "@"){
							if (!emailCheck(value_)){
										error = true;
										$flag = false;
										$temp_message += app[i][2];
							}
						} else if (app[i][1] == "m"){
							// alert(value_);
							if (value_.length == 0){
								error = true;
								$flag = false;
								$temp_message += app[i][2];
							}
						} else if (app[i][1] == "b"){
							// alert(value_);
							if (value_.indexOf(" ") !=-1){
								error = true;
								$flag = false;
								$temp_message += app[i][2];
							}
						} else if (app[i][1] == "lmax"){
								if (value_.length > app[i][3]){
									error = true;
									$flag = false;
									$temp_message += app[i][2];
								}
						} else if (app[i][1] == "lmin"){
								if (value_.length < app[i][3]){
									error = true;
									$flag = false;
									$temp_message += app[i][2];
								}
								
						} else if (app[i][1] == "lid"){
							id_1 = document.getElementById("contact[identification][0]").value;
							
							id_2 = document.getElementById("contact[identification][1]").value;
								if ( id_1.length > 10 || (id_1.length != 0 || id_2.length != 0 ) && ((id_1.length < 7) || id_2.length != 1)    ){
									error = true;
									$flag = false;
									$temp_message += app[i][2];
								}
						} else if (app[i][1] == "g"){
								if (value_ == ""){
									g_count++;
								}
						} else if (app[i][1] == "n"){
							// n = number
							if (value_ < 1 || value_.length > 20){
								error = true;
								$flag = false;
								$temp_message += app[i][2];
							}
						} else if (app[i][1] == "to"){
							if (value_.length == 0)
								namecounter++;
							
						} else if (app[i][1] == "age"){
								if (!callvalid(11)){
									error = true;
									$flag = false;
									$temp_message += app[i][2];
								}
						} else if (app[i][1] == "isNan"){

								if (!isNan(value_)){
									error = true;
									$flag = false;
									$temp_message += app[i][2];
								}
						} else if (app[i][1] == "eq"){
						        
								if (value_ != findvalue(app[i][3])) {
									error = true;
									$flag = false;
									$temp_message += app[i][2];
								}

					    } else if (app[i][1] == "ze"){

								if (value_ == 0) {
									error = true;
									$flag = false;
									$temp_message += app[i][2];
								}
					    }
					}
				}

				if (error){
					$message += $temp_message;
					counter++;
				}
	}
	
	
	if (namecounter == 2){
		$flag = false;
		$temp_message = "\n "+counter+": \t";
		$message += $temp_message + "請填好你的中文名字 或 英文名字 ！";
		error = true;
		counter++;
		
	}

	if (g_count == 3){
		$temp_message = "\n "+counter+": \t";
		$flag = false;
		$message += $temp_message + "請填好你的電話號碼!";
		error = true;
		counter++;		
	}	
	if ($flag == false){
		alert($message);
		//temp = $message.split("\n");
		//err_msg.innerHTML = "<table> <tr><td>";
		//for (i=0; i < temp.length; i++)
		//	err_msg.innerHTML += "<font color=red>"+temp[i]+"</font><BR>";
			
		//err_msg.innerHTML += " </td></tr></table>";
			
	}

if ($flag)
	saveco();
enable_form("TutorForm");
//return false;
return $flag;
}


function playsound(soundfile){
		if (document.all && document.getElementById){
		document.getElementById("soundeffect").src="" //reset first in case of problems
		document.getElementById("soundeffect").src=soundfile
		}
}

function bindsound(tag, soundfile, masterElement){
		if (!window.event) return
		var source=event.srcElement
		while (source!=masterElement && source.tagName!="HTML"){
		if (source.tagName==tag.toUpperCase()){
		playsound(soundfile)
		break
		}
		source=source.parentElement
		}
}


		function findvalue($name){
			//12345
			//var dob_year = document.getElementById("contact[dob][0]").value;
			
			for (var i=0;i < document.TutorForm.elements.length;i++)
			{
		   		var total = document.TutorForm.elements[i];
		   		
		   		var text = total.name
		   		text = text.substring(0, $name.length); 
		   		//	alert(text + total.value);
		   		
		    	if (text == $name ){
		    		//
		    		//alert(total.name + ": " + total.type);
		    		if (total.type == "radio" && total.checked){
		    			return (total.value);
		    		} else if (total.type == "select-one" ){
		    			return total.value;
		    		} else if (total.type == "checkbox" && total.checked){
		    			return (total.value);
		    		} else if (total.type == "text" || total.type == "password" || total.type == "hidden"){
		    			return (total.value);
		    		}
		    		
		    		//alert(total.type);
		    		
		      }
			}
			return "";
			
		}
		$mem = Array();
		$mem[1] = " ";
		$mem[7] = "";
			
		
		function trim_id_up($name, length){
			$name.value = $name.value.substr(0,length);
			if ($name.length > length){
				$name.value = $name.value.substr(0,length);
			}
		}


		function callvalid($age){
			
			var dob_year = document.getElementById("contact[dob][0]").value;
			var dob_mon = document.getElementById("contact[dob][1]").value;
			var dob_date = document.getElementById("contact[dob][2]").value;
			var age_item = document.getElementById("age");
			
			var _d = new Date();
			age = _d.getYear() - dob_year;
			age_item.value = age;
			if ( age < 100 && age > $age){
				if (dob_date >= 0 && dob_date <= max_day(dob_mon, dob_year) )
			  	return true;
			  else 
			  	return false;
			  	
			} else {
				return false;
			}
		}
		
		function updatedob($age){
			var _d = new Date();
			if ($age.length < 4 && $age > 0 && $age <100){
							tempitem = document.getElementById("contact[dob][0]");
			 				tempitem.value = (_d.getYear() - $age );
//							var dob_year = document.getElementById("contact[dob][0]").value;
//							var dob_mon = document.getElementById("contact[dob][1]").value;
//							var dob_date = document.getElementById("contact[dob][2]").value;
			  
			}
			return "";

		}


	
	function birthday(){
		// (document.getElementById("contact[dob][0]").value);
		ageitem = document.getElementById("age") ; 
		
		error =false;
		var today = new Date(); 
		var year = today.getYear();
		var n_month = today.getMonth()+1;
		var n_date = today.getDate();
		//alert (n_month)
		//alert (n_date)
		
		var dob_year = document.getElementById("contact[dob][0]").value;
		var dob_mon = document.getElementById("contact[dob][1]").value;
		var dob_date = document.getElementById("contact[dob][2]").value;

		var message = "日期輸入錯唔! (年份/月份/日期)\n";
			{
				if ( dob_year > (year - 12)  || dob_year < (year - 70) ){
					message += "導師年齡太大或太小\n";
					error = true;
				} else if ( dob_mon > 12  || dob_mon < 1){
					message += "月份 輸入不正確 \n";
					error = true;
				} else if ( dob_date > 31  || dob_date < 1){
					message += "日期 輸入不正確 \n";
					error = true;
				} else if ( dob_date > max_day(dob_mon, dob_year) ){
					error = true;
				}
				
				if (error == true){
					alert( message );
					return false;
				} else {
					   if ((n_month - dob_mon) > 0) {
						ageitem.value = year - dob_year;
				       } else  if ((n_month - dob_mon) < 0) {
						ageitem.value = year - dob_year - 1;
				       } else if ((n_date - dob_date) >= 0) {
						   ageitem.value = year - dob_year;
					   } else {
						   ageitem.value = year - dob_year -1;
					   }
					    return true;
				}
			}
	}
	
	function emailCheck (emailStr) { 
		var checkTLD=0; 
		var knownDomsPat=/ ^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/; 
		var emailPat=/^(.+)@(.+)$/; 
		var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]"; 
		var validChars="\[^\\s" + specialChars + "\]"; 
		var quotedUser="(\"[^\"]*\")"; 
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; 
		var atom=validChars + '+'; 
		var word="(" + atom + "|" + quotedUser + ")"; 
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); 
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); 
		var matchArray=emailStr.match(emailPat); 
		if (matchArray==null) { 
			// alert("The Email Address Is Invalid"); 
			return false; 
		} 
		var user=matchArray[1]; 
		var domain=matchArray[2]; 
		for (i=0; i<user.length; i++) { 
			if (user.charCodeAt(i)>127) { 
			//	alert("The Username Contains Invalid Characters."); 
				return false; 
			} 
		} 
		for (i=0; i<domain.length; i++) { 
			if (domain.charCodeAt(i)>127) { 
				//alert("Ths Domain Name Contains Invalid Characters."); 
				return false; 
			} 
		} 
		if (user.match(userPat)==null) { 
			// alert("The Username Is Invalid."); 
			return false; 
		} 
		var IPArray=domain.match(ipDomainPat); 
		if (IPArray!=null) { 
			for (var i=1;i<=4;i++) { 
				if (IPArray>255) { 
					// alert("The Destination IP Address Is Invalid."); 
					return false; 
				} 
			} 
			return true; 
		} 
		var atomPat=new RegExp("^" + atom + "$"); 
		var domArr=domain.split("."); 
		var len=domArr.length; 
		for (i=0;i<len;i++) { 
			if (domArr[i].search(atomPat)==-1) { 
				// alert("The Domain Name Is Invalid."); 
				return false; 
			} 
		} 
	//	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	//	domArr[domArr.length-1].search(knownDomsPat)==-1) { 
	//		// alert("The Domain Name Extension Is Invalid"); 
	//		return false; 
	//	} 
		if (len<2) { 
			//	alert("The Address Is Missing A Hostname."); 
			return false; 
		}
		return true;
	} 
	
	function stu_val(){
		
		app = Array(
			Array("name", "lmax", "名字不能超過40個字！", 40),
			Array("name", "lmin", "名字不能少於2個字！", 2),
			Array("age", "n", "請填好你的年齡！"),
			Array("email", "@", "請填好你的電子郵件地址！"),
			Array("cphone", "g", "請填好你的電話！"),
			Array("wphone", "g", "請填好你的電話！"),
			Array("hphone", "g", "請填好你的電話！"),
			Array("hk_location", "m", "請選擇好你想的教授地區！"),
			Array("subject", "s", "請選好學習科目！")
			
		);		
			//var _ret=true; /* false means not validated */
			//var _m="Your input number must be provided by equal number of items";
			$flag = true;
			var len = app.length;
			var $message = "";
			var counter = 1;
			var phonecounter = 0;
			for (var i = 0 ; i < len; i++)	{
						var error = false;
						
						var value_ = findvalue(app[i][0]);
						
						if (value_ != "NULL"){
							if (app[i][0] != ""){
								$temp_message = "\n "+counter+": \t";
								if (app[i][1] == "@"){
									if (value_ != "" && !emailCheck(value_)){
											error = true;
											$flag = false;
											$temp_message += app[i][2];
									}

								} else if (app[i][1] == "m"){
									if (value_.length == 0 || value_ == 0){
										error = true;
										$flag = false;
										$temp_message += app[i][2];
									}
								} else if (app[i][1] == "lmax"){
										
										// l = max length
										if (value_.length > app[i][3]){
											error = true;
											$flag = false;
											$temp_message += app[i][2];
										}
									
								} else if (app[i][1] == "lmin"){
										
										// l = max length
										//alert(app[i][0] + value_);
										if (value_.length < app[i][3]){
											error = true;
											$flag = false;
											$temp_message += app[i][2];
										}
								} else if (app[i][1] == "s"){
									// n = number 
									if (value_ == "" || value_ == 0 || value_.length == 0){
										error = true;
										$flag = false;
										$temp_message += app[i][2];
									}
								} else if (app[i][1] == "n"){
									
									if (value_.length < 0 || value_.length > 20 || (value_.length > 0 && !(value_ > 0))){
										error = true;
										$flag = false;
										$temp_message += app[i][2];
									} else {
										
									}
								} else if (app[i][1] == "g"){
									
									if (value_.length < 0 || value_.length > 20 || !(value_ > 0)){
										phonecounter ++;
										if (phonecounter == 3){
											error = true;
											$temp_message += app[i][2];
											$flag = false;
										}
									}
									
								}
							}
						}
						if (error){
							$message += $temp_message;
							counter++;
						}
			}
			
			if ($flag == false)
				alert($message);
		
		//enable_form("TutorForm");
		return $flag;
		}

		
		function Set_Cookie( name, value, expires, path, domain, secure ) {
					// set time, it's in milliseconds
					var today = new Date();
					today.setTime( today.getTime() );
					
					/*
					if the expires variable is set, make the correct 
					expires time, the current script below will set 
					it for x number of days, to make it for hours, 
					delete * 24, for minutes, delete * 60 * 24
					*/
					if ( expires )
					{
					expires = expires * 1000 * 60;
					}
					
					var expires_date = new Date( today.getTime() + (expires) );
					
					document.cookie = name + "=" +escape( value ) +
					( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
					( ( path ) ? ";path=" + path : "" ) + 
					( ( domain ) ? ";domain=" + domain : "" ) +
					( ( secure ) ? ";secure" : "" );
		}
			
		
		
		// this function gets the cookie, if it exists
		function Get_Cookie( name ) {
						var start = document.cookie.indexOf( name + "=" );
						var len = start + name.length + 1;
						if ( ( !start ) &&	( name != document.cookie.substring( 0, name.length ) ) )						{
								return null;
						}
						if ( start == -1 ) 
							return null;
						var end = document.cookie.indexOf( ";", len );
						if ( end == -1 ) end = document.cookie.length;
						
						return unescape( document.cookie.substring( len, end ) );
		}
		
		
		
		// this deletes the cookie when called
		function Delete_Cookie( name, path, domain ) {
						if ( Get_Cookie( name ) ) document.cookie = name + "=" +
						( ( path ) ? ";path=" + path : "") +
						( ( domain ) ? ";domain=" + domain : "" ) +
						";expires=Thu, 01-Jan-1970 00:00:01 GMT";
		}
		
		function saveco(){
			
			Set_Cookie("clearcookie" , 0, 20, '/', '', '' ); 
			Delete_Cookie("all", '/', '' ) ;
			j = 0;
						for (var i=0;i < document.TutorForm.elements.length;i++){
									var obj = document.TutorForm.elements[i];
									Delete_Cookie( obj.name, '/', '' ) ;
				   				Delete_Cookie( obj.name + "_" + obj.value, '/', '' ) ;

									if (obj.name != null && obj.name != "" && obj.name.slice(0,5) != "apply" ){
										//alert(j);
												j++;
												if ( ( obj.type == "textarea"  || obj.type == "text" ) && obj.name != null && obj.name != "" && obj.value != null && obj.value != "" && obj.value != 0){
														save_value( obj.name , obj.value);
									   		} else if (obj.type == "select-one"){
									   				save_value( obj.name , obj.value);
									   		} else if (obj.type == "radio" && obj.checked){
									   				save_value( obj.name+"_"+obj.value,1);
									   		} else if (obj.type == "checkbox" && obj.checked){
									   				save_value( obj.name+"_"+obj.value, 1);
									   		}
								   }
								   if (obj.name.slice(0,5) == "apply" ){
								   		return true;
								   }
								   if (j >= 19){
								   		return true;
								   }
						}
		}
		
		function loadco(){
			// alert("Loading...");
			if (Get_Cookie("clearcookie") != 1) {
				
				for (var i=0;i < document.TutorForm.elements.length;i++){
					
			 		var obj = document.TutorForm.elements[i];
			 				if (obj.name != ""){
					 						
								 		if (load_value( obj.name ) != "" && ( obj.type == "textarea"  || obj.type == "text" ) && obj.name != ""){
								 				//alert("loading"+obj.name);
												obj.value = load_value( obj.name );
								 		} else if (obj.type == "select-one"){
									  		obj.value = load_value( obj.name ) * 1;
									  } else if (obj.type == "checkbox" ||obj.type == "radio" ){
									  		if (load_value( obj.name+"_"+obj.value ) == 1){
									  			
													obj.checked = true;
												} else {
													obj.checked = false;
												}
													
									  }
							}
				}
			}
		}
		
		function clearcookie(){
			if (cover_enable == false)
						for (var i=0;i < document.TutorForm.elements.length;i++){
				   			var obj = document.TutorForm.elements[i];
				   			
				   			if (obj.type == "text" || obj.type == "textarea")
				   				obj.value = "";
				   			else if (obj.type == "checkbox" || obj.type == "radio" )
				   				obj.checked = false;
				   			else if (obj.type == "select-one" )
				   				obj.value = "0";
				   			
				   			Delete_Cookie( obj.name, '/', '' ) ;
				   			Delete_Cookie( obj.name + "_" + obj.value, '/', '' ) ;
						}
		}
		
	changeok = false;
	function reset(){
		var ns6=document.getElementById&&!document.all?1:0;
		if (cover_enable == true){
			if (changeok){
			
			} else {
				y = (document.layers || ns6) ? e.pageY : document.body.scrollTop+event.clientY;
				tmp.value="";
				tmp.style.posTop 	= y - 10;
				tmp.focus()
			}
			clearcookie();
			// saveco();
		}
		
	}
	
	function toggle(item){
		if (cover_enable == true){
			item.checked =! item.checked;
		}
	}
	
	function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}


function max_day(mn, yr){
	  var mDay;
	  if((mn == 4) || (mn == 6) || (mn == 9) || (mn == 11)){ 
	    	mDay = 30;
	  } else if(mn == 2){
	    //calling leap year function 
	   	 mDay = isLeapYear(yr) ? 29 : 28;    
	  } else if (mn >= 1 && mn <= 12){
	   	 mDay = 31;
	  } else {
	  		mDay = 0;
	  }
	  return mDay; 
}


function regular(link) {
	makeWindow(1024,600,"1024x600", "./?action=loadblock&id="+link  );
}

function makeWindow(x,y,t, link) {
  var _i = "toolbar=yes,status=yes,scrollbars=yes,location=yes,menubar=yes,directories=yes";
  var _w = "width=";
  var _h = "height=";
  var _window = window.open(link, t , _i+','+_w+x+','+_h+y);
}

// function to check leap year
function isLeapYear(yr)
{
  if      (yr % 4 != 0)   return false;
  else if (yr % 400 == 0) return true;
  else if (yr % 100 == 0) return false;
  else                    return true;
}

var soundfile="./sound/alarm.wav" //path to sound file, or pass in filename directly into playsound()


function changeHKCEE(x)
{
	var v = document.TutorForm.elements["hkcee[1]"];
	var vSelectedIndex = v.selectedIndex;
	var w = document.TutorForm.elements["hkcee[2]"];
	var wSelectedIndex = w.selectedIndex;
	var y = document.all.div_hkcee_eng
	v.options.length = 0;
	w.options.length = 0;
	if(x==2007)
	{
		 v.options[v.options.length] = new Option('無','0');
		 v.options[v.options.length] = new Option('5*','7');
		 v.options[v.options.length] = new Option('5','6');
		 v.options[v.options.length] = new Option('4','5');
		 v.options[v.options.length] = new Option('3','4');
		 v.options[v.options.length] = new Option('2','3');
		 v.options[v.options.length] = new Option('1','2');
		 v.options[v.options.length] = new Option('U','1');		 
		 v.options[vSelectedIndex].selected = true;
		 w.options[w.options.length] = new Option('無','0');
		 w.options[w.options.length] = new Option('5*','7');
		 w.options[w.options.length] = new Option('5','6');
		 w.options[w.options.length] = new Option('4','5');
		 w.options[w.options.length] = new Option('3','4');
		 w.options[w.options.length] = new Option('2','3');
		 w.options[w.options.length] = new Option('1','2');
		 w.options[w.options.length] = new Option('U','1');		 
		 w.options[wSelectedIndex].selected = true;
		 y.style.display ="none";
		 
	}	 
	else
	{
		v.options[v.options.length] = new Option('無','0');
		 v.options[v.options.length] = new Option('A','7');
		 v.options[v.options.length] = new Option('B','6');
		 v.options[v.options.length] = new Option('C','5');
		 v.options[v.options.length] = new Option('D','4');
		 v.options[v.options.length] = new Option('E','3');
		 v.options[v.options.length] = new Option('F','2');
		 v.options[v.options.length] = new Option('U','1');		 
		 v.options[vSelectedIndex].selected = true;
		 w.options[w.options.length] = new Option('無','0');
		 w.options[w.options.length] = new Option('A','7');
		 w.options[w.options.length] = new Option('B','6');
		 w.options[w.options.length] = new Option('C','5');
		 w.options[w.options.length] = new Option('D','4');
		 w.options[w.options.length] = new Option('E','3');
		 w.options[w.options.length] = new Option('F','2');
		 w.options[w.options.length] = new Option('U','1');
		 w.options[wSelectedIndex].selected = true;	
		 y.style.display ="";
	}
}

function showadvance()
{
if (document.getElementById("advance_search").style.display == "none")
{
document.getElementById("advance_search") .style.display="";
}
else
{
document.getElementById("advance_search") .style.display="none";
}
}