/*
22.02.2010
Kevin McGill
JS include file for PCA site.
Mainly used for jQuery
*/

$(document).ready(function(){
	
	$("ul#navigation li.parental a.parental").click(function() {
  		// toggle the appearance of sub-menu items, also update the class of the parent item
		$(this).parent().children("ol").slideToggle("slow",
			function() {
		    	// Animation complete.
				if ($(this).is(':visible') == true) {
					$(this).parent().addClass("current");
				} else {
					$(this).parent().removeClass("current");
				};
			}
		);
		return false;
	});
	
	$("ul#navigation li.parental ol").each(function() {
  		// by default if we are loading a sub0menu page we want to apply the current style to the parent item
		if ($(this).is(':visible') == true) {
			$(this).parent().addClass("current");
		} else {
			$(this).parent().removeClass("current");
		};
	});


	if ($("div#animation").is(':visible') == true) {
		$("div#animation").flash(
	        { src: "flash_dev/aw16.swf",
	          width: 513,
	          height: 455 }
	    );
	};
		
	$("#ubspage-4 form#application").submit(function() {
  		// check the application form
		var errorStr = '';
		
		if(!$("input#f2_privacy").is(':checked')) { errorStr = errorStr + '\n- Privacy declaration'; };
		if($("input#f2_familyName").val() == "") { errorStr = errorStr + '\n- Family name'; };
		if($("input#f2_firstName").val() == "") { errorStr = errorStr + '\n- First name'; };
		//if((!$("input#f2_titleMR").is(':checked')) && (!$("input#f2_titleMS").is(':checked'))) { errorStr = errorStr + '\n- Title'; };
		if($("input#f2_dob").val() == "") { errorStr = errorStr + '\n- Date of birth'; };
		if($("input#f2_studentNumber").val() == "") { errorStr = errorStr + '\n- Year 12 student number'; };
		if($("input#f2_address").val() == "") { errorStr = errorStr + '\n- Address'; };
		if($("input#f2_suburb").val() == "") { errorStr = errorStr + '\n- Suburb/town'; };
		if($("input#f2_postcode").val() == "") { errorStr = errorStr + '\n- Postcode'; };
		if($("input#f2_email").val() == "") { errorStr = errorStr + '\n- Email'; };
		if($("input#f2_telephone").val() == "") { errorStr = errorStr + '\n- Telephone'; };
		if($("input#f2_parentAddress").val() == "") { errorStr = errorStr + '\n- Parents residential address'; };
		if($("input#f2_parentSuburb").val() == "") { errorStr = errorStr + '\n- Parents suburb/town'; };
		if($("input#f2_parentPostcode").val() == "") { errorStr = errorStr + '\n- Parents postcode'; };
		if((!$("input#f2_residentCitizen").is(':checked')) && (!$("input#f2_residentPerm").is(':checked'))) { errorStr = errorStr + '\n- Residential status'; };
		if($("input#f2_schoolName").val() == "") { errorStr = errorStr + '\n- School name'; };
		if($("input#f2_schoolAddress").val() == "") { errorStr = errorStr + '\n- School address'; };
		if($("input#f2_schoolSuburb").val() == "") { errorStr = errorStr + '\n- School suburb/town'; };
		if($("input#f2_schoolPostcode").val() == "") { errorStr = errorStr + '\n- School postcode'; };
		if(($("input#f2_y11_subject_1").val() == "") || ($("input#f2_y11_units_1").val() == "") || ($("input#f2_y11_result_1").val() == "") || ($("input#f2_y11_position_1").val() == "") || ($("input#f2_y11_number_1").val() == "")) { errorStr = errorStr + '\n- Year 11 - end of year results'; };
		if(($("input#f2_pref1_uni").val() == "") || ($("input#f2_pref1_degree").val() == "") || ($("input#f2_pref1_reason").val() == "")) { errorStr = errorStr + '\n- University course that you intend applying for'; };
		if($("textarea#f2_whyBC").val() == "") { errorStr = errorStr + '\n- Why are you applying for a UBS Cadetship'; };
		if($("textarea#f2_pref").val() == "") { errorStr = errorStr + '\n- Why would you like to work at UBS'; };
		if($("textarea#f2_skills").val() == "") { errorStr = errorStr + '\n- What qualities and skills can you offer UBS'; };
		if($("textarea#f2_experience").val() == "") { errorStr = errorStr + '\n- What work experience have you undertaken and what have you learned from it'; };
		if($("textarea#f2_teamwork").val() == "") { errorStr = errorStr + '\n- How are you involved in team work at your school and/or in the community'; };
		if($("textarea#f2_achievement").val() == "") { errorStr = errorStr + '\n- What do you believe sets you apart from other cadetship applicants'; };
		if((!$("input#f2_furthernetYes").is(':checked')) && (!$("input#f2_furthernetNo").is(':checked'))) { errorStr = errorStr + '\n- furthernet Talent Bank'; };
		if($("input#f2_photo").val() == "") { errorStr = errorStr + '\n- Attach a scanned recent photo of yourself'; };
		if(!$("input#f2_declaration").is(':checked')) { errorStr = errorStr + '\n- Declaration'; };
		
		if(errorStr != '') {
			alert('Sorry, you have not completed the form.\nPlease check the following:' + errorStr); 
			return false;
		};
		if(errorStr == '') {
			errorStr = 'Your form will now be submitted. If there are problems you will be asked to edit some fields and re-submit the form.'
			errorStr = errorStr + '\nIf your form has no errors your application form will be submitted to Professional Cadetships Australia for further review.';
			errorStr = errorStr + '\nAn email will also be sent to to your nominated email address (' + $("input#f2_email").val() + ') from info@businesscadetships.com.au outlining the next steps involved in the process.'
			errorStr = errorStr + '\nYou may need to to adjust your spam/junk mail settings to allow emails from info@businesscadetships.com.au.';
			errorStr = errorStr + '\n\nPlease confirm that your email address is ' + $("input#f2_email").val();
			var answer = confirm(errorStr);
			if (answer) { return true; } else { return false; };
		};
	});
	
});
