<!--//--><![CDATA[//><!--
(function(document){

var globals = [];
globals.max_family = 6;
globals.max_apaper = 10;
globals.req_apaper = 5;
globals.max_ibpaper = 10;
globals.req_ibpaper = 5;
globals.max_actnuspaper = 5;
globals.req_actnuspaper = 3;
globals.max_sat2paper = 3;
globals.max_language = 5;

//CHECK SINGAPORE POSTAL CODE
function checkSingaporePostalCode(p) {/*
	if (p.length!=6) {
		return false;
	}*/
	var pattern = /[0-9]{6}/;
	if (p.match(pattern)) {
		return 1;
	}
	return false;
}

function countTotalSAT1() {
	var sat1v = $('#test_sat1_verbal').val(),
		sat1w = $('#test_sat1_written').val(),
		sat1m = $('#test_sat1_math').val();
	if (isNaN(sat1v) || sat1v==='') {
		$('#test_sat1_verbal').val(0);
		sat1v = 0;
	}
	if (isNaN(sat1w) || sat1w==='') {
		$('#test_sat1_written').val(0);
		sat1w = 0;
	}
	if (isNaN(sat1m) || sat1m==='') {
		$('#test_sat1_math').val(0);
		sat1m = 0;
	}
	total = parseInt(sat1v, 10) + parseInt(sat1w, 10) + parseInt(sat1m, 10);
	$('#test_sat1_result').val(total);
}

function countTotalSAT2() {
	var sat21 = $('#test_sat2_result1').val(),
		sat22 = $('#test_sat2_result2').val(),
		sat23 = $('#test_sat2_result3').val();
	if (isNaN(sat21) || sat21==='') {
		$('#test_sat2_result1').val(0);
		sat21 = 0;
	}
	if (isNaN(sat22) || sat22==='') {
		$('#test_sat2_result2').val(0);
		sat22 = 0;
	}
	if (isNaN(sat23) || sat23==='') {
		$('#test_sat2_result3').val(0);
		sat23 = 0;
	}
	total = parseInt(sat21, 10) + parseInt(sat22, 10) + parseInt(sat23, 10);
	$('#test_sat2_result').val(total);
}

function countTotalGRE() {
	var grea = $('#test_gre_analytical').val(),
		grev = $('#test_gre_verbal').val(),
		greq = $('#test_gre_quantitative').val();
	if (isNaN(grea) || grea==='') {
		$('#test_gre_analytical').val(0);
		grea = 0;
	}
	if (isNaN(grev) || grev==='') {
		$('#test_gre_verbal').val(0);
		grev = 0;
	}
	if (isNaN(greq) || greq==='') {
		$('#test_gre_quantitative').val(0);
		greq = 0;
	}
	total = parseInt(grev, 10) + parseInt(greq, 10);
	$('#test_gre_result').val(total);
}

function validatePersonalParticular(growl) {
	if (growl===null) {
		growl = false;
	}
	var focus = [],
		i = 0;
	if ($.trim($('#fullname').val())==='') {
		if (growl) { $.jGrowl("Please enter your fullname."); }
		focus[i++] = 'fullname';
	}
	if ($.trim($('#nric').val())==='') {
		if (growl) { $.jGrowl("Please enter your NRIC / Passport No."); }
		focus[i++] = 'nric';
	}
	if ($('#nationality').attr("selectedIndex")===1 || $('#nationality').attr("selectedIndex")===0) {
		if (!checkNRIC($('#nric').val())) {
			if (growl) { $.jGrowl("The NRIC you key in is invalid."); }
			focus[i++] = 'nric';
		}
	}
	if ($('#gender').attr("selectedIndex")===0) {
		if (growl) { $.jGrowl("Please select your gender."); }
		focus[i++] = 'gender';
	}
	if ($('#marital_status').attr("selectedIndex")===0) {
		if (growl) { $.jGrowl("Please select your marital status."); }
		focus[i++] = 'marital_status';
	}
	if ($.trim($('#dob_date').val())==='' || $.trim($('#dob_date').val())=="0000-00-00") {
		if (growl) { $.jGrowl("Please enter your date of birth."); }
		focus[i++] = 'dob_date';
	}
	if ($('#birth_country').attr("selectedIndex")===0) {
		if (growl) { $.jGrowl("Please select your birth country."); }
		focus[i++] = 'birth_country';
	}
	if ($('#race').attr("selectedIndex")===0) {
		if (growl) { $.jGrowl("Please select your race."); }
		focus[i++] = 'race';
	}
	if ($('#religion').attr("selectedIndex")===0) {
		if (growl) { $.jGrowl("Please select your religion."); }
		focus[i++] = 'religion';
	}
	if ($.trim($('#address').val())==='') {
		if (growl) { $.jGrowl("Please enter your address."); }
		focus[i++] = 'address';
	}
	if ($('#address_country').attr("selectedIndex")===0) {
		if (growl) { $.jGrowl("Please select the country of your current address."); }
		focus[i++] = 'address_country';
	}
	if ($('#address_country').attr("selectedIndex")===1) {
		if ($.trim($('#address_postal').val())==='') {
			if (growl) { $.jGrowl("Please enter your current postal code."); }
			focus[i++] = 'address_postal';
		}
		if (!checkSingaporePostalCode($('#address_postal').val())) {
			if (growl) { $.jGrowl("Please enter a valid Singapore postal code.\nInclude the leading zero if it is less than 6 digits.\nExample: 054267"); }
			focus[i++] = 'address_postal';
		}
	}
	if ($.trim($('#mailing_address').val())!=='') {
		if ($('#mailing_country').attr("selectedIndex")===0) {
			if (growl) { $.jGrowl("Please select the country of your mailing address."); }
			focus[i++] = 'mailing_country';
		}
		if ($.trim($('#mailing_postal').val())==='') {
			if (growl) { $.jGrowl("Please enter your mailing postal code."); }
			focus[i++] = 'mailing_postal';
		}
		if ($('#mailing_country').attr("selectedIndex")===1) {
			if (!checkSingaporePostalCode($('#mailing_postal').val())) {
				if (growl) { $.jGrowl("Please enter a valid Singapore postal code.\nInclude the leading zero if it is less than 6 digits.\nExample: 054267"); }
				focus[i++] = 'mailing_postal';
			}
		}
	}
	if ($.trim($('#contact_main').val())==='') {
		if (growl) { $.jGrowl("Please enter your main contact."); }
		focus[i++] = 'contact_main';
	}
	return focus;
}

function validateFamilyParticular(growl) {
	if (growl===null) {
		growl = false;
	}
	var focus = [],
		i,
		j = 0,
		father = 0,
		mother = 0,
		guardian = 0;
	for (i=1; i<=globals.max_family; i++) {
		if ($.trim($('#family_fullname'+i).val())!=='') {
			if ($('#family_relationship'+i).attr("selectedIndex")===0) {
				if (growl) { $.jGrowl("Please select your relationship with " + $('#family_fullname'+i).val() + "."); }
				focus[j++] = 'family_relationship'+i;
			}
			else if ($('#family_relationship'+i).attr("selectedIndex")===1) {
				father = i;
			}
			else if ($('#family_relationship'+i).attr("selectedIndex")==2) {
				mother = i;
			}
			else if ($('#family_relationship'+i).attr("selectedIndex")==6) {
				guardian = i;
			}
			if ($('#family_nationality'+i).attr("selectedIndex")===0) {
				if (growl) { $.jGrowl("Please enter " + $('#family_fullname'+i).val() + "'s nationality."); }
				focus[j++] = 'family_nationality'+i;
			}
			if ($.trim($('#family_dob_date'+i).val())==='' || $.trim($('#family_dob_date'+i).val())=='0000-00-00') {
				if (growl) { $.jGrowl("Please enter " + $('#family_fullname'+i).val() + "'s date of birth."); }
				focus[j++] = 'family_dob_date'+i;
			}
			if ($('#family_birth_country'+i).attr("selectedIndex")===0) {
				if (growl) { $.jGrowl("Please enter " + $('#family_fullname'+i).val() + "'s country of birth."); }
				focus[j++] = 'family_birth_country'+i;
			}
			if ($.trim($('#family_occupation'+i).val())==='') {
				if (growl) { $.jGrowl("Please enter " + $('#family_fullname'+i).val() + "'s occupation."); }
				focus[j++] = 'family_occupation'+i;
			}
		}
	}
	if (father===0 && mother===0 && guardian===0) {
		if (growl) { $.jGrowl("Please enter at least one of your parents' or guardian's detail."); }
		focus[j++] = 'family_fullname1';
	}
	return focus;
}

function validateNS(growl) {
	if (growl===null) {
		growl = false;
	}
	var focus = [],
		i = 0,
		ns = $('#ns_status').attr("selectedIndex");
	if ($('#gender').attr("selectedIndex")===1 && ($('#nationality').attr("selectedIndex")===1 || $('#nationality').attr("selectedIndex")===0)) {
		if (ns===0) {
			if (growl) { $.jGrowl("Please select your national service status."); }
			focus[i++] = 'ns_status';
		}
		else {
			if (ns===1 || ns==2 || ns==3) {
				if ($.trim($('#ns_enlistment_date').val())==='' || $.trim($('#ns_enlistment_date').val())=='0000-00-00') {
					if (growl) { $.jGrowl("Please enter your enlistment date."); }
					focus[i++] = 'ns_enlistment_date';
				}
				if ($('#ns_rank').attr("selectedIndex")===0) {
					if (growl) { $.jGrowl("Please select your rank."); }
					focus[i++] = 'ns_rank';
				}
			}
			if (ns==3 || ns==5) {
				if ($.trim($('#ns_reason').val())==='') {
					if (growl) { $.jGrowl("Please enter your reason for exemption/deferment from National Service."); }
					focus[i++] = 'ns_reason';
				}
			}
		}
	}
	return focus;
}

function validateEducation(growl) {
	if (growl===null) {
		growl = false;
	}
	var focus = [],
		i,
		j = 0;
	// Education Records - O Level
	if ($.trim($('#education_institution1').val())==='') {
		if (growl) { $.jGrowl("Please enter your GCE 'O' Level or Equivalent Institution name."); }
		focus[j++] = 'education_institution1';
	}
	if ($('#education_start_yyyy1').attr("selectedIndex")===0) {
		if (growl) { $.jGrowl("Please enter your GCE 'O' Level or Equivalent start date."); }
		focus[j++] = 'education_start_yyyy1';
	}
	else if ($('#education_start_mm1').attr("selectedIndex")===0) {
		if (growl) { $.jGrowl("Please enter your GCE 'O' Level or Equivalent start date."); }
		focus[j++] = 'education_start_mm1';
	}
	if ($.trim($('#education_institution2').val())!=='') {
		if ($('#education_end_yyyy1').attr("selectedIndex")===0) {
			if (growl) { $.jGrowl("Please enter your GCE 'O' Level or Equivalent graduation date."); }
			focus[j++] = 'education_end_yyyy1';
		}
		else if ($('#education_end_mm1').attr("selectedIndex")===0) {
			if (growl) { $.jGrowl("Please enter your GCE 'O' Level or Equivalent graduation date."); }
			focus[j++] = 'education_end_mm1';
		}
	}
	if ($('#education_country1').attr("selectedIndex")===0) {
		if (growl) { $.jGrowl("Please select the country of your GCE 'O' Level or Equivalent Institution."); }
		focus[j++] = 'education_country1';
	}
	if ($('#education_course1').attr("selectedIndex")===0) {
		if (growl) { $.jGrowl("Please select your GCE 'O' Level or Equivalent Stream."); }
		focus[j++] = 'education_course1';
	}
	if ($('#education_level1').attr("selectedIndex")===0 && $.trim($('#education_o_subject1').val())==='') {
		if (growl) { $.jGrowl("Please enter the subject which you had taken at your GCE 'O' Level or Equivalent."); }
		focus[j++] = 'education_o_subject1';
	}
	else if ($('#education_level1').attr("selectedIndex")===1 && $.trim($('#education_ips_subject1').val())==='') {
		if (growl) { $.jGrowl("Please enter the subject which you had taken at your GCE 'O' Level or Equivalent."); }
		focus[j++] = 'education_ips_subject1';
	}
	else if ($('#education_level1').attr("selectedIndex")==2 && $.trim($('#education_os_subject1').val())==='') {
		if (growl) { $.jGrowl("Please enter the subject which you had taken at your GCE 'O' Level or Equivalent."); }
		focus[j++] = 'education_os_subject1';
	}
	if ($('#education_country1').attr("selectedIndex")===1 && $('#education_start_yyyy2').attr("selectedIndex")!==0 && $('#education_start_mm2').attr("selectedIndex")!==0 && $.trim($('#education_cumulative_score1').val())==='') {
		if (growl) { $.jGrowl("Please enter your Aggregate L1 R5 / CAP / GPA Score."); }
		focus[j++] = 'education_cumulative_score1';
	}

	// Education Records - A Level
	if ($('#school option:selected').val()!='secondary' && $('#school option:selected').val()!='overseas') {
		if ($.trim($('#education_institution2').val())==='') {
			if (growl) { $.jGrowl("Please enter your GCE 'A' Level or Equivalent Institution name."); }
			focus[j++] = 'education_institution2';
		}
		if ($('#education_start_yyyy2').attr("selectedIndex")===0) {
			if (growl) { $.jGrowl("Please enter your GCE 'A' Level or Equivalent start date."); }
			focus[j++] = 'education_start_yyyy2';
		}
		else if ($('#education_start_mm2').attr("selectedIndex")===0) {
			if (growl) { $.jGrowl("Please enter your GCE 'A' Level or Equivalent start date."); }
			focus[j++] = 'education_start_mm2';
		}
		if ($.trim($('#education_institution3').val())!=='') {
			if ($('#education_end_yyyy2').attr("selectedIndex")===0) {
				if (growl) { $.jGrowl("Please enter your GCE 'A' Level or Equivalent graduation date."); }
				focus[j++] = 'education_end_yyyy2';
			}
			else if ($('#education_end_mm2').attr("selectedIndex")===0) {
				if (growl) { $.jGrowl("Please enter your GCE 'A' Level or Equivalent graduation date."); }
				focus[j++] = 'education_end_mm2';
			}
		}
		if ($('#education_country2').attr("selectedIndex")===0) {
			if (growl) { $.jGrowl("Please select the country of your GCE 'A' Level or Equivalent Institution."); }
			focus[j++] = 'education_country2';
		}
		if ($('#education_level2').attr("selectedIndex")===0) {
			if ($('#education_course2_JC').attr("selectedIndex")===0) {
				if (growl) { $.jGrowl("Please select your A Level Stream."); }
				focus[j++] = 'education_course2_JC';
			}
			count = 0;
			for (i=1; i<=globals.max_apaper; i++) {
				if ($('#education_a_level'+i).attr("selectedIndex")!==0 && $.trim($('#education_a_subject'+i).val())!=='') {
					count++;
				}
			}
			if (count<globals.req_apaper) {
				if (growl) { $.jGrowl('Please enter at least '+globals.req_apaper+' A Level subjects which you take including your S/H3 Paper if applicable.'); }
				focus[j++] = 'education_a_level1';
			}
		}
		else if ($('#education_level2').attr("selectedIndex")===1) {
			if ($.trim($('#education_course2_Diploma').val())==='') {
				if (growl) { $.jGrowl("Please enter your Diploma Name."); }
				focus[j++] = 'education_course2_Diploma';
			}
			if ($('#education_current_year2').attr("selectedIndex")===0) {
				if (growl) { $.jGrowl("Please select your current year of Diploma."); }
				focus[j++] = 'education_current_year2';
			}
			diplomaGPA = $.trim($('#education_cumulative_score2_Diploma').val());
			if (diplomaGPA!=='' && isNaN(diplomaGPA)) {
				if (growl) { $.jGrowl('Please enter your cumulative Diploma GPA.\nPlease only insert numerical value.'); }
				focus[j++] = 'education_cumulative_score2_Diploma';
			}
		}
		else if ($('#education_level2').attr("selectedIndex")==2) {
			count = 0;
			for (i=1; i<=globals.max_ibpaper; i++) {
				if ($('#education_ib_level'+i).attr("selectedIndex")!==0 && $.trim($('#education_ib_subject'+i).val())!=='') {
					count++;
				}
			}
			if (count<globals.req_ibpaper) {
				if (growl) { $.jGrowl('Please enter at least '+globals.req_ibpaper+' IB subjects which you take.'); }
				focus[j++] = 'education_ib_level1';
			}
			ibScore = $.trim($('#education_cumulative_score2_IB').val());
			if (ibScore==='' || isNaN(ibScore)) {
				if (growl) { $.jGrowl('Please enter your total IB score.\nPlease only insert numerical value.'); }
				focus[j++] = 'education_cumulative_score2_IB';
			}
		}
		else if ($('#education_level2').attr("selectedIndex")==3) {
			count = 0;
			for (i=1; i<=globals.max_actnuspaper; i++) {
				if ($.trim($('#education_actnus_subject'+i).val())!=='') {
					count++;
				}
			}
			if (count<globals.req_actnuspaper) {
				if (growl) { $.jGrowl('Please enter at least '+globals.req_actnuspaper+' subjects which you take.'); }
				focus[j++] = 'education_actnus_subject1';
			}
		}
	}

	// Education Records - Tertiary
	if ($.trim($('#education_institution3').val())!=='') {
		if ($('#education_level3').attr("selectedIndex")===0) {
			if (growl) { $.jGrowl("Please select your tertiary level."); }
			focus[j++] = 'education_level3';
		}
		if ($('#education_start_yyyy3').attr("selectedIndex")===0) {
			if (growl) { $.jGrowl("Please select your tertiary start date."); }
			focus[j++] = 'education_start_yyyy3';
		}
		else if ($('#education_start_mm3').attr("selectedIndex")===0) {
			if (growl) { $.jGrowl("Please select your tertiary start date."); }
			focus[j++] = 'education_start_mm3';
		}
		if ($('#education_country3').attr("selectedIndex")===0) {
			if (growl) { $.jGrowl("Please select the country of your Tertiary Institution."); }
			focus[j++] = 'education_country3';
		}
		if ($.trim($('#education_course3').val())==='') {
			if (growl) { $.jGrowl("Please enter your tertiary course of study."); }
			focus[j++] = 'education_course3';
		}
		if ($('#education_current_year3').attr("selectedIndex")===0) {
			if (growl) { $.jGrowl("Please select your current year of tertiary study."); }
			focus[j++] = 'education_current_year3';
		}
		tertiaryGPA = $.trim($('#education_cumulative_score3').val());
		if (tertiaryGPA!=='' && isNaN(tertiaryGPA)) {
			if (growl) { $.jGrowl('Please enter your cumulative Tertiary GPA.\nPlease only insert numerical value.'); }
			focus[j++] = 'education_cumulative_score3';
		}
		if (tertiaryGPA>0 && $('#education_tertiaryAux_max_gpa').attr("selectedIndex")===0) {
			if (growl) { $.jGrowl("Please select the maximum GPA of your tertiary study."); }
			focus[j++] = 'education_tertiaryAux_max_gpa';
		}
	}
	return focus;
}

function validateTestResult(growl) {
	if (growl===null) {
		growl = false;
	}
	var focus = [],
		i, sat1v, sat1w, sat1m, sat2r, grea, grev, greq
		j = 0;
	if ($.trim($('#test_sat1_date').val())!=='' && $.trim($('#test_sat1_date').val())!="0000-00-00") {
		if ($.trim($('#test_sat1_center').val())==='') {
			if (growl) { $.jGrowl("Please enter your SAT 1 Test Centre."); }
			focus[j++] = 'test_sat1_center';
		}
		sat1v = $('#test_sat1_verbal').val();
		sat1w = $('#test_sat1_written').val();
		sat1m = $('#test_sat1_math').val();
		if (sat1v>0 && (sat1v > 800 || sat1v < 200)) {
			if (growl) { $.jGrowl("Your SAT 1 critical reading / verbal score should range from 200-800."); }
			focus[j++] = 'test_sat1_verbal';
		}
		if (sat1w>0 && (sat1w > 800 || sat1w < 200)) {
			if (growl) { $.jGrowl("Your SAT 1 writing score should range from 200-800."); }
			focus[j++] = 'test_sat1_written';
		}
		if (sat1m>0 && (sat1m > 800 || sat1m < 200)) {
			if (growl) { $.jGrowl("Your SAT 1 mathematics score should range from 200-800."); }
			focus[j++] = 'test_sat1_math.focus';
		}
	}
	if ($.trim($('#test_sat2_date').val())!=='' && $.trim($('#test_sat2_date').val())!="0000-00-00") {
		if ($.trim($('#test_sat2_center').val())==='') {
			if (growl) { $.jGrowl("Please enter your SAT 2 Test Centre."); }
			focus[j++] = 'test_sat2_center';
		}
		count = 0;
		for (i=1; i<=globals.max_sat2paper; i++) {
			if ($.trim($('#test_sat2_paper'+i).val()).value!=='') {
				count++;
				sat2r = $('#test_sat2_result'+i).val();
				if (sat2r < 0 || sat2r > 800) {
					if (growl) { $.jGrowl("Your SAT 2 subject score should range from 0-800."); }
					focus[j++] = 'test_sat2_result'+i;
				}
			}
		}
		if (count===0) {
			if (growl) { $.jGrowl("Please enter your SAT 2 paper."); }
			focus[j++] = 'test_sat2_paper1';
		}
	}
	if ($.trim($('#test_toefl_date').val())!=='' && $.trim($('#test_toefl_date').val())!="0000-00-00") {
		if ($.trim($('#test_toefl_center').val())==='') {
			if (growl) { $.jGrowl("Please enter your TOEFL Test Centre."); }
			focus[j++] = 'test_toefl_center';
		}
		result = $('#test_toefl_result').val();
		if (result < 0 || result > 800) {
			if (growl) { $.jGrowl("Your TOEFL score should range from 0-800."); }
			focus[j++] = 'test_toefl_result';
		}
	}
	if ($.trim($('#test_gmat_date').val())!=='' && $.trim($('#test_gmat_date').val())!="0000-00-00") {
		if ($.trim($('#test_gmat_center').val())==='') {
			if (growl) { $.jGrowl("Please enter your GMAT Test Centre."); }
			focus[j++] = 'test_gmat_center';
		}
		result = $('#test_gmat_result').val();
		if (result < 0 || result > 800) {
			if (growl) { $.jGrowl("Your GMAT score should range from 0-800."); }
			focus[j++] = 'test_gmat_result';
		}
	}
	if ($.trim($('#test_gre_date').val())!=='' && $.trim($('#test_gre_date').val())!="0000-00-00") {
		if ($.trim($('#test_gre_center').val())==='') {
			if (growl) { $.jGrowl("Please enter your GRE Test Centre."); }
			focus[j++] = 'test_gre_center';
		}
		grea = $('#test_gre_analytical').val();
		grev = $('#test_gre_verbal').val();
		greq = $('#test_gre_quantitative').val();
		if (grea < 0 && grea > 6) {
			if (growl) { $.jGrowl("Your GRE analytical writing score range from 0-6."); }
			focus[j++] = 'test_gre_analytical';
		}
		if (grev>0 && (grev > 800 || grev < 200)) {
			if (growl) { $.jGrowl("Your GRE verbal reasoning score range from 200-800."); }
			focus[j++] = 'test_gre_verbal';
		}
		if (greq>0 && (greq > 800 || greq < 200)) {
			if (growl) { $.jGrowl("Your GRE quantitative reasoning score range from 200-800."); }
			focus[j++] = 'test_gre_quantitative';
		}
	}
	countTotalSAT1();
	countTotalSAT2();
	countTotalGRE();
	return focus;
}

function validateLanguage(growl) {
	if (growl===null) {
		growl = false;
	}
	var focus = [],
		i,
		j = 0,
		lang = '';
	for (i=1; i<=globals.max_language; i++) {
		if ($('#language_languageid'+i).attr("selectedIndex")!==0) {
			lang = $("#language_languageid" + i + " option:selected").text();
			if ($('#language_proficiency_speak'+i).attr("selectedIndex")===0) {
				if (growl) { $.jGrowl("Please select your " + lang + "'s verbal proficiency."); }
				focus[j++] = 'language_proficiency_speak'+i;
			}
			if ($('#language_proficiency_read'+i).attr("selectedIndex")===0) {
				if (growl) { $.jGrowl("Please select your " + lang + "'s reading proficiency."); }
				focus[j++] = 'language_proficiency_read'+i;
			}
			if ($('#language_proficiency_write'+i).attr("selectedIndex")===0) {
				if (growl) { $.jGrowl("Please select your " + lang + "'s written proficiency."); }
				focus[j++] = 'language_proficiency_write'+i;
			}
		}
	}
	return focus;
}

function checkPercentile(obj) {
	if (isNaN(obj.value) || obj.value==='' || obj.value<0) {
		obj.value = 0;
	}
	else if (obj.value>100) {
		obj.value = 100;
	}
}

function toggleJCDiploma() {
	var target, i, j, aux, tmp, course,
		obj = document.getElementById("education_level2");
		objLength = obj.options.length;
	for (i=0; i<objLength; i++) {
		tmp = obj.options[i].value;
		target = document.getElementById("a_"+tmp);
		course = document.getElementById("education_course2_"+tmp);
		cum_score = document.getElementById("education_cumulative_score2_"+tmp);
		if (tmp=='Diploma' || tmp=='ACT_NUS') {
			for (j=1; j<=5; j++) {
				aux[j] = document.getElementById("education_aux2_"+tmp+"_"+j);
			}
		}
		else {
			aux = document.getElementById("education_aux2_"+tmp);
		}
		if (tmp==obj.value) {
			target.style.display = "block";
			course.disabled = false;
			cum_score.disabled = false;
			if (tmp=='Diploma' || tmp=='ACT_NUS') {
				for (j=1; j<=5; j++) {
					aux[j].disabled = false;
				}
			}
			else {
				aux.disabled = false;
			}
		}
		else {
			target.style.display = "none";
			course.disabled = true;
			cum_score.disabled = true;
			if (tmp=='Diploma' || tmp=='ACT_NUS') {
				for (j=1; j<=5; j++) {
					aux[j].disabled = true;
				}
			}
			else {
				aux.disabled = true;
			}
		}
	}
}

function toggleSecondary() {
	var target, i, tmp,
		obj = document.getElementById("education_level1");
		objLength = obj.options.length;
	for (i=0; i<objLength; i++) {
		tmp = obj.options[i].value;
		target = document.getElementById("o_"+tmp);
		if (tmp==obj.value) {
			target.style.display = "block";
		}
		else {
			target.style.display = "none";
		}
	}
}

function changeALevelGrade(gradeIndex) {
	var prolist = document.getElementById('education_promo_grade'+gradeIndex),
		prelist = document.getElementById('education_prelim_grade'+gradeIndex),
		reslist = document.getElementById('education_result_grade'+gradeIndex),
		gradelevel = document.getElementById('education_a_level'+gradeIndex).value,
		i;

	for (i=0; i < prolist.length;) {
		prolist.options[0] = null;
		prelist.options[0] = null;
		reslist.options[0] = null;
	}
	for (i=0; i < grade[gradelevel].length; i++) {
		prolist.options[i] = new Option(grade[gradelevel][i]);
		prolist.options[i].value = grade[gradelevel][i];
		prelist.options[i] = new Option(grade[gradelevel][i]);
		prelist.options[i].value = grade[gradelevel][i];
		reslist.options[i] = new Option(grade[gradelevel][i]);
		reslist.options[i].value = grade[gradelevel][i];
	}
}

function changeIBLevelGrade(gradeIndex) {
	var prolist = document.getElementById('education_ib_promo_grade'+gradeIndex),
		prelist = document.getElementById('education_ib_prelim_grade'+gradeIndex),
		reslist = document.getElementById('education_ib_result_grade'+gradeIndex),
		gradelevel = document.getElementById('education_ib_level'+gradeIndex).value,
		i;

	for (i=0; i < prolist.length;) {
		prolist.options[0] = null;
		prelist.options[0] = null;
		reslist.options[0] = null;
	}
	for (i=0; i < grade[gradelevel].length; i++) {
		prolist.options[i] = new Option(grade[gradelevel][i]);
		prolist.options[i].value = grade[gradelevel][i];
		prelist.options[i] = new Option(grade[gradelevel][i]);
		prelist.options[i].value = grade[gradelevel][i];
		reslist.options[i] = new Option(grade[gradelevel][i]);
		reslist.options[i].value = grade[gradelevel][i];
	}
}

function validate(obj, growl) {
	if (growl===null) {
		growl = false;
	}
	var $sectionTabs = $('#profileForm').tabs(),
		check = [];

	check = validatePersonalParticular(true);
	if (check.length>0) {
		$sectionTabs.tabs('select','#personalparticulars');
		$('#'+check[0]).focus();
		return false;
	}

	check = validateFamilyParticular(growl);
	if (check.length>0) {
		$sectionTabs.tabs('select','#familyparticulars');
		$('#'+check[0]).focus();
		return false;
	}

	check = validateNS(growl);
	if (check.length>0) {
		$sectionTabs.tabs('select','#nationalservice');
		$('#'+check[0]).focus();
		return false;
	}

	check = validateEducation(growl);
	if (check.length>0) {
		$sectionTabs.tabs('select','#education_all');
		$('#'+check[0]).focus();
		return false;
	}

	check = validateTestResult(growl);
	if (check.length>0) {
		$sectionTabs.tabs('select','#testresult');
		$('#'+check[0]).focus();
		return false;
	}

	check = validateLanguage(growl);
	if (check.length>0) {
		$sectionTabs.tabs('select','#language');
		$('#'+check[0]).focus();
		return false;
	}

	$('#mandatoryfields').val(1);
	obj.submit();
	return true;
}

function validateAjax() {
	var mf = 0;
	if (!validatePersonalParticular().length && !validateFamilyParticular().length && !validateNS().length && !validateEducation().length && !validateTestResult().length && !validateLanguage().length)
		mf = 1;
	$('#mandatoryfields').val(mf);
}

$(document).ready(function() {
	if (document.getElementById("education_level2")) {
		toggleJCDiploma(document.getElementById("education_level2"));
	}
	$(".family_dob").datepicker({
		changeMonth:true,
		changeYear:true,
		dateFormat:'yy-mm-dd',
		yearRange:'1930:+0'
	});
	$(".dp_date:not(.family_dob)").datepicker({
		changeMonth:true,
		changeYear:true,
		dateFormat:'yy-mm-dd',
		yearRange:'1960:+10'
	});
	$("#education_institution1").autocomplete("suggest.php", {
		extraParams: {param:'school_olvl'},
		max:25,
		width: 250,
		selectFirst: false
	});
	$("#education_institution2").autocomplete("suggest.php", {
		extraParams: {param:'school_alvl'},
		max:25,
		width: 250,
		selectFirst: false
	});
	$(".subject_olvl").autocomplete("suggest.php", {
		extraParams: {param:'subject_olvl'},
		width: 250,
		selectFirst: false
	});
	$(".subject_alvl").autocomplete("suggest.php", {
		extraParams: {param:'subject_alvl'},
		width: 250,
		selectFirst: false
	});
	$(".subject_iblvl").autocomplete("suggest.php", {
		extraParams: {param:'subject_iblvl'},
		width: 250,
		selectFirst: false
	});
	$(".subject_actnuslvl_major").autocomplete("suggest.php", {
		extraParams: {param:'subject_actnuslvl'},
		width: 250,
		selectFirst: false
	});
	var $sectionTabs = $('#profileForm').tabs({
		select: function(event, ui) {
			var tmp, previousIndex, check;
			previousIndex = $('#tabIndex').val();
			if (ui.index==5) {
				$("#btnNext").hide();
			}
			else {
				$("#btnNext").show();
			}
			validateAjax();
			switch (previousIndex) {
				case '0':
					check = validatePersonalParticular(true);
					if (check.length>0) {
						$('#'+check[0]).focus();
						return false;
					}
					tmp = $("#personalparticulars input, #personalparticulars textarea, #personalparticulars select, #tabIndex, #mandatoryfields").serialize();
					break;
				case '1':
					tmp = $("#familyparticulars input, #familyparticulars textarea, #familyparticulars select, #tabIndex, #mandatoryfields").serialize();
					break;
				case '2':
					tmp = $("#nationalservice input, #nationalservice textarea, #nationalservice select, #tabIndex, #mandatoryfields").serialize();
					break;
				case '3':
					tmp = $("#education_all input, #education_all textarea, #education_all select, #tabIndex, #mandatoryfields").serialize();
					break;
				case '4':
					tmp = $("#testresult input, #testresult textarea, #testresult select, #tabIndex, #mandatoryfields").serialize();
					break;
				case '5':
					tmp = $("#language input, #language textarea, #language select, #tabIndex, #mandatoryfields").serialize();
					break;
				default:
					break;
			}
			$.ajax({
				type:"POST",
				url:"/ops/jsProfileAjax.php",
				async:false,
				data:tmp,
				success: function(html){
					if (html>0) {
						$.jGrowl('Some updates failed!<br />Please contact the administrator at brightsparks@jobsfactory.com to continue!');
						ui.index = previousIndex;
					}
				}
			});
			if (ui.index==previousIndex)
				return false;
			$('#tabIndex').val(ui.index);
			return true;
		}
	});
	$('#education_level1').change(function () {
		toggleSecondary();
	});
	$('#education_level2').change(function () {
		toggleJCDiploma();
	});
	$('select.level_a').change(function () {
		var prefix = 'education_a_level',
			prefixLength = prefix.length,
			index;
		index = this.id.substring(prefixLength);
		changeALevelGrade(index);
	});
	$('select.level_ib').change(function () {
		var prefix = 'education_ib_level',
			prefixLength = prefix.length,
			index;
		index = this.id.substring(prefixLength);
		changeIBLevelGrade(index);
	});
	$('input.sat1.score').change(function () {
		countTotalSAT1();
	});
	$('input.sat2.score').change(function () {
		countTotalSAT2();
	});
	$('input.percentile').change(function () {
		checkPercentile(this);
	});
	$('input.gre.score').change(function () {
		countTotalGRE();
	});
	$("#btnNext").click(function(event) {
		$sectionTabs.tabs('select', $sectionTabs.tabs('option', 'selected') + 1);/*
		var next = $sectionTabs.tabs('option', 'selected') + 1,
			length = $sectionTabs.tabs('length');
		if (next >= length) {
			return validate(document.getElementById("profileForm"));
		}
		$sectionTabs.tabs('select', next);*/
	});
	$("#btnSubmit").click(function(event){
		return validate(document.getElementById("profileForm"), true);
	});
});

})(document);
//--><!]]>
