/******************************************************************************
 *	Function:		Utility Scripts
 *	Created:		06/11/2007
 *
 *	Purpose:		JavaScript library of enhanced text utility functions.
 *
 *	Functions:		
 *					textCounter
 *					trimAll
 *
*******************************************************************************
Date:				
Author:  			
Mod Description:	
******************************************************************************/

// ########################################################
// TEXTCOUNTER
// ########################################################
//	Function: 	textCounter()
//	Purpose:  	Counts the number of characters entered in a field object and 
//				displays remaining characters from the allotted amount.
//	Returns: 	remaining characters allotted
//	Arguements: field		- actual field name of the textarea
//				cntfield	- field showing the remaining characters
//				maxlimit	- number of characters to allow
// #################################################################################
/*
Dynamic Version by: Nannette Thacker
http://www.shiningstar.net
Original by :  Ronnie T. Moore
Web Site:  The JavaScript Source
Use one function for multiple text areas on a page
Limit the number of characters per textarea
*/
function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) 
		// if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	else
		// otherwise, update 'characters left' counter
		cntfield.value = maxlimit - field.value.length;
}

// #################################################################################
// TRIM ALL SPACES
// #################################################################################
// Function: 	trimAll()
// Author:		Steven Semrau
// Created:		06/11/2007
// Purpose:  	trims all leading and trailing spaces in a string
// Returns:		string stripped of spaces
// Arguements:	strValue - string value to be checked
// #################################################################################
function trimAll( strValue ) {		
	var objRegExp = /^(\s*)$/;
	//check for all spaces
	if(objRegExp.test(strValue)) {
		strValue = strValue.replace(objRegExp, '');
		if( strValue.length == 0) {
			return strValue;
		}
	}
	//check for leading & trailing spaces
	var objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
	if(objRegExp.test(strValue)) {
		//remove leading and trailing whitespace characters
		strValue = strValue.replace(objRegExp, '$2');
	}
	return strValue;
}	

