// auto-resize campi di testo
resizeIt = function(nomeCampo) {

	var str = $(nomeCampo).value;
	var cols = $(nomeCampo).cols;
	var linecount = 0;
	
	$A(str.split("\n")).each( function(l) {
				linecount += Math.ceil(l.length / cols); // take into account long lines
			}
		)
	
	$(nomeCampo).rows = linecount + 2;
};

// invio form ajax
function formToString(form){
	var str			= "";
	var elements	= form.elements;
	for(var i=0;i<elements.length;i++){
		var el = form.elements[i]; 
		if(el.tagName=="INPUT"){
			if(el.type.toUpperCase()=="RADIO"){
				if(!el.checked)
					continue;
			}
			if(el.type.toUpperCase()=="CHECKBOX"){
				if(!el.checked)
					continue;
			}
		}
		if(!el.name)
			continue;
		if(str!="")
			str += "&";
		str += el.name + "=" + form.elements[i].value;
	}
	return str;
}

// campo 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--;
		}
		
	}

}

// campo lettere
function lettere(campo){
	
	var chiffres = new RegExp("[a-zA-Z]"); /* 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--;
		}
		
	}

}

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