//GESTIONNAIRE LOCATION
/**
 * CHANGEMENT DE LA VILLE
 */
	Event.observe(window,'load',function(e){
		//Observe city change status
		if ($('post_location'))Event.observe($('post_location'),'change',handleCityChange); // element to observer,event,callback function
		//Observe country change status
		if ($('country_post'))Event.observe($('country_post'),'change',handleCountryChange); // element to observer,event,callback function
	});
	
	
	/**
	 * Display country list by continent (given param)
	 * use effect
	 * @see journal
	 */
	function display_country(id){
		$('cont_country').setOpacity(0);
		$('cont_country').innerHTML=$('ct_list_cont_'+id).innerHTML;
		$('cont_country').fade({ duration: 0.3,from: 0, to: 1 });
	}
	
	
	//If post_location change => change post_location_id
	function handleCityChange(){$('post_location_id').value="";}
	
	//If country chang => city,long,lat must be empty
	function handleCountryChange(){
		if($F('country_post')!=country){
			$('post_location').value="";
			/*
			if(typeof(ville_completer)!='undefined'){ 
					ville_completer.options.defaultParams='country_post='+$F('country_post');
			}*/
			country = $F('country_post');
			//$('map_post_lat').value="";
			//$('map_post_long').value="";	
		}
	}
	
	//default country choice
	var country=false;
	//Hide/Display country select, save default country choice
	function change_country(){
		if($('ct_ct').getStyle('display')=='block')$('ct_ct').setStyle({display: 'none'});
		else $('ct_ct').setStyle({display: 'block'});
		country=$F('country_post');
	}
	// FIN DE CHANGEMENT DE PAYS

	/**
	 * MAJ city/lat/longi from autocomplete search
	 * return false
	 */
	function add_city(id,name,lat,longi){
		$('post_location_id').value=id.strip();
		$('post_location').value=name.strip().toLowerCase();
		$('map_post_lat').value=lat.strip();
		$('map_post_long').value=longi.strip();
		$('ct_list_city').setStyle({display: 'none'});
		if($('cityname')!=null){
			$('cityname').update(name.strip().toLowerCase().capitalize() );
		}
		if($('change_city')!=null){
			$('change_city').hide();
		}
		return false;
	}

	/*
	 * Fonction utilisé dans home et dans post pour rechercher une ville / a un pays
	 * @param $F('post_location') au moins les 3 premiers caractères de la ville
	 * @param $F('country_post') id du pays
	 * @return false / une liste de ville 
	 */
	function get_city_list() {
		/*if ($F('post_location').length>2)
		{*/$('post_location_id').value="";
			new Ajax.Request(URL_BASE + '/location/ajax_find_city/', {
				method: 'post',
				postBody: 'post_location='+$F('post_location')+"&country_post="+$F('country_post'),
				onLoading: function(t) {
					$('location_indicator').setStyle({display: 'block'});
				},
				onSuccess: function(transport) {
					$('ct_list_city').update(transport.responseText);
					$('ct_list_city').setStyle({display: 'block'});
					$('location_indicator').setStyle({display: 'none'});
				}
			});
			return false;
		/*}*/
	}
	//quick post view
	function location_xy(lx,ly,zoom){
		$("lx").value = lx;
		$("ly").value = ly;
	}			
//FIN GESTIONNAIRE LOCATION
