function numbersonly(e){
	var unicode=e.charCode? e.charCode : e.keyCode;
	if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
		if (unicode<48||unicode>57) { //if not a number
			return false; //disable key press
		}
	}
}

/*
function numbersonlyExt(e){
	var unicode=e.charCode? e.charCode : e.keyCode;
	if (unicode!=8 && unicode!=46 && unicode!=44){ //if the key isn't the backspace key (which we should allow), and the decimal, and the comma
		if (unicode<48||unicode>57) { //if not a number
			return false; //disable key press
		}
	}
}
*/

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);
return num;
}


//formcont.anual.value

function numbersonlyExt2(formItem){
	theVar = formItem.value;
	
	
	
	//alert (afterDecimal + ' ' + charsAfterDecimal );
	
	if (theVar.indexOf(".") > 0){ //the input has a decimal-- deal with it!
	
		var afterDecimal = theVar.substr(theVar.indexOf(".") + 1);
		var charsAfterDecimal = afterDecimal.length;
	
		if (charsAfterDecimal == 2){ //this means that someone entered something like 1.5B
			theVar = theVar.replace(".",",");
			
			theVar = theVar.replace(/b/i,"00,000,000");
			theVar = theVar.replace(/m/i,"00,000");
			theVar = theVar.replace(/k/i,"00");
		}
		else if (charsAfterDecimal == 3){ //this means that someone entered something like 1.25m
			theVar = theVar.replace(".",",");
			
			theVar = theVar.replace(/b/i,"0,000,000");
			theVar = theVar.replace(/m/i,"0,000");
			theVar = theVar.replace(/k/i,"0");
		}
		else if (charsAfterDecimal == 4){ //this means that someone entered something like 1.255m
			theVar = theVar.replace(".",",");
			
			theVar = theVar.replace(/b/i,",000,000");
			theVar = theVar.replace(/m/i,",000");
			theVar = theVar.replace(/k/i,"");
		}
	}
	else if (isNaN(theVar)) { //this means that someone entered something like 1m - it has no decimal but there must be a non-numerical character
		theVar = theVar.replace(/b/i,",000,000,000");
		theVar = theVar.replace(/m/i,",000,000");
		theVar = theVar.replace(/k/i,",000");
	}
	else { //maybe it's just a bunch of numbers that need formatting
		theVar = formatCurrency(theVar);
	}
	
	formItem.value = theVar;
}

function numbersonlyExt(e){
	var unicode=e.charCode? e.charCode : e.keyCode;
	if (unicode!=8 && unicode!=46 && unicode!=44 && unicode!=66 && unicode!=98 && unicode!=75 && unicode!=107 && unicode!=77 && unicode!=109){ //allow: backspace, decimal, comma, B, b, K, k, M, m
		if (unicode<48||unicode>57) { //if not a number
			return false; //disable key press
		}
	}
}
