	var filter;
	var provincia;

	function selectChange(select, stato)
	{
		if(stato == null)
		{
			stato = 2;
		}
		
		var nextSelectId = getNextSelectId(select);
		
		if(nextSelectId != "")
		{
			var nextSelect = document.getElementById(nextSelectId);
				
			if(nextSelect != null)
			{
				var continua = true;
				if(select.id.match(/^(.*)_categoria(\d{1})$/g) != null)
				{
					var sezione = RegExp.$1;
					
					if(nextSelectId == sezione + "_provincia")
					{
						filter = select.value;
						
						/*if(document.getElementById(sezione + "_categoria1") != null)
						{
							if(document.getElementById(sezione + "_categoria1").value > 0)
							{
								continua = false;
							}
						}*/
					}
					else
					{
						filter = null;
					}
				}
				
				if(continua)
				{
					var firstOptionId = nextSelect.options[0].value;
					var firstOptionValue = nextSelect.options[0].text;
					removeAllChilds(nextSelect);
					nextSelect.options.add(new Option(firstOptionValue, firstOptionId), 0);
				}
					
				if(select.value == "-1")
				{
					if(continua)
					{
						nextSelect.value = "-1";
						selectChange(nextSelect);
					}
				}
				else if(select.value > 0)
				{
					if(select.id.match(/^(.*)_categoria1$/g) != null)
					{
						var sezione = RegExp.$1;

						if(document.getElementById(sezione + "_provincia") != null)
						{
							var firstOptionId = document.getElementById(sezione + "_provincia").options[0].id;
							var firstOptionValue = document.getElementById(sezione + "_provincia").options[0].text;
							removeAllChilds(document.getElementById(sezione + "_provincia"));
							document.getElementById(sezione + "_provincia").options.add(new Option(firstOptionValue, firstOptionId), 0);
					
							if(filter != null)
							{
								// alert("1) " + "category=" + cfg['dove-andare-id'] + "&filter=" + select.value + "&language=it");
								
								makeRequest(cfg["root"] + "ajax/categories.php", "POST", "category=" + cfg['dove-andare-id'] + "&filter=" + filter + "&language=it", "selectChange-" + sezione + "_provincia");
							}
							else
							{
								// alert("2) " + "category=" + cfg['dove-andare-id'] + "&language=it");
								
								makeRequest(cfg["root"] + "ajax/categories.php", "POST", "category=" + cfg['dove-andare-id'] + "&language=it&notempty=true", "selectChange-" + sezione + "_provincia");
							}
							
							document.getElementById(sezione + "_provincia").style.display = "none";
							document.getElementById("loading_" + sezione + "_provincia").style.display = "block";
						}
					}
					else if(select.id.match(/^(.*)_categoria2$/g) != null && sezione == "attivita")
					{
						var sezione = RegExp.$1;
												
						if(document.getElementById(sezione + "_provincia") != null)
						{
							var firstOptionId = document.getElementById(sezione + "_provincia").options[0].id;
							var firstOptionValue = document.getElementById(sezione + "_provincia").options[0].text;
							removeAllChilds(document.getElementById(sezione + "_provincia"));
							document.getElementById(sezione + "_provincia").options.add(new Option(firstOptionValue, firstOptionId), 0);
							
							// alert("3) category=" + cfg['dove-andare-id'] + "&filter=" + select.value + "&language=it");
							makeRequest(cfg["root"] + "ajax/categories.php", "POST", "category=" + cfg['dove-andare-id'] + "&filter=" + filter + "&language=it", "selectChange-" + sezione + "_provincia");
							
							document.getElementById(sezione + "_provincia").style.display = "none";
							document.getElementById("loading_" + sezione + "_provincia").style.display = "block";
						}
					}
					else if(select.id.match(/^(.*)_provincia$/g) != null)
					{
						provincia = select.value;
					}
					
					if(nextSelectId.match(/^(.*)_comune$/g) != null)
					{
						if(filter != null)
						{
							// alert("5) category=" + provincia + "&filter=" + filter + "&language=it");
							
							makeRequest(cfg["root"] + "ajax/categories.php", "POST", "category=" + provincia + "&filter=" + filter + "&language=it", "selectChange-" + nextSelectId);
						}
						else
						{
							// alert("6) category=" + provincia + "&language=it");
							makeRequest(cfg["root"] + "ajax/categories.php", "POST", "category=" + provincia + "&language=it", "selectChange-" + nextSelectId);
						}
						
						nextSelect.style.display = "none";
						document.getElementById("loading_" + nextSelectId).style.display = "block";
					}
					else if(nextSelectId.match(/^(.*)_provincia$/g) == null)
					{
						if(RegExp.$1 == "destinazioni")
						{
							// alert("7) " + "category=" + select.value + "&language=it&stato=" + stato);
						
							makeRequest(cfg["root"] + "ajax/categories.php", "POST", "category=" + select.value + "&language=it&stato=" + stato, "selectChange-" + nextSelectId);
						}
						else
						{
							// alert("8) " + "category=" + select.value + "&language=it&stato=" + stato);
						
							makeRequest(cfg["root"] + "ajax/categories.php", "POST", "category=" + select.value + "&language=it&stato=" + stato + "&notempty=true", "selectChange-" + nextSelectId);
						}
						
						nextSelect.style.display = "none";
						document.getElementById("loading_" + nextSelectId).style.display = "block";
					}
				}
			}
		}
	}
	
	function getNextSelectId(select)
	{		
		if(select.id == "destinazioni_categoria1")
		{
			return "destinazioni_categoria2";
		}
		else if(select.id == "attivita_categoria1")
		{
			return "attivita_categoria2";
		}
		else if(select.id == "attivita_categoria2")
		{
			return "attivita_provincia";
		}
		else if(select.id == "attivita_provincia")
		{
			return "attivita_comune";
		}
		else if(select.id == "strutture_ricettive_categoria1")
		{
			return "strutture_ricettive_provincia";
		}
		else if(select.id == "strutture_ricettive_provincia")
		{
			return "strutture_ricettive_comune";
		}
		else if(select.id == "inserisci_struttura_provincia")
		{
			return "inserisci_struttura_comune";
		}
		
		return "";
	}
	
	function stateChange(http_request, action)
	{
		var request = http_request;
		
		if(request != null)
		{		
			if(request.readyState == 4)
			{
				var go = false;

				var response = request.responseXML;
				
				if(response != null)
				{
					error = getNodeValue(response, "error");
					
					if(error != null)
					{
						if(error == "-1")
						{
							go = true;
						}
						else
						{
							alert(error);
						}
					}
				}
				else
				{
					alert("Unable to get responseXML.");
				}

				if(go)
				{
					if(action.match(/^selectChange-(.*)$/g) != null)
					{
						var selectId = RegExp.$1;
						var select = document.getElementById(selectId);
						
						if(select != null)
						{
							var records = getNode(response, "subcategories");

							if(records != null)
							{
								var subcategories = records.getElementsByTagName('subcategory');
								var id;
								var title;
								
								if(subcategories.length > 0)
								{								
									for(var i = 0; i < subcategories.length; i++)
									{
										id = getNodeValue(subcategories[i], "id", false);
										title = getNodeValue(subcategories[i], "title", false);
										
										if(id != null && title != null)
										{
											select.options.add(new Option(title, id), select.options.length);
										}
									}
								}
							}
							
							select.style.display = "block";
							document.getElementById("loading_" + selectId).style.display = "none";
						}
					}
				}
			}
		}
		else
		{
			alert("Unable to get request.");
		}
	}