// JavaScript Document
/************************FUNCTIONS *************************
IsNumeric - Check whether the input is a number or a decimal point. Used on OnkeyUp method of the Text object Type.
IsOnlyNumber - Check whether the input is a numeric charater. Used on OnKeyUp method of the Text object Type.
checkYear - check if the Year informed is a valid year. If should be equal or lower than the current year. Used after the IsOnlyNumber check and called on OnBlur method.
bgr_color - Change the color of the background(require two parameters. Example:(Changing the color of a row:  <tr bgcolor="FFFFFF" onmouseover="bgr_color(this, 'e6e4cb')" onmouseout="bgr_color(this, 'FFFFFF')">
formatCurrency - Format a number to money format (1,000.00) pass the parameter "this.value" to the function
************************************************************/
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.value.length && IsNumber == true; i++) 
	  { 
	  Char = sText.value.charAt(i); 
	  if (ValidChars.indexOf(Char) == -1) 
		 {
		 alert("Only numbers or decimal point are allowed here");
		 var obj = eval("document.forms[0]." + sText.name);
		 obj.value = sText.value.substring(0, i);
		 
		 IsNumber = false;
		 }
	  }
   return IsNumber;
   
   }
   

function IsOnlyNumber(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.value.length && IsNumber == true; i++) 
	  { 
	  Char = sText.value.charAt(i); 
	  if (ValidChars.indexOf(Char) == -1) 
		 {
		 alert("Only numbers are allowed here");
		 sText.value = sText.value.substring(0, i);
		 
		 IsNumber = false;
		 }
	  }
   return IsNumber;
   
}

function checkYear(Field){
		var today = new Date(); // Initialize Date in raw form
		var year = today.getYear(); // Get the year	
		if(year < 2000){year = year+1900;}
		if(Field.value > year){
			alert("Invalid Year. The value should be " + year + " or lower.");
			Field.value = "";
			Field.focus();
			return false;
		}
		if(Field.value.length < 4){
			alert("Sorry, invalid year.");
			Field.value = "";
			Field.focus();
			return false;
		}
		return true;

}
   
   
function bgr_color(obj, color) {
	obj.style.backgroundColor=color;
}

/* Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents);
}
//  End -->

