// JavaScript Document

function isInteger(s) {
  return (s.toString().search(/^-?[0-9]+$/) == 0);
}

function listenForEventIn(obj,type,func,bubble){
	if (obj.addEventListener){
		obj.addEventListener(type,func,bubble); // For Presto and Gecko
	}else if ( obj.attachEvent ){
		obj.attachEvent("on" + type, func); // For Trident
	}
}
function check(e){
	
	var k;
	if (e.charCode){
		k = e.charCode; // For Gecko
	}else if (e.keyCode){
		k = e.keyCode; // For Presto
	}

	if(!isInteger(String.fromCharCode(k)) && k!=8 && k!=9){			// 8 to allow backspace, 9 to allow tab	
		if ( e.preventDefault ){
			e.preventDefault(); // For Presto and Gecko
		}else{
			return false; // For Trident
		}				
	}
}
// Window.onload
function listenForDigit(fieldId){
	var n = document.getElementById(fieldId);

	if(typeof(n)=="object"){				
		if (window.addEventListener || window.attachEvent){
			listenForEventIn(n, "keypress", check, false); // For Presto and Gecko
		}else{
			listenForEventIn(n, "keydown", check, false); // For Trident
		}
	}
}
