document.observe('dom:loaded', function () {
	var select_country = $('select_country');
	if (select_country) {
		Event.observe(select_country, 'change', changeLocations, false);
	}
	var select_location = $('select_location');
	if (select_location) {
		Event.observe(select_location, 'change', changeLocationsSub, false);
	}
});

function changeLocations() {
	// disableLocationsSub();
	new Ajax.Updater('select_location', '/ajax/locations', { method: 'get', parameters: 'country='+$('select_country').value }); // , onComplete: disableLocationsSub
}

function changeLocationsSub() {
	var select_location_sub = $('select_location_sub');
	if (select_location_sub) {
		select_location_sub.enable();
	} else {
		return false;
	}

	var id_location = $F('select_location');
	if (id_location != '0') {
		new Ajax.Updater('select_location_sub', '/ajax/locations', { method: 'get', parameters: 'country='+$('select_country').value + '&location='+$('select_location').value });
	} else {
		disableLocationsSub();
	}
}

function disableLocationsSub() {
	var select_location_sub = $('select_location_sub');
	if (select_location_sub) {
		select_location_sub.selectedIndex = 0;
		select_location_sub.disable();
	}
}

