function update_region_select() {
	var region_select   = document.getElementById( 'region_select'   );
	var district_select = document.getElementById( 'district_select' );

	if ( region_select.selectedIndex == 0 ) {
		_clear_district_select();
		_clear_suburb_select();
	}
	else {
		_clear_district_select();
		_clear_suburb_select();

		district_select.disabled = '';

		var region_id = region_select.options[region_select.selectedIndex].value;

		for ( var district_id in $regions[region_id] ) {
			if ( district_id == 'name' ) {
				continue;
			}

			var option   = document.createElement( 'option' );
			option.value = district_id;
			option.appendChild( document.createTextNode( $regions[region_id][district_id]['name'] ) );

			district_select.appendChild( option );
		}
	}
}

function update_district_select() {
	var region_select   = document.getElementById( 'region_select'   );
	var district_select = document.getElementById( 'district_select' );
	var suburb_select   = document.getElementById( 'suburb_select'   );

	if ( district_select.selectedIndex == 0 ) {
		_clear_suburb_select();
	}
	else {
		_clear_suburb_select();

		suburb_select.disabled = '';

		var region_id   = region_select.options[region_select.selectedIndex].value;
		var district_id = district_select.options[district_select.selectedIndex].value;

		for ( var suburb_id in $regions[region_id][district_id] ) {
			if ( suburb_id == 'name' ) {
				continue;
			}

			var option   = document.createElement( 'option' );
			option.value = suburb_id;
			option.appendChild( document.createTextNode( $regions[region_id][district_id][suburb_id] ) );

			suburb_select.appendChild( option );
		}
	}
}

function _clear_district_select() {
	var district_select      = document.getElementById( 'district_select' );
	district_select.disabled = 'disabled';

	while ( district_select.hasChildNodes() ) {
		district_select.removeChild( district_select.firstChild );
	}

	var option   = document.createElement( 'option' );
	option.value = 0;
	option.appendChild( document.createTextNode( 'Please select a district' ) );

	district_select.appendChild( option );
}

function _clear_suburb_select() {
	var suburb_select      = document.getElementById( 'suburb_select' );
	suburb_select.disabled = 'disabled';

	while ( suburb_select.hasChildNodes() ) {
		suburb_select.removeChild( suburb_select.firstChild );
	}

	var option   = document.createElement( 'option' );
	option.value = 0;
	option.appendChild( document.createTextNode( 'Please select a suburb' ) );
	
	suburb_select.appendChild( option );
}

