function set_region_options( country_obj, region_obj ) {
	if( region_obj.length > 0 ) {
		region_obj.selectedIndex = -1;
		for( var i = region_obj.length - 1; i >= 0; i-- ) {
			region_obj.options[i] = null;
		}
		region_obj.options[0] = new Option( 'Any region', '', false, true );
		region_obj.selectedIndex = -1;
	}

	if( country_obj.selectedIndex == 0 ) {
		return;
	}

	if( country_obj.selectedIndex >= 0 ) {
		var id = country_obj.options[ country_obj.selectedIndex ].value;

		if( country_regions[id].length == 0 ) {
			region_obj.options[0] = new Option( 'Any region', '', false, true );
			return;
		}

		var select_count = 0;
		for( var i = 0; i < country_obj.options.length; i++ ) {
			if( country_obj.options[i].selected ) {
				select_count++;
				if( select_count > 1 ) { break; }
			}
		}

		if( select_count == 1 ) {
			for( var i = 0; i < country_regions[id].length; i++ ) {
				var region_id = country_regions[id][i];
				region_obj.options[i + 1] = new Option( regions[region_id], region_id, false, false );
			}
			region_obj.selectedIndex = 0;
		}
	}
}

function numericSort(a,b)
{
    return a-b;
}

function regionSort(a,b)
{
	if (regions[a] < regions[b])
		return -1
	if (regions[a] > regions[b])
		return 1
	// a must be equal to b
		return 0
}

function set_super_region_options( super_region_obj, region_obj, toggle_visiblity ) {
	if( region_obj.length > 0 ) {
		region_obj.selectedIndex = -1;
		for( var i = region_obj.length - 1; i >= 0; i-- ) {
			region_obj.options[i] = null;
		}
		region_obj.options[0] = new Option( 'Any region', '', false, true );
		region_obj.selectedIndex = -1;
	}
	if( super_region_obj.selectedIndex <= 0 ) {
		if( toggle_visiblity ) {
			region_obj.style.visibility = 'hidden';
		}
		return;
	}

	var id = super_region_obj.options[ super_region_obj.selectedIndex ].value;
	if( ! super_regions[id] || super_regions[id].length == 0 ) {
		region_obj.options[0] = new Option( 'Any region', '', false, true );
		if( toggle_visiblity ) {
			region_obj.style.visibility = 'hidden';
		}
		return;
	}
	

	var select_count = 0;
	for( var i = 0; i < super_region_obj.options.length; i++ ) {
		if( super_region_obj.options[i].selected ) {
			select_count++;
			if( select_count > 1 ) { break; }
		}
	}

	if( select_count != 1 ) {
		if( toggle_visiblity ) {
			region_obj.style.visibility = 'hidden';
		}
		return;
	}
	
//	super_regions[id]=super_regions[id].sort(numericSort);
	super_regions[id]=super_regions[id].sort(regionSort);
	for( var i = 1; i < super_regions[id].length+1; i++ ) {
		var region_id = super_regions[id][i-1];
		region_obj.options[i] = new Option( regions[region_id], region_id, false, false );
	}
	region_obj.selectedIndex = 0;

	if( toggle_visiblity ) {
		region_obj.style.visibility = 'visible';
	}
}

