function formatoEuro(numero) {
	var signum = "";
	if(isNaN(numero) || (numero == "undefined") || (numero == "")) {
		numero = "0"; 
	} 
	var numero = numero.toString().replace(/\$|\,/g,'');
	numero = parseFloat(numero);
	if (numero < 0)
		signum = "-";
 
	numero = Math.abs(numero);
	numero = Math.floor(numero*100+0.50000000001);
	centesimi = numero%100;
	numero = Math.floor(numero/100).toString();
	if(centesimi<10)
		centesimi = "0" + centesimi;
	return (signum + numero + '.' + centesimi);

}

function formatoEuroPerChiNonSaLeggere(numero) {
	var pointPos = numero.indexOf(".");
	if (pointPos > -1){
		var lungh = numero.substring(pointPos + 1, numero.length);
			if(lungh.length > 2){
				numero = numero.replace(".", "") + ".00";
			}
	}else{
		numero = numero + ".00";
	}
	return numero;
}

function checkNotMail(src){
	if (src != ""){
		Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
   		return Filtro.test(src)
   	}
   	return true;
}

function isCodiceFiscale(codiceFiscale){
   var cf = codiceFiscale.toUpperCase();
   var cfReg = /^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/;
   if (!cfReg.test(cf))
      return false;
      
   var set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
   var s = 0;
   for( i = 1; i <= 13; i += 2 )
      s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
   for( i = 0; i <= 14; i += 2 )
      s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
   if ( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
      return false;
   return true;
}

function isNumeroIntero(e){

// NetScape
	if (!e) {
		var e = window.event;
	}
	
// NetScape
	if (e.which) 
		return isDigit(e.which);

// Explorer	
	if (e.keyCode)
		return isDigit(e.keyCode);
}

function isNumeroDecimale(e, src){
	if (!e) // NetScape
		e = window.event;
	
	var c = ''; // tasto premuto
	
	if (e.which) // NetScape
		c = e.which;
	
  	if (c == asciiCode(",")) { 
   		 var cambiaCarattere = document.createEvent("KeyEvents");
    	 cambiaCarattere.initKeyEvent("keypress", true, true, document.defaultView,  e.ctrlKey, e.altKey, e.shiftKey,  e.metaKey, 0, ".".charCodeAt(0)); 
   		 e.preventDefault(); 
    	 e.target.dispatchEvent(cambiaCarattere); 
 	 }
	
	if (e.keyCode) // Explorer
		c = e.keyCode;

	if(c == asciiCode(",")){
		e.keyCode = asciiCode(".");
		c = e.keyCode;
	}
	
	return caratterePermessoPerNumeroDecimale(c , src)
}

function caratterePermessoPerNumeroDecimale(c , src){
	if (src.value.indexOf('.') == -1){
		return isDigitOrDecimalSeparator(c);
	}
	return isDigit(c);
}

function isDigit(c){
	return (c >= asciiCode('0') && c <= asciiCode('9') || c == String.fromCharCode(String('8').charCodeAt(0)));
}

function isDigitOrDecimalSeparator(c){
	return (c == asciiCode('.')) || isDigit(c);
}

function asciiCode(c){
	return String(c).charCodeAt(0);
}

function parseIntParameter(value){
	return isNaN(parseInt(value, 10)) ? 0 : parseInt(value, 10);
}

function Conta(what, countSrc, limit){
	var visualizzaParole = objId(countSrc);
	var numeroMassimoParole = limit;
  var countParole = contaParole(what.value);

	var paroleRimanenti = (numeroMassimoParole - (parseIntParameter(countParole) - 1));
	
	if (countParole > numeroMassimoParole)
		what.value = what.value.substring(0, what.value.length - 1);

	visualizzaParole.innerHTML = paroleRimanenti;
}

function controllaTesto(evento, what, tag, numeroParole){
		if (evento.which != 8)/*NetScape*/
			what.value = replaceWord(what.value);
		contaTesto(what, tag, numeroParole);
		var paroleTesto = contaParole(what.value);
		if (paroleTesto > numeroParole){
			if (evento.which != 8)/*NetScape*/
				return false;
		}
}

function contaTesto(what, countSrc, limit){
		var visualizzaParole = objId(countSrc);
		var numeroMassimoParole = limit;
	  	var countParole = contaParole(what.value);
		var paroleRimanenti = (numeroMassimoParole - (parseIntParameter(countParole) - 1));
		visualizzaParole.innerHTML = paroleRimanenti;
}

function replaceWord(value){
		var result = value;
		result = result.replace(/[.]\s?/g, ". ");
		result = result.replace(/[,]\s?/g, ", ");
		result = result.replace(/[:]\s?/g, ": ");
		result = result.replace(/[;]\s?/g, ": ");
		result = result.replace(/[-]\s?/g, "- ");
		result = result.replace(/[']\s?/g, "' ");
		result = result.replace(/[\"]\s?/g, "\" ");
		result = result.replace(/[\\]\s?/g, "\\ ");
		result = result.replace(/[/]\s?/g, "/ ");
		result = result.replace(/[#]\s?/g, "# ");
		result = result.replace(/[_]\s?/g, "_ ");
		result = result.replace(/[@]\s?/g, "@ ");
		result = result.replace(/[*]\s?/g, "* ");
		result = result.replace(/[!]\s?/g, "! ");
		result = result.replace(/[?]\s?/g, "? ");
		return result;
}

function isEnter(evento){
	var code = null;
	if(evento.keyCode)
		code = evento.keyCode;
	else
		code = evento.which;
		
	return !(code == 13);
}