function validaCampoForm(form,campo,obbligatorio,tipoCampo){
	var campoform = eval("document."+form+"."+campo);
	var valorecampo = Trim(eval("document."+form+"."+campo+".value"));
	var campoerrore = "err_"+campo
	var err = ""
	if (valorecampo == "") {
		if (obbligatorio ==	"1") {
			err = "campo obbligatorio"	
		}
	} else {
		if (tipoCampo == 1) { // solo testo

		}
		if (tipoCampo == 2) { // codice fiscale
			var re = /^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/;
			var Codice=Trim(valorecampo.toUpperCase());
			if (re.test(Codice) == false) {
				err = "codice fiscale non corretto"
			}
		}
		if (tipoCampo == 3) { // numerico
			if (isNaN(valorecampo)) {
				err = "valore non corretto"
			}
		}
		if (tipoCampo == 4) { // email
		var re = /^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/;
			var Codice=Trim(valorecampo.toUpperCase());
			if (re.test(Codice) == false) {
				err = "email non corretta"
			}
		}
		if (tipoCampo == 5) { // data
			var re = /^(?=\d)(?:(?!(?:(?:0?[5-9]|1[0-4])(?:\.|-|\/)10(?:\.|-|\/)(?:1582))|(?:(?:0?[3-9]|1[0-3])(?:\.|-|\/)0?9(?:\.|-|\/)(?:1752)))(31(?!(?:\.|-|\/)(?:0?[2469]|11))|30(?!(?:\.|-|\/)0?2)|(?:29(?:(?!(?:\.|-|\/)0?2(?:\.|-|\/))|(?=\D0?2\D(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC))))))|2[0-8]|1\d|0?[1-9])([-.\/])(1[012]|(?:0?[1-9]))\2((?=(?:00(?:4[0-5]|[0-3]?\d)\x20BC)|(?:\d{4}(?:$|(?=\x20\d)\x20)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$/;
			if (re.test(valorecampo) == false) {
				err = "data non corretta"
			}
		}
		if (tipoCampo == 6) { // id(numerico > 0)
			if (isNaN(valorecampo)) {
				err = "valore non corretto"
			} else {
				if ((valorecampo == "0") && (obbligatorio == "1")) {err="campo obbligatorio"}
			}
		}
	}

	if (err != "") {
		if (flagvalidita == true) {
			eval("document."+form+"."+campo+".focus()");
		}
		flagvalidita=false
		if (!$(campoerrore)) {
			new Insertion.After(campoform, "<span class=\"alert_text_form\" id=\""+campoerrore+"\">"+err+"</span>");
		} else {
			Element.update(campoerrore,err)	
		}
	} else {
		if (!$(campoerrore) == false) {Element.remove(campoerrore)}
	}
}

function Trim(sString) {
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
return sString;
}
