/*
	utility.js
*/

// find the index of an element in a function
Array.prototype.indexof = function(myItem) {
	var result=-1;
	
	if ((this.length<1)||(arguments.length!=1))
	{
		return -1;
		exit;
	}
	
	for (i=0;i<this.length;i++) {
		if (this[i]==myItem) {
			result=i;
			break;
		}
	}
	return result;
	
	if (!Array.prototype.indexof)
	{
		Array.prototype.indexof=indexof;
	}
}


	
// Return string with leading and trailing whitespace removed
function trim( string ) {
	//return empty string if empty
	if ( string == "" ) {
		return string;
	}
	
	// find first non-whitespace character
	start = string.search( /\S/ );
	
	// return empty string if input is all whitespace
	if ( start == -1 ) {
		return "";
	}
	
	end = -1;
	
	// find last non-white-space charcter
	for ( i = (string.length-1); i >= 0; i-- ) {
		// if it is whitespace, continue
		if ( string.charAt( i ).search( /\s/ ) != -1 ) { 
			continue;
		}
		else {
			end = i + 1;
			break;
		}
	}
	
	return string.substring( start, end );
}
