/* 
	Purpose: Checks if an input field has been filed or not
	Results: If the input field is empty an alert is displayed for user; returns false. If the input field is filled returns true.
	Page(s) of use: functions.js
*/
function valBlank(objID, errMsg)
{
	if (objID.value == null || objID.value == "")
	{
		alert(errMsg);
		objID.focus();
		return false;
	}
	return true;
}

/* 
	Purpose: Checks if a checkbox has been selected or not
	Results: If the checkbox is empty an alert is displayed for user; returns false. If the checkbox is filled returns true.
	Page(s) of use: functions.js
*/
function checkreqired(objID, errMsg)
{
	if (objID.checked == false)
	{
		alert(errMsg);
		objID.focus();
		return false;
	}
	return true;
}

/*
	Purpose: Checks if the input follows the standards for emails
	Results: True or False
	Pages(s) of use: functions.js
*/
function valEmail(objID)
{ //test email string against proper email Format. 
	var emailFormat=/^.+@.+\..{2,3}$/;
	
	if(!(valBlank(objID,"Please enter your email address")))
	{
		return false;
	}
	if (!(emailFormat.test(objID.value))) 
	{ 
       		alert("Please enter a valid email address.");
		objID.focus();	
		return false;
	}
	//test against invalid email address characters.
	var badChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	if (objID.value.match(badChars)) 
	{
   		alert("The email address contains illegal characters.");
		objID.focus();
		return false;
	}
	return (valLength(objID, 75, "Email address must be less than 75 charaters.") && true);
}

/*
	Purpose: Checks if the input is less thana given size
	Results: True or False
	Pages(s) of use: functions.js
*/
function valLength(objID, maxSize, errMsg)
{ 
	if (objID.value.length > maxSize) 
	{
        	alert(errMsg);
            	objID.focus();
            	return false; 
	}
	return true;
}

/*
	Purpose: Checks if the two inputs are equal
	Results: True or False
	Pages(s) of use: functions.js
*/
function match(objONE, objTWO, errMsg)
{
	if(objONE.value != objTWO.value)
	{
		alert(errMsg);
		objTWO.focus();
		return false;
	}
	return true;
}

/*
	Purpose: Checks if input is in correct range
	Results: True or False
	Pages(s) of use: functions.js
*/
function val_range(floor, target, cieling)
{
	if (target.value < floor.value)
	{
		alert("Entered number is to low");
		target.focus();
		return false;
	}
	else if (target.value > cieling.value)
	{
		alert("Entered number is to high");
		target.focus();
		return false;
	}
	return true;
}