
var locations = Array();
var locations1 = Array();


function load_location(regionID, locID, name, selected) {

	locations.push(Array(locID, regionID, name, selected));
	
}

function update_locations() {

	var region_select = document.getElementById('region_select');
	var location_select = document.getElementById('location_select');

	location_select.options.length = 0;

	var tmp_arr = locations.slice(0, locations.length);
	var val = region_select.options[region_select.options.selectedIndex].value;
	var i = 0;

	selectedIndex = 0;
	location_select.options[0] = new Option("-- Location --", 0);
	i = 1;
	while(tmp_arr.length > 0) {
		el = tmp_arr.pop();
		if(val == el[1]) {
			location_select.options[i] = new Option(el[2], el[0]);
			if(el[3] == 1) selectedIndex = i;
			i += 1;
		}
	}
	location_select.options.selectedIndex = selectedIndex;


}


function load_location1(countryID, locID, name, selected) {

	locations1.unshift(Array(locID, countryID, name, selected));
	
}

function update_locations1() {

	var country_select = document.getElementById('country_select');
	var location_select = document.getElementById('location_select');

	location_select.options.length = 0;

	var tmp_arr = locations1.slice(0, locations1.length);
	
//		SA
//	var val = country_select.options[country_select.options.selectedIndex].value;
	var val;
	if (country_select.type == "select-one") val = country_select.options[country_select.options.selectedIndex].value;
	else val = country_select.value;
//		SA

	var i = 0;

	selectedIndex = 0;
	location_select.options[0] = new Option("-- Location --", 0);
	i = 1;
	while(tmp_arr.length > 0) {
		el = tmp_arr.pop();
		if(val == el[1] || val == 0) {
			location_select.options[i] = new Option(el[2], el[0]);
			if(el[3] == 1) selectedIndex = i;
			i += 1;
		}
	}
	location_select.options.selectedIndex = selectedIndex;


}
