function topmenu() {	   
	for (i=1; i<=7; i++) { 	
		document.write("<td  width=\"160\" onmouseover=\"document.getElementById('t"+i+"').src = 'images/title"+i+".jpg'\" onmouseout=\"document.getElementById('t"+i+"').src = 'images/no"+i+".jpg';\"><a><img  id=\"t"+i+"\" src='images/no"+i+".jpg'/></a></td>");	
	
	}
}		


var menu_arr = new Array();
		menu_arr[0] = Array("Overview", "");
		menu_arr[1] = Array("How to Participate ", "");
		menu_arr[2] = Array("Definition of Sub-themes", "");
		menu_arr[3] = Array("Entry Criteria", "");
		menu_arr[4] = Array("Judging Criteria ", "");
		menu_arr[5] = Array("Awards & Prizes", "");
		menu_arr[6] = Array("Key Dates", "");
		menu_arr[7] = Array("Key Stakeholders", "");
	


function leftmenu() {	   
	for (i=0; i<(menu_arr.length); i++) { 
		if(i==0){
				document.write("<a class=\"aa\" href=\"#\"><p id=\"c"+i+"\" style=\"background-image:url(images/left_bg.png) ;color:#CD3335;height:26px;*height:20px; line-height:20px; width:170px;font-size:12px; padding-left:11px; background-repeat:no-repeat\">"+menu_arr[i][0]+"</p></a>");	
		}else{		
			document.write("<a class=\"aa\" href=\"#\"><p id=\"c"+i+"\" style=\"height:26px; width:170px;line-height:10px;line-height:20px; padding-left:11px;font-size:12px; color:#666666; background-repeat:no-repeat\" onmouseover=\"document.getElementById('c"+i+"').style.backgroundImage = 'url(images/left_bg.png)';document.getElementById('c"+i+"').style.color='#CD3335';\" onmouseout=\"document.getElementById('c"+i+"').style.backgroundImage = '';document.getElementById('c"+i+"').style.color='#666666';\">"+menu_arr[i][0]+"</p></a>");	
		}
	}
}

//--------------------------------------------------------------------------//

function loginform_submit(frm){
	if($J('#member_login').trimval()  == ""){
		alert('Please enter the Login Name.');
		$J('#member_login').focus();
		return false;
	}else if($J('#member_password').trimval()  == ""){
		alert('Please enter the Login Password.');
		$J('#member_password').focus();
		return false;
	}
	return true;
}

function bbcaloginform_submit(frm){
	if($J('#username').trimval()  == ""){
		alert('Please enter the Login Name.');
		$J('#username').focus();
		return false;
	}else if($J('#password').trimval()  == ""){
		alert('Please enter the Login Password.');
		$J('#password').focus();
		return false;
	}
	return true;
}

function bbcaupload_submit(frm){
	
	var textlength = $J('#desp').val().split(/\b[\s,\.-:;]*/).length;
	/*
	if($J('#title').trimval()  == ""){
		alert('Please enter the Title.');
		$J('#title').focus();
		return false;
	}else if($J('#desp').trimval()  == ""){
		alert('Please enter the Description.');
		$J('#desp').focus();
		return false;
	}else if(textlength > 30){
		alert('Description too long.');
		$J('#desp').focus();
		return false;
	}else if($J('#file').trimval()  == ""){
		alert('Please upload your Trailer.');
		$J('#file').focus();
		return false;
	}else if($J('#thumbnail').trimval()  == ""){
		alert('Please upload your Thumbnail.');
		$J('#thumbnail').focus();
		return false;
	}
	*/
	if($J('#desp').trimval()  == ""){
		alert('Please enter the Description.');
		$J('#desp').focus();
		return false;
	}else if(textlength > 50){
		alert('Description too long.');
		$J('#desp').focus();
		return false;
	}
	
	return true;
}

function bbcateameditform_submit(frm){
	if(teameditform_submit(frm)){
		var division = $J('input[name="division"]:checked').val();
		var msg2user = "";
		
		var all_additional1input = "";
		$J('input[name$="_of_additional_student_1"]').each(function(){
			all_additional1input += $J(this).trimval();
		});

		if(all_additional1input != "MF"){
			msg2user += teammember_checker('additional_student_1','additional member 1', division, 's', 'edit');
		}
		var all_additional1input = "";
		$J('input[name$="_of_additional_student_2"]').each(function(){
			all_additional1input += $J(this).trimval();
		});
		if(all_additional1input != "MF"){
			msg2user += teammember_checker('additional_student_2','additional member 2', division, 's', 'edit');
		}
		if(msg2user != ""){
			alert(msg2user);
			return false;
		}
	} else {
		return false;
	}
	return true;
}
function registerform_submit(frm){
	//alert("Form checking");
	
	// check team information
	if($J('input[name="division"]:checked').length != 1){
		alert('Please select Division.');
		return false;
	}else if($J('#name_of_team').trimval()  == ""){
		alert('Please enter the Name of Team.');
		$J('#name_of_team').focus();
		return false;
	}else if($J('#title_of_team').trimval()  == ""){
		alert('Please enter the Project Title.');
		$J('#title_of_team').focus();
		return false;
	}else if($J('#subtheme_of_team').trimval()  == ""){
		alert('Please enter the Sub-Theme.');
		$J('#subtheme_of_team').focus();
		return false;
	}else if($J('#country').trimval()  == ""){
		alert('Please enter the Country.');
		$J('#country').focus();
		return false;
	} else if($J('#country').trimval() == 25){
		if($J('#other_country').val()  == ""){
			alert('Please specify the Country.');
			$J('#other_country').focus();
			return false;
		}
	}else if($J('#authorization_form').trimval()  == ""){
		alert('Please upload your Authorization Form.');
		$J('#authorization_form').focus();
		return false;
	}else{ 
	//if(getFileExt('authorization_form') != 'pdf' && getFileExt('authorization_form') != 'PDF' && (getFileExt('authorization_form') != 'doc' && getFileExt('authorization_form') != 'DOC' && (getFileExt('authorization_form') != 'docx'&& getFileExt('authorization_form') != 'DOCX'){

		switch (getFileExt('authorization_form').toLowerCase()){
			case "pdf":
			case "doc":
			case "docx":
				break;
			default:
				alert('The submitted file should be in doc, docx and pdf format only.');
				$J('#authorization_form').focus();
				return false;
		}
	}
	
	//check team member information
	var division = $J('input[name="division"]:checked').val();
		var msg2user = "";
		msg2user += teammember_checker('student_1','Team Leader', division, 's');
		for(var counter = 2; counter <= 3; counter ++){
			//alert($J('#firstname_of_student_'+counter).trimval());
			msg2user += teammember_checker('student_'+counter,'member '+counter, division, 's');
		}
	if(division == "u"){
		var all_student4input = "";
		$J('input[name$="_of_student_4"]').each(function(){
			all_student4input += $J(this).trimval();
		});
		if(all_student4input != "MF"){
			msg2user += teammember_checker('student_4','member 4', division, 's');
		}
	}
	
	var all_teacher_input = "";
	$J('input[name$="_of_teacher"]').each(function(){
		all_teacher_input += $J(this).trimval();
	});
	if(all_teacher_input != "MF" || division == "s" ){
		msg2user += teammember_checker('teacher','mentor', division, 't');
	}
	
	if(msg2user != ""){
		alert(msg2user);
		return false;
	}
	
	if($J('#source_of_challenge').val()  == ""){
		alert('Please indicate where did you hear about this Challenge?');
		$J('#source_of_challenge').focus();
		return false;
	}else if($J('#source_of_challenge').trimval() == 5){
		if($J('#other_source_of_challenge').val()  == ""){
			alert('Please specify where did you hear about this Challenge.');
			$J('#other_source_of_challenge').focus();
			return false;
		}
	}else if($J('input[name="declaration1"]:checked').length != 1){
		alert('Please ensure you have read the Declaration before proceeding with your registration.');
		$J('#declaration1').focus();
		return false;
/*	}else if($J('input[name="declaration2"]:checked').length != 1){
		alert('Please ensure you have read the Declaration before proceeding with your registration.');
		$J('#declaration2').focus();
		return false;
	}else if($J('input[name="declaration3"]:checked').length != 1){
		alert('Please ensure you have read the Declaration before proceeding with your registration.');
		$J('#declaration3').focus();
		return false;
	}else if($J('input[name="declaration4"]:checked').length != 1){
		alert('Please ensure you have read the Declaration before proceeding with your registration.');
		$J('#declaration4').focus();
		return false;
	}else if($J('input[name="declaration5"]:checked').length != 1){
		alert('Please ensure you have read the Declaration before proceeding with your registration.');
		$J('#declaration5').focus();
		return false;*/
	}
	return true;
}

function teammember_checker(id_prefix, msg_prefix, division, type, mode){
	var count = 0;
	var msg = "";
		if($J('#firstname_of_'+id_prefix).trimval() == ""){
			msg += "Please enter First Name of "+msg_prefix+".\r\n";
			count++;
		}

		if($J('#lastname_of_'+id_prefix).trimval() == ""){
			msg += "Please enter Last Name of "+msg_prefix+".\r\n";
			count++;
		}

		if(mode != "edit")
			if($J('input[name="sex_of_'+id_prefix+'"]:checked').length != 1){
				msg += "Please enter Gender of "+msg_prefix+".\r\n";
				count++;
			}
		if(type == "t")
			if($J('#title_of_'+id_prefix).trimval() == ""){
					msg += "Please enter Title of "+msg_prefix+".\r\n";
					count++;
			}
		if(type == "s")
			if($J('#year_of_'+id_prefix).trimval() == ""){
				msg += (division == "s")? "Please enter Form/Class of "+msg_prefix+".\r\n" : "Please enter Year of Study of "+msg_prefix+".\r\n";
				count++;
			}

		if($J('#school_name_of_'+id_prefix).trimval() == ""){
			msg += "Please enter School Name of "+msg_prefix+".\r\n";
			count++;
		}
		
		if(division == "u")
			if($J('#faculty_of_'+id_prefix).trimval() == ""){
				msg += "Please enter Faculty/School of "+msg_prefix+".\r\n";
				count++;
			}
		
		
		if(division == "u")
			if($J('#department_of_'+id_prefix).trimval() == ""){
				msg += "Please enter Department of "+msg_prefix+".\r\n";
				count++;
			}
		
		if(division == "u" && type == "s")
			if($J('#programme_of_'+id_prefix).trimval() == ""){
				msg += "Please enter Enrolled Programme of "+msg_prefix+".\r\n";
				count++;
			}
		
		if(!isValidPhone($J('#tel_of_'+id_prefix).trimval())){
			msg += "Please enter Telephone no. of "+msg_prefix+".\r\n";
			count++;
		}
		if(!isValidEmail($J('#email_of_'+id_prefix).trimval())){
			msg += "Please enter Email of "+msg_prefix+".\r\n";
			count++;
		}
		if(mode != "edit")
			if($J('#email_confirm_of_'+id_prefix).trimval() != $J('#email_of_'+id_prefix).trimval()){
				msg += "Emails of "+msg_prefix+" are not the same.  Please check.\r\n";
				count++;
			}
		if($J('#address1_of_'+id_prefix).trimval() == ""){
			msg += "Please enter Address1 of "+msg_prefix+".\r\n";
			count++;
		}
		if(mode != "edit"){
			if(division != "s" && type != "t") {
				if($J('#resume_of_'+id_prefix).trimval() == ""){
					msg += "Please upload Resume of "+msg_prefix+".\r\n";
					count++;
				} else if(getFileExt('resume_of_'+id_prefix) != 'pdf' && getFileExt('resume_of_'+id_prefix) != 'doc' && getFileExt('resume_of_'+id_prefix) != 'docx'){
					msg += "Please convert Resume of "+msg_prefix+" into PDF, DOC or DOCX format."+".\r\n";
					count++;
				}
			}
		}
		if(count > 3){
			return "Please fill in information of "+msg_prefix+".\r\n";
		} else {
			return msg;
		}
		return "";
}

function teameditform_submit(frm){
	//check team member information
	var division = $J('#division').trimval();
		var msg2user = "";
		msg2user += teammember_checker('student_1','Team Leader', division, 's', 'edit');
		
		for(var counter = 2; counter <= 3; counter ++){
			//alert($J('#firstname_of_student_'+counter).trimval());
			msg2user += teammember_checker('student_'+counter,'member '+counter, division, 's', 'edit');
		}
	if(division == "u"){
		var all_student4input = "";
		$J('input[name$="_of_student_4"]').each(function(){
			all_student4input += $J(this).trimval();
		});
		if(all_student4input != "MF"){
			msg2user += teammember_checker('student_4','member 4', division, 's', 'edit');
		}
	}
	
	var all_teacher_input = "";
	$J('input[name$="_of_teacher"]').each(function(){
		all_teacher_input += $J(this).trimval();
	});
	
	if(all_teacher_input != "MF" || division == "s" ){
		msg2user += teammember_checker('teacher','mentor', division, 't', 'edit');
	}
	
	if(msg2user != ""){
		alert(msg2user);
		return false;
	}
	
	return true;
}

function business_plan_submit(frm){
	if($J('#agree:checked').length  == 0){
		alert('Please ensure you have read the agreement and confirm your consent by checking the box.');
		$J('#agree').focus();
		return false;
	}
	var go = true;
	$J('input[type="file"]').each(function(){
		var theFileName = $J(this).attr('id');
		if(!(getFileExt(theFileName) == 'pdf' || $J('#'+theFileName).val().toString().length==0) && $J('#download_uploaded_'+theFileName).length < 1){
			alert('The submitted file should be in pdf format only.');
			$J('#'+theFileName).focus();
			go = false;
			return false;
		}
	});
	return go;
}

function form_1_submit(frm){
	if($J('#agree:checked').length  == 0){
		alert('Please check on the disclaimer before submission.');
		$J('#agree').focus();
		return false;
	}else if($J('#sub_theme_1').val()  == ""){
		alert('Please enter the Theme.');
		$J('#sub_theme_1').focus();
		return false;
	}
	var go = true;
	$J('input[type="file"]').each(function(){
		var theFileName = $J(this).attr('id');
		if(!(getFileExt(theFileName) == 'pdf' || getFileExt(theFileName) == 'doc' || getFileExt(theFileName) == 'docx' || $J('#'+theFileName).val().toString().length==0) && $J('#download_uploaded_'+theFileName).length < 1){
			alert('The submitted file should be in doc, docx and pdf format only.');
			$J('#'+theFileName).focus();
			go = false;
			return false;
		}
	});
	return go;
}

function form_edit_submit(frm){
	if($J('input[name="division"]:checked').length != 1){
		alert('Please select Division');
		return false;
	}else if($J('#name_of_school').trimval()  == ""){
		alert('Please enter the Name of school.');
		$J('#name_of_school').focus();
		return false;
	}else if($J('#address_of_school').trimval()  == ""){
		alert('Please enter the School Address.');
		$J('#address_of_school').focus();
		return false;
	}else if($J('#country').trimval()  == ""){
		alert('Please enter the Country.');
		$J('#country').focus();
		return false;
	}else if($J('#name_of_team').trimval() == ""){
		alert('Please enter the Name of the team.');
		$J('#name_of_team').focus();
		return false;
	}else if($J('input[name="division"]:checked').val() == "s"){
		var msg2user = "";
		for(var counter = 1; counter <= 3; counter ++){
			if($J('#name_of_student_'+counter).trimval() == ""){	msg2user += "Please enter Name of student "+counter+"\r\n";	}
			if($J('#sex_of_student_'+counter).trimval() == ""){	msg2user += "Please enter Sex of student "+counter+"\r\n";	}
			if($J('#from_of_student_'+counter).trimval() == ""){	msg2user += "Please enter Form of student "+counter+"\r\n";	}
			if($J('#stream_of_student_'+counter).trimval() == ""){	msg2user += "Please enter Stream of student "+counter+"\r\n";	}
			if($J('#department_of_student_'+counter).trimval() == ""){	msg2user += "Please enter Department of student "+counter+"\r\n";	}
			if(!isValidPhone($J('#tel_of_student_'+counter).trimval())){	msg2user += "Please enter Contact no. of student "+counter+"\r\n";	}
			if(!isValidEmail($J('#email_of_student_'+counter).trimval())){	msg2user += "Please enter Email of student "+counter+"\r\n";	}
		}
		
		if($J('#name_of_teacher').trimval() == ""){	msg2user += "Please enter Name of teacher "+"\r\n";	}
		if($J('#title_of_teacher').trimval() == ""){	msg2user += "Please enter Title of teacher "+"\r\n";	}
		if($J('#position_of_teacher').trimval() == ""){	msg2user += "Please enter Position of teacher "+"\r\n";	}
		if($J('#department_of_teacher').trimval() == ""){	msg2user += "Please enter Department of teacher "+"\r\n";	}
		if(!isValidPhone($J('#tel_of_teacher').trimval())){	msg2user += "Please enter Contact no. of teacher "+"\r\n";	}
		if(!isValidEmail($J('#email_of_teacher').trimval())){	msg2user += "Please enter Email of teacher "+"\r\n";	}
		
		if(msg2user != ""){
			alert(msg2user);
			return false;
		}
	}else if($J('input[name="division"]:checked').val() == "u"){
		var msg2user = "";
		for(var counter = 1; counter <= 3; counter ++){
			if($J('#name_of_student_'+counter).trimval() == ""){	msg2user += "Please enter Name of student "+counter+"\r\n";	}
			if($J('#sex_of_student_'+counter).trimval() == ""){	msg2user += "Please enter Sex of student "+counter+"\r\n";	}
			if($J('#from_of_student_'+counter).trimval() == ""){	msg2user += "Please enter Form of student "+counter+"\r\n";	}
			if($J('#stream_of_student_'+counter).trimval() == ""){	msg2user += "Please enter Stream of student "+counter+"\r\n";	}
			if($J('#department_of_student_'+counter).trimval() == ""){	msg2user += "Please enter Department of student "+counter+"\r\n";	}
			if(!isValidPhone($J('#tel_of_student_'+counter).trimval())){	msg2user += "Please enter Contact no. of student "+counter+"\r\n";	}
			if(!isValidEmail($J('#email_of_student_'+counter).trimval())){	msg2user += "Please enter Email of student "+counter+"\r\n";	}
		}
		
		var all_student4input = "";
		$J('input[name$="_of_student_4"]').each(function(){
			all_student4input += $J(this).trimval();
		});
		if(all_student4input != "nothisguy"){
			counter = 4;
			if($J('#name_of_student_'+counter).trimval() == ""){	msg2user += "Please enter Name of student "+counter+"\r\n";	}
			if($J('#sex_of_student_'+counter).trimval() == ""){	msg2user += "Please enter Sex of student "+counter+"\r\n";	}
			if($J('#from_of_student_'+counter).trimval() == ""){	msg2user += "Please enter Form of student "+counter+"\r\n";	}
			if($J('#stream_of_student_'+counter).trimval() == ""){	msg2user += "Please enter Stream of student "+counter+"\r\n";	}
			if($J('#department_of_student_'+counter).trimval() == ""){	msg2user += "Please enter Department of student "+counter+"\r\n";	}
			if(!isValidPhone($J('#tel_of_student_'+counter).trimval())){	msg2user += "Please enter Contact no. of student "+counter+"\r\n";	}
			if(!isValidEmail($J('#email_of_student_'+counter).trimval())){	msg2user += "Please enter Email of student "+counter+"\r\n";	}
		}

		var all_teacher_input = "";
		$J('input[name$="_of_teacher"]').each(function(){
			all_teacher_input += $J(this).trimval();
		});
		if(all_teacher_input != "nothisguy"){
			if($J('#name_of_teacher').trimval() == ""){	msg2user += "Please enter Name of teacher "+"\r\n";	}
			if($J('#title_of_teacher').trimval() == ""){	msg2user += "Please enter Title of teacher "+"\r\n";	}
			if($J('#position_of_teacher').trimval() == ""){	msg2user += "Please enter Position of teacher "+"\r\n";	}
			if($J('#department_of_teacher').trimval() == ""){	msg2user += "Please enter Department of teacher "+"\r\n";	}
			if(!isValidPhone($J('#tel_of_teacher').trimval())){	msg2user += "Please enter Contact no. of teacher "+"\r\n";	}
			if(!isValidEmail($J('#email_of_teacher').trimval())){	msg2user += "Please enter Email of teacher "+"\r\n";	}
		}
		if(msg2user != ""){
			alert(msg2user);
			return false;
		}
	}
}
function form_4_submit(frm){
	var msg2user = new Array();
	var i, x, err, theVal_1, temp_1, theVal_2, temp_2, nameTemp;
	var today = new Date();
	var input_d_1 = new Date();
	var input_d_2 = new Date();
	var isSponsored=document.getElementById('qp_sponsored_1').value=='y' || document.getElementById('qp_sponsored_1').length ==0;
	
	var isStudent=document.getElementById('is_student').value=='y' || document.getElementById('is_student').length ==0;
	
	var isbookby=$J('[name^="qa_a_book_by_polyu_"]:checked').val()=='y' || isSponsored;
	
	var isaccbookby=$J('[name^="ac_book_by_polyu_"]:checked').val()=='y';
	
	var check = [
		{'name':'qm_fullname_','method':'trimval','msg':'Enter First Name'},
		//{'name':'qm_firstname_','method':'trimval','msg':'Enter First Name'},
//		{'name':'qm_lastname_','method':'trimval','msg':'Enter Last Name'},
		{'name':'qm_title_','method':'radio_others','msg':'Select Title Or Input the others','others':'Others'},
		{'name':'qp_passport_','method':'trimval','msg':'Enter Passport No.'},
		{'name':'qm_sex_','method':'radio','msg':'Select Gender'},
		{'name':'qp_nationality_','method':'trimval','msg':'Enter Nationality.'},
		{'name':'qp_date_of_birth_','method':'date_before','msg':'Enter Date of birth.'},
//		{'name':'qp_country_code_','method':'number','msg':'Enter Valid Country Code.'},
//		{'name':'qp_area_code_','method':'number','msg':'Enter Valid Area Code.'},
//		{'name':'qp_local_code_','method':'number','msg':'Enter Valid Local Code.'},
		{'name':'qp_contact_','method':'phone','msg':'Enter Valid Contact No.'},
//		{'name':'qp_mobile_country_code_','method':'number','msg':'Enter Valid Mobile-Country Code.'},
		{'name':'qp_mobile_contact_','method':'phone','msg':'Enter Valid Mobile-Contact No.'},
//		{'name':'qp_roaming_','method':'radio','msg':'Select Roaming Service available'},
		{'name':'qm_email_','method':'email','msg':'Enter Valid Personal Email.'},
		{'name':'qp_photo_passport_','method':'file_prototype','msg':'Select ONLY (.jpg, .gif, .pdf) for photo page (with personal details) of your passport'},
		{'name':'qp_photo_student_doc_','method':'file_prototype_type','msg':'Select ONLY (.jpg, .gif, .pdf) for your Student ID Card (or any other document/ card which can prove your student identity)'},

		{'name':'qa_a_date_','method':'date_after','msg':'Select Arrival Date & Time'},
		{'name':'qa_a_airport_','method':'trimval_bookby','msg':'Enter Nearest International Airport of departure'},
		{'name':'qa_a_city_','method':'trimval','msg':'Enter Departure City'},
		{'name':'qa_a_country_','method':'trimval','msg':'Enter Departure Country'},
		{'name':'qa_a_est_time_','method':'trimval_notsponsor','msg':'Enter Estimated Time of Arrival'},
		{'name':'qa_a_flight_','method':'trimval_notsponsor','msg':'Enter Arrival Flight No'},
		
		

		{'name':'qd_d_date_','method':'date_after','msg':'Select Departure Date & Time'},
		{'name':'qd_d_airport_','method':'trimval_bookby','msg':'Enter Nearest International Airport of arrival'},
		{'name':'qd_d_city_','method':'trimval','msg':'Enter Arrival City'},
		{'name':'qd_d_country_','method':'trimval','msg':'Enter Arrival Country'},
		{'name':'qd_d_est_time_','method':'trimval_notsponsor','msg':'Enter Estimated Time of Departure'},
		{'name':'qd_d_flight_','method':'trimval_notsponsor','msg':'Enter Departure Flight No'},
		{'name':'qd_d_date_,qa_a_date_','method':'date_later','msg':'Select Departure Date Time later than Arrival Date Time'},

		{'name':'ac_checkin_date_','method':'date_after_acc','msg':'Select Check-in Date'},
		{'name':'ac_checkout_date_,ac_checkin_date_','method':'date_later_acc','msg':'Select Check-out Date later than Check-in Date'},
		{'name':'ac_hotel_','method':'trimval_accnotbookby','msg':'Enter Hotel'},
		{'name':'ac_room_','method':'radio_acc','msg':'Select Room Type'},
		{'name':'ac_special_','method':'trimval_acc','msg':'Enter Special Requirement'},
		
		{'name':'qo_hindrance_','method':'radio_others','msg':'Indicate with physical hindance or not','others':'y'},
		{'name':'qo_special_','method':'radio_others','msg':'Indicate the need of special arrangement','others':'y'},
		{'name':'qo_dietary_','method':'radio_others','msg':'Indicate the need of special dietary','others':'y'},
/*
		{'name':'qs_prototype_','method':'radio','msg':'Select any available prototype'},
		{'name':'qs_present_','method':'radio','msg':'Select willing to present the prototype'},
		{'name':'qs_photo_name_','method':'file_prototype','msg':'Select ONLY (.jpg, .gif) for prototype photo'},
*/
		{'name':'qe_name_','method':'trimval','msg':'Enter Emergency Contact Name'},
		{'name':'qe_relationship_','method':'trimval','msg':'Enter Emergency Contact Relationship'},
//		{'name':'qe_home_country_code_','method':'number','msg':'Enter Valid Phone (Home)-Country Code.'},
//		{'name':'qe_home_area_code_','method':'number','msg':'Enter Valid Phone (Home)-Area Code.'},
		{'name':'qe_home_contact_','method':'phone','msg':'Enter Valid Phone (Home)-Contact No.'},
//		{'name':'qe_mobile_country_code_','method':'number','msg':'Enter Valid Phone (Mobile)-Country Code.'},
		{'name':'qe_mobile_contact_','method':'phone','msg':'Enter Valid Phone (Mobile)-Contact No.'},
		{'name':'qe_email_','method':'email','msg':'Enter Valid Emergency Contact Email'},
		{'name':'qe_address_','method':'trimval','msg':'Enter Valid Emergency Address'}
	];
	try{
		var totalMember = $J('input[id^="qm_fullname_"]').length;
		
		for(i=1;i<=totalMember;i++){
			for(x in check){
				err = false;
				switch(check[x].method){
					case 'file_prototype':	
						/*if(isSponsored){*/
							if($J('input#'+check[x].name+i+'').trimval()=='' && $J('#p_'+check[x].name+i+'').length==1){
							}else if($J('input#'+check[x].name+i+'').trimval()!='' && !prototype_patt.test($J('input#'+check[x].name+i+'').trimval())){
								err = true;
							}else if($J('input#'+check[x].name+i+'').trimval()==''){
								err = true;
							}
						/*}*/
						break;
					case 'file_prototype_student':	
						if(isStudent){
							if($J('input#'+check[x].name+i+'').trimval()=='' && $J('#p_'+check[x].name+i+'').length==1){
							}else if($J('input#'+check[x].name+i+'').trimval()!='' && !prototype_patt.test($J('input#'+check[x].name+i+'').trimval())){
								err = true;
							}else if($J('input#'+check[x].name+i+'').trimval()==''){
								err = true;
							}
						}
						break;
					case 'file_prototype_type':	
						if(isStudent){
							if($J('input#'+check[x].name+i+'').trimval()!='' && !prototype_patt.test($J('input#'+check[x].name+i+'').trimval())){
								err = true;
							}
						}
						break;
					case 'trimval':	err = ($J('input#'+check[x].name+i+'').trimval()=="");	break;
					case 'trimval_notsponsor':	if(!isSponsored){err = ($J('input#'+check[x].name+i+'').trimval()=="");}	break;
					case 'trimval_bookby':	if(isbookby) {err = ($J('input#'+check[x].name+i+'').trimval()=="");}	break;
					case 'trimval_notbookby':	if(!isbookby && !isSponsored) {err = ($J('input#'+check[x].name+i+'').trimval()=="");}	break;
					
					case 'trimval_notbookby':	if(!isaccbookby && !isSponsored) {err = ($J('input#'+check[x].name+i+'').trimval()=="");}	break;
					
					case 'trimval_acc':	if(isaccbookby) {err = ($J('input#'+check[x].name+i+'').trimval()=="");}	break;
					case 'trimval_accnotbookby':	if(!isaccbookby && !isStudent) {err = ($J('input#'+check[x].name+i+'').trimval()=="");}	break;
					case 'trimval_issponsor':	if(isSponsored){err = ($J('input#'+check[x].name+i+'').trimval()=="");}	break;
					case 'phone':	err = (! isValidPhone($J('input#'+check[x].name+i+'').trimval()));	break;
					case 'number':	err = (! isValidNumber($J('input#'+check[x].name+i+'').trimval()));	break;
					case 'email':	err = (! isValidEmail($J('input#'+check[x].name+i+'').trimval()));	break;
					case 'radio':	err = ($J('input[name="'+check[x].name+i+'"]:checked').length==0);	break;
					case 'radio_acc':	if(isaccbookby) { err = ($J('input[name="'+check[x].name+i+'"]:checked').length==0);}	break;
					case 'radio_others':
						if($J('input[name="'+check[x].name+i+'"]:checked').length==0){
							err = true;
						}else{
							if($J('input[name="'+check[x].name+i+'"]:checked').val()==check[x].others && $J('input#'+check[x].name+i+'_specify').trimval()==""){
								err = true;
							}
						}
						break;
					case 'date_later':
						nameTemp = check[x].name.split(',');
						theVal_1 = $J('input#'+nameTemp[0]+i+'').trimval().match(/^\d{4}-\d{2}-\d{2}/);
						if(! theVal_1){
							err=true;
						}else{
							theVal_2 = $J('input#'+nameTemp[1]+i+'').trimval().match(/^\d{4}-\d{2}-\d{2}/);
							if(! theVal_2){
								err=true;
							}else{
								temp_1 = theVal_1[0].split('-');
								input_d_1.setFullYear(temp_1[0],temp_1[1]-1,temp_1[2]);
								temp_2 = theVal_2[0].split('-');
								input_d_2.setFullYear(temp_2[0],temp_2[1]-1,temp_2[2]);
								if(input_d_1<input_d_2 || input_d_1<today || input_d_2<today){
									err=true;
								}
							}
						}
						break;
						
					case 'date_later_acc':
						if(!isStudent){
							nameTemp = check[x].name.split(',');
							theVal_1 = $J('input#'+nameTemp[0]+i+'').trimval().match(/^\d{4}-\d{2}-\d{2}/);
							if(! theVal_1){
								err=true;
							}else{
								theVal_2 = $J('input#'+nameTemp[1]+i+'').trimval().match(/^\d{4}-\d{2}-\d{2}/);
								if(! theVal_2){
									err=true;
								}else{
									temp_1 = theVal_1[0].split('-');
									input_d_1.setFullYear(temp_1[0],temp_1[1]-1,temp_1[2]);
									temp_2 = theVal_2[0].split('-');
									input_d_2.setFullYear(temp_2[0],temp_2[1]-1,temp_2[2]);
									if(input_d_1<input_d_2 || input_d_1<today || input_d_2<today){
										err=true;
									}
								}
							}
						}
						break;
						
					case 'date_after_acc':
						if(!isStudent){
							theVal_1 = $J('input#'+check[x].name+i+'').trimval().match(/^\d{4}-\d{2}-\d{2}/);
							if(! theVal_1){
								err=true;
							}else{
								temp_1 = theVal_1[0].split('-');
								input_d_1.setFullYear(temp_1[0],temp_1[1]-1,temp_1[2]);
								if(check[x].method=="date_after_acc"){
									err=(input_d_1<today);
								}else{
									err=(input_d_1>today);
								}
							}

						}
						break;
						
						
					case 'date_after':
					case 'date_before':
						theVal_1 = $J('input#'+check[x].name+i+'').trimval().match(/^\d{4}-\d{2}-\d{2}/);
						if(! theVal_1){
							err=true;
						}else{
							temp_1 = theVal_1[0].split('-');
							input_d_1.setFullYear(temp_1[0],temp_1[1]-1,temp_1[2]);
							if(check[x].method=="date_after"){
								err=(input_d_1<today);
							}else{
								err=(input_d_1>today);
							}
						}
						break;
				}
				if(check[x].name.match(/^q(a|d)_(a|d)_(est_time|flight)_/)){
					if($J('input[name="qa_a_book_by_polyu_'+1+'"]:checked').val()=='y'){
						$J('input#'+check[x].name+i+'').val('');
						err = false;
					}
				}
				if(err){
					msg2user.push('Please '+check[x].msg+'.');
				}
			}
		}
	}catch(e){
		alert('Exception.'+e.description + "\r\nIN "+ check[x].name + "\r\nBY "+ check[x].method);
		return false;
	}
	i--;
	
	if(!isStudent && $J('input#division').trimval() == "u"){
		if(!$J('input#ex_join_day1_'+i+':checked').val() && !$J('input#ex_join_day2_'+i+':checked').val() && !$J('input#ex_not_join_'+i+':checked').val()){
			//alert('input#ex_join_day1_'+i+ ' ' + $J('input#ex_join_day1_'+i+':checked').val() + ", " + $J('input#ex_join_day2_'+i+':checked').val() + ", " + $J('input#ex_not_join_'+i+':checked').val());
			msg2user.push('Please Choose Excursion programmes.');
		}
	}
	if(msg2user.length!=0){
		alert(msg2user.join('\r\n'));
		return false;
	}else{
		return true;
	}
}

function form_5_submit(frm){
	var msg2user = new Array();
	var i, x, err, theVal_1, temp_1, theVal_2, temp_2, nameTemp;
	var check = [
		{'name':'header_t_name_','method':'trimval','msg':'Enter First Name'},
		{'name':'header_t_gender_','method':'trimval','msg':'Enter Last Name'}
	];
}

function form_2_submit(frm){
	/*if($J('#agree:checked').length  == 0){
		alert('Please check on the disclaimer before submission.');
		$J('#agree').focus();
		return false;
	}else */
	
	if(!(
		 	getFileExt('file_name_2') == 'fla' || 
			getFileExt('file_name_2') == 'swf' || 
			getFileExt('file_name_2') == 'ppt' || 
			getFileExt('file_name_2') == 'pptx' || 
			getFileExt('file_name_2') == 'zip' || 
			getFileExt('file_name_2') == 'rar' || 
			$J('#file_name_2').val().toString().length==0 && $J('#download_uploaded_file_name_2').length >= 1
		) ){
		alert('Please select ONLY (.fla, .swf, .ppt, .pptx, .zip, .rar) to submit.');
		$J('#file_name_2').focus();
		return false;
	}
	
	return true;
}

function fill_sample(){
	$J('input[type="text"]:not([name*="sex"]):not([name*="tel"]):not([name*="email"])').each(function(){
		$J(this).val($J(this).attr('name'));
	});
	var mydate= new Date();
	$J('input[type="text"][name="name_of_team"]').val(mydate);
	$J('input[type="text"][name*="sex"]').val('M');
	$J('input[type="text"][name*="tel"]').val('12345678');
	$J('input[type="text"][name*="email"]').val('peter.ho@westcomzivo.com');
}
function fill_sample2(){
	var x = "00"+(Math.floor(Math.random()*12)+1);
	x = x.substr(x.length-2,2);
	$J('input[type="text"]:not([name*="login_name"],[name*="name_of_team"],[name*="name_of_school"])').each(function(){
		switch($J(this).attr('name').replace(/_\d+_specify/,'').replace(/_\d+/,'')){
			case "qp_roaming":
			case "qp_title":
			case "qo_hindrance":
			case "qo_special":
			case "qo_dietary":
				break;
			case "qe_mobile_no":
			case "qe_home_no":
			case "qp_contact":
			case "qe_home_contact":
			case "qe_mobile_contact":
			case "qp_mobile_contact":
				$J(this).val(x+"8765423");
				break;
			case "qp_country_code":
			case "qp_area_code":
			case "qp_local_code":
			case "qe_mobile_country_code":
			case "qe_home_country_code":
			case "qe_home_area_code":
			case "qp_mobile_country_code":
				$J(this).val(x);
				break;
			case "qe_email":
			case "qp_email":
				$J(this).val(x+"peter.ho@westcomzivo.com");
				break;
			default:
				$J(this).val(x+$J(this).attr('name'));
				break;
		}
	});
	$J('input[type="radio"]').each(function(){
		$J(this).attr('checked', 'checked').click();
	});
	for(i=1;i<=$J('input[id^="qp_firstname_"]').length;i++){
		$J('#qu_from_'+i).val('2009-08-03');
		$J('#qu_to_'+i).val('2009-08-03');
		$J('#qa_a_date_'+i).val('2009-08-03');
		$J('#qd_d_date_'+i).val('2009-08-11');
		$J('#qp_date_of_birth_'+i).val('1984-08-11');
	}
}

function themeDIV(){
	var themes = new Array("Health & Wellness", "Lifestyle", "Environment & Sustainability");
}

function getFileExt(sourceID){
	var a=document.getElementById(sourceID).value.toString().split(".")
	return a[a.length-1];
}

function isValidEmail(str){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	return (filter.test(str));
}

function isValidPhone(str){
	//var patt1 = new RegExp(/^(ext|x)*[0-9 \(\)\+\-]{8,20}$/i);
	var patt1 = new RegExp(/^(ext|x)*[0-9 \(\)\+\-]{1,50}$/i);
	return patt1.test(str);
}

function isValidNumber(str){
	var patt1 = new RegExp(/^[0-9]+$/i);
	return patt1.test(str);
}

/* BBCA Voter Registration */

function form_bbca_vote_registration(frm){
	if($J('#email').val()  == ""){
		alert('Please enter your Email.');
		$J('#email').focus();
		return false;
	} else if(!isValidEmail($J('#email').val())){
		alert('Your Email address is not valid, please re-enter your Email.');
		$J('#email').focus();
		return false;
	} else if($J('#firstname').val()  == ""){
		alert('Please enter your First name.');
		$J('#firstname').focus();
		return false;
	} else if($J('#lastname').val()  == ""){
		alert('Please enter your Last name.');
		$J('#lastname').focus();
		return false;
/*	} else if($J('#password').val()  == ""){
		alert('Please enter your Password.');
		$J('#password').focus();
		return false;
	} else if($J('#category_information').val()  == ""){
		alert('Please enter information of your School or Company.');
		$J('#category_information').focus();
		return false;*/
	}
	
	
	return true;
}

function limitChars(textid, limit, infodiv) {
	var text = $J('#'+textid).val(); 
	var textlength = text.split(/\b[\s,\.-:;]*/).length;
	if(textlength > limit) {
		$J('#' + infodiv).html('You cannot write more then '+limit+' words!');
		 $J('#'+textid).val(text.substr(0,limit));
		return false;
	} else {
		$J('#' + infodiv).html('You have '+ (limit - textlength) +' words left.');
		return true;
	}
}
