function validateRegistration(theForm) {
	var isInputInvalid = false;
	var errorMessage = "Please revise the following errors:\n";		//this will only be printed if isInputInvalid == true

	//get all the values from the form
	var username = theForm.username.value;
	var password = theForm.password.value;
	var passwordConfirm = theForm.passwordConfirm.value;
	var isGenderProvided = theForm.gender[0].checked || theForm.gender[1].checked;
	//var birthMonth = theForm.birthMonth.selectedIndex;			//COMMENTED OUT AFTER IRB REQUESTED CHANGES
	//var birthDay = theForm.birthDay.selectedIndex;				//COMMENTED OUT AFTER IRB REQUESTED CHANGES
	var birthYear = theForm.birthYear.value;
	var yearsOfEducation = theForm.yearsOfEducation.selectedIndex;
	var nativeLanguage = theForm.nativeLanguage.selectedIndex;
	var countryOfResidence = theForm.countryOfResidence.selectedIndex;
	var policyAgreed = theForm.policyAgree.checked;
	var IRBAgreed = theForm.IRBAgree.checked;

	//FIRST, CHECK IF THE USER IS AT LEAST 18 YEARS OLD (APPROX BASED ON BIRTH YEAR)
	var todaysDate = new Date();
	var todaysYear = todaysDate.getFullYear();
	if(todaysYear - birthYear >= 18) {

		//ensure a valid username has been entered
		if(username == "") {
			isInputInvalid = true;
			errorMessage += "-You must enter a username.\n";
		}
		else if(username.length < 5) {
			isInputInvalid = true;
			errorMessage += "-Your username must contain at least 5 characters.\n";
		}
		
		//ensure password was correctly confirmed
		if(password != passwordConfirm) {
			isInputInvalid = true;
			errorMessage += "-You did not confirm your password correctly.\n";
		}

		//ensure a valid password has been entered
		if(password == "") {
			isInputInvalid = true;
			errorMessage += "-You must enter a password for your account.\n";
		}
		else if(password.length < 5) {
			isInputInvalid = true;
			errorMessage += "-Your password must contain at least 5 characters.\n";
		}

		//ensure gender is provided
		if(!isGenderProvided) {
			isInputInvalid = true;
			errorMessage += "-You must indicate your gender.\n";
		}
		
		//ensure a valid birthdate is provided
		//if(birthMonth == 0 || birthDay == 0 || birthYear == 0) {				//COMMENTED OUT AFTER IRB REQUESTED CHANGES
		if(birthYear == 0) {
			isInputInvalid = true;
			//errorMessage += "-You must indicate your birth date.\n";			//COMMENTED OUT AFTER IRB REQUESTED CHANGES
			errorMessage += "-You must indicate your birth year.\n";
		}
		
		//ensure the years of education field is provided
		if(yearsOfEducation == 0) {
			isInputInvalid = true;
			errorMessage += "-You must indicate the years of education you received.\n";
		}

		//ensure the native language field is provided
		if(nativeLanguage == 0) {
			isInputInvalid = true;
			errorMessage += "-You must indicate your native language.\n";
		}

		//ensure the country of residence field is provided
		if(countryOfResidence == 0) {
			isInputInvalid = true;
			errorMessage += "-You must indicate your country of residence.\n";
		}

		//ensure the privacy policy was read and agreed
		if(!policyAgreed) {
			isInputInvalid = true;
			errorMessage += "-You must agree to the privacy policy in order to proceed. If you do, please check the corresponding checkbox. If you do not, you may close the browser window to exit.\n";
		}

		//ensure the IRB form was read and agreed
		if(!IRBAgreed) {
			isInputInvalid = true;
			errorMessage += "-You must agree to the Informed Consent Form in order to proceed. If you do, please check the corresponding checkbox. If you do not, you may close the browser window to exit.\n";
		}

		if(isInputInvalid) {
			alert(errorMessage);
			return false;
		}
		else{
			return true;
		}
	}
	else {
		alert("We are currently only collecting samples of users at least 18 years old.");
		return false;
	}
}

function displayPreferredLanguage(language) {
	if(language != "en_US" && language != "es_ES" && language != "ko_KR" && language != "ja_JP" && language != "ru_RU") {
		document.getElementById("preferredLanguage").style.display = "block";
	}
	else {
		document.getElementById("preferredLanguage").style.display = "none";
	}
}
