// JavaScript Document
var selected = false;
function initFormGusto4Salti() {
	if ($("#formGusto").html()) {
		resetFormGusto();
		setInterval(checkChangeSelect,100);
	}
}

function resetFormGusto() {
	$("select[name=primi]").parent().children("div").children("span").text($("select[name=primi] > option[value='']").text());
	$("select[name=il-forno-dello-chef]").parent().children("div").children("span").text($("select[name=il-forno-dello-chef] > option[value='']").text());
	$("select[name=sughetti]").parent().children("div").children("span").text($("select[name=sughetti] > option[value='']").text());
	$("select[name=secondi]").parent().children("div").children("span").text($("select[name=secondi] > option[value='']").text());
	$("select[name=contorni]").parent().children("div").children("span").text($("select[name=contorni] > option[value='']").text());
}

function checkChangeSelect() {
	if (selected == false) {
		var defaultPrimi = $("select[name=primi] > option[value='']").text();
		var valPrimi = $("select[name=primi]").parent().children("div").children("span").text();
		if (defaultPrimi != valPrimi) {
			var url = $("select[name=primi] > option").filter(function() {
				return $(this).text() == valPrimi;
			}).val();
			document.location.href = BASE_URL+url;
			selected = true;
		}
		
		var defaultForno = $("select[name=il-forno-dello-chef] > option[value='']").text();
		var valForno = $("select[name=il-forno-dello-chef]").parent().children("div").children("span").text();
		if (defaultForno != valForno) {
			var url = $("select[name=il-forno-dello-chef] > option").filter(function() {
				return $(this).text() == valForno;
			}).val();
			document.location.href = BASE_URL+url;
			selected = true;
		}
		
		var defaultSughetti = $("select[name=sughetti] > option[value='']").text();
		var valSughetti = $("select[name=sughetti]").parent().children("div").children("span").text();
		if (defaultSughetti != valSughetti) {
			var url = $("select[name=sughetti] > option").filter(function() {
				return $(this).text() == valSughetti;
			}).val();
			document.location.href = BASE_URL+url;
			selected = true;
		}
		
		var defaultSecondi = $("select[name=secondi] > option[value='']").text();
		var valSecondi = $("select[name=secondi]").parent().children("div").children("span").text();
		if (defaultSecondi != valSecondi) {
			var url = $("select[name=secondi] > option").filter(function() {
				return $(this).text() == valSecondi;
			}).val();
			document.location.href = BASE_URL+url;
			selected = true;
		}
		
		var defaultContorni = $("select[name=contorni] > option[value='']").text();
		var valContorni = $("select[name=contorni]").parent().children("div").children("span").text();
		if (defaultContorni != valContorni) {
			var url = $("select[name=contorni] > option").filter(function() {
				return $(this).text() == valContorni;
			}).val();
			document.location.href = BASE_URL+url;
			selected = true;
		}
	}
	
	
	
}	
