function show_overlay(){
	overlay = new Element('div', { id: 'overlay', styles: { zIndex: 1, 'height':$('site').getCoordinates().height, 'width':'100%', 'background-color': '#000000', 'opacity':0.8 } });
	overlay.inject(document.body, 'top');
}
function remove_overlay(){
	if($('overlay')){ $('overlay').destroy(); }
}

function clear_responses(){
	$('geo_x').set('value', '');
	$('geo_y').set('value', '');
	$('region').set('value', '');
	$('departement').set('value', '');
	$('pays').set('value', '');
	$('affiche_resultat').innerHTML='';
	$('affiche_resultat').setStyle('display','none');
	remove_overlay();
}
function getAllInfos(response){
	clear_responses();
	show_overlay();http://www.alphabounce.com/
	if (response && response.Status.code == 200) {
		$each(response.Placemark, function(value){
			var ct = value.AddressDetails.Country;
			var ad = ct.AdministrativeArea;
			if(ct && value.Point && value.Point.coordinates[1] && ct.CountryName && ad && ad.SubAdministrativeArea && ad.SubAdministrativeArea.Locality && ad.SubAdministrativeArea.Locality.LocalityName){
				var obj = {
					ville:ad.SubAdministrativeArea.Locality.LocalityName,
					departement:(ad.SubAdministrativeArea && ad.SubAdministrativeArea.SubAdministrativeAreaName)?ad.SubAdministrativeArea.SubAdministrativeAreaName:'',
					region:(ad.AdministrativeAreaName?ad.AdministrativeAreaName:''),
					pays:ct.CountryName,
					x:value.Point.coordinates[1],
					y:value.Point.coordinates[0]
				};
				afficheChoix(obj);
			}
		})
	}
}

function afficheChoix(place){
	var html = place.ville+'  (<em>'+place.departement+' '+place.region+'</em>) en <strong>'+place.pays+'</strong>';
	var line = new Element('div', { 'class':'choix_ville', 'html':html, 'events':{ 'click': function(){ selChoix(line);  }, 'mouseleave':function(){ line.removeClass('survol') }, 'mouseenter':function(){ line.addClass('survol') } }  });
	line.place = place;
	var radio = new Element('input', { 'type':'radio' });
	radio.inject(line, 'top');
	line.injectInside($('affiche_resultat'));
	$('affiche_resultat').setStyle('display','');

}


function selChoix(obj){
	place = obj.place
	$('geo_x').set('value', place.x);
	$('geo_y').set('value', place.y);
	$('region').set('value', place.region);
	$('departement').set('value', place.departement);
	$('pays').set('value', place.pays);
	$('ville').set('value', place.ville);
	$('affiche_resultat').innerHTML = '';
	remove_overlay();
}
window.addEvent('domready', function(){
	$('affiche_resultat').setStyle('display','none');
})
