function editProperName( oText)
{
	var sText = oText.value;

	oText.value = sText.substr(0, 1).toUpperCase() + sText.substr(1).toLowerCase();
	
	return true;
}

function editMoney( oText)
{
	var decimalPosition;
	var dollars;
	var cents;
	var sText = oText.value;

	decimalPosition = sText.indexOf('.');
	
	if ( decimalPosition == 0)
	{
		dollars = "0";
		cents = sText.substr( decimalPosition + 1);
	}
	else if ( decimalPosition > 0)
	{
		dollars = sText.substr( 0, decimalPosition);
		cents = sText.substr( decimalPosition + 1);

		if (cents.length > 2)
		{
			cents = cents.substr( 0, 2);
		}
		else if (cents.length < 2)
		{
			cents = cents + "00".substr( 0, 2 - cents.length);
		}
	}
	else
	{
		dollars = sText;
		cents = "00";
	}
	
	oText.value = dollars + "." + cents;
	
	return true;
}

function isMoney( oText)
{
	var len = oText.value.length;
	var numbers = ".0123456789";
	var decimalPosition;
	var i;
	
	if (oText.value.indexOf('.') != oText.value.lastIndexOf('.'))
	{
		alert ( "Field must contain dollar amount.");
		oText.focus();
		oText.select();
		return false;
	}
	
	for (i = 0; i < len; i++)
	{
		if ((numbers.indexOf(oText.value.charAt(i))) < 0)
		{
			alert ( "Field must contain dollar amount.");
			oText.focus();
			oText.select();
			return false;
		}
	}

	decimalPosition = oText.value.indexOf('.');
	if (decimalPosition > 0)
	{
		if ((oText.value.length - (decimalPosition + 1)) > 2)
		{
			alert ( "Field must contain dollar amount.");
			oText.focus();
			oText.select();
			return false;
		}
	}
		
	return true;
}

function numericValue( sText)
{
	var len = sText.length;
	var numbers = "0123456789";
	var i;
	
	for (i = 0; i < len; i++)
	{
		if ((numbers.indexOf(sText.charAt(i))) < 0)
		{
			return false;
		}
	}
	
	return true;
}

function isNumeric( oText)
{
	if (! numericValue( oText.value))
	{
		alert ( "Field must be numeric.");
		oText.focus();
		oText.select();
		return false;
	}
	
	return true;
}

function isPhone( oText)
{
	var len = oText.value.length;
	var sText = oText.value;

	if (len != 12)
	{
		alert ( "Enter a valid phone number in the format of 999-999-9999.");
		oText.focus();
		oText.select();
		return false;
	}

	if ( (! numericValue( sText.substr( 0, 3))) ||
		 (sText.charAt(3) != "-") ||
		 (! numericValue( sText.substr( 4, 3))) ||
		 (sText.charAt(7) != "-") ||
		 (! numericValue( sText.substr( 8, 3))) )
	{
		alert ( "Enter a valid phone number in the format of 999-999-9999.");
		oText.focus();
		oText.select();
		return false;
	}

	return true;
}

function isEmail(oText)
{
	var strEmail = oText.value;
	
	if (! ((strEmail.indexOf(".") > 2) && (strEmail.indexOf("@") > 1)))
	{
		alert ( "Enter a valid Email address.");
		oText.focus();
		oText.select();
		return false;
	}

	return true;
}

function isURL(oText)
{
	var strURL = oText.value;
	var strRE = new RegExp("^http://|^https://");
	var arrResults = strURL.match( strRE);
	
	if (arrResults == null)
	{
		alert ( "Enter a valid URL in the format of http:\\your.website.com");
		oText.focus();
		oText.select();
		return false;
	}

	return true;
}

function isDate( oText)
{
	var len = oText.value.length;
	var sText = oText.value;
	var oToday = new Date();
	var arrDate = sText.split("/");

	if (arrDate.length != 3)
	{
		alert ( "Enter a valid date in the format of MM/DD/YYYY.");
		oText.focus();
		oText.select();
		return false;
	}

	if ( (! numericValue( arrDate[0])) ||
		 (! numericValue( arrDate[1])) ||
		 (! numericValue( arrDate[2])) )
	{
		alert ( "Enter a valid date in the format of MM/DD/YYYY.");
		oText.focus();
		oText.select();
		return false;
	}

	if ( ((arrDate[0] < 1) || (arrDate[0] > 12)) ||
		 ((arrDate[1] < 1) || (arrDate[1] > 31)) ||
		 ((arrDate[2] < oToday.getFullYear()) || (arrDate[2] > oToday.getFullYear() + 1)) )
	{
		alert ( "Enter a valid date in the format of MM/DD/YYYY.");
		oText.focus();
		oText.select();
		return false;
	}

	return true;
}

function isValidStringLen( oText, iMinLength, iMaxLength)
{
	var len = oText.value.length;
	
	if ((len == 0) && (iMinLength > 0))
	{
		alert ("Field is required.");
		oText.focus();
		oText.select();
		return false;
	}
	else if ((len < iMinLength) || (len > iMaxLength))
	{
		if (iMinLength != iMaxLength)
			alert ("Field must be between " + iMinLength + " and " + iMaxLength + " characters long.");
		else
			alert ("Field must be " + iMinLength + " characters long.");

		oText.focus();
		oText.select();
		return false;
	}
		
	return true;
}


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;       // Get length of string

      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 URLencode(sStr) 
{
	return escape(sStr).replace(/\+/g, '%2C').replace(/\"/g,'%22').replace(/\'/g, '%27');
}

function URLdecode(sStr) 
{
	return unescape(sStr).replace(/'%2C'/g, '\+').replace(/%22/g,'\"').replace(/%27/g, '\'');
}
