//Student Services JavaScript Common Functions
//Created by Martin Rybak
//Boston College Information Technology Services
//Last Updated: Wednesday, August 6, 2003
///Displays error message for invalid course credit value
function validateCourseCredits(txbInput)
{
	strInput = txbInput.value;
	
	if (isNumeric(strInput) == false || strInput < .5 || strInput > 10)
	{
		alert('Course credits must be a number from .5 to 10.');
		txbInput.value = "";
	}
}
//Displays error message for invalid current credits value
function validateCurrentCredits(txbInput)
{
	strInput = txbInput.value;
	
	if (isNumeric(strInput) == false || strInput < 0)
	{
		alert('Current credits must be a number greater than 0.');
		txbInput.value = "";
	}
}
//Displays error message for invalid letter grade value
function validateGrade(txbInput)
{
	strInput = txbInput.value;
	
	if (computeGradeValue(strInput) == 'error')
	{
		alert('Grade must be one of the following: A, A-, B+, B, B-, C+, C, C-, D+, D, D-, F.');
		txbInput.value = "";
	}
}
//Displays error message for invalid GPA value
function validateGPA(txbInput)
{
	strInput = txbInput.value;
	
	if (isNumeric(strInput) == false || strInput < 0 || strInput > 4)
	{
		alert('GPA must be a number from 0 to 4.0.');
		txbInput.value = "";
	}
}
//Displays error message for invalid interest rate value
function validateInterestRate(txbInput)
{
	strInput = txbInput.value;
	
	if (isNumeric(strInput) == false || strInput < 0.1 || strInput > 20)
	{
		alert('Interest rate must be a number from 0.1 to 20.');
		txbInput.value = "";
	}
}
//Displays error message for invalid number of payments value
function validateNumPayments(txbInput)
{
	strInput = txbInput.value;
	
	if (isNumeric(strInput) == false || strInput < 2 || strInput > 400)
	{
		alert('Number of monthly payments must be a number from 2 to 400.');
		txbInput.value = "";
	}
}
//Displays error message for invalid montly payment value
function validateMonthlyPayment(txbInput)
{
	strInput = txbInput.value;
	
	if (isNumeric(strInput) == false || strInput < 1 || strInput > 10000)
	{
		alert('Monthly payment must be a number from 1 to 10000.');
		txbInput.value = "";
	}
}
//Displays error message for invalid loan amount value
function validateLoanAmount(txbInput)
{
	strInput = txbInput.value;
	
	if (isNumeric(strInput) == false || strInput < 100 || strInput > 999999)
	{
		alert('Loan amount must be a number from 100 to 999999.');
		txbInput.value = "";
	}
}
//Returns true for a valid number
function isNumeric(strInput)
{
	//Declare variables
	var i;
	var chrLetter;
	for (i = 0; i < strInput.length; i++)
	{
		var chrLetter = strInput.substring(i, i + 1);
		if ((chrLetter < '0' || '9' < chrLetter) && chrLetter != '.')
			return false;
	}
}
//Rounds number to X decimal places, defaults to 2
function round(number, x)
{
	x = (!x ? 2 : x);
	return Math.round(number * Math.pow(10, x)) / Math.pow(10, x);
}