// JavaScript Document


///Auto Formats Phone Number

function validate_form()
{
	if (document.registration.terms.checked == true)
	{
	var prefix = "Your ";
	var canSubmit = true;
	var toAlert = "The Following Fields are missing:\n";
		if (document.getElementsByName('firstName')[0].value == '')
		{
			toAlert += "Your First Name\n";
			canSubmit = false;
		}
		
		if (document.getElementsByName('lastName')[0].value == '')
		{
			toAlert += "Your Last Name\n";
			canSubmit = false;
		}
	
		if (document.registration.address.value == '')
		{
			toAlert += "Your Address\n";
			canSubmit = false;
			
		}
		
		if (document.registration.city.value == '')
		{
			toAlert += "Your City\n";
			canSubmit = false;
		}
		if (document.registration.country.value == '')
		{
			toAlert += "Your Country\n";
			canSubmit = false;
		}
		if (document.registration.postalZip.value == '')
		{
			toAlert += "Your Postal Code or Zip Code\n";
			canSubmit = false;	
		}
		if (document.registration.directTel.value == '')
		{
			toAlert += "Your Telephone Number\n";
			canSubmit = false;
		}

				
		if (document.getElementsByName('personalEmail')[0].value == '')
		{
				toAlert += "Your Personal Email\n";
				canSubmit = false;
		} else {
			// Confirms Email is correctly entered
				var apos=document.getElementsByName('personalEmail')[0].value.indexOf("@");
				var dotpos=document.getElementsByName('personalEmail')[0].value.lastIndexOf(".");
				if (apos<1||dotpos-apos<2) {
					toAlert += "Your Email is present but not valid\n";
					canSubmit = false;
				}
		}
			
			///////
			
	
		
		if (document.registration.nominate.value == 'other')
		{
			if (document.getElementsByName('firstNameOther')[0].value == '')
			{
				toAlert += "Your Nominee's First Name\n";
				canSubmit = false;
			}
			
			if (document.getElementsByName('lastNameOther')[0].value == '')
			{
				toAlert += "Your Nominee's Last Name\n";
				canSubmit = false;
			}
			if (document.registration.address.value == '')
			{
				toAlert += "Your Nominee's Address\n";
				canSubmit = false;
				
			}
			
			if (document.registration.cityOther.value == '')
			{
				toAlert += "Your Nominee's City\n";
				canSubmit = false;
			}
			if (document.registration.countryOther.value == '')
			{
				toAlert += "Your Nominee's Country\n";
				canSubmit = false;
			}
			if (document.registration.postalZipOther.value == '')
			{
				toAlert += "Your Nominee's Postal Code or Zip Code\n";
				canSubmit = false;	
			}
			if (document.registration.directTelOther.value == '')
			{
				toAlert += "Your Nominee's Telephone Number\n";
				canSubmit = false;
			}
	
				if (document.getElementsByName('personalEmailOther')[0].value == '')
				{
					toAlert += "Your Nominee's Personal Email\n";
					canSubmit = false;
				} else {
					// Confirms Email is correctly entered
					var apos=document.getElementsByName('personalEmailOther')[0].value.indexOf("@");
					var dotpos=document.getElementsByName('personalEmailOther')[0].value.lastIndexOf(".");
					if (apos<1||dotpos-apos<2) {
						toAlert += "Your Nominee's Email is present but not valid\n";
						canSubmit = false;
					}
				}
				
				///////
				
				if (document.getElementsByName('directTelOther')[0].value == '')
				{
					toAlert += "Your Nominee's Direct Telephone Number\n";
					canSubmit = false;
				}
				
				prefix = "Your Nominee's ";
				
				
		}
		if (document.registration.sex.value == '')
		{
			toAlert += prefix + "Gender\n";
			canSubmit = false;
		}		
		if ((document.registration.day.value == '---') || (document.registration.month.value == '---') || (document.registration.year.value == '---'))
		{
			toAlert += prefix + "Date of Birth\n";
			canSubmit = false;
		}
		if (document.registration.currentlyIn.value != 'High School / Secondary')
		{
			if (document.registration.education.value == '')
			{
				toAlert += prefix + "Major in University or College\n";
			}
		}
		
		if (document.registration.institution.value == '')
		{
			toAlert += prefix + "Educational Institution\n";
			canSubmit = false;
		}	
		if (document.registration.essay.value == '')
		{
			toAlert += prefix + "Essay\n";
			canSubmit = false;
		}
	
		if (canSubmit == false)
		{
			alert (toAlert);
		} else {

		}
		return canSubmit;
	} else {
		alert('Please read over the Terms and Conditions on the right before submiting');
		return false;
	}
		
		
}

function showOtherNominee() {
	var otherNom = document.getElementById('nominateOther');
	if (document.registration.nominate.value == 'other')
	{
		otherNom.style.display = 'block';
		
	} else {
		otherNom.style.display = 'none';
	}
}