/**
 * Gestion de la suggestion/correction ajax des villes (potentiellement multisaisie)
 *
 * @author Damien BENOIT <benoit@benchmark.fr>
 * @package parcours
 * @subpackage html_include
 * @version 1.00
 * @since 1.00 - 03/03/2008 Damien BENOIT <benoit@benchmark.fr> Création du fichier
 *
 *
 */

/**
 * A chaque modification du libellé d'une ville on vide la valeur des champs hidden
 */
var changementville = function(id) {
	$('#f_id_ville_'+id).val('');
	$('#f_code_postal_'+id).val('');

}

/**
* fonction callback réussit par defaut 
*/
var selectionnerVille = function(data) {

	/* on retrouve ici le parent dont on va pouvoir récuperer l'ID 
	* afin de regler le champs f_id_ville_n
	*/
	
	tlId = $(this).attr("v_id");
	
	toolTipSuppression($(this).attr('id'));
	$(this).attr('title','Ville valide');
	$(this).removeClass("classerreur");
	// trouver format generique "normal"
	$(this).css('color','#000000'); 
	$(this).css('font-weight','normal'); 
		
	nomVille = $(this).attr('id');
	nomVoisin = 'f_id_voisin'+tlId;
	nomQuartier = 'f_quartier_'+tlId;
	nomCp = 'f_code_postal_'+tlId;

	// on l'utilise pour régler le hidden correspondant
	$('#f_id_ville_'+tlId).val(data.id);

	// on règle aussi le code postal 
	$('#f_code_postal_'+tlId).val(data.code_postal);
	
	// on charge les quartiers correspondants si activé:
	if(inclusion_quartiers){$('#'+nomQuartier).load('/cgi/recherche/recherche_proposition_quartier.norevue.php?f_id_ville='+$('#'+nom_hidden_id+tlId).val()+'&f_index='+tlId).fadeIn();}
	
	// on recharge le nombre de voisins si activé:
	if(inclusion_voisins){$('#'+nomVoisin).load('/cgi/recherche/recherche_nombre_voisin_quartier.norevue.php?f_id_qt='+tlId).fadeIn();}
	javasacript_supplementaire(tlId);
};


/**
* fonction callback en echec par defaut 
*/

var villeInvalide = function(data)
{
	// récuperation de l'id
	tlId = $(this).attr("v_id");
	
	$('#f_id_ville_'+tlId).val('');
	
	// on n'agit que si le nom fait au moins 3 char
	if ($(this).val().length >= 3) {
		$(this).addClass("classerreur");
		$(this).attr('title','Ville non trouvée, merci de retenter');
		toolTip($(this).attr('id'),message_invalide);//

	}
};
