
function LTrim(str)
{
	if (str == "") return "";
	for ( var i = 0; i < str.length && str.charAt( i ) <= " "; i++ );
    return str.substring(i, str.length);
}

function RTrim(str)
{
	if (str == "") return "";
	var whitespace = new String(" \t\n\r");
	var s = new String(str);

	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) 
	{
		var i = s.length - 1;
		while (i >= 0 && whitespace.indexOf( s.charAt( i ) ) != -1) i--;
		s = s.substring(0, i+1);
	}
	return s;
}

function Trim(str)
{
	return RTrim(LTrim(str));
}

function testForEnter( btn )
{
	if (event.keyCode == 13) 
	{
		event.cancelBubble = true;				
		event.returnValue = false;
		
		if ( ! btn.disabled ) 
			btn.click( );
	}
}	

function ValidateTrustFields( )
{
	var separator = " \t\n";
	var result = new String( );
	for ( var i = 0; i < arguments.length; i++ )
	{
		var desc = arguments[ i ];
		var edt = arguments[ ++i ];
		var st = edt.value;
		var idx = -1;
		while( ( idx = st.indexOf( "<", idx + 1 ) ) >= 0 && idx < st.length - 1 )
		{
			if ( separator.indexOf( st.charAt( idx + 1 ) ) == -1 )
			{
				if( result.length == 0 )
				{
					edt.select( );
					edt.focus( );
				} else
					result = result.concat( ", " );
				result = result.concat( desc );						
				break;
			}
		}
	}
	return result;
}

function ValidateWebSafe( )
{
	var separator = " \t\n";
	for ( var i = 0; i < arguments.length; i++ )
	{
		var edt = arguments[ i ];
		var st = edt.value;
		var idx = 0;
		while( ( idx = st.indexOf( "<", idx + 1 ) ) >= 0 && idx < st.length - 1 )
		{
			if ( separator.indexOf( st.charAt( idx + 1 ) ) == -1 )
			{
				edt.value = "";
				break;
			}
		}
	}
}


