$(document).ready(bakeca_send_form);

/*
 * Funzione che applica l'evento click sul bottone di invio form.
 * Costruisce l'url in base alla action del form e i campi selezionati.
 */
function bakeca_send_form() {
	
	$("div.bakeca-box-ricerca").each(function() {
		
		var myAction = $(this).find("form").attr("action");
		myAction = myAction.replace("http://","");
		
		$(this).find("input.button").click(function(e) {
			
			e.preventDefault();
			
			var what = $(this).parent().find(".what input").val();
			var where = $(this).parent().find(".where select").val();
			var city = $(this).parent().find(".city select").val();
			
			//alert(what + ' ' + where + ' ' + city);

			var myUrl = 'http://'+city+'.'+myAction+'/'+where+'-0';
			if(what && what!='') { 
				myUrl += '?'+what;
			}
			window.document.location = myUrl;

		});
		
		
	});
	
	

	
}
