		// This method takes a grade, when it was earned, and determines if it is a valid grade or not.
		// If the grade is valid, it returns it worth for calculating a GPA.
		// param: isPreSummer09, boolean.  If true then minus grades are not allowed.
		// param: gradeToCheck, string. The grade being validated.
		// returns: real.  If return value is -1 then the grade is invalid, 0 if the field is empty, or it returns the grade's value.
		function ConvertGradeToValue(isPreSummer09, gradeToCheck)
		{
			var validPreSummer09Grades = ["A", "B+", "B", "C+", "C", "D+", "D", "E", "WF", "I", "NG", "S", "U"];
			var validPreSummer09Values = [4, 3.5, 3, 2.5, 2, 1.5, 1, 0, 0, 0, 0, 0, 0];
			var validPostSpring09Grades = ["A", "A-","B+", "B", "B-", "C+", "C", "C-", "D+", "D", "D-", "E", "WF", "I", "NG", "S", "U"];
			var validPostSpring09Values = [4, 3.67, 3.33, 3, 2.67, 2.33, 2, 1.67, 1.33, 1, 0.67, 0, 0, 0, 0, 0, 0];
			var index;
			var gradeValue = 0;

			gradeToCheck = gradeToCheck.toUpperCase();
			gradeValue = -1;
			
			if (isPreSummer09)
			{
				index = jQuery.inArray(gradeToCheck, validPreSummer09Grades);
				
				if (index>-1)
				{
					gradeValue = validPreSummer09Values[index];
				}
			}
			else
			{
				index = jQuery.inArray(gradeToCheck, validPostSpring09Grades);
				
				if (index>-1)
				{
					gradeValue = validPostSpring09Values[index];
				}
			}
				
			return gradeValue;
		}
		
		// This function validates a field's number of credit hours.
		// Allowed values range from 0.5 to 10.
		// Returns: boolean; true if valid number.
		function CreditHoursIsValid(hours)
		{
			var isValid = false;
			var numRegex = new RegExp(/^\d{1,2}$|^\d\.\d$|^\d\d\.?$/);
			
			if (hours.match(numRegex))
			{
				isValid = (hours >= 0.5) && (hours <= 10);
			}
			
			return isValid;
		}
			
		// This function computes the grade points earned for a particular row.
		// It is called whenever the # of credits or grade earned column changes
		// in that row.
		// Columns are bound in the jQuery ready event.
		// Function returns nothing (void)
		function ComputeRow(event)
		{			
			var creditHours = $("input[name='units']", $(event.target).parents("tr:first")).val();
			
			if (CreditHoursIsValid(creditHours))
			{
				var preGradeEarned = $("input[name='gradePre']", $(event.target).parents("tr:first")).val();
				var postGradeEarned = $("input[name='gradePost']", $(event.target).parents("tr:first")).val();			
				var gradeValue; 
				
				if ((preGradeEarned != "") && (postGradeEarned == ""))
				{
					gradeValue = ConvertGradeToValue(true, preGradeEarned);
				}
				else if ((preGradeEarned == "") && (postGradeEarned != ""))
				{
					gradeValue = ConvertGradeToValue(false, postGradeEarned);
				}
				else if ((preGradeEarned != "") && (postGradeEarned != ""))
				{
					alert("Please only enter one grade per row.");
					$("input[name='gradepoints']", $(event.target).parents("tr:first")).val("");
					return;
				}
				
				if (gradeValue>=0)
				{
					var gradePointsEarned = creditHours * gradeValue;
					$("input[name='gradepoints']", $(event.target).parents("tr:first")).val(gradePointsEarned);
					SumForm();
				}
			}
			else if (creditHours != "")
			{
				alert("Invalid number of credits entered.  '" + creditHours + "' is not a number between 0.5 and 10.");
				$("input[name='units']", $(event.target).parents("tr:first")).focus();
			}
		}
		
		// This function clears a particular row
		// Called by the row's "reset" button.
		function ClearRow(event)
		{
			$("input[name='units']", $(event.target).parents("tr:first")).val("");
			$("input[name='gradePre']", $(event.target).parents("tr:first")).val("");
			$("input[name='gradePost']", $(event.target).parents("tr:first")).val("");
			$("input[name='gradepoints']", $(event.target).parents("tr:first")).val("");
			SumForm();
		}
		
		// This method calculates the overall credits taken, earned, and GPA.
		// It is called whenever a row is updated or the specified button is clicked.
		function SumForm() 
		{
			var totalCreditsTaken = 0, totalPointsEarned = 0, totalGPA;
			
			$("input[name='units']").each(function(){
				if ($(this).val() != "")
				{
					totalCreditsTaken += parseInt($(this).val());
				}
			})			
			$("input[name='gradepoints']").each(function(){
				if ($(this).val() != "")
				{
					totalPointsEarned += parseFloat($(this).val());
				}
			})
			
			totalGPA = totalPointsEarned/totalCreditsTaken;
			$("#TotalCredits").val(totalCreditsTaken);
			$("#TotalPointsEarned").val(totalPointsEarned);
			
			if (totalCreditsTaken > 0) {
			    totalGPA = (Math.floor(totalGPA * 100)) / 100;
				$("#TotalGPA").val(totalGPA.toFixed(3));
				var deficitPts = 0;
				
				if (totalGPA < 2.0)
				{
					deficitPts = totalCreditsTaken * (2.0 - totalGPA);					
				}
				
				$("#DeficitPoints").val(deficitPts.toFixed(3));
			}
			else
			{
				$("#TotalGPA").val(0);
				$("#DeficitPoints").val(0);
			}
			
		} 		
		
		// Clears the totals row at the bottom of the table.
		// Called by the row total's reset button.
		function ResetTotals() 
		{
			$("#TotalCredits").val("");
			$("#TotalPointsEarned").val("");
			$("#TotalGPA").val("");
			$("#DeficitPoints").val("");
		} 

