/* ----------------------------------------------------------------------------------------------
Author:	Brent McClintock - bmcclintock@legis.state.pa.us
Date:	08/08/2002
Purpose: collection of general form validation functions
Includes:	
	1) isInteger(object_id, value)
	2) isNumber(value)
	3) isRequired(object_id)	***** REQUIRES stringFunctions.js library for TRIM() function *****
	4) textAreaTooLong(object_id,max_length)
----------------------------------------------------------------------------------------------- */

//**********************************************************************************************
//returns true if value is integer, else false
function isInteger(obj_id,val) {
	val = Trim(val);
	var digits="1234567890";
	for (var i=0; i < val.length; i++) 
	{
		if (digits.indexOf(val.charAt(i))==-1)
		{ 
			alert("Please enter an integer");
			var thisObj = document.getElementById(obj_id);
			thisObj.focus();
			thisObj.select();
			return false; 
		}
	}
	return true;
}
	
//**********************************************************************************************
//returns true if value is a number, else false
function isNumber(val) 
{ 
	val = Trim(val);
	return !isNaN(val); 
}	
//**********************************************************************************************
//returns true if field contains data, false if field is empty
//NOTE: requires stringFunctions.js for		function Trim()	!!!!
function isRequired(object_id)
{
	var thisObj = document.getElementById(object_id);
	temp_val = thisObj.value;
	
	if(temp_val.length > 0){ temp_val = Trim(temp_val); }
	if(temp_val.length == 0)
	{
		alert("Please enter a value, this is a required field.");
		thisObj.focus();
		thisObj.select();
		return false;
	}
	else
	{ return true; }
}
//**********************************************************************************************
// checks each keystroke on a TEXT AREA field to make sure it hasn't exceeded it's maximum
function textAreaTooLong(object_id,maxx)
{
	var thisObj = document.getElementById(object_id);
	var theTxt = thisObj.value;
	var txtLen = theTxt.length;
	if(txtLen >= maxx) 
	{ thisObj.value = theTxt.substr(0,maxx); }
}