document.TimerMenu = new Array();

// all'evento load della pagina eseguo la preparazione dei menù
$(window).load(function () {
	$("ul.menu li").each(function() {
			var id = $(this).attr("id");
			$(this).hover(
				function() { CancellaTimer(id); MostraMenu(id); },
				function() { CreaTimer(id); }	
			);
			$(this).find("ul.sottoMenu").hover(
				function() { CancellaTimer(id); },
				function() { CreaTimer(id); }
			);
		});	
});

// funzioni che elaborano il menù e ne permettono la chiusura e l'apertura
function CancellaTimer(id) {
	if (document.TimerMenu[id] != null) {
		clearTimeout(document.TimerMenu[id]);
		document.TimerMenu[id] = null;
	}
}
function CreaTimer(id) {
	if (document.TimerMenu[id] != null)
		clearTimeout(document.TimerMenu[id]);
	document.TimerMenu[id] = setTimeout("NascondiMenu('"+id+"')", 500);
}
function NascondiMenu(id) {
	$("#"+id+" ul.sottoMenu").slideUp(500);	
}
function MostraMenu(id) {
	$("#"+id+" ul.sottoMenu").slideDown(500);	
}


// FUNZIONI PER IL CONTROLLO DEI FORM DI INVIO
function controllaForm(idForm) {
	var risposta = "";
	
	$("#"+idForm).find("input").each(function() {
		var input = $(this);
		if (input.attr("id").substr(0, 8) == "required" && input.val().length == 0)
			risposta += "\n - Il campo '" + input.attr("id").replace("required", "").replace(/_/g, " ") + "' non puo' essere vuoto";
	});
	
	if (risposta.length > 0) {
		alert("Si sono verificati i seguenti errori:" + risposta);
	} else
		$("#"+idForm).submit();
}
