var ie = (navigator.appName.indexOf('Microsoft Internet Explorer') > -1);

function KeyPressImporto(importo,e) {
	var k;
	var valore = importo.value;
	if(ie) {
		k = e.keyCode;
	} else {
		k = e.which;
	}
	
	if( ((k > 47) && (k < 58)) || (k == 44) )
	{
		// Impediamo di digitare due volte la virgola
		if (k == 44) {
			if (importo.value.split(",").length == 2) return false;
		}
	
	}else {
		if((k != 8) && (k !=0)) return false;
	}
}

function KeyUpImporto(textinput,e) {
	var k;
	if(ie) {
		k = e.keyCode;
	} else {
		k = e.which;
	}

	if (k !=110 & k !=188 & k != 37) {
		valore=textinput.value.replace(/\./g,"");

		// Conserva i centesimi
		centesimi="";

		if (valore.indexOf(",")>-1) {
			espr=valore.split(",");
			centesimi=valore.substring(valore.indexOf(",")+1,valore.length+1);
			if (centesimi.length > 5){ centesimi = centesimi.substring(0,5); } 
			valore=valtomod;
		}
		else
		{
			if (valore.length > 13){ valore = valore.substring(0,14); } 
		}

		// Toglie gli zeri iniziali

		if (valore.length !=1 && valore.substr(0,1)=='0') {
			valore=valore.substr(1,valore.length-1);
		}

		temp="";
		// Aggiungi i punti
		while (valore.length>0) {
			if (valore.length>3) {
				temp="."+valore.substr(valore.length-3,3)+temp;
				valore=valore.substr(0,valore.length-3);
			} else {
				temp=valore+temp;
				valore="";
			}
		}
		if (centesimi!="") {
			temp=temp+","+centesimi;
		}

		textinput.value=temp;
	}
}

function KeyPressOnlyNum(e) {
var k;
if(ie) {
	k = e.keyCode;
} else {
	k = e.which;
}
if((k < 48) || (k > 57)) 
	{
		// Serve per abilitare le operazioni di modifica cancella	per browser diversi da IE
		if(k != 8 && k !=0) return false;				
	}
}
