// copia valore
function scrivi(nomeCampo, valore){

	var campo = document.getElementById(nomeCampo);
	campo.value = valore;
	
}

// conversione formato come PHP number_format
function number_format( number, decimals, dec_point, thousands_sep ) {
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // *     example 1: number_format(1234.5678, 2, '.', '');
    // *     returns 1: 1234.57
 
    var i, j;
 
    // input sanitation & defaults
    if( isNaN(decimals = Math.abs(decimals)) ){
        decimals = 2;
    }
    if( dec_point == undefined ){
        dec_point = ",";
    }
    if( thousands_sep == undefined ){
        thousands_sep = ".";
    }
 
    i = parseInt(number = (+number || 0).toFixed(decimals)) + "";
 
    if( (j = i.length) > 3 ){
        j = j % 3;
    } else{
        j = 0;
    }
 
    return (j ? i.substr(0, j) + thousands_sep : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep) + (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).slice(2) : "");
}

// copia valori
function scrivi2(nomeCampo, campoPrezzo, prezzo, valore){

	var campo = document.getElementById(nomeCampo);
	var costo = document.getElementById(campoPrezzo);
	campo.value = valore;
	costo.value = prezzo;
	
}

// cambia foto
function cambiaFoto(path){
	
	document.getElementById('foto').src = path;
	
}

// numeri telefonici e cellulari
function cell(campo){
	
	var chiffres = new RegExp("[+0-9]"); /* Modifier pour : var chiffres = new RegExp("[0-9]"); */
	var verif;
	var points = 0;

	for(x = 0; x < campo.value.length; x++){
		
		verif = chiffres.test(campo.value.charAt(x));
		
		if(campo.value.charAt(x) == "."){
			points++;
		}
		
		if(points > 1){
			verif = false; 
			points = 1;
		}
		
		if(verif == false){
			campo.value = campo.value.substr(0,x) + campo.value.substr(x+1,campo.value.length-x+1);
			x--;
		}
		
	}

}

// solo numeri
function numeri(campo){
	
	var chiffres = new RegExp("[0-9]"); /* Modifier pour : var chiffres = new RegExp("[0-9]"); */
	var verif;
	var points = 0;

	for(x = 0; x < campo.value.length; x++){
		
		verif = chiffres.test(campo.value.charAt(x));
		
		if(campo.value.charAt(x) == "."){
			points++;
		}
		
		if(points > 1){
			verif = false; 
			points = 1;
		}
		
		if(verif == false){
			campo.value = campo.value.substr(0,x) + campo.value.substr(x+1,campo.value.length-x+1);
			x--;
		}
		
	}

}
