//*****************************
//Funzioni per controllo campi*
//*****************************
function checkForm() {
	if (checkField("modulo","NOME_COGNOME","nome e cognome")) return;
	if (checkField("modulo","EMAIL","email")) return;
	if (checkEmail("modulo","EMAIL")) return;
	if (checkBox("modulo","TRATTAMENTO_DATI")) return;
	document.modulo.submit();
}
function checkRicerca() {
  	if (checkLength("ricerca","chiave",3)) return;
	document.ricerca.submit();
}
function checkRicercaAvanzata() {
	document.ricerca_avanzata.submit();
}
function checkField(numf,numc,nome) {
	var codstr=" ";
	var thischar;
	var cont=0;
	if (document.forms[numf].elements[numc].value=="") {
		showMsg("Inserire il campo obbligatorio "+nome.toUpperCase());
   		return true;
	}
	for (var i=0; i<document.forms[numf].elements[numc].value.length; i++) {
		thischar=document.forms[numf].elements[numc].value.substring(i,i+1);
		if (codstr.indexOf(thischar)<0) cont++;
	}
	if (cont==0) {
		showMsg("Inserire il campo obbligatorio "+nome.toUpperCase());
       	return true;
	}
	return false;
}
function checkEmail(numf,numc) {
	if (document.forms[numf].elements[numc].value.indexOf('@',0)==-1 || document.forms[numf].elements[numc].value.indexOf('.',0)==-1) {
		showMsg("L\'indirizzo EMAIL inserito non e\' valido");
		return true;
	}
	return false;
}
function checkBox(numf,numc) {
	if (document.forms[numf].elements[numc].checked==false) {
		showMsg("Non e\' stato dato il consenso al trattamento dei dati personali");
        return true;
	}
	return false;
}
function checkLength(numf,numc,min) {
    if (document.forms[numf].elements[numc].value.length<min) {
		showMsg("Per effettuare la ricerca inserire almeno "+min+" caratteri");
        return true;
	}
	return false;
}
function showMsg(x) {
   	alert("\nINFORMAZIONI INCOMPLETE:\n\n"+x+".");
}

//*************************
//Funzioni per focus campi*
//*************************
function colorOn(elemento,codcolor) {
	if(document.all) {
		elemento.style.backgroundColor=codcolor;
	} else {
		if(document.getElementById) { elemento.style.backgroundColor=codcolor; }
	}
}
function colorOff(elemento,codcolor) {
	if(document.all) {
		elemento.style.backgroundColor=codcolor;
	} else {
		if(document.getElementById) { elemento.style.backgroundColor=codcolor; }
	}
}

