

function fontSize(val){
	var size = 12 + (2 * val);
	obj = document.getElementById('body-id');
	obj.style.fontSize = size+'px';
}


function validaForm(theForm) {
	
	
	if (theForm.cognome.value.length < 2) {
		alert("Riempire il campo 'Cognome'.");
		theForm.cognome.focus();
		return false;
	}
	
	if (theForm.nome.value.length < 2) {
		alert("Riempire il campo 'Nome'.");
		theForm.nome.focus();
		return false;
	}

        if(!validaemail(theForm.email.value)) {
		alert("Inserire un indirizzo di e-mail valido.");
		theForm.email.focus();
		return false;
	}
	
	if (theForm.professione.value == 0) {
		alert("Selezionare la professione.");
		theForm.professione.focus();
		return false;
	}

        if (theForm.piva.value.length == 0 && theForm.codf.value.length == 0) {
		alert("Inserire almeno uno dei campi P.Iva e Cod.Fiscale.");		
		return false;
	}

        if (theForm.piva.value.length != 0) {
            if(theForm.piva.value.length < 11){
		alert("Il campo P.Iva deve contenere 11 caratteri.");
		theForm.piva.focus();
		return false;
            }
	}

        if (theForm.codf.value.length != 0) {
            if(theForm.codf.value.length < 16){
		alert("Il campoCod.Fiscale deve contenere 16 caratteri.");
		theForm.codf.focus();
		return false;
            }
	}

        if (theForm.via.value.length < 2) {
		alert("Riempire il campo 'Via'.");
		theForm.via.focus();
		return false;
	}

         if (theForm.citta.value.length < 2) {
		alert("Riempire il campo 'Citta'.");
		theForm.citta.focus();
		return false;
	}

         if (theForm.provincia.value.length < 2) {
		alert("Riempire il campo 'Provincia'.");
		theForm.provincia.focus();
		return false;
	}

         if (theForm.cap.value.length != 5) {
		alert("Riempire il campo 'C.a.p.' correttamente.");
		theForm.cap.focus();
		return false;
             
	}

        if (theForm.prefisso.value.length < 2) {
		alert("Riempire il campo 'Prefisso' correttamente.");
		theForm.prefisso.focus();
		return false;
	}

        if (theForm.telefono.value.length < 3) {
		alert("Riempire il campo 'Telefono' correttamente.");
		theForm.telefono.focus();
		return false;
	}
	
        if ((theForm.consenso2 != undefined && theForm.consenso2.checked) || (theForm.consensochk != undefined && !theForm.consensochk.checked)) {
		alert("Impossibile procedere senza il consenso al trattamento dei suoi dati personali.");
		return false;
	}

}


function validaemail(email) {
	if (email.indexOf('@')==-1) return false;
	
	var splitemail = email.split('@');
	
	if (splitemail[0].length == 0 || splitemail[0].length > 63) return false;
	
	if (splitemail[1].indexOf('.') == -1) return false;
	
	var validdomain = splitemail[1].split('.');
	
	if (validdomain[0].length == 0 || validdomain[0].length > 63) return false;
	
	return true;
}

