function sanityCheck(current_stage, application_type) 
{
	var returnVal = true;
	
	// Do special value validation before allowing sumbit here
	switch(current_stage) 
	{
		case 0: // Start
			// Do nothing
			break;
		case 1: // Personal Info
			returnVal = personalInfoSanityCheck();
			break;
		case 2: // Academics
			returnVal = academicInfoSanityCheck();
			break;
		case 3: // Work Experience
			/*if (document.forms[0].f_OtherInterests.value == "") 
			{
				alert("You have not listed your extra-curricular interests");
				returnVal = false;
			}*/
			break;
		case 4: // Questionnaire
			if(application_type == "teaching") {
				returnVal = questionnaireSanityCheckEnglishPositions();
			} else if(application_type == "technical") {
				returnVal = questionnaireSanityCheck();
			} else {
				alert("Unknown Application Type.");
				returnVal = false;
			}
			break;
		case 5: // Review
			break;
		case 6: // Finish
			break;
		default:
			// do nothing
	}

	return returnVal;
}//end of sanityCheck()

function personalInfoSanityCheck()
{
	var returnVal = true;
	var acadAreaCounter = 0;
	var c;
	
	for (c=0; c<document.forms[0].f_AcademicStudy.length; c++) 
	{
		if (document.forms[0].f_AcademicStudy[c].checked == false) 
		{ acadAreaCounter++; } 
	}

	if (acadAreaCounter == document.forms[0].f_AcademicStudy.length) 
	{
		alert("You have not selected an Area of Academic Study");
		document.forms[0].f_AcademicStudy[0].select();
		document.forms[0].f_AcademicStudy[0].focus();
		returnVal = false;
		return returnVal;
	}
	else
	{
		if(document.forms[0].f_AcademicStudy[0].checked == true)
		{
			if(document.forms[0].f_AcademicStudy_Discipline.selectedIndex == 0)
			{
				alert("You have not selected a Discipline.");
				document.forms[0].f_AcademicStudy_Discipline.focus();
				returnVal = false;
				return returnVal;
			}
		}
		else if(document.forms[0].f_AcademicStudy[1].checked == true || document.forms[0].f_AcademicStudy[2].checked == true || document.forms[0].f_AcademicStudy[3].checked == true)
		{
			if(document.forms[0].f_AcademicStudy_Major.value == "")
			{
				alert("You have not provided a Major. Write 'na' if you do not have a major.");
				document.forms[0].f_AcademicStudy_Major.select();
				document.forms[0].f_AcademicStudy_Major.focus();
				returnVal = false;
				return returnVal;
			}
			else if(document.forms[0].f_AcademicStudy_Minor.value == "")
			{
				alert("You have not provided a Minor. Write 'na' if you do not have a minor.");
				document.forms[0].f_AcademicStudy_Minor.select();
				document.forms[0].f_AcademicStudy_Minor.focus();
				returnVal = false;
				return returnVal;
			}
		}
		else if(document.forms[0].f_AcademicStudy[4].checked == true)
		{
			if(document.forms[0].f_AcademicStudy_Other.value == "")
			{
				alert("Please specify your other area of study.");
				document.forms[0].f_AcademicStudy_Other.select();
				document.forms[0].f_AcademicStudy_Other.focus();
				returnVal = false;
				return returnVal;
			}
		}
	}

	if(document.forms[0].f_Gender.selectedIndex == 0)
	{
		alert("Please specify your gender.");
		document.forms[0].f_Gender.focus();
		returnVal = false;
		return returnVal;
	}

	if(document.forms[0].f_MaritalStatus.selectedIndex == 0)
	{
		alert("Please indicate your Marital Status.");
		document.forms[0].f_MaritalStatus.focus();
		returnVal = false;
		return returnVal;
	}


	if (document.forms[0].f_FirstName.value == "") 
	{
		alert("You have not given your First name");
		document.forms[0].f_FirstName.select();
		document.forms[0].f_FirstName.focus();
		returnVal = false;
		return returnVal;
	}

	if (document.forms[0].f_LastName.value == "") 
	{
		alert("You have not given your Last name");
		document.forms[0].f_LastName.select();
		document.forms[0].f_LastName.focus();
		returnVal = false;
		return returnVal;
	}

	if (document.forms[0].f_Email.value == "") 
	{
		alert("Please enter an e-mail address.");
		document.forms[0].f_Email.select();
		document.forms[0].f_Email.focus();
		returnVal = false;
		return returnVal;
	}

	if(document.forms[0].f_CitizenshipStatus.selectedIndex == 0)
	{
		alert("Please specify your Citizenship Status.");
		document.forms[0].f_CitizenshipStatus.focus();
		returnVal = false;
		return returnVal;
	}

	if (document.forms[0].f_CurrentAddress_1.value == "") 
	{
		alert("You have not given your Current Address (first line)");
		document.forms[0].f_CurrentAddress_1.select();
		document.forms[0].f_CurrentAddress_1.focus();
		returnVal = false;
		return returnVal;
	}

	if (document.forms[0].f_CurrentCity.value == "") 
	{
		alert("You have not given your Current City");
		document.forms[0].f_CurrentCity.select();
		document.forms[0].f_CurrentCity.focus();
		returnVal = false;
		return returnVal;
	}

	if (document.forms[0].f_CurrentCountry.value == "") 
	{
		alert("You have not given your Current Country");
		document.forms[0].f_CurrentCountry.select();
		document.forms[0].f_CurrentCountry.focus();
		returnVal = false;
		return returnVal;
	}

	if(document.forms[0].f_CurrentProvince.value == "")
	{
		alert("You have not given your Current Province");
		document.forms[0].f_CurrentProvince.select();
		document.forms[0].f_CurrentProvince.focus();
		returnVal = false;
		return returnVal;
	}

	if (document.forms[0].f_CurrentPostalCode.value == "") 
	{
		alert("You have not given your Current Postal Code");
		document.forms[0].f_CurrentPostalCode.select();
		document.forms[0].f_CurrentPostalCode.focus();
		returnVal = false;
		return returnVal;
	}

	if (document.forms[0].f_CurrentPhoneNumber_A.value == "" ||
		document.forms[0].f_CurrentPhoneNumber_B.value == "" ||
		document.forms[0].f_CurrentPhoneNumber_C.value == "" ||
		document.forms[0].f_CurrentPhoneNumber_A.value.length < 3 ||
		document.forms[0].f_CurrentPhoneNumber_B.value.length < 3 ||
		document.forms[0].f_CurrentPhoneNumber_C.value.length < 4)
	{
		alert("You have not given your Current Phone Number");
		document.forms[0].f_CurrentPhoneNumber_A.select();
		document.forms[0].f_CurrentPhoneNumber_A.focus();
		returnVal = false;
		return returnVal;
	}

	if (document.forms[0].f_CurrentCellPhoneNumber_A.value != "" ||
		document.forms[0].f_CurrentCellPhoneNumber_B.value != "" ||
		document.forms[0].f_CurrentCellPhoneNumber_C.value != "")
	{
		if(document.forms[0].f_CurrentCellPhoneNumber_A.value.length < 3 ||
		   document.forms[0].f_CurrentCellPhoneNumber_B.value.length < 3 ||
		   document.forms[0].f_CurrentCellPhoneNumber_C.value.length < 4)
		{
			alert("You have not given your Current Cell Phone Number");
			document.forms[0].f_CurrentCellPhoneNumber_A.select();
			document.forms[0].f_CurrentCellPhoneNumber_A.focus();
			returnVal = false;
			return returnVal;
		}
	}

	if(document.forms[0].f_isPermAddr[1].checked)
	{
		if (document.forms[0].f_PermanentAddress_1.value == "") 
		{
			alert("You have not given your Permanent Address (first line)");
			document.forms[0].f_PermanentAddress_1.select();
			document.forms[0].f_PermanentAddress_1.focus();
			returnVal = false;
			return returnVal;
		}

		if (document.forms[0].f_PermanentCity.value == "") 
		{
			alert("You have not given your Permanent City");
			document.forms[0].f_PermanentCity.select();
			document.forms[0].f_PermanentCity.focus();
			returnVal = false;
			return returnVal;
		}

		if (document.forms[0].f_PermanentCountry.value == "") 
		{
			alert("You have not given your Permanent Country");
			document.forms[0].f_PermanentCountry[0].select();
			document.forms[0].f_PermanentCountry[0].focus();
			returnVal = false;
			return returnVal;
		}

		if(document.forms[0].f_PermanentProvince.value == "")
		{
			alert("You have not given your Permanent Province");
			document.forms[0].f_PermanentProvince[0].select();
			document.forms[0].f_PermanentProvince[0].focus();
			returnVal = false;
			return returnVal;
		}

		if (document.forms[0].f_PermanentPostalCode.value == "") 
		{
			alert("You have not given your Permanent Postal Code");
			document.forms[0].f_PermanentPostalCode.select();
			document.forms[0].f_PermanentPostalCode.focus();
			returnVal = false;
			return returnVal;
		}
	
		if (document.forms[0].f_PermanentPhoneNumber_A.value == "" ||
			document.forms[0].f_PermanentPhoneNumber_B.value == "" ||
			document.forms[0].f_PermanentPhoneNumber_C.value == "" ||
			document.forms[0].f_PermanentPhoneNumber_A.value.length < 3 ||
			document.forms[0].f_PermanentPhoneNumber_B.value.length < 3 ||
			document.forms[0].f_PermanentPhoneNumber_C.value.length < 4)
		{
			alert("You have not given your Permanent Phone Number");
			document.forms[0].f_PermanentPhoneNumber_A.select();
			document.forms[0].f_PermanentPhoneNumber_A.focus();
			returnVal = false;
			return returnVal;
		}
	}

	return returnVal;
}//end of personalInfoSanityCheck()

function academicInfoSanityCheck()
{
	var returnVal = true;

	if (document.forms[0].f_AcademicHistorySchool_A.selectedIndex == 0)
	{
		alert("You have not specified University/College");
		document.forms[0].f_AcademicHistorySchool_A.focus();		
		returnVal = false;
		return returnVal;
	}

	if(document.forms[0].f_AcademicHistoryStudentID_A.value == "")
	{
		alert("You have not specified your Student ID");
		document.forms[0].f_AcademicHistoryStudentID_A.select();
		document.forms[0].f_AcademicHistoryStudentID_A.focus();
		returnVal = false;
		return returnVal;
	}

	if(document.forms[0].f_AcademicHistoryCity_A.value == "")
	{
		alert("You have not specified your University/College City");
		document.forms[0].f_AcademicHistoryCity_A.select();
		document.forms[0].f_AcademicHistoryCity_A.focus();
		returnVal = false;
		return returnVal;
	}

	if(document.forms[0].f_AcademicHistoryProvince_A.value == "")
	{
		alert("You have not specified your University/College Province");
		document.forms[0].f_AcademicHistoryProvince_A.select();
		document.forms[0].f_AcademicHistoryProvince_A.focus();
		returnVal = false;
		return returnVal;
	}

	if(document.forms[0].f_AcademicHistoryCurrentYear_A.value == "")
	{
		alert("You have not specified your Current Academic Year or Credit Hours you have completed");
		document.forms[0].f_AcademicHistoryCurrentYear_A.select();
		document.forms[0].f_AcademicHistoryCurrentYear_A.focus();
		returnVal = false;
		return returnVal;
	}

	if(document.forms[0].f_AcademicHistoryGPA_A.value == "")
	{
		alert("You have not specified your Grade");
		document.forms[0].f_AcademicHistoryGPA_A.select();
		document.forms[0].f_AcademicHistoryGPA_A.focus();
		returnVal = false;
		return returnVal;
	}

	if(document.forms[0].f_AcademicHistoryGPAScale_A.selectedIndex == 0)
	{
		alert("Please specify your Grade Scale.");
		document.forms[0].f_AcademicHistoryGPAScale_A.focus();
		returnVal = false;
		return returnVal;
	}

//	if(document.forms[0].f_AcademicHistoryWorkTermsCompleted_A.selectedIndex == 0)
//	{
//		alert("Please specify your Number of Co-op Terms Completed.");
//		document.forms[0].f_AcademicHistoryWorkTermsCompleted_A.focus();
//		returnVal = false;
//		return returnVal;
//	}

	if(document.forms[0].f_haveAcademicTermsRemaining[0].checked != true &&
	   document.forms[0].f_haveAcademicTermsRemaining[1].checked != true)
	{
		alert("Please specify whether you have at least one full academic term remaining after participation in the Co-opJapan Program");
		document.forms[0].f_haveAcademicTermsRemaining[0].select();
		document.forms[0].f_haveAcademicTermsRemaining[0].focus();
		returnVal = false;
		return returnVal;
	}

	if(document.forms[0].f_LanguageAbility.selectedIndex == 0)
	{
		alert("Please specify your level of Japanese Language Ability.");
		document.forms[0].f_LanguageAbility.focus();
		returnVal = false;
		return returnVal;
	}

	if(document.forms[0].f_takenLangCourse[0].checked != true &&
	   document.forms[0].f_takenLangCourse[1].checked != true)
	{
		alert("Please specify whether you have taken any Japanese language courses.");
		document.forms[0].f_takenLangCourse[0].select();
		document.forms[0].f_takenLangCourse[0].focus();
		returnVal = false;
		return returnVal;
	}
	else if(document.forms[0].f_takenLangCourse[1].checked == true)
	{
		if(document.forms[0].f_willEnrollLangCourse[0].checked != true &&
		   document.forms[0].f_willEnrollLangCourse[1].checked != true)
		{
			alert("Since you have never taken a Japanese language course, please specify whether you would agree "
					+ "to enroll and complete such a course before the deadline.");
			document.forms[0].f_willEnrollLangCourse[0].select();
			document.forms[0].f_willEnrollLangCourse[0].focus();
			returnVal = false;
			return returnVal;
		}
	}

	if(document.forms[0].f_haveTraveledInternationally[0].checked != true &&
	   document.forms[0].f_haveTraveledInternationally[1].checked != true)
	{
		alert("Please specify whether you have traveled to Japan or other countries before.");
		document.forms[0].f_haveTraveledInternationally[0].select();
		document.forms[0].f_haveTraveledInternationally[0].focus();
		returnVal = false;
		return returnVal;
	}
	else if(document.forms[0].f_haveTraveledInternationally[0].checked == true)
	{
		if(document.forms[0].f_haveTraveledInternationallyList.value == "")
		{
			alert("Since you have traveled to Japan or another country before, please specify where you have travelled");
			document.forms[0].f_haveTraveledInternationallyList.select();
			document.forms[0].f_haveTraveledInternationallyList.focus();
			returnVal = false;
			return returnVal;
		}
	}

	return returnVal; 
}//end of academicInfoSanityCheck()

function questionnaireSanityCheck()
{
	var returnVal = true;

	if(document.forms[0].f_understandAppFees[0].checked == false &&
	   document.forms[0].f_understandAppFees[1].checked == false)
	{
		alert("Please specify whether you agree with paying a non-refundable application fee and a language test fee");
		document.forms[0].f_understandAppFees[0].select();
		document.forms[0].f_understandAppFees[0].focus();
		returnVal = false;
		return returnVal;
	}

	if(document.forms[0].f_understandCosts[0].checked == false &&
	   document.forms[0].f_understandCosts[1].checked == false)
	{
		alert("Please specify whether you understand the financial costs associated with the Canada-Japan Co-op Program");
		document.forms[0].f_understandCosts[0].select();
		document.forms[0].f_understandCosts[0].focus();
		returnVal = false;
		return returnVal;
	}

	if(document.forms[0].f_understandMandatoryAttendance[0].checked == false &&
	   document.forms[0].f_understandMandatoryAttendance[1].checked == false)
	{
		alert("Please specify whether you understand that attendance is mandatory for the training week in Vancouver");
		document.forms[0].f_understandMandatoryAttendance[0].select();
		document.forms[0].f_understandMandatoryAttendance[0].focus();
		returnVal = false;
		return returnVal;
	}

	if(document.forms[0].f_understandRelationships[0].checked == false &&
	   document.forms[0].f_understandRelationships[1].checked == false)
	{
		alert("Please specify whether you understand the terms of a placement in Japan through the Canada-Japan Co-op Program");
		document.forms[0].f_understandRelationships[0].select();
		document.forms[0].f_understandRelationships[0].focus();
		returnVal = false;
		return returnVal;
	}

	return returnVal; 
}//end of questionnaireSanityCheck()

function questionnaireSanityCheckEnglishPositions()
{
	var returnVal = true;

	if(document.forms[0].f_understandAppFees[0].checked == false &&
	   document.forms[0].f_understandAppFees[1].checked == false)
	{
		alert("Please specify whether you agree with paying a non-refundable application fee");
		document.forms[0].f_understandAppFees[0].select();
		document.forms[0].f_understandAppFees[0].focus();
		returnVal = false;
		return returnVal;
	}

	if(document.forms[0].f_understandCosts[0].checked == false &&
	   document.forms[0].f_understandCosts[1].checked == false)
	{
		alert("Please specify whether you understand the financial costs associated with the Canada-Japan Co-op Program");
		document.forms[0].f_understandCosts[0].select();
		document.forms[0].f_understandCosts[0].focus();
		returnVal = false;
		return returnVal;
	}

	if(document.forms[0].f_understandMandatoryAttendance[0].checked == false &&
	   document.forms[0].f_understandMandatoryAttendance[1].checked == false)
	{
		alert("Please specify whether you understand that attendance is recommended for the training day in Vancouver");
		document.forms[0].f_understandMandatoryAttendance[0].select();
		document.forms[0].f_understandMandatoryAttendance[0].focus();
		returnVal = false;
		return returnVal;
	}
	
	return returnVal; 
}//end of questionnaireSanityCheck()