function ValidateForm()
{
	
	if (MM_findObj("firstName").value == "") {
		alert("Please enter your first name.");
		MM_findObj("firstName").focus();
		return false;
	}
	if (MM_findObj("lastName").value == "") {
		alert("Please enter your last name.");
		MM_findObj("lastName").focus();
		return false;
	}
	if (MM_findObj("address").value == "") {
		alert("Please enter your address.");
		MM_findObj("address").focus();
		return false;
	}
	if (MM_findObj("city").value == "") {
		alert("Please enter your city.");
		MM_findObj("city").focus();
		return false;
	}
	if (MM_findObj("provinceState").selectedIndex == 0) {
		alert("Please enter your province.");
		MM_findObj("provinceState").focus();
		return false;
	}
	if (MM_findObj("provinceState").selectedIndex == 14 && MM_findObj("otherProvinceState").value == "") {
		alert("Please enter your province / state.");
		MM_findObj("otherProvinceState").focus();
		return false;
	}
	if (MM_findObj("country").selectedIndex == 0) {
		alert("Please enter your country.");
		MM_findObj("country").focus();
		return false;
	}
	if (MM_findObj("postalCode").value == "") {
		alert("Please enter your postal code.");
		MM_findObj("postalCode").focus();
		return false;
	}
	if (MM_findObj("telephone").value == "") {
		alert("Please enter your telephone.");
		MM_findObj("telephone").focus();
		return false;
	}

	if (MM_findObj("email").value == "") {
		alert("Please enter your email.");
		MM_findObj("email").focus();
		return false;
	}

	if (MM_findObj("gender")[0].checked == false && MM_findObj("gender")[1].checked == false) {
		alert("Please enter your gender.");
		MM_findObj("gender")[0].focus();
		return false;
	}

	if (MM_findObj("appliedToOCT")[0].checked == false && MM_findObj("appliedToOCT")[1].checked == false) {
		alert("Please enter if you have applied to the Ontario College of Teachers for certification.");
		MM_findObj("appliedToOCT")[0].focus();
		return false;
	}
	if (MM_findObj("appliedToOCT")[0].checked == true && MM_findObj("specifyRegistrationNumber").value == "") {
		alert("Please specify your College of Teachers registration number.");
		MM_findObj("specifyRegistrationNumber").focus();
		return false;
	}

	if (MM_findObj("certifiedInOntario")[0].checked == false && MM_findObj("certifiedInOntario")[1].checked == false) {
		alert("Please enter if you are certified to teach in Ontario.");
		MM_findObj("certifiedInOntario")[0].focus();
		return false;
	}
	if (MM_findObj("certifiedInOntario")[1].checked == true && MM_findObj("reasonNotCertified").selectedIndex == 0) {
		alert("Please indicate the reason why.");
		MM_findObj("reasonNotCertified").focus();
		return false;
	}
	if (MM_findObj("certifiedInOntario")[1].checked == true && MM_findObj("reasonNotCertified").selectedIndex == 5 && MM_findObj("otherReasonNotCertified").value == "") {
		alert("Please specify the other reason why.");
		MM_findObj("otherReasonNotCertified").focus();
		return false;
	}

	if (MM_findObj("countryOfProfessionalTeacherEducation").value == "") {
		alert("Please enter in what country you completed your professional teacher education program.");
		MM_findObj("countryOfProfessionalTeacherEducation").focus();
		return false;
	}
	if (MM_findObj("languageOfProfessionalTeacherEducation").value == "") {
		alert("Please enter in what language you completed your professional teacher education program.");
		MM_findObj("languageOfProfessionalTeacherEducation").focus();
		return false;
	}
	if (MM_findObj("countryOfPostSecondaryAcademicQualifications").value == "") {
		alert("Please enter in what country you completed your post-secondary academic qualifications.");
		MM_findObj("countryOfPostSecondaryAcademicQualifications").focus();
		return false;
	}

	if (MM_findObj("jkQualified").checked == false &&
		MM_findObj("kQualified").checked == false &&
		MM_findObj("1Qualified").checked == false &&
		MM_findObj("2Qualified").checked == false &&
		MM_findObj("3Qualified").checked == false &&
		MM_findObj("4Qualified").checked == false &&
		MM_findObj("5Qualified").checked == false &&
		MM_findObj("6Qualified").checked == false &&
		MM_findObj("7Qualified").checked == false &&
		MM_findObj("8Qualified").checked == false &&
		MM_findObj("9Qualified").checked == false &&
		MM_findObj("10Qualified").checked == false &&
		MM_findObj("11Qualified").checked == false &&
		MM_findObj("12Qualified").checked == false ) {
		alert("Please specify what grades your teacher education program prepared you to teach.");
		MM_findObj("jkQualified").focus();
		return false;
	}
 
	/*optional

	if ((MM_findObj("7Qualified").checked == true ||
		MM_findObj("8Qualified").checked == true ||
		MM_findObj("9Qualified").checked == true ||
		MM_findObj("10Qualified").checked == true) &&
		MM_findObj("preparedToTeachIntermediate")[0].checked == false && MM_findObj("preparedToTeachIntermediate")[1].checked == false) {
		alert("Please specify whether you were prepared to teach at least one curriculum subject at the Intermediate level.");
		MM_findObj("preparedToTeachIntermediate")[0].focus();
		return false;
	}

	if (MM_findObj("preparedToTeachIntermediate")[0].checked == true && MM_findObj("whichIntermediateSubjects").value == "") {
		alert("Please specify the Intermediate subjects.");
		MM_findObj("whichIntermediateSubjects").focus();
		return false;
	}


	if ((MM_findObj("11Qualified").checked == true ||
		MM_findObj("12Qualified").checked == true) &&
		MM_findObj("preparedToTeachSenior")[0].checked == false && MM_findObj("preparedToTeachSenior")[1].checked == false) {
		alert("Please specify whether you were prepared to teach at least two curriculum subjects at the Senior level.");
		MM_findObj("preparedToTeachSenior")[0].focus();
		return false;
	}
	if (MM_findObj("preparedToTeachSenior")[0].checked == true && MM_findObj("whichSeniorSubjects").value == "") {
		alert("Please specify the Senior subjects.");
		MM_findObj("whichSeniorSubjects").focus();
		return false;
	}
	*/

	if (MM_findObj("certifiedToTeach")[0].checked == false && MM_findObj("certifiedToTeach")[1].checked == false) {
		alert("Please indicate if you have been certified to teach in another jurisdiction in any of these areas.");
		MM_findObj("certifiedToTeach")[0].focus();
		return false;
	}
	if (MM_findObj("certifiedToTeach")[0].checked == true && 
		MM_findObj("certifiedToTeachFrenchElementary").checked == false &&
		MM_findObj("certifiedToTeachFrenchSecondary").checked == false &&
		MM_findObj("certifiedToTeachMathSecondary").checked == false &&
		MM_findObj("certifiedToTeachChemistrySecondary").checked == false &&
		MM_findObj("certifiedToTeachPhysicsSecondary").checked == false &&
		MM_findObj("certifiedToTeachTechStudiesSecondary").checked == false &&
		MM_findObj("certifiedToTeachComputersSecondary").checked == false) {
		alert("Please indicate what area.");
		MM_findObj("certifiedToTeachFrenchElementary").focus();
		return false;
	}

	if (MM_findObj("supportOption1")[0].checked == false && MM_findObj("supportOption1")[1].checked == false) {
		alert("Please indicate if each one of the four services interests you.");
		MM_findObj("supportOption1")[0].focus();
		return false;
	}
	if (MM_findObj("supportOption2")[0].checked == false && MM_findObj("supportOption2")[1].checked == false) {
		alert("Please indicate if each one of the four services interests you.");
		MM_findObj("supportOption2")[0].focus();
		return false;
	}
	if (MM_findObj("supportOption3")[0].checked == false && MM_findObj("supportOption3")[1].checked == false) {
		alert("Please indicate if each one of the four services interests you.");
		MM_findObj("supportOption3")[0].focus();
		return false;
	}
	if (MM_findObj("supportOption4")[0].checked == false && MM_findObj("supportOption4")[1].checked == false) {
		alert("Please indicate if each one of the four services interests you.");
		MM_findObj("supportOption4")[0].focus();
		return false;
	}
	if (MM_findObj("supportOption1")[1].checked == true && 
		MM_findObj("supportOption2")[1].checked == true && 
		MM_findObj("supportOption3")[1].checked == true && 
		MM_findObj("supportOption4")[1].checked == true) {
		alert("You must select at least one of the four services.");
		MM_findObj("supportOption1")[0].focus();
		return false;
	}

	if (MM_findObj("consentCheck").checked == false) {
		alert("You have to consent to the collection, use and disclosure of personal information for the Teach in Ontario project.");
		MM_findObj("consentCheck").focus();
		return false;
	}

	return true;
}	


function validateAndSubmit() {

	errorMessage = '';

	// Check form validation here. Simply add to the variable ERRORMESSAGE a listing of all 
	// fields that are incomplete. E.g.
	//
	// 	if (document.applicatioForm.lastName.value == '') errorMessage = errorMessage + "You haven't specified LAST NAME.";
	//
	// All questions on this form are mandatory except email address. That means that anywhere 
	// there's a group of radio buttons, one must be selected, and anywhere there's a group of
	// checkboxes, AT LEAST one must be selected. It's important that none of these are selected
	// by default when the page loads, since users might simply ignore it and then there'd be
	// bad data in the system.
	//
	// Also note that the "I Consent" checkbox at the bottom of the page MUST be checked for
	// the form to be submitted. If the checkbox isn't checked, add to the error message something
	// like "You haven't clicked the CONSENT checkbox."

	if (errorMessage != '') {
		alert(errorMessage);
		return false;
	}
	else {

		// Add code here which submits the form and emails the contents to one of
		// three email addresses based on the following logic:
		//
		// - If the postal code begins with a K, submit to ws@ottawa-worldskills.org
		// - Otherwise, submit at random to one of these two email addresses:
		//   info@teachinontario.ca or sfc@skillsforchange.org 
		//
		// I've written the randomization function below to simply pop up a dialog
		// box showing where the email would go. Feel free to adapt it. The important
		// thing is that the two addresses being randomized each get about 50% of the
		// email from this form.

		if (document.applicationForm.postalCode.value.substring(0,1) == "K" || document.applicationForm.postalCode.value.substring(0,1) == "k") {
			alert("This form would be sent to ws@ottawa-worldskills.org");
			return true;
		}
		else {

			var randomNumber = parseInt(Math.random() * 10);
			if (randomNumber < 5) {
				alert("This form would be sent to info@teachinontario.ca");
				return true;
			}
			else {
				alert("This form would be sent to sfc@skillsforchange.org");
				return true;
			}

		}

	}

	return false;

}
