	
$('categoria').addEvent('change', function() {
	
	$('tipologia').innerHTML = '';
	s = $('categoria').getSelected();
	
	if (s.get('value') == "0") {
		
		t = new Array("Tutte",
					  "Appartamento", 
					  "Attico", 
					  "Baita Chalet Trullo", 
					  "Bungalow", 
					  "Casa Bi Trifamiliare", 
					  "Casa indipendente", 
					  "Cantina Solaio", 
					  "Garage", 
					  "Immobile di prestigio", 
					  "Loft", 
					  "Mansarda", 
					  "Monolocale", 
					  "Nuova costruzione", 
					  "Porzione di casa", 
					  "Posto Barca", 
					  "Rustico Casale", 
					  "Terreno", 
					  "Terreno edificabile", 
					  "Terratetto Terracielo", 
					  "Villa", 
					  "Villetta a schiera");
	} else { 
		
		t = new Array("Tutte",
					  "Albergo", 
					  "Esercizio Licenza comm", 
					  "Azienda agricola", "Bar", 
					  "Capannone", 
					  "Cessazioni di aziende", 
					  "Garage", 
					  "Laboratorio", "Locale commerciale", 
					  "Magazzino", 
					  "Negozio",
					  "Nuova costruzione",
					  "Palazzo",
					  "Ristorante",
					  "Show room",
					  "Terreno agricolo",
					  "Terreno industriale",
					  "Ufficio");
	}
	
	for (i = 0; i < t.length; i++)
		//$('tipologia').outerHTML += '<option value="' + i + '">' + t[i] + '</option>'
		$('tipologia').options[i] = new Option(t[i], i); 
	
});

$('province').addEvent('change', function() {
	
	s = $('province').getSelected();
	$('comuni').load('/cities/view/' + s.get('value') + '/1');
});


function onRegione(regione) {
	
	$('sopra').setAttribute('src', '/img/' + regione + '_selected.gif');
}

function outRegione() {

	$('sopra').setAttribute('src', '/img/transparent.gif');
}

function onProvincia(provincia) {

	$('sopra').setAttribute('src', '/img/select_prov_' + provincia + '.gif');
}

function outProvincia() {
 
	$('sopra').setAttribute('src', '/img/transparent.gif');
}

function backItaly() {
  
	$('maps').load('/files/map/italia.html');
	
	$('comune').setStyle('display', 'none');
	$('autocomplete').setStyle('display', 'inherit');
}

function clickRegione(regione,id) {
 
	$('maps').load('/files/map/' + regione + '.html');
	$('comuni').load('/cities/all/' + id + '/1');
	$('province').load('/provinces/view/' + id);
	
	$('comune').setStyle('display', 'inherit');
	$('prov').setStyle('display', 'inherit');
	$('autocomplete').setStyle('display', 'none');
}

function clickProvincia(id) {
 
	$('comuni').load('/cities/view/' + id + '/1');
	Array.each($('province').getChildren(), function(el){
		if (el.value == id)
			el.selected = true;
	});
	$('selezionato').setStyle('background-image','url(/img/select_prov_' + prov[id] + '.gif)');
}

function foo() {
	
	if ($('HousesTypeVendita').checked) {
		
		tipo = 'vendita';
	
	} else if ($('HousesTypeAffitto').checked) {
		
		tipo = 'affitto';
	
	} else {
		
		tipo = 'affittovacanza';
	}
	
	s = $('categoria').getSelected();
	categoria = s.get('text');
	
	s = $('comuni').getSelected();
	
	try {
		
		if (s.get('value') == '') {
			
			cit = $('autoc').get('value');
			p = $('province').getSelected();
			
			if (cit != 'es. Roma') {
				city = $('autoc').get('value');
			
			} else if(p.get('value') != '') {
				
				city = 'provincia-' + p.get('text');
			
			} else {
			
				alert('Inserisci un comune o una provincia per la ricerca');
				return false;
			}
		}
		else
			city = s.get('text');
	} catch(e) {
		cit = $('autoc').get('value');
		
		if (cit != 'es. Roma')
			city = $('autoc').get('value');
		else {
			
			alert('Inserisci un comune o una provincia per la ricerca');
			return false;
		}
	}
	
	s = $('tipologia').getSelected();
	
	if (s.get('value') != 0)
		tipologia = s.get('text');
	else
		tipologia = 'case';
	
	optional = '';
	
	s = $('prezzo').getSelected();
	
	if (s.get('value') != 0)
		optional += '/euro' + s.get('value');
	
	s = $('mq').getSelected();
	
	if (s.get('value') != 0)
		optional += '/mq' + s.get('text');
	
	s = $('arredato').getSelected();
	
	if (s.get('value') != 0)
		optional += '/arredato' + s.get('value');
	
	s = $('prezzomax').getSelected();
	
	if (s.get('value') != 0)
		optional += '/max' + s.get('value');
	
	s = $('mqmax').getSelected();
	
	if (s.get('value') != 0)
		optional += '/dim' + s.get('text');
	
	var chknuovo = $('nuovo').checked;

	
	if (chknuovo)
		optional += '/nuovo';
	
	
	location.href = '/' + tipo + '/' + categoria + '/' + city + '/' + tipologia + optional;
	
	return false;
}


