/*******************************************************************
*	Trim Prototype, this function eliminates the leading and 
*	trailing white spaces from a String.
*	To use: strValue.trim();
*******************************************************************/
	String.prototype.trim = function() { 
		return( this.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ); 
	}
/*******************************************************************
*	isEmpty fucntion returns true if the value of the parameter is
*	empty or null. Also returns an error Message depending on what
*	language is specified.
*******************************************************************/
	function isEmpty(objText, strLanguage) {
			if(objText.value.trim() == "") {
						alert(eval("msgArray_" + strLanguage)[objText.name]);
				objText.focus();
				return true;
			}
		return false;
	}
/*******************************************************************
*	isFloat fucntion returns true if the value of the parameter is
*	a valid flaoting point number. Also returns an error Message 
*	depending on what language is specified.
*******************************************************************/
	function isFloat(oInput, strLanguage) {
		var strNumber = oInput.value + "";

			if(strNumber.trim() == "") {
				alert(eval("msgArray_" + strLanguage)[oInput.name]);
				oInput.focus();
				return false;
			}

		var iDot = strNumber.indexOf(".");
				
			if(iDot != -1) {
					for(var i=0; i<iDot; i++)
						if (strNumber.charAt(i) < "0" || strNumber.charAt(i) > "9") {
							alert(eval("msgArray_" + strLanguage)[oInput.name]);
							oInput.focus();
							return false;
						}

					for(var i=iDot+1; i<strNumber.length; i++)
						if (strNumber.charAt(i) < "0" || strNumber.charAt(i) > "9") {
							alert(eval("msgArray_" + strLanguage)[oInput.name]);
							oInput.focus();
							return false;
						}
			}
			else {
					for(var i=0; i<strNumber.length; i++)
						if (strNumber.charAt(i) < "0" || strNumber.charAt(i) > "9") {
							alert(eval("msgArray_" + strLanguage)[oInput.name]);
							oInput.focus();
							return false;
						}
			}
		return true;
	}
/*******************************************************************
*	isDate_SP returns true if the paraemter is a valid string in
*	format MM/DD/YYYY. If not, it returns error messages in 
*	spanish
*******************************************************************/
	function isDate_SP(oInput) {
		var dateStr = oInput.value;
		var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;
		var matchArray = dateStr.match(datePat);
		
   			if (matchArray == null) {
				alert("Introduzca una fecha con el formato mm/dd/yyyy.");
				oInput.focus();
				return false;
			}
		
		iMonth	= matchArray[1];
		iDay	= matchArray[3];
		iYear	= matchArray[5];

			if (iMonth < 1 || iMonth > 12) {
				alert("El mes debe ser entre 01 y 12.");
				oInput.focus()
				return false;
			}

		    if (iDay < 1 || iDay > 31) {
				alert("El dia debe ser entre 01 y 31.");
				oInput.focus();
				return false;
			}

			if ((iMonth==4 || iMonth==6 || iMonth==9 || iMonth==11) && iDay==31) {
				alert("El mes " + iMonth + " no tiene 31 dias!")
				oInput.focus()
				return false;
			}

			if (iMonth == 2) {
				var isLeap = (iYear % 4 == 0 && (iYear % 100 != 0 || iYear % 400 == 0));
		
					if (iDay > 29 || (iDay==29 && !isLeap)) {
						alert("Febrero del " + iYear + " no tiene " + iDay + " dias!");
						oInput.focus();
						return false;
					}
			}
		
		return true;
	}
/*******************************************************************
*	isDate_EN returns true if the paraemter is a valid string in
*	format MM/DD/YYYY. If not, it returns error messages in 
*	spanish
*******************************************************************/
	function isDate_SP(oInput) {
		var dateStr = oInput.value;
		var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;
		var matchArray = dateStr.match(datePat);

   			if (matchArray == null) {
				alert("Type in a date in the format mm/dd/yyyy.");
				oInput.focus();
				return false;
			}

		iMonth	= matchArray[1];
		iDay	= matchArray[3];
		iYear	= matchArray[5];

			if (iMonth < 1 || iMonth > 12) {
				alert("The month must be a value between 01 and 12.");
				oInput.focus()
				return false;
			}

		    if (iDay < 1 || iDay > 31) {
				alert("The day must be a value between 01 and 31.");
				oInput.focus();
				return false;
			}

			if ((iMonth==4 || iMonth==6 || iMonth==9 || iMonth==11) && iDay==31) {
				alert("The month " + iMonth + " doesn\'t have 31 days!")
				oInput.focus()
				return false;
			}

			if (iMonth == 2) {
				var isLeap = (iYear % 4 == 0 && (iYear % 100 != 0 || iYear % 400 == 0));
		
					if (iDay > 29 || (iDay==29 && !isLeap)) {
						alert("Feebruary of " + iYear + " doesn't have " + iDay + " days!");
						oInput.focus();
						return false;
					}
			}
		
		return true;
	}
