<!--
// funzioni JavaScript per la convalida
// ogni funzione convalida(form) viene scritta dinamicamente dalla funzione PHP in base alle situazioni
// chiamando o meno determinate funzioni


function convalidaNumero(formElement){
	if (formElement.value=="" || (formElement.value!="0" && isNaN(parseInt(formElement.value))==false)) { return true; }
	else {
		alert("inserire un numero valido");
		formElement.select();
		return false;}
}


function convalidaGiorno(formElement){
	strGiorno=formElement.value
	if (strGiorno.charAt(0)=="0") {strGiorno=strGiorno.charAt(1)}
	if ((strGiorno=="") || ((isNaN(parseInt(strGiorno))==false)) && (1<=(parseInt(strGiorno)) && (parseInt(strGiorno))<=31)) {
		return true }
	else {
		alert("inserire un giorno valido");
		formElement.select();
		return false;}
}


function convalidaMese(formElement){
	strMese=formElement.value
	if (strMese.charAt(0)=="0") {strMese=strMese.charAt(1)}
	if ((strMese=="") || ((isNaN(parseInt(strMese))==false)) && (1<=(parseInt(strMese)) && (parseInt(strMese))<=12)) {
		return true }
	else {
		alert("inserire un mese valido");
		formElement.select();
		return false;}
}


function convalidaAnno(formElement){
	if ((formElement.value=="") || ((isNaN(parseInt(formElement.value))==false)) && ((parseInt(formElement.value))>=1900)) {
		return true }
	else {
		alert("inserire un anno valido");
		formElement.select();
		return false;}
}


function convalidaData(formElementGiorno, formElementMese, formElementAnno){
	// deve essere una data valida e completa
	if (convalidaGiorno(formElementGiorno) && convalidaMese(formElementMese) && convalidaAnno(formElementAnno) && ((formElementGiorno.value=="" && formElementMese.value=="" && formElementAnno.value=="") || (formElementGiorno.value!="" && formElementMese.value!="" && formElementAnno.value!="")))	{
		return true;}
	else {
		alert("Inserire una data corretta.");
		formElementGiorno.select();
		return false; }
}


function convalidaMail(formElement){
	re = new RegExp("^[_A-Z_a-z0-9-]+(\.[_A-Z_a-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*$")
	arrRe=re.exec(formElement.value)
	if (arrRe!=null || formElement.value=="") { return true; }
	else {
		alert("inserire un indirizzo valido");
		formElement.select();
		return false;}
}


function convalidaOrdineData(formElementGiorno, formElementMese, formElementAnno){
	// se uno specifica solo il giorno senza il mese e l'anno oppure solo il mese senza l'anno
	if (!convalidaGiorno(formElementGiorno) || !convalidaMese(formElementMese) || !convalidaAnno(formElementAnno) || (formElementGiorno.value!="" && formElementMese.value=="" && formElementAnno.value=="") || (formElementMese.value!="" && formElementAnno.value=="") || (formElementGiorno.value!="" && formElementMese.value=="" && formElementAnno.value!=""))
	{
	alert("Inserire giorno mese e anno, oppure solo mese e anno, oppure solo anno.");
	formElementGiorno.select();
	return false
	}
	else {
	return true
	}
}


function convalidaUP(formElement){
	// convalida nome utente e password, privi di spazi e caratteri strani
	re = new RegExp("^[A-Za-z0-9]{6,}$")
	arrRe=re.exec(formElement.value)
	if (arrRe!=null) { return true; }
	else {
		alert("inserire un dato valido, privo di spazi e di almeno sei lettere/cifre");
		formElement.select();
		return false;}
}

function convalida255(formElement){
	// convalida che il campo abbia meno di 255 caratteri
	if (formElement.value.length>255) {
		alert("campo '"+formElement.name+"' troppo lungo.\nRimuovere almeno " +(parseInt(formElement.value.length)-255)+" caratteri.");
		formElement.select();
		return false;}
	else {return true;}
}


function convalidaUrl(formElement){
	// convalida i campi con indirizzi http
	re = new RegExp("http://\.*")
	arrRe=re.exec(formElement.value)
	if (arrRe!=null || formElement.value=="") { return true; }
	else {
		alert("il campo '"+formElement.name+"' deve cominciare con http://");
		formElement.select();
		return false;}
}

function convalidaOre(formElement){
	// convalida le ore
	if (parseInt(formElement.value)>=0 && parseInt(formElement.value)<24) { return true; }
	else {
		alert("il campo '"+formElement.name+"' deve essere valido");
		formElement.select();
		return false;}
}

function convalidaMinuti(formElement){
	// convalida i minuti
	if (parseInt(formElement.value)>=0 && parseInt(formElement.value)<60) { return true; }
	else {
		alert("il campo '"+formElement.name+"' deve essere valido");
		formElement.select();
		return false;}
}

function convalidaOb(formElement){
	// convalida i campi obbligatori
	re = new RegExp("^[A-Za-z0-9]")
	arrRe=re.exec(formElement.value)
	if (arrRe!=null) { return true; }
	else {
		alert("campo '"+formElement.name+"' obbligatorio");
		formElement.select();
		return false;}
}

function controllaCheck(formElement){
	if (formElement.checked==false) {
		alert("Occorre esprimere il consenso per il trattamento dei dati personali");
//		formElement.checked=true;
		document.getElementById("etichettaAccetto").style.color="red";
	} else return true;
}


// -->
