//*****************************
//Funzioni per controllo campi*
//*****************************
function checkForm() {
	if (checkField("modulo","NOME","nome")) return;
	if (checkField("modulo","EMAIL","email")) return;
	if (checkEmail("modulo","EMAIL")) return;
	if (checkField("modulo","OGGETTO","oggetto")) return;
    if (checkBox("modulo","TRATTAMENTO_DATI")) return;
	document.modulo.submit();
}
function checkRicerca() {
    if (checkLength("ricerca","chiave",3)) return;
	document.ricerca.submit();
}
function checkWikipedia() {
    if (checkLength("wikipedia","search",3)) return;
	document.wikipedia.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) {
    var temp=js_trim(document.forms[numf].elements[numc].value);
    if (temp.length<min) {
		showMsg("Per effettuare la ricerca inserire almeno "+min+" caratteri");
        return true;
	}
	return false;
}
function js_trim(str) {
    return str.replace(/\s+$|^\s+/g,"");
}
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; }
	}
}

//****************************
//Funzioni per finestre popup*
//****************************
function apri(strpage,strname,w,h,s) {
 	var psTop=(screen.height-h)/2;
	var psLeft=(screen.width-w)/2;
	if (document.all) {
	    var opzioni='width='+w+','+'height='+h+',top='+psTop+',left='+psLeft+',toolbar=0,location=0,status=0,menubar=0,scrollbars='+s+',resizable=0';
 		var dialogo=window.open(strpage,strname,opzioni);
    } else {
		var opzioni='width='+w+',height='+h+',top='+psTop+',left='+psLeft+',toolbar=0,location=0,status=0,menubar=0,scrollbars='+s+',resizable=0';
		var dialogo=window.open('',strname,opzioni);
		dialogo.moveTo(psLeft,psTop);
		dialogo.location.href=strpage;
	}
	return false;
}