//
// Global.js
//
// This JavaScript library is included in every page and contains
// functions and prototypes that every page can use.
//----------------------------------------------------------------------
//		string.trim()
//		string.ltrim()
//		string.rtrim()
//		IsBlank( string )
//		IsNumeric( string )
//		IsValidEmail( string )
//----------------------------------------------------------------------


//
// Adds trim() method to strings to remove leading and trailing spaces.
//
String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/g,"");
}



//
// Adds ltrim() method to strings to remove leading spaces.
//
String.prototype.ltrim = function()
{
	return this.replace(/^\s+/,"");
}



//
// Adds rtrim() method to strings to remove trailing spaces.
//
String.prototype.rtrim = function()
{
	return this.replace(/\s+$/,"");
}



//
// Checks whether a string is blank or not.
//
function IsBlank( str )
{
	var result = true;
	
	if ( str != null && str != undefined )
	{
		if ( str.trim() != "" )
		{
			result = false;
		}
	}
	return result;
}



//
// Checks whether the input string is a number (including decimal values).
//
function IsNumeric(sText)
{
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++)
	{
		Char = sText.charAt(i);
		if ( ValidChars.indexOf(Char) == - 1)
		{
			IsNumber = false;
		}
	}
	return IsNumber;
}



//
// Checks whether the input string looks like a valid email address.
//
function IsValidEmail(str)
{
   return (str.lastIndexOf(".") > 1) && (str.indexOf("@") > 0);
}