<!--//--><![CDATA[//><!--
var globals = new Array();
var i;
globals['max_futurecourse'] = 1;
globals['max_educationplan'] = 5;
globals['max_otherapp'] = 10;
globals['max_cca'] = 10;
globals['max_award'] = 5;
globals['max_otherqualification'] = 4;
globals['max_employment'] = 4;
globals['max_referee'] = 2;

$(document).ready(function() {
	var $sectionTabs = $('#applicationForm').tabs({
		select: function(event, ui) {
			var tmp, previousIndex;
			previousIndex = $('#tabIndex').val();
			switch (previousIndex) {
				case '0':
					tmp = $("#educationplan input, #educationplan textarea, #educationplan select, #tabIndex, #schappid, #schid").serialize();
					break;
				case '1':
					tmp = $("#otherApp input, #otherApp textarea, #otherApp select, #tabIndex, #schappid, #schid").serialize();
					break;
				case '2':
					tmp = $("#cca input, #cca textarea, #cca select, #tabIndex, #schappid, #schid").serialize();
					break;
				case '3':
					tmp = $("#prize input, #prize textarea, #prize select, #tabIndex, #schappid, #schid").serialize();
					break;
				case '4':
					tmp = $("#otherQualification input, #otherQualification textarea, #otherQualification select, #tabIndex, #schappid, #schid").serialize();
					break;
				case '5':
					tmp = $("#employment input, #employment textarea, #employment select, #tabIndex, #schappid, #schid").serialize();
					break;
				case '6':
					tmp = $("#referee input, #referee textarea, #referee select, #tabIndex, #schappid, #schid").serialize();
					break;
				case '7':
					tmp = $("#otherinformation input, #otherinformation textarea, #otherinformation select, #tabIndex, #schappid, #schid").serialize();
					break;
				default:
					break;
			}
			$.ajax({
				type:"POST",
				url:"/ops/jsFormAjax.php",
				async:false,
				data:tmp,
				success: function(html){
					if (html>0)
						$.jGrowl('Some updates failed!');
				}
			});
			$('#tabIndex').val(ui.index);
			return true;
		}
	});
	$(".dp_date").datepicker({
		changeMonth:true,
		changeYear:true,
		dateFormat:'yy-mm-dd',
		yearRange:'-30:+20'
	});
	$("input.university").autocomplete("suggest.php", {
		extraParams: {param:'list_university'},
		max:25,
		width: 250,
		selectFirst: false
	});
});
function validate(obj) {
	var $sectionTabs = $('#applicationForm').tabs();
	// Education Plan
	for (i=1; i<=globals['max_futurecourse']; i++) {
		if (obj['future_course'+i].selectedIndex==0) {
			$sectionTabs.tabs('select','#educationplan');
			$.jGrowl("Please select your future course of study preference.");
			obj['future_course'+i].focus();
			return false;
		}
 	}/*
	if (trim(obj['intended_date'].value)=='' || trim(obj['intended_date'].value)=='0000-00-00') {
		$sectionTabs.tabs('select','#educationplan');
		$.jGrowl("Please enter your intended commencement date.");
		obj.intended_date.focus();
		return false;
	}*/
	for (i=1; i<=globals['max_educationplan']; i++) {
		if (trim(obj['eduplan_university'+i].value)!="") {
			if (obj['eduplan_country'+i].selectedIndex==0) {
				$sectionTabs.tabs('select','#educationplan');
				$.jGrowl("Please select the country of the university.");
				obj['eduplan_country'+i].focus();
				return false;
			}
			if (trim(obj['eduplan_course'+i].value)=="") {
				$sectionTabs.tabs('select','#educationplan');
				$.jGrowl("Please enter the course of study that you apply at the university.");
				obj['eduplan_course'+i].focus();
				return false;
			}
			if (obj['eduplan_outcome'+i].selectedIndex==0) {
				$sectionTabs.tabs('select','#educationplan');
				$.jGrowl("Please enter the status/outcome of the application.");
				obj['eduplan_outcome'+i].focus();
				return false;
			}
			if (trim(obj['eduplan_apply_date'+i].value)=='' || trim(obj['eduplan_apply_date'+i].value)=='0000-00-00') {
				$sectionTabs.tabs('select','#educationplan');
				$.jGrowl("Please enter the application date.");
				obj['eduplan_apply_date'+i].focus();
				return false;
			}
		}
	}

 	// Other Scholarship Application / Grant
	for (i=1; i<=globals['max_otherapp']; i++) {
		if (trim(obj['otherapp_scholarship_name'+i].value)!="") {
			if (trim(obj['otherapp_organization'+i].value)=="") {
				$sectionTabs.tabs('select','#otherApp');
				$.jGrowl("Please enter the organization name.");
				obj['otherapp_organization'+i].focus();
				return false;
			}
			if (obj['otherapp_outcome'+i].selectedIndex==0) {
				$sectionTabs.tabs('select','#otherApp');
				$.jGrowl("Please enter the status/outcome of the application.");
				obj['otherapp_outcome'+i].focus();
				return false;
			}
			if (trim(obj['otherapp_apply_date'+i].value)=='' || trim(obj['otherapp_apply_date'+i].value)=='0000-00-00') {
				$sectionTabs.tabs('select','#otherApp');
				$.jGrowl("Please enter the application date.");
				obj['otherapp_apply_date'+i].focus();
				return false;
			}
		}
	}

	// CCA
	for (i=1; i<=globals['max_cca']; i++) {
		if (trim(obj['cca_institution'+i].value)!="") {
			if (obj['cca_level'+i].selectedIndex==0) {
				$sectionTabs.tabs('select','#cca');
				$.jGrowl("Please select your CCA level.");
				obj['cca_level'+i].focus();
				return false;
			}
			if (obj['cca_type'+i].selectedIndex==0) {
				$sectionTabs.tabs('select','#cca');
				$.jGrowl("Please select your CCA type.");
				obj['cca_type'+i].focus();
				return false;
			}
			if (trim(obj['cca_position'+i].value)=="") {
				$sectionTabs.tabs('select','#cca');
				$.jGrowl("Please enter your position / role.");
				obj['cca_position'+i].focus();
				return false;
			}
			if (obj['cca_pos_type'+i].selectedIndex==0) {
				$sectionTabs.tabs('select','#cca');
				$.jGrowl("Please select your CCA position type.");
				obj['cca_pos_type'+i].focus();
				return false;
			}
			if (trim(obj['cca_from_date'+i].value)=='' || trim(obj['cca_from_date'+i].value)=='0000-00-00') {
				$sectionTabs.tabs('select','#cca');
				$.jGrowl("Please enter the start date.");
				obj['cca_from_date'+i].focus();
				return false;
			}
		}
	}

	// Award
	for (i=1; i<=globals['max_award']; i++) {
		if (trim(obj['prize_award'+i].value)!="") {
			if (trim(obj['prize_award_date'+i].value)=='' || trim(obj['prize_award_date'+i].value)=='0000-00-00') {
				$sectionTabs.tabs('select','#prize');
				$.jGrowl("Please specify when you get the award.");
				obj['prize_award_date'+i].focus();
				return false;
			}
		}
	}

	// Other Qualification / Certification
	for (i=1; i<=globals['max_otherqualification']; i++) {
		if (trim(obj['qualification_qualification'+i].value)!="") {
			if (trim(obj['qualification_institution'+i].value)=="") {
				$sectionTabs.tabs('select','#otherQualification');
				$.jGrowl("Please enter the institution name.");
				obj['qualification_institution'+i].focus();
				return false;
			}
		}
	}

	// Employment History
	for (i=1; i<=globals['max_employment']; i++) {
		if (trim(obj['employment_employer'+i].value)!="") {
			if (trim(obj['employment_start_date'+i].value)=='' || trim(obj['employment_start_date'+i].value)=='0000-00-00') {
				$sectionTabs.tabs('select','#employment');
				$.jGrowl("Please enter your start date.");
				obj['employment_start_date'+i].focus();
				return false;
			}
			if (trim(obj['employment_position'+i].value)=="") {
				$sectionTabs.tabs('select','#employment');
				$.jGrowl("Please enter your last position.");
				obj['employment_position'+i].focus();
				return false;
			}
		}
	}

	// Referee
	for (i=1; i<=globals['max_referee']; i++) {
		if (trim(obj['referee_fullname'+i].value)!="") {
			if (trim(obj['referee_occupation'+i].value)=="") {
				$sectionTabs.tabs('select','#referee');
				$.jGrowl("Please enter the referee's occupation.");
				obj['referee_occupation'+i].focus();
				return false;
			}
			if (trim(obj['referee_organization'+i].value)=="") {
				$sectionTabs.tabs('select','#referee');
				$.jGrowl("Please enter the referee's organization.");
				obj['referee_organization'+i].focus();
				return false;
			}
			if (trim(obj['referee_contact'+i].value)=="") {
				$sectionTabs.tabs('select','#referee');
				$.jGrowl("Please enter the referee's contact.");
				obj['referee_contact'+i].focus();
				return false;
			}
			if (trim(obj['referee_email'+i].value)!="") {
				if (!check_email(obj['referee_email'+i].value)) {
					$sectionTabs.tabs('select','#referee');
					$.jGrowl("Please enter a valid email address.");
					obj['referee_email'+i].focus();
					return false;
				}
			}
		}
	}

	// Other Information
	if (obj.declaration1_1.checked==false && obj.declaration1_2.checked==false) {
		$sectionTabs.tabs('select','#otherinformation');
		$.jGrowl("Have you been or are suffering from any disease/illness/major medical condition or physical impairment?");
		obj.declaration1_2.focus();
		return false;
	}
	if (obj.declaration1_1.checked==true && trim(obj.declaration1_explanation.value)=="") {
		$sectionTabs.tabs('select','#otherinformation');
		$.jGrowl("Please enter the details.");
		obj.declaration1_explanation.focus();
		return false;
	}
	if (obj.declaration2_1.checked==false && obj.declaration2_2.checked==false) {
		$sectionTabs.tabs('select','#otherinformation');
		$.jGrowl("Have you ever been convicted in a court of law in any country (including traffic offences)?");
		obj.declaration2_2.focus();
		return false;
	}
	if (obj.declaration2_1.checked==true && trim(obj.declaration2_explanation.value)=="") {
		$sectionTabs.tabs('select','#otherinformation');
		$.jGrowl("Please enter the details.");
		obj.declaration2_explanation.focus();
		return false;
	}
	if (obj.declaration5_1.checked==false && obj.declaration5_2.checked==false) {
		$sectionTabs.tabs('select','#otherinformation');
		$.jGrowl("Do you have any pending court case or police investigation?");
		obj.declaration5_2.focus();
		return false;
	}
	if (obj.declaration5_1.checked==true && trim(obj.declaration5_explanation.value)=="") {
		$sectionTabs.tabs('select','#otherinformation');
		$.jGrowl("Please enter the details.");
		obj.declaration5_explanation.focus();
		return false;
	}/*
	if (obj.declaration6_1.checked==false && obj.declaration6_2.checked==false) {
	toggleSection(obj.id, 'otherinformation');
	$.jGrowl("Have you ever been convicted in a court of law in any other country (excluding parking offences or criminal records disclosed above)?");
	obj.declaration6_2.focus();
	return false;
	}
	if (obj.declaration6_1.checked==true && trim(obj.declaration6_explanation.value)=="") {
	toggleSection(obj.id, 'otherinformation');
	$.jGrowl("Please enter the details.");
	obj.declaration6_explanation.focus();
	return false;
	}*/

	// Declaration
	if (obj.declaration_1.checked!=true) {
		$.jGrowl("Please indicate that you agree with the declaration terms and condition.");
		obj.declaration_1.focus();
		return false;
	}
	obj.submit();
	return true;
}

function toggleSection(formID, newSectionID) {
	var objForm, currentSectionID, currentSection, newSection;
	objForm = document.getElementById(formID);
	currentSectionID = objForm['currentSection'].value;
	if (currentSectionID!=newSectionID) {
		newSection = document.getElementById(newSectionID);
		objForm['currentSection'].value = newSectionID;
		if (currentSectionID)
			currentSection = document.getElementById(currentSectionID);
	  else
	   currentSection = newSection;
	  currentSection.style.display = "none";
	  newSection.style.display = "block";
		newSection.focus();
	}
}
//--><!]]>