function LTrim(str)
{
        var whitespace = new String(" \t\n\r ");
        var s = new String(str);
        if (whitespace.indexOf(s.charAt(0)) != -1)
		{
            var j=0, i = s.length;
            while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			{
                j++;
			}
            s = s.substring(j, i);
        }
        return s;
}

function RTrim(str)
{
        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 isEmail (sEmailAddress)
{
	var isEmail=/^\w(\.?[\w-])+@\w(\.?[\w-])+\.[a-z]{2,4}(\.[a-z]{2})?$/i;
	if (!isEmail.test(sEmailAddress))
	{
		return false;
	}
	else
	{
		return true;
	}
}

// Checks that the string supplied can be expressed as a number (float)
function isNumeric(strNumber)
{
	return (strNumber.search(/^(-|\+)?\d+(\.\d+)?$/) != -1);
}

// Checks that the string supplied can be expressed as an unsigned number (float)
function isUnsignedNumeric(strNumber)
{
	return (strNumber.search(/^\d+(\.\d+)?$/) != -1);
}

// Checks that the string supplied can be expressed as an integer
function isInteger(strInteger)
{
	return (strInteger.search(/^(-|\+)?\d+$/) != -1);
}

// Checks that the string supplied can be expressed as an unsigned integer
function isUnsignedInteger(strInteger)
{
	return (strInteger.search(/^\d+$/) != -1);
}

// Internal function. Returns 29 when a leap year, else 28
function daysInFebruary (year)
{ // 29 days in febr, when it's a leap year. Not with a century, unless dev. by 400
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

// Checks if a string is empty or NULL. Trims first
function isEmpty(s)
{   
	s = Trim(s)
	return ((s == null) || (s.length == 0))
}


// Checks if the three date elements together form a valid date
function isDate (year, month, day)
{
	if (isEmpty(year) || isNaN(year)) return false
	if (isEmpty(month) || isNaN(month)) return false
	if (isEmpty(day) || isNaN(day)) return false
	var longMonth
	var isFebruary
	longMonth = false
	isFebruary = false
	if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
	{
		longMonth = true;
	}
	if (month == 2)
	{
		isFebruary = true;
	}
	if (longMonth && day > 31) return false
	if (!longMonth && day > 30) return false
	if (isFebruary && day > daysInFebruary(year)) return false
	return true
}

