/****************************************************************************************************
Name:			ASTcommon_Trim_Function
Description:	Trim white space from a string.
History:
				Created: 03/19/2001	JC
				
Copyright(c) 2001, Vignette Corporation. All rights reserved.  
THIS PROGRAM IS AN UNPUBLISHED WORK AND TRADE SECRET OF THE COPYRIGHT HOLDER,  
AND DISTRIBUTED ONLY UNDER RESTRICTION.

No  part  of  this  program  may be used,  installed,  displayed,  reproduced, 
distributed or modified  without the express written consent  of the copyright
holder.

EXCEPT AS EXPLICITLY STATED  IN A WRITTEN  AGREEMENT BETWEEN  THE PARTIES, THE 
SOFTWARE IS PROVIDED AS-IS, WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY,  FITNESS FOR A PARTICULAR
PURPOSE, NONINFRINGEMENT, PERFORMANCE, AND QUALITY.
****************************************************************************************************/

function trim(arg,func) { // pass in a string object and trim right, left, or both (default)
	if (arg==null) return "";
	if (func==null) func="both";
	if (arg.length==0) return "";	
	var left=0, right=arg.length-1;	
	if (func=="left" || func=="both")
		for (;left < arg.length; left++) {
			c=arg.charAt(left);
			if(c!=" " && c!="\t" && c!="\n" && c!="\r") break;
		}
	if (func=="right" || func=="both")
		for (; right > left; right--) {
			c=arg.charAt(right);
			if(c!=" " && c!="\t" && c!="\n" && c!="\r") break;
		}
	return arg.slice(left,right+1);
}
