// JavaScript Document for the REU on-lin application form.



// This function will open a new window for form links so they do not lose their form information.

function openNewWindow($URL) {

	var $new = window.open($URL,'','scrollbars=yes,menubar=yes,height=600,width=800,resizable=yes,toolbar=no,location=no');

}



$collegeCount = 1;

$employerCount = 1;

$maxCollege = 4;

$maxEmployer = 4;



// This function will delete a college from the table of "College or University Education."

function removeCollege() {

	// As long as there are additional colleges to remove allow.

	if ($collegeCount > 1) {

		$docPosition = document.getElementById("college");

		$lastNode = $docPosition.lastChild;

		$docPosition.removeChild($lastNode);

		$collegeCount--;

		document.getElementById("numCollege").value = $collegeCount;

	}

	// If not, well then, spew out message.

	else {

		alert("There are no additional Colleges or Universities to delete.");

	}



	return 0;

}

	

// This function will delete an employer from the table of "Professional or Work Experience."

function removeEmployer() {

	// As long as there are additional colleges to remove allow.

	if ($employerCount > 1) {

		$docPosition = document.getElementById("employer");

		$lastNode = $docPosition.lastChild;

		$docPosition.removeChild($lastNode);

		$employerCount--;

		document.getElementById("numEmployer").value = $employerCount;

	}

	// If not, well then, spew out message.

	else {

		alert("There are no additional Employers to delete.");

	}



	return 0;

}



// This function will add a college to the table of "College or University Education."

function addCollege() {

	// As long as the current number is less than the max number.

	if ($collegeCount < $maxCollege) {

		// Set position in document and create TBODY.

		$docPosition = document.getElementById("college");

		$tableBody = document.createElement("tbody");

		

		// Create spacer cell and main TR.

		$headBlankRow = document.createElement("tr");

		$headBlankCell = document.createElement("td");

		$headBlankCell.className = "tableHeader";

		$headBlankCell.setAttribute("colSpan","3");

		$headBlankCell.setAttribute("id","headerJS");

		$textVal = "additional college or university (" +$collegeCount +")";

		$textNode = document.createTextNode($textVal);

		$headBlankCell.appendChild($textNode);

	

		// Append spacer to main TR.

		$headBlankRow.appendChild($headBlankCell); 

		

		// Create "institution" header, cell, and main TR.

		$instLocTR = document.createElement("tr");

		$institutionHead = document.createElement("td");

		$institutionHead.className = "tableFormRequest";

		$textVal = "Institution";

		$textNode = document.createTextNode($textVal);

		$institutionHead.appendChild($textNode);

		

		// Create "location" header and cell.

		$locationHead = document.createElement("td");

		$locationHead.setAttribute("colSpan","2");

		$locationHead.className = "tableFormRequest";

		$textVal = "Location";

		$textNode = document.createTextNode($textVal);

		$locationHead.appendChild($textNode);

	

		// Append headers to main TR.  

		$instLocTR.appendChild($institutionHead);

		$instLocTR.appendChild($locationHead);

  

		// Creat the "institution" input box, cell, and main TR.

		$instLocInputTR = document.createElement("tr");

		$instInputTD = document.createElement("td");

		$instInput = document.createElement("input");

		$instInput.className = "userInput";

		$instInput.setAttribute("size","40");

		$nameID = "collegeInst" +$collegeCount;

		$instInput.setAttribute("name",$nameID);

		$instInput.setAttribute("id",$nameID);

		$instInput.setAttribute("type","text");

		$instInputTD.appendChild($instInput);



		// Create the "location" input box and cell.

		$locInputTD = document.createElement("td");

		$locInputTD.setAttribute("colSpan","2");

		$locInput = document.createElement("input");

		$locInput.className = "userInput";

		$locInput.setAttribute("size","40");

		$nameID = "collegeLoc" +$collegeCount;

		$locInput.setAttribute("name",$nameID);

		$locInput.setAttribute("id",$nameID);

		$locInput.setAttribute("type","text");

		$locInputTD.appendChild($locInput);

	

		// Append input boxes to main TR.

		$instLocInputTR.appendChild($instInputTD);

		$instLocInputTR.appendChild($locInputTD);



		// Create the "field of study" header, cell and main TR.

		$stdDateCreditTR = document.createElement("tr");

		$studyHead = document.createElement("td");

		$studyHead.className = "tableFormRequest";

		$textVal = "Field of Study";

		$textNode = document.createTextNode($textVal);

		$studyHead.appendChild($textNode);



		// Create the "date from-to" header and cell.

		$dateHead = document.createElement("td");

		$dateHead.className = "tableFormRequest";

		$textVal = "Dates Attended (mm-yyyy)";

		$textNode = document.createTextNode($textVal);

		$dateHead.appendChild($textNode);  

	

		// Create the "credits earned" header and cell.

		$creditHead = document.createElement("td");

		$creditHead.className = "tableFormRequest";

		$textVal = "Credits Earned";

		$textNode = document.createTextNode($textVal);

		$creditHead.appendChild($textNode);

	

		// Append all the input headers to main TR.

		$stdDateCreditTR.appendChild($studyHead);

		$stdDateCreditTR.appendChild($dateHead);

		$stdDateCreditTR.appendChild($creditHead);

	

		// Create "field of study" input box and cell.

		$stdDateCreditInputTR = document.createElement("tr");

		$studyInputTD = document.createElement("td");

		$studyInput = document.createElement("input");

		$studyInput.className = "userInput";

		$studyInput.setAttribute("size","40");

		$nameID = "collegeStudy" +$collegeCount;

		$studyInput.setAttribute("name",$nameID);

		$studyInput.setAttribute("id",$nameID);

		$studyInput.setAttribute("type","text");

		$studyInputTD.appendChild($studyInput);



		// Create "date from-to" input boxes and cells.

		$dateInputTD = document.createElement("td");

		$dateInput = document.createElement("input");

		$dateInput.className = "userInput";

		$dateInput.setAttribute("size","7");

		$dateInput.setAttribute("maxlength","7");

		$nameID = "collegeDateFrom" +$collegeCount;

		$dateInput.setAttribute("name",$nameID);

		$dateInput.setAttribute("id",$nameID);

		$dateInput.setAttribute("type","text");

		$dateInputTD.appendChild($dateInput);

		$textVal = " to ";

		$textNode = document.createTextNode($textVal);

		$dateInputTD.appendChild($textNode);

		$dateInput = document.createElement("input");

		$dateInput.className = "userInput";

		$dateInput.setAttribute("size","7");

		$dateInput.setAttribute("maxlength","7");

		$nameID = "collegeDateTo" +$collegeCount;

		$dateInput.setAttribute("name",$nameID);

		$dateInput.setAttribute("id",$nameID);

		$dateInput.setAttribute("type","text");

		$dateInputTD.appendChild($dateInput);



		// Create "credits earned" input box and cell.

		$creditInputTD = document.createElement("td");

		$creditInput = document.createElement("input");

		$creditInput.className = "userInput";

		$creditInput.setAttribute("size","6");

		$creditInput.setAttribute("maxlength","6");

		$nameID = "collegeCredit" +$collegeCount;

		$creditInput.setAttribute("name",$nameID);

		$creditInput.setAttribute("id",$nameID);

		$creditInput.setAttribute("type","text");

		$creditInputTD.appendChild($creditInput);

	

		// Append all the input cells to the main TR.

		$stdDateCreditInputTR.appendChild($studyInputTD);

		$stdDateCreditInputTR.appendChild($dateInputTD);

		$stdDateCreditInputTR.appendChild($creditInputTD);

  

		// Add all the pieces to the TBODY and append to document.

		$tableBody.appendChild($headBlankRow);

		$tableBody.appendChild($instLocTR);

		$tableBody.appendChild($instLocInputTR);

		$tableBody.appendChild($stdDateCreditTR);

		$tableBody.appendChild($stdDateCreditInputTR);

		$docPosition.appendChild($tableBody);

		

		// Increase the current count of colleges.

		$collegeCount++;

		document.getElementById("numCollege").value = $collegeCount;

	}

	else {

		alert("You have added the maximum number of additional Colleges or Universities allowed.");

	}

	

	return 0;

} 



// This function will add a college to the table of "College or University Education."

function addEmployer() {

	// As long as the current number is less than the max number.

	if ($employerCount < $maxEmployer) {

		// Set position in document and create TBODY.

		$docPosition = document.getElementById("employer");

		$tableBody = document.createElement("tbody");

		

		// Create spacer cell and main TR.

		$headBlankRow = document.createElement("tr");

		$headBlankCell = document.createElement("td");

		$headBlankCell.className = "tableHeader";

		$headBlankCell.setAttribute("colSpan","2");

		$textVal = "additional employer (" +$employerCount +")";

		$textNode = document.createTextNode($textVal);

		$headBlankCell.appendChild($textNode);

	

		// Append spacer to main TR.

		$headBlankRow.appendChild($headBlankCell); 

		

		// Create "employer" header, cell, and main TR.

		$empLocTR = document.createElement("tr");

		$empHead = document.createElement("td");

		$empHead.className = "tableFormRequest";

		$textVal = "Employer";

		$textNode = document.createTextNode($textVal);

		$empHead.appendChild($textNode);

		

		// Create "location" header and cell.

		$locHead = document.createElement("td");

		$locHead.className = "tableFormRequest";

		$textVal = "Location";

		$textNode = document.createTextNode($textVal);

		$locHead.appendChild($textNode);

	

		// Append headers to main TR.  

		$empLocTR.appendChild($empHead);

		$empLocTR.appendChild($locHead);

  

		// Creat the "employer" input box, cell, and main TR.

		$empLocInputTR = document.createElement("tr");

		$empInputTD = document.createElement("td");

		$empInput = document.createElement("input");

		$empInput.className = "userInput";

		$empInput.setAttribute("size","40");

		$nameID = "employerEmp" +$employerCount;

		$empInput.setAttribute("name",$nameID);

		$empInput.setAttribute("id",$nameID);

		$empInput.setAttribute("type","text");

		$empInputTD.appendChild($empInput);



		// Create the "location" input box and cell.

		$locInputTD = document.createElement("td");

		$locInput = document.createElement("input");

		$locInput.className = "userInput";

		$locInput.setAttribute("size","40");

		$nameID = "employerLoc" +$employerCount;

		$locInput.setAttribute("name",$nameID);

		$locInput.setAttribute("id",$nameID);

		$locInput.setAttribute("type","text");

		$locInputTD.appendChild($locInput);

	

		// Append input boxes to main TR.

		$empLocInputTR.appendChild($empInputTD);

		$empLocInputTR.appendChild($locInputTD);



		// Create the "date from-to" header, cell and main TR.

		$datePosTR = document.createElement("tr");

		$dateHead = document.createElement("td");

		$dateHead.className = "tableFormRequest";

		$textVal = "Dates Employed (mm-yyyy)";

		$textNode = document.createTextNode($textVal);

		$dateHead.appendChild($textNode);  

	

		// Create the "position" header and cell.

		$posHead = document.createElement("td");

		$posHead.className = "tableFormRequest";

		$textVal = "Nature of Position";

		$textNode = document.createTextNode($textVal);

		$posHead.appendChild($textNode);

	

		// Append all the input headers to main TR.

		$datePosTR.appendChild($dateHead);

		$datePosTR.appendChild($posHead);

	

		// Create "date from-to" input box and cell.

		$datePosInputTR = document.createElement("tr");

		$dateInputTD = document.createElement("td");

		$dateInput = document.createElement("input");

		$dateInput.className = "userInput";

		$dateInput.setAttribute("size","7");

		$dateInput.setAttribute("maxlength","7");

		$nameID = "employerDateFrom" +$employerCount;

		$dateInput.setAttribute("name",$nameID);

		$dateInput.setAttribute("id",$nameID);

		$dateInput.setAttribute("type","text");

		$dateInputTD.appendChild($dateInput);

		$textVal = " to ";

		$textNode = document.createTextNode($textVal);

		$dateInputTD.appendChild($textNode);

		$dateInput = document.createElement("input");

		$dateInput.className = "userInput";

		$dateInput.setAttribute("size","7");

		$dateInput.setAttribute("maxlength","7");

		$nameID = "employerDateTo" +$employerCount;

		$dateInput.setAttribute("name",$nameID);

		$dateInput.setAttribute("id",$nameID);

		$dateInput.setAttribute("type","text");

		$dateInputTD.appendChild($dateInput);



		// Create "positoin" input box and cell.

		$posInputTD = document.createElement("td");

		$posInput = document.createElement("input");

		$posInput.className = "userInput";

		$posInput.setAttribute("size","40");

		$nameID = "employerPosition" +$employerCount;

		$posInput.setAttribute("name",$nameID);

		$posInput.setAttribute("id",$nameID);

		$posInput.setAttribute("type","text");

		$posInputTD.appendChild($posInput);

	

		// Append all the input cells to the main TR.

		$datePosInputTR.appendChild($dateInputTD);

		$datePosInputTR.appendChild($posInputTD);

  

		// Add all the pieces to the TBODY and append to document.

		$tableBody.appendChild($headBlankRow);

		$tableBody.appendChild($empLocTR);

		$tableBody.appendChild($empLocInputTR);

		$tableBody.appendChild($datePosTR);

		$tableBody.appendChild($datePosInputTR);

		$docPosition.appendChild($tableBody);

		

		// Increase the current count of colleges.

		$employerCount++;

		document.getElementById("numEmployer").value = $employerCount;

	}

	else {

		alert("You have added the maximum number of additional Employers allowed.");

	}

	

	return 0;

}



// This function will check to see if a value is a number or not.

function is_number($value) { 

	for (var $i=0; $i<$value.length; $i++) {

		var $digit = $value.charAt($i);

		if ($digit <"0" || $digit > "9") { 

			return false;

		} 

	} 

	return true;

}



// This function will disable and enable the research project checkboxs as long as

// there is less than three selected (enable) and not more (disable).

function controlProjects($id) {

	if (document.getElementById("numSelectedProjects").value < 0) {

		document.getElementById("numSelectedProjects").value = 0;

	}

	

	// If the applicant just checked the box.

	if (document.getElementById($id).checked) {

		// Add one to the total count.

		document.getElementById("numSelectedProjects").value = eval(document.getElementById("numSelectedProjects").value) + 1;

		

		// If the count is greater than or equal to 3 disable all the others without disabling checked ones.

		if (document.getElementById("numSelectedProjects").value >= 3) {

			var $maxProjects = document.getElementById("numProjects").value;

		

			for (var $i=1; $i<=$maxProjects; $i++) {

				if ($i <= 9) {

					$name = "project0" +$i;

				}

				else {

					$name = "project" +$i;

				}

				

				if (!document.getElementById($name).checked) {

					document.getElementById($name).disabled = true;

				}

			}

		}

	}

	// If the applicant just unchecked a box.

	else if (!document.getElementById($id).checked) {

		// If the count is greater than or equal to 3 enable all the others.

		if (document.getElementById("numSelectedProjects").value >= 3) {

			var $maxProjects = document.getElementById("numProjects").value;

		

			for (var $i=1; $i<=$maxProjects; $i++) {

				if ($i <= 9) {

					$name = "project0" +$i;

				}

				else {

					$name = "project" +$i;

				}

				

				if (!document.getElementById($name).checked) {

					document.getElementById($name).disabled = false;

				}

			}

		}

		// Take one away from the total count.

		document.getElementById("numSelectedProjects").value = eval(document.getElementById("numSelectedProjects").value) - 1;

	}

	

	return 0;

}



// This function will check a full date in the format mm-dd-yyyy.

// It will not check for a valid calendar month or year.

function checkFullDate($date) {

	var $dash = "-";

	var $month = $date.substr(0,2);

	var $day = $date.substr(3,2);

	var $year = $date.substr(6,4);

	

	// Make sure the date is of the correct length.

	if ($date.length != 10) {

		return false;

	}

	// Make sure the month is a number.

	if (!is_number($month)) {

		return false;

	}

	// Make sure there is a slash as the third character.

	if ($date.substr(2,1) != $dash) {

		return false;

	}

	// Make sure the day is a number.

	if (!is_number($day)) {

		return false;

	}

	// Make sure there is a slash as the sixth character.

	if ($date.substr(5,1) != $dash) {

		return false;

	}

	// Make sure the year is a number.

	if (!is_number($year)) {

		return false;

	}

	

	return true;

}



// This function will check a partial date in the format mm-yyyy.

// It will not check for a valid calendar month or year.

function checkPartDate($date) {

	var $dash = "-";

	var $year = $date.substr(3,4);

	var $month = $date.substr(0,2);



	// Make sure the date if of the correct length.

	if ($date.length != 7) {

		return false;

	}

	// Make sure there is a slash as the third character.

	if ($date.substr(2,1) != $dash) {

		return false;

	}

	// Make sure the month is a number.

	if (!is_number($month)) {

		return false;

	}

	// Make sure the year is a number.

	if (!is_number($year)) {

		return false;

	}

	

	return true;

}



// This function will validate and e-mail address to make sure it is in the correct

// format.

function validateEmail() {

	var $address = document.getElementById("email").value;

	var $at="@";

	var $dot=".";

	var $lat=$address.indexOf($at);

	var $lstr=$address.length;

	var $ldot=$address.indexOf($dot);

	

	// Check to make sure there is an @.

	if ($address.indexOf($at)==-1) {

	   return false;

	}

	// Check to make sure there is no @ in the begging or end and one exists.

	if ($address.indexOf($at)==-1 || $address.indexOf($at)==0 || $address.indexOf($at)==$lstr) {

	   return false;

	}

	// Check to make sure there is no . in the begging or end and one exists.

	if ($address.indexOf($dot)==-1 || $address.indexOf($dot)==0 || $address.indexOf($dot)==$lstr) {

		return false;

	}

	// Check to make sure there is at least one character before the @.

	if ($address.indexOf($at,($lat+1))!=-1) {

	   return false;

	}

	// Check to make sure there is at least one character before the ..

	if ($address.substr($lat-1,$lat)==$dot || $address.substr($lat+1,$lat+2)==$dot) {

	   return false;

	}

	// Check to make sure there is not a . in the begging.

	if ($address.indexOf($dot,($lat+2))==-1) {

	   return false;

	}

	// Check to make sure there is not a space.

	if ($address.indexOf(" ")!=-1) {

	   return false;

	}



	return true;					

}



// This function will validate the form and alert the applicant of any errors on the form.

// JavaScript validation was used instead of PHP because of the nature of the dynamic college

// and employer information.

function validateForm() {

	// Begin error message.

	var $errorMsg = "You are missing some required information, please fill in or fix the following: \n\n";

	var $error = false;



	// Reset background color of form elements.

	document.getElementById("lastname").style.backgroundColor = "#FFFFFF";

	document.getElementById("firstname").style.backgroundColor = "#FFFFFF";

	document.getElementById("email").style.backgroundColor = "#FFFFFF";

	document.getElementById("mailAdd").style.backgroundColor = "#FFFFFF";

	document.getElementById("mailCity").style.backgroundColor = "#FFFFFF";

	document.getElementById("mailState").style.backgroundColor = "#FFFFFF";

	document.getElementById("mailZip").style.backgroundColor = "#FFFFFF";

	document.getElementById("homeAdd").style.backgroundColor = "#FFFFFF";

	document.getElementById("homeCity").style.backgroundColor = "#FFFFFF";

	document.getElementById("homeState").style.backgroundColor = "#FFFFFF";

	document.getElementById("homeZip").style.backgroundColor = "#FFFFFF";

	document.getElementById("tel1").style.backgroundColor = "#FFFFFF";

	document.getElementById("tel2").style.backgroundColor = "#FFFFFF";

	document.getElementById("tel3").style.backgroundColor = "#FFFFFF";

	document.getElementById("atel1").style.backgroundColor = "#FFFFFF";

	document.getElementById("atel2").style.backgroundColor = "#FFFFFF";

	document.getElementById("atel3").style.backgroundColor = "#FFFFFF";

	document.getElementById("citizenship").style.backgroundColor = "#FFFFFF";

	document.getElementById("citizenOther").style.backgroundColor = "#FFFFFF";		

	document.getElementById("perResident").style.backgroundColor = "#FFFFFF";		

	document.getElementById("perDate").style.backgroundColor = "#FFFFFF";

	document.getElementById("perDate").style.backgroundColor = "#FFFFFF";

	document.getElementById("collegeDegree").style.backgroundColor = "#FFFFFF";

	document.getElementById("collegeMajor").style.backgroundColor = "#FFFFFF";

	document.getElementById("gpa").style.backgroundColor = "#FFFFFF";

	document.getElementById("possGpa").style.backgroundColor = "#FFFFFF";

	document.getElementById("gradDate").style.backgroundColor = "#FFFFFF";

	document.getElementById("greDate").style.backgroundColor = "#FFFFFF";

	document.getElementById("honors").style.backgroundColor = "#FFFFFF";

	document.getElementById("extraActivities").style.backgroundColor = "#FFFFFF";

	document.getElementById("area2").style.backgroundColor = "#FFFFFF";

	document.getElementById("area3").style.backgroundColor = "#FFFFFF";

	document.getElementById("DOBdate").style.backgroundColor = "#FFFFFF";

	document.getElementById("ethnic").style.backgroundColor = "#FFFFFF";

	document.getElementById("ethnicOther").style.backgroundColor = "#FFFFFF";

	

	// Begin checking:

	// LAST NAME

	if (document.getElementById("lastname").value == "") {

		$errorMsg += "  - Last Name \n";

		$error = true;

		document.getElementById("lastname").style.backgroundColor = "#FFFFCC";

	}

	// FIRST NAME

	if (document.getElementById("firstname").value == "") {

		$errorMsg += "  - First Name \n";

		$error = true;

		document.getElementById("firstname").style.backgroundColor = "#FFFFCC";

	}

	// EMAIL

	if (document.getElementById("email").value == "") {

		$errorMsg += "  - E-mail Address \n";

		$error = true;

		document.getElementById("email").style.backgroundColor = "#FFFFCC";

	}

	if (document.getElementById("email").value != "") {

		if (!validateEmail()) {

			$errorMsg += "  - Invalid E-mail Address \n";

			$error = true;

			document.getElementById("email").style.backgroundColor = "#FFFFCC";

		}

	}

	// MAILING ADDRESS

	if (document.getElementById("mailAdd").value == "") {

		$errorMsg += "  - Mailing Address \n";

		$error = true;

		document.getElementById("mailAdd").style.backgroundColor = "#FFFFCC";

	}

	// MAILING ADDRESS CITY

	if (document.getElementById("mailCity").value == "") {

		$errorMsg += "  - Mailing Address: City \n";

		$error = true;

		document.getElementById("mailCity").style.backgroundColor = "#FFFFCC";

	}

	// MAILING ADDRESS STATE

	if (document.getElementById("mailState").value == "") {

		$errorMsg += "  - Mailing Address: State \n";

		$error = true;

		document.getElementById("mailState").style.backgroundColor = "#FFFFCC";

	}

	// MAILING ADDRESS ZIP

	if (document.getElementById("mailZip").value == "") {

		$errorMsg += "  - Mailing Address: Zip \n";

		$error = true;

		document.getElementById("mailZip").style.backgroundColor = "#FFFFCC";

	}

	// HOME ADDRESS

	if (document.getElementById("homeAdd").value == "") {

		$errorMsg += "  - Home Address \n";

		$error = true;

		document.getElementById("homeAdd").style.backgroundColor = "#FFFFCC";

	}

	// HOME ADDRESS CITY

	if (document.getElementById("homeCity").value == "") {

		$errorMsg += "  - Home Address: City \n";

		$error = true;

		document.getElementById("homeCity").style.backgroundColor = "#FFFFCC";

	}

	// HOME ADDRESS STATE

	if (document.getElementById("homeState").value == "") {

		$errorMsg += "  - Home Address: State \n";

		$error = true;

		document.getElementById("homeState").style.backgroundColor = "#FFFFCC";

	}

	// HOME ADDRESS ZIP

	if (document.getElementById("homeZip").value == "") {

		$errorMsg += "  - Home Address: Zip \n";

		$error = true;

		document.getElementById("homeZip").style.backgroundColor = "#FFFFCC";

	}

	// TELEPHONE NUMBER

	if (document.getElementById("tel1").value == "" || document.getElementById("tel2").value == "" || document.getElementById("tel3").value == "") {

		$errorMsg += "  - Telephone Number \n";

		$error = true;

		document.getElementById("tel1").style.backgroundColor = "#FFFFCC";

		document.getElementById("tel2").style.backgroundColor = "#FFFFCC";

		document.getElementById("tel3").style.backgroundColor = "#FFFFCC";

	}

	if (!is_number(document.getElementById("tel1").value) || !is_number(document.getElementById("tel2").value) || !is_number(document.getElementById("tel3").value)) {

		$errorMsg += "  - Invalid Telephone Number \n";

		$error = true;

		document.getElementById("tel1").style.backgroundColor = "#FFFFCC";

		document.getElementById("tel2").style.backgroundColor = "#FFFFCC";

		document.getElementById("tel3").style.backgroundColor = "#FFFFCC";

	}

	// ALTERNATE TELEPHONE NUMBER

	if (document.getElementById("tel1").value != "" && (document.getElementById("tel2").value == "" || document.getElementById("tel3").value == "")) {

		$errorMsg += "  - Invalid Alt. Telephone Number \n";

		$error = true;

		document.getElementById("atel1").style.backgroundColor = "#FFFFCC";

		document.getElementById("atel2").style.backgroundColor = "#FFFFCC";

		document.getElementById("atel3").style.backgroundColor = "#FFFFCC";

	}

	if (!is_number(document.getElementById("atel1").value) || !is_number(document.getElementById("atel2").value) || !is_number(document.getElementById("atel3").value)) {

		$errorMsg += "  - Invalid Alt. Telephone Number \n";

		$error = true;

		document.getElementById("atel1").style.backgroundColor = "#FFFFCC";

		document.getElementById("atel2").style.backgroundColor = "#FFFFCC";

		document.getElementById("atel3").style.backgroundColor = "#FFFFCC";

	}

	// CITIZENSHIP

	if (document.getElementById("citizenship").value == "other" && document.getElementById("citizenOther").value == "") {

		$errorMsg += "  - Citizenship Other: Specify \n";

		$error = true;

		document.getElementById("citizenship").style.backgroundColor = "#FFFFCC";

		document.getElementById("citizenOther").style.backgroundColor = "#FFFFCC";

	}

	if (document.getElementById("citizenship").value == "permenant" && document.getElementById("perResident").value == "") {

		$errorMsg += "  - Alien Registration Number \n";

		$error = true;

		document.getElementById("citizenship").style.backgroundColor = "#FFFFCC";

		document.getElementById("perResident").style.backgroundColor = "#FFFFCC";

	}

	if (document.getElementById("citizenship").value == "permenant" && document.getElementById("perResident").value != "" && document.getElementById("perDate").value == "") {

		$errorMsg += "  - Permenant Resident Date of Issue \n";

		$error = true;

		document.getElementById("citizenship").style.backgroundColor = "#FFFFCC";

		document.getElementById("perResident").style.backgroundColor = "#FFFFCC";

		document.getElementById("perDate").style.backgroundColor = "#FFFFCC";

	}

	if (document.getElementById("perDate").value != "") {

		if (!checkFullDate(document.getElementById("perDate").value)) {

			$errorMsg += "  - Invalid Permenant Resident Date of Issue \n";

			$error = true;

			document.getElementById("perDate").style.backgroundColor = "#FFFFCC";

		}

	}

	// COLLEGE OR UNIVERSITY INFORMATION

	for (var $i=1; $i<=$collegeCount; $i++) {

		var $count = $i - 1;

		var $inst = "collegeInst" +$count;

		var $loc = "collegeLoc" +$count;

		var $study = "collegeStudy" +$count;

		var $dateFrom = "collegeDateFrom" +$count;

		var $dateTo = "collegeDateTo" +$count;

		var $credit = "collegeCredit" +$count;

		

		if (document.getElementById($inst).value == "" || document.getElementById($loc).value == "" || document.getElementById($study).value == "" || document.getElementById($dateFrom).value == "" || document.getElementById($dateTo).value == "" || document.getElementById($credit).value == "") {

			$errorMsg += "  - Incomplete College or University Information \n";

			$error = true;

			document.getElementById($inst).style.backgroundColor = "#FFFFCC";

			document.getElementById($loc).style.backgroundColor = "#FFFFCC";

			document.getElementById($study).style.backgroundColor = "#FFFFCC";

			document.getElementById($dateFrom).style.backgroundColor = "#FFFFCC";

			document.getElementById($dateTo).style.backgroundColor = "#FFFFCC";

			document.getElementById($credit).style.backgroundColor = "#FFFFCC";

		}

		else {

			document.getElementById($inst).style.backgroundColor = "#FFFFFF";

			document.getElementById($loc).style.backgroundColor = "#FFFFFF";

			document.getElementById($study).style.backgroundColor = "#FFFFFF";

			document.getElementById($dateFrom).style.backgroundColor = "#FFFFFF";

			document.getElementById($dateTo).style.backgroundColor = "#FFFFFF";

			document.getElementById($credit).style.backgroundColor = "#FFFFFF";

		}

		if (document.getElementById($dateFrom).value != "") {

			var $resultFrom = checkPartDate(document.getElementById($dateFrom).value);

			var $resultTo = checkPartDate(document.getElementById($dateTo).value);

			

			if (!$resultFrom) {

				$errorMsg += "  - Invalid College or University 'from' Date \n";

				$error = true;

				document.getElementById($dateFrom).style.backgroundColor = "#FFFFCC";

			}

		}

		if (document.getElementById($dateTo).value != "") {

			if (!$resultTo) {

				$errorMsg += "  - Invalid College or University 'to' Date \n";

				$error = true;

				document.getElementById($dateTo).style.backgroundColor = "#FFFFCC";

			}

		}

	}

	// COLLEGE DEGREE

	if (document.getElementById("collegeDegree").value == "") {

		$errorMsg += "  - College Degree \n";

		$error = true;

		document.getElementById("collegeDegree").style.backgroundColor = "#FFFFCC";

	}

	// COLLEGE MAJOR

	if (document.getElementById("collegeMajor").value == "") {

		$errorMsg += "  - College Major \n";

		$error = true;

		document.getElementById("collegeMajor").style.backgroundColor = "#FFFFCC";

	}

	// COLLEGE GPA

	if (document.getElementById("gpa").value == "") {

		$errorMsg += "  - College GPA \n";

		$error = true;

		document.getElementById("gpa").style.backgroundColor = "#FFFFCC";

	}

	// COLLEGE POSSIBLE GPA

	if (document.getElementById("possGpa").value == "") {

		$errorMsg += "  - College Possible GPA \n";

		$error = true;

		document.getElementById("possGpa").style.backgroundColor = "#FFFFCC";

	}

	// GRADUATION DATE

	if (document.getElementById("gradDate").value == "") {

		$errorMsg += "  - College Graduation Date \n";

		$error = true;

		document.getElementById("gradDate").style.backgroundColor = "#FFFFCC";

	}

	else if (!checkPartDate(document.getElementById("gradDate").value)) {

		$errorMsg += "  - Invalid College Graduation Date \n";

		$error = true;

		document.getElementById("gradDate").style.backgroundColor = "#FFFFCC";

	}

	// PROFESSIONAL OR WORK EXPERIENCE

	for (var $i=1; $i<=$employerCount; $i++) {

		var $count = $i - 1;

		var $emp = "employerEmp" +$count;

		var $loc = "employerLoc" +$count;

		var $dateFrom = "employerDateFrom" +$count;

		var $dateTo = "employerDateTo" +$count;

		var $position = "employerPosition" +$count;

		

		if ((document.getElementById($emp).value != "" || document.getElementById($loc).value != "" || document.getElementById($dateFrom).value != "" || document.getElementById($dateTo).value != "" || document.getElementById($position).value != "") && (document.getElementById($emp).value == "" || document.getElementById($loc).value == "" || document.getElementById($dateFrom).value == "" || document.getElementById($dateTo).value == "" || document.getElementById($position).value == "")) {

			$errorMsg += "  - Incomplete Professional or Work Experience \n";

			$error = true;

			document.getElementById($emp).style.backgroundColor = "#FFFFCC";

			document.getElementById($loc).style.backgroundColor = "#FFFFCC";

			document.getElementById($dateFrom).style.backgroundColor = "#FFFFCC";

			document.getElementById($dateTo).style.backgroundColor = "#FFFFCC";

			document.getElementById($position).style.backgroundColor = "#FFFFCC";

		}

		else {

			document.getElementById($emp).style.backgroundColor = "#FFFFFF";

			document.getElementById($loc).style.backgroundColor = "#FFFFFF";

			document.getElementById($dateFrom).style.backgroundColor = "#FFFFFF";

			document.getElementById($dateTo).style.backgroundColor = "#FFFFFF";

			document.getElementById($position).style.backgroundColor = "#FFFFFF";

		}

		if (document.getElementById($dateFrom).value != "") {

			if (!checkPartDate(document.getElementById($dateFrom).value)) {

				$errorMsg += "  - Invalid Professional or Work Experience 'from' Date \n";

				$error = true;

				document.getElementById($dateFrom).style.backgroundColor = "#FFFFCC";

			}

		}

		if (document.getElementById($dateTo).value != "") {

			if (!checkPartDate(document.getElementById($dateTo).value)) {

				$errorMsg += "  - Invalid Professional or Work Experience 'to' Date \n";

				$error = true;

				document.getElementById($dateTo).style.backgroundColor = "#FFFFCC";

			}

		}

	}

	// GRE DATE

	if (document.getElementById("greDate").value != "") {

		if (!checkFullDate(document.getElementById("greDate").value)) {

			$errorMsg += "  - Invalid GRE Test Date \n";

			$error = true;

			document.getElementById("greDate").style.backgroundColor = "#FFFFCC";

		}

	}

	// HORNORS AND OTHER AWARDS

	if (document.getElementById("honors").value == "") {

		$errorMsg += "  - Academic Honors, Prizes, Scholarships, or Honor Socitiest (must at least contain 'none') \n";

		$error = true;

		document.getElementById("honors").style.backgroundColor = "#FFFFCC";

	}

	// EXTRA ACTIVITIES

	if (document.getElementById("extraActivities").value == "") {

		$errorMsg += "  - Extracurricular Activities (must at least contain 'none') \n";

		$error = true;

		document.getElementById("extraActivities").style.backgroundColor = "#FFFFCC";

	}

	// RESEARCH AREAS

	if (document.getElementById("area1").value == document.getElementById("area2").value) {

		$errorMsg += "  - Invalid Research Area Selections \n";

		$error = true;

		document.getElementById("area2").style.backgroundColor = "#FFFFCC";

	}

	else if (document.getElementById("area1").value == document.getElementById("area3").value) {

		$errorMsg += "  - Invalid Research Area Selections \n";

		$error = true;

		document.getElementById("area3").style.backgroundColor = "#FFFFCC";

	}

	else if (document.getElementById("area2").value == document.getElementById("area3").value) {

		$errorMsg += "  - Invalid Research Area Selections \n";

		$error = true;

		document.getElementById("area3").style.backgroundColor = "#FFFFCC";

	}

	// RESEARCH PROJECTS

	if (document.getElementById("numSelectedProjects").value == 0) {

		$errorMsg += "  - Invalid Number of Research Projects Selected (must be at least 1) \n";

		$error = true;

	}

	// DATE OF BIRTH

	if (document.getElementById("DOBdate").value != "") {

		if (!checkFullDate(document.getElementById("DOBdate").value)) {

			$errorMsg += "  - Invalid Birth Date \n";

			$error = true;

			document.getElementById("DOBdate").style.backgroundColor = "#FFFFCC";

		}

	}

	// EHTNIC GROUP

	if (document.getElementById("ethnic").value == "other" && document.getElementById("ethnicOther").value == "") {

		$errorMsg += "  - Invalid Ethnic Other: Specify \n";

		$error = true;

		document.getElementById("ethnic").style.backgroundColor = "#FFFFCC";

		document.getElementById("ethnicOther").style.backgroundColor = "#FFFFCC";

	}

	

	// If there were errors then alert the applicant.

	if ($error) {

		alert($errorMsg);

		return false;

	}

	// Otherwise, ask to confirm if they have checked.

	else {

		var $bYes;

		$bYes = confirm("Have you double checked your entries?");

	

		if ($bYes == true) {

			return true;

		}

		else {

			return false;

		}

	}

}