/**
 * @author SECI
 */

if($('area')) $('area').observe('change', popola_1);
$('citta').observe('change', zone_citta);

function popola_1(e){
	var options = {
		method: 'post',
		postBody: 'id='+$F('area'),
		onSuccess: popola_2
	}

	new Ajax.Request('pubblico/_utility/area.php', options);
}

function popola_2(t){
	var sel = $('citta');
	selector_risorsa = sel;
	var opts = Element.descendants(sel);
	for (x = 0; x < opts.length; x++) 
		sel.remove(opts[x]);
		
	var opt = document.createElement('option');
	opt.value = "";
	opt.appendChild(document.createTextNode('Selezionare...'));
	sel.appendChild(opt);
		
	var cities = t.responseText.split(',');
	
	for (x = 0; x < cities.length; x++) {
		var opt = document.createElement('option');
		opt.value = cities[x];
		opt.appendChild(document.createTextNode(cities[x]));
		selector_risorsa.appendChild(opt);
	}
}

function zone_citta(e){
	if($F('citta') == 'Bari')
		$('zona_citta').show();
	else
		$('zona_citta').hide();
}
