// JavaScript Document
function verify() {
	// Setup script
	var alert_message = ""
	var allTags = document.getElementsByTagName("*");
	var colorDefault = "#ffffff";
	var colorReqd = "#ff6600";
	
	// Specific input values
	var gpaGrade = document.form.calc_gpa.value;
	var actScore= document.form.calc_act.value;
	var houseIncome = document.form.calc_income.value;
	var scholarShip = document.form.calc_scholarships.value;
	
	// Variables for special formatting
	var gpa_val = /(^(\d{1})|(\d{1}\.\d{1,2}$))/;
	var act_val = /(^\d{1,2}$)/
	var money_val = /(^\$?\d+(\.\d{2})?$)|(^\$?\d{1,3}(\,\d{3})*(\.\d{2})?$)/;
	// Ensure each field is not blank if it has the class name of reqd.
	for (var j=0; j<allTags.length; j++) {
		
		// If field is blank change its background color
		if (allTags[j].className.indexOf("reqd") > -1 && allTags[j].value =="")  {
			alert_message = alert_message + allTags[j].title + " - ";
			allTags[j].style.backgroundColor = colorReqd;
			form_validate = false;
		} 
		// If field is not blank preserver or change it back to white
		if (allTags[j].className.indexOf("reqd") > -1 && allTags[j].value !="") {
			allTags[j].style.backgroundColor = colorDefault;
		}
	}	
		
	// Conditional checks
	// GPA validation
	  if (gpaGrade != "") {
		// Validate the number
		if (gpa_val.test(gpaGrade) == false || (gpaGrade < 0 || gpaGrade > 4)) {
			document.form.calc_gpa.style.backgroundColor = colorReqd;;
			alert_message = alert_message + "valid gpa - ";
		} else {
			document.form.calc_gpa.style.backgroundColor = colorDefault;	
		}
	 }
	 
	 // Act validation
	 if (actScore != "") {
		// Validate the number
		if (act_val.test(actScore) == false) {
			document.form.calc_act.style.backgroundColor = colorReqd;;
			alert_message = alert_message + "valid act score - ";
		} else {
			document.form.calc_act.style.backgroundColor = colorDefault;	
		}
	 }
	 
	 // Income validation
	 if (houseIncome != "") {
		 if (money_val.test(houseIncome) == false) {
			 document.form.calc_income.style.backgroundColor = colorReqd;;
			alert_message = alert_message + "valid income value - ";
		} else {
			document.form.calc_income.style.backgroundColor = colorDefault;	
		}
	 }
	 
	  // Scholarship validation
	 if (scholarShip != "") {
		 if (money_val.test(scholarShip) == false) {
			 document.form.calc_scholarships.style.backgroundColor = colorReqd;;
			alert_message = alert_message + "valid scholarship value - ";
		} else {
			document.form.calc_scholarships.style.backgroundColor = colorDefault;	
		}
	 }

	// If no errors, process form, else return the alert message
	if (alert_message == "") {
		return true;
	} else {
		alert("You are required to complete the following fields: " + alert_message);
		return false;
	}
}