var	city_other_label = "Other >";
var cities_addOther  = false;
var brows_name = navigator.appName;


function toggleCityOtherObj(visible) {
	cityOtherObj  = document.getElementById('city_other');
	if (cityOtherObj) {
		cityOtherObj.style.display = visible ? 'block' : 'none';
	}
}


function changeRegion() {
	countryObj = document.getElementById('countryObj');
	regionObj  = document.getElementById('regionObj');
	cityObj  = document.getElementById('cityObj');
	_hf = document.getElementById('_hf');
	if (brows_name == "Microsoft Internet Explorer")
	{
		_hf.location.href = '/addon/geo.php?c=' + countryObj.value;
		}
	else {
		_hf.src = '/addon/geo.php?c=' + countryObj.value;
		}
	while (regionObj.options.length) {
		regionObj.options[0] = null;
	}
	while (cityObj.options.length) {
		cityObj.options[0] = null;
	}
	toggleCityOtherObj(0);
}

function setRegions(data) {
	regionObj  = document.getElementById('regionObj');
	regionObj.options.length = 0;
	regionObj.options[0] = new Option("Choisissez la région :", '0');
    if (data) {
   		for (i = 1; i <= data.length; i++){
   			regionObj.options[i] = new Option(data[i-1][1], data[i-1][0]);
   		}
    }
    toggleCityOtherObj(0);
}


function changeCity(addOther) {
	addOther = addOther ? 1 : 0;
	cities_addOther = addOther;
	regionObj = document.getElementById('regionObj');
	cityObj  = document.getElementById('cityObj');
	_hf = document.getElementById('_hf');
	if (brows_name == "Microsoft Internet Explorer")
	{
		_hf.location.href = '/addon/geo.php?r=' + regionObj.value;
		}
	else {
		_hf.src = '/addon/geo.php?r=' + regionObj.value;
		}
	while (cityObj.options.length) {
		cityObj.options[0] = null;
	}
}

function setCities(data) {
	cityObj  = document.getElementById('cityObj');
	cityObj.options.length = 0;
	cityObj.options[0] = new Option("Choisissez la ville :", '0');
    if (data) {
   		for (i = 1; i <= data.length; i++){
   			cityObj.options[i] = new Option(data[i-1][1], data[i-1][0]);
   		}
    }
    if (cities_addOther) {
    	cityObj.options[i] = new Option(city_other_label, '-1');
    }
    toggleCityOtherObj(0);
}


function checkOtherCity() {
	cityObj  = document.getElementById('cityObj');
	if (cityObj) {
		if (cityObj.value == -1)
		  	toggleCityOtherObj(1);
		else
			toggleCityOtherObj(0);
  	}
}