/**
* Page		: notation.js
* Contenu	: Code javascript pour le système de notation
* Date		: 15/02/11
* @author	Gael Sauvanet
* @version	1.0
*/

var mode_colonne_droite = 1; 	// 1 feuille de route, 2 notation
var layerNotation;		// Couche contenant les informations de notations
var layerSelection;		// Couche pour mettre en évidence le tronçon sélectionné
var controlClick;		// Contrôler le clic sur la carte

var listeTroncons = [];
var nbTroncons = 0;
var tronconSelectionne = -1;
var modeSelection = 1;		// Mode de sélection de tronçons, 0 = par tronçons individuels, 1 = par rue (basé sur le nom)
var peutSupprimerNote = 0;

OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {                
	defaultHandlerOptions: {
	    'single': true,
	    'double': false,
	    'pixelTolerance': 0,
	    'stopSingle': false,
	    'stopDouble': false
	},

	initialize: function(options) {
	    this.handlerOptions = OpenLayers.Util.extend(
		{}, this.defaultHandlerOptions
	    );
	    OpenLayers.Control.prototype.initialize.apply(
		this, arguments
	    ); 
	    this.handler = new OpenLayers.Handler.Click(
		this, {
		    'click': this.trigger
		}, this.handlerOptions
	    );
	}, 

	trigger: function(e) {
		if(connecte)
		{
			cacherAstuce();
		    	var lonlat = MToLonLat(map.getLonLatFromViewPortPx(e.xy));
			OpenLayers.loadURL(URL_BASE_SITEWEB+DOSSIER_SITEWEB+'get_troncon.php?lon='+lonlat.lon+'&lat='+lonlat.lat+"&parVoie="+modeSelection, {}, null, onLoadTroncon, onLoadFailedTroncon);
		}
	}

});

/**
 * Initialisation du mode de notation
 */
function initialiserModeNotation()
{
	// Gestion
	$j(function() {
	    $j( "#radioSelection" ).buttonset();
	});
	$j(function() {
		$j( "#radioMode" ).buttonset();
	});
	$j('#radioModeItineraire').click(function(){
		afficherNotation(1);return false;});
	$j('#radioModeOSB').click(function(){
		afficherNotation(3);return false;});
	if(ZONE_MODE_NOTATION)
		$j('#radioModeNotation').click(function(){
			afficherNotation(2);return false;});
	if(ZONE_MODE_NOTATION)
		$j('#radioModeBalade').click(function(){
			afficherNotation(4);return false;});
	if(ZONE_MODE_CIRCUITS)
		$j('#radioModeCircuits').click(function(){
			afficherNotation(5);return false;});
	if(ZONE_MODE_ITINERAIRES_TOURISTIQUES)
		$j('#radioModeTouristique').click(function(){
			afficherNotation(6);return false;});
	
	if(ZONE_MODE_NOTATION)
	{
		controlClick = new OpenLayers.Control.Click();
		map.addControl(controlClick);
		
		// Création de la couche des informations de notation
		layerNotation = new OpenLayers.Layer.Vector("Notation");
		layerNotation.displayInLayerSwitcher = false;
		map.addLayer(layerNotation);
		layerNotation.setOpacity(0.4);
	
		layerSelection = new OpenLayers.Layer.Vector("Troncon sélectionné");
		layerSelection.displayInLayerSwitcher = false;
		map.addLayer(layerSelection);
		layerSelection.setOpacity(0.5);
		
		$j('#radioSelectionTroncons').click(function(){
			modeSelection = 0;return false;});
		$j('#radioSelectionVoies').click(function(){
			modeSelection = 1;return false;});
	}
	
	// Couche et contrôle OpenStreetBugs
	osbLayer = new OpenLayers.Layer.OpenStreetBugs("Erreurs sur la carte");
	osbLayer.setVisibility(false);
	osbLayer.displayInLayerSwitcher = false;
	
	osbControl = new OpenLayers.Control.OpenStreetBugs(osbLayer); // osbLayer is an instance of OpenLayers.Layer.OpenStreetBugs, see above
	map.addControl(osbControl); // map is your instance of OpenLayers.Map
}

/**
 * Afficher la colonne de notation
 */
function afficherNotation(mode) {
	if(!connecte && mode == 2)
	{
		messageModal("Vous devez vous connecter pour accéder à la notation des voies.");
		return;
	}
	cacherAstuce();
	var mode_colonne_droite_eq = mode_colonne_droite == 6 ? 1 : mode_colonne_droite;
	var mode_eq = mode == 6 ? 1 : mode;
	var afficherBoutonPartager = [0,1,1,0,1,0,1];
	var afficherBoutonImprimer = [0,1,0,0,1,0,1];
	if(mode_colonne_droite_eq != mode_eq)
	{
		// Désactivation de l'onglet courant
		if(mode_colonne_droite_eq == 1)
		{
			if(ZONE_POI)layerPOI.setVisibility(false);
			if(ZONE_VLS){layerVLS.setVisibility(false);layerVLS.displayInLayerSwitcher = false;}
			if(ZONE_MODE_EVENEMENTS){layerPOIs.setVisibility(false);layerPOIs.displayInLayerSwitcher = false;}
			if(ZONE_TRAVAUX){layerTram.setVisibility(false);;layerTram.displayInLayerSwitcher = false;}
			if(ZONE_TRAVAUX)
			{
				layerTram.setVisibility(false);
				document.formTravaux.afficher.checked = false;
			}
			layerMarkers.setVisibility(false);
			for(i = 1; i < layerItineraires.length; i++)
			{
			    layerItineraires[i].setVisibility(false);
			}

			controlDrag.deactivate();
			$j('#fdr').hide();
			$j('#calcul_itineraire').hide();
			$j('#map').disableContextMenu();
			$j('#boutonNaviguerFDR').hide();
			gestionnaireCouchesPOI.desactiver();
			marqueurPoint.cacher();
		}
		else if(mode_colonne_droite_eq == 2)
		{
			$j('#notation').hide();
			$j('#notation_contenu').hide();
			controlClick.deactivate();
			layerNotation.setVisibility(false);
			layerSelection.setVisibility(false);
			layerCyclabiliteUtilisateur.setVisibility(false);
			$j("#cacherfeuille").show();
			feuille_visible = false;switchfeuille();
		}
		else if(mode_colonne_droite_eq == 3)
		{
			osbControl.deactivate();
			osbLayer.setVisibility(false);
			map.removeLayer(osbLayer);
			$j("#osb_contenu").hide();
			
			$j("#cacherfeuille").show();
			feuille_visible = false;switchfeuille();
		}
		//Initialisation de l'onglet Balade dans le "ui-buttonset"
		else if(mode_colonne_droite_eq == 4)
		{
			layerPOI.setVisibility(false);
			$j('#fdr').hide();
			$j('#balade').hide();
			$j('#creerBalade').hide();
			$j('#calcul_itineraire').hide();
			$j('#balades_contenu').hide();		//pour cacher l'accordian balade
			//$j('#map').disableContextMenu();
			//$j('#map2').disableContextMenu();
			$j("#cacherfeuille").show();
			feuille_visible = false;switchfeuille();
			layerBaladeTrace.removeAllFeatures();
			layerPOIsBalades.removeAllFeatures();
			layerListeBalades.setVisibility(false);
			gestionnaireCouchesPOI.desactiver();
		}
		else if(mode_colonne_droite_eq == 5)
		{
			$j("#cacherfeuille").show();
			feuille_visible = false;switchfeuille();
			gestionnaireCouchesPOI.desactiver();
			$j("#circuits_contenu").hide();
			layerCircuits.setVisibility(false);
			layerVisuCircuit.setVisibility(false);
			layerEnsembleCircuit.setVisibility(false);
		}
		// Cofigurer pour le nouvel onglet
		if(mode_eq == 1)
		{
			$j('#fdr').show();
			$j('#calcul_itineraire').show();
			if(ZONE_POI)majSourcePOI();
			if(ZONE_VLS){layerVLS.displayInLayerSwitcher = true;}
			if(ZONE_MODE_EVENEMENTS){layerPOIs.displayInLayerSwitcher = true;}
			if(ZONE_TRAVAUX){layerTram.displayInLayerSwitcher = true;}
			if(ZONE_TRAVAUX)
			{
				layerTram.setVisibility(document.formTravaux.afficher.checked);
			}
			layerMarkers.setVisibility(true);
			for(i = 1; i < layerItineraires.length; i++)
			{
			    layerItineraires[i].setVisibility(true);
			}
			menuContextuelItineraire();
			$j('#map').enableContextMenu();
			if(ZONE_VLS){layerVLS.displayInLayerSwitcher = true;}
			if(ZONE_MODE_EVENEMENTS){layerPOIs.displayInLayerSwitcher = true;}
			if(ZONE_TRAVAUX){layerTram.displayInLayerSwitcher = true;}
			controlDrag.activate();
			gestionnaireCouchesPOI.activer();
			$j('#boutonNaviguerFDR').show();
			marqueurPoint.montrer();
		}
		else if(mode_eq == 2)
		{
			$j('#notation').show();
			$j('#notation_contenu').show();
			$j('#notation_selection').accordion({
				fillSpace: true
			});
			layerNotation.setVisibility(true);
			layerSelection.setVisibility(true);
			layerCyclabiliteUtilisateur.setVisibility(true);
			// Si aucun tronçon sélectionné, on cache l'accordéon
			if(nbTroncons == 0)
				$j('#notation_accordion').hide();
			
			$j("#cacherfeuille").hide();
			feuille_visible = listeTroncons.length == 0;switchfeuille();
			
			controlClick.activate();
			voirAstuce(1);
		}
		else if(mode_eq == 3)
		{
			map.addLayer(osbLayer);
			if(connecte)
				osbLayer.username = NOM_UTILISATEUR + " via Géovélo";
			else
				osbLayer.username = "Utilisateur anonyme via Géovélo";
			osbLayer.setVisibility(true);
			
			osbControl.activate();
			
			$j('#osb_accordion').accordion({
				fillSpace: true
			});
			$j("#osb_contenu").show();
			
			$j("#cacherfeuille").hide();
			feuille_visible = true;switchfeuille();
		}
		//Configuration de l'onglet Balade dans le "ui-buttonset"
		else if(mode_eq == 4)
		{
			// on affiche la liste des balades si on n'a pas affaire à un permalien balade
			chargerListeBalade();
			map.addLayer(layerPOIsBalades);
			map.addLayer(layerBaladeTrace);
			layerBaladeTrace.removeAllFeatures();
			layerPOIsBalades.removeAllFeatures();
			$j('#balades_contenu').show();
			$j('#balades_affichage').accordion({
				fillSpace: true
			});
			$j('#liste_balades').accordion();
			layerBaladeTrace.setVisibility(true);
			layerPOIsBalades.setVisibility(true);
			feuille_visible = true;switchfeuille();
			gestionnaireCouchesPOI.activer();
			voirAstuce(2);
		}
		else if(mode_eq == 5)
		{
			debutChargement();
			$j("#cacherfeuille").hide();
			feuille_visible = true;switchfeuille();
			chargerCircuits();
			gestionnaireCouchesPOI.activer();
			$j("#circuits_contenu").show();
		}
	}
	if(afficherBoutonPartager[mode])$j("#boutonPartagerNotation").show(); else $j("#boutonPartagerNotation").hide();
	if(afficherBoutonImprimer[mode])$j("#boutonImprimer").show(); else $j("#boutonImprimer").hide();
	if(mode_colonne_droite == 6 && mode == 1 || mode_colonne_droite == 1 && mode == 6)
	{
		if(mode == 6)voirAstuce(3);
		swapItineraire();
	}
	mode_colonne_droite = mode;
	if(mode_eq == 1)
	{
		maj_affichageFDR();
		if(mode_colonne_droite == 6)
		{
			$j("#img-bouton-poi").hide();
			layerPOI.protocol.options.url = "get_poi.php?types=gare,chateau,religieux,monument";
			layerPOI.setVisibility(true);
			layerPOI.refresh();
		}
		else
		{
			majSourcePOI();
			$j("#img-bouton-poi").show();
		}
	}
	if(ZONE_MODE_TRAIN)
	{
		if(typeRequete != 1){changeTypeRequete(1);$j("#radioTR1").attr('checked',true);}
		if(mode_colonne_droite == 6)$j("#zone-option-train").hide(); else $j("#zone-option-train").show();
	}
}

/**
 * Supprimer tous les tronçons sélectionnés
 */
function suppressionListeTroncons()
{
	layerNotation.removeAllFeatures();
	layerSelection.removeAllFeatures();
	nbTroncons = 0;
	listeTroncons = [];
	$j('#notation_table > tbody').empty();
	$j('#notation_vider').hide();
	$j('#notation_accordion').hide();
	feuille_visible = true;switchfeuille();
}

/**
 * Essaye de supprimer un tronçon
 */
function suppressionTroncon(numero)
{
	var troncon_existant = array_search(numero, listeTroncons)
	if(troncon_existant > -1)	// Si le tronçon existe
	{
		// Si le tronçon n'était pas sélectionné, on le sélectionne
		if(numero != tronconSelectionne)
			montrerTroncon(numero,false);
		// Sinon on supprime le tronçon
		else
		{
			montrerTronconOut();
			layerNotation.removeFeatures(listeTroncons[troncon_existant].geom);

			listeTroncons[troncon_existant].ligne.remove();
			update_rows();

			listeTroncons = middlepop(listeTroncons,troncon_existant);
			nbTroncons--;
			if(nbTroncons <= 0) {
				$j('#notation_vider').hide();
				$j('#notation_accordion').hide();
				feuille_visible = true;switchfeuille();
			}
		}
		return true;
	}

	return false;
}

function update_rows()
{
    $j("#notation_table > tbody > tr:even").css("background-color", "#e4f0b4");
    $j("#notation_table > tbody > tr:odd").css("background-color", "#ffffff");
}

/**
 * Montrer un tronçon
 * @param numero numéro de troncon dans OSM way_id
 * @param recentrer booléen spécifiant s'il faut centrer la vue sur le tronçon
 */
function montrerTroncon(numero,recentrer)
{
	montrerTronconOut();
	var troncon_existant = array_search(numero, listeTroncons);
	if(troncon_existant > -1)
	{
		tronconSelectionne = numero;

		$j("#"+tronconSelectionne).css("font-weight","bold");

		if(recentrer)map.panTo(listeTroncons[troncon_existant].geom.geometry.getBounds().getCenterLonLat());

		var objetGeo1 = listeTroncons[troncon_existant].geom.geometry.clone();
		var objetGeo2 = listeTroncons[troncon_existant].geom.geometry.clone();
		//cadreTroncon = new OpenLayers.Feature.Vector(listeTroncons[troncon_existant].geom.geometry.getBounds().toGeometry(),null,cadrestyle);
		cadreTroncon = new OpenLayers.Feature.Vector(objetGeo2,null,linestringstyle[2]);
		layerSelection.addFeatures(cadreTroncon);
		cadreTroncon = new OpenLayers.Feature.Vector(objetGeo1,null,linestringstyle[categorie_couleur[listeTroncons[troncon_existant].categorie1]]);
		layerSelection.addFeatures(cadreTroncon);

		$j("#notation_infos_nomrue").empty();
		$j("#notation_infos_nomrue").append(listeTroncons[troncon_existant].nom);
		var amenagement;
		$j("#notation_infos_amenagement").empty();
		switch(listeTroncons[troncon_existant].categorie1) 
		{ 
			case '1':
				amenagement = "piste cyclable";
			break; 
			case '2':
				amenagement = "bande cyclable";
			break; 
			case '3':
				amenagement = "bande cyclable en sens inverse";
			break; 
			case '4':
				amenagement = "voie mixte bus/vélo";
			break; 
			case '5':
				amenagement = "voie mixte piéton/vélo";
			break; 
			case '6':
				amenagement = "aucun aménagement";
			break; 
			case '7':
				amenagement = "contre sens cyclable";
			break; 
			default:
				amenagement = "non défini";
			break; 
		}
		$j("#notation_infos_amenagement").append(amenagement);

		var sens;
		$j("#notation_infos_sens").empty();
		switch(listeTroncons[troncon_existant].sens_unique) 
		{ 
			case 'oui':
				sens = "sens unique";
			break; 
			default:
				sens = "double sens";
			break; 
		}
		$j("#notation_infos_sens").append(sens);

                
		$j("#notation_infos_notegeovelo").empty();

		for(var i = 0; i < 5; i++)
		{
		    $j("#notation_infos_notegeovelo").append('<input name="star_geovelo" type="radio" class="star"  />');
		}
			$j("#notation_infos_notecommunaute").empty();
		for(var i = 0; i < 5*4; i++)
		{
		    $j("#notation_infos_notecommunaute").append('<input name="star_communaute" type="radio" class="star {split:4}" />');
		}

		labels = ["Mauvais","Passable","Acceptable","Bon","Très bon"];
		$j("#notation_infos_notemoi").empty();
		for(var i = 0; i < 5; i++)
		{
			$j("#notation_infos_notemoi").append('<input class="auto-submit-star" type="radio" name="star_moi" value="'+i+'" title="'+labels[i]+'" />');
		}
		
		$j('input.star').rating();

		$j("#commentaires_affichage").empty();
		
	
	    commentaires = listeTroncons[troncon_existant].commentaires;
	    for(numComm = 0; numComm < commentaires.length; numComm++)
	    {
		texteComm = commentaires[numComm]["commentaire"];
		idUtil = commentaires[numComm]["idUtil"];
		pseudo = commentaires[numComm]["pseudo"];
		note = commentaires[numComm]["tranquilite"];
		if(note != -1)
		{
		    for(var bouton = 0; bouton < 5; bouton++)
		    {
		    	$j("#commentaires_affichage").append('<input name="star_comm'+numComm+'" type="radio" class="star" />');
		    }
		    $j(function(){
		    	$j('input[name="star_comm'+numComm+'"]').rating();
		    	$j('input[name="star_comm'+numComm+'"]').rating('select',4-note);
		    	$j('input[name="star_comm'+numComm+'"]').rating('disable');
		    });
		}
		if(texteComm)
		{
		    $j("#commentaires_affichage").append('<span class="commentaireTexte">'+texteComm+'</span>');
		}
		$j("#commentaires_affichage").append('<span class="commentaireUtil"> - '+pseudo+"</span>");
		if(peutSupprimerNote)
		{
		    $j("#commentaires_affichage").append('<a href="#" onclick="javascript:xajax_supprimerNote('+idUtil+',\''+listeTroncons[troncon_existant].numero+'\');return false"><img src="res/img/icone-supprimer.png"></a>');
		}
		$j("#commentaires_affichage").append("<br>");
	    }



	if(listeTroncons[troncon_existant].commentaire_utilisateur)
	{
		document.form_notation.commentaireUtilisateur.value = listeTroncons[troncon_existant].commentaire_utilisateur;
	}

	// Fonction chargée de soumettre la note 
         $j('.auto-submit-star').rating({
          callback: function(value, link){
            troncons = "";

            if($j("#notation_note_selection").attr('checked'))
            {
                for(i = 0; i < listeTroncons.length;i++)
                {
                    if(i > 0)troncons += ",";
                    troncons += listeTroncons[i].numero;
                    listeTroncons[i].note_utilisateur = value;
                }
            }
            else
            {
                troncons = tronconSelectionne;
                for(i = 0; i < listeTroncons.length;i++)
                {
                    if(listeTroncons[i].numero == tronconSelectionne)
                    {
                        listeTroncons[i].note_utilisateur = value;
                    }
                }
            }

            if(value == undefined)
            {
                xajax_noterTroncon(troncons,-1);
            }
            else
            {
                xajax_noterTroncon(troncons,value);
            }
          }
         });

	if(listeTroncons[troncon_existant].note_utilisateur != -1)
	{
	    $j('input[name="star_moi"]').rating('select',4-listeTroncons[troncon_existant].note_utilisateur,false);	// wantCallback=false
	}

        $j('input[name="star_geovelo"]').rating('select',4-listeTroncons[troncon_existant].note_officielle);
        $j('input[name="star_geovelo"]').rating('disable');

        if(listeTroncons[troncon_existant].note_communautaire != -1)
        	$j('input[name="star_communaute"]').rating('select',3+4*4-Math.round(4*listeTroncons[troncon_existant].note_communautaire));
        $j('input[name="star_communaute"]').rating('disable');

	}
}

/**
 * Cacher un tronçon
 */
function montrerTronconOut()
{
	$j("#"+tronconSelectionne).css("font-weight","");
	tronconSelectionne = -1;
	layerSelection.removeAllFeatures();
}

/**
 * Maj chargement tronçon
 */
function onLoadTroncon(r)
{
	// TODO instruction non définitive:on supprime systématiquement la sélection existante 
	suppressionListeTroncons();
	if (r.status == 200)
	{

		$j('#notation_accordion').show();

		var reader = new OpenLayers.Format.KML();
		data = reader.read(r.responseText);
		numero = 0;
                
		for (var i=0; i<data.length; i++)
		{
			// On récupère les informations du tronçon
			data[i].geometry.transform(new OpenLayers.Projection("EPSG:4326"),new OpenLayers.Projection("EPSG:900913"));

			var troncon = [];
			troncon.numSequence = i;
			troncon.numero = data[i].attributes.numero;
			troncon.categorie1 = data[i].attributes.categorie1;
			troncon.sens_unique = data[i].attributes.sens_unique;
			troncon.note_officielle = data[i].attributes.note_officielle;
			troncon.note_communautaire = data[i].attributes.note_communautaire;
			troncon.note_utilisateur = data[i].attributes.note_utilisateur;
			troncon.commentaires = eval(data[i].attributes.commentaires);
			troncon.commentaire_utilisateur = data[i].attributes.commentaire_utilisateur;
			troncons = new OpenLayers.Feature.Vector(data[i].geometry,null,linestringstyle[categorie_couleur[troncon.categorie1]]);
			troncon.geom = troncons;
			if(data[i].attributes.name == undefined)
				troncon.nom = "Nom non défini";
			else
				troncon.nom = data[i].attributes.name;

			numero = troncon.numero;
			
			peutSupprimerNote = data[i].attributes.suppression;
			
			// On essaye de supprimer le tronçon s'il existe, sinon on l'ajoute
			if(!suppressionTroncon(troncon.numero))
			{
				layerNotation.addFeatures(troncons);

				$j('#notation_table > tbody:last').append('<tr id="'+troncon.numero+'"><td class="notation_amenage'+categorie_couleur[troncon.categorie1]+'"></td><td class="notation_table_td1">'+troncon.nom+'</td>'/*<td class="notation_rating"><input name="star1" type="radio" class="star {half:true}"/><input name="star1" type="radio" class="star {half:true}"/><input name="star1" type="radio" class="star {half:true}"/><input name="star1" type="radio" class="star {half:true}"/><input name="star1" type="radio" class="star {half:true}"/><input name="star1" type="radio" class="star {half:true}"/></td>*/+'<td class="notation_table_td2"><a href="#" onclick="suppressionTroncon(\''+troncon.numero+'\');return false"><img src="res/img/croix.png" title="Retirer de la sélection"></td></a></tr>');
				troncon.ligne = $j('#notation_table > tbody > tr:last');
//				$j('input.star').rating();
//				troncon.ligne.onclick = function(){map.zoomToExtent(data[i].geometry.getBounds()); return false;}
				troncon.ligne.mouseover(function(){
					$j("#notation_table > tbody > tr").css("font-weight","normal");
					var numLigne = 0;
					for(var j = 0; j< listeTroncons.length; j++)
					{
						if(listeTroncons[j].numero == this.id)
							numLigne = j;
					}
					$j("#notation_table > tbody > tr:eq("+numLigne+")").css("font-weight","bold");
					montrerTroncon(this.id,true);
					});
				$j('#notation_vider').show();
				listeTroncons.push(troncon);
				nbTroncons++;
			}
		}
		update_rows();
		montrerTroncon(numero,false);
	}
	// Si la colonne de droite n'est pas visible, on force son affichage
	if(!feuille_visible && listeTroncons.length > 0)
		switchfeuille();

	$j('#notation_accordion').accordion({
		fillSpace: true
	});
}

/**
 * Erreur suite au chargement tronçon
 */
function onLoadFailedTroncon(r) {
	alert('Erreur chargement tronçon');
}

/**
Fonction callback pour le rechargement d'un tronçon
*/
function onLoadTronconRechargement(r)
{
	if (r.status == 200)
	{
		var reader = new OpenLayers.Format.KML();
		data = reader.read(r.responseText);
		for (var i=0; i<data.length; i++)
		{
			// On essaye de supprimer le tronçon s'il existe, sinon on l'ajoute
			suppressionTroncon(data[i].attributes.numero);
		}
		onLoadTroncon(r);
	}
}

/**
Demande le rechargement des données d'un tronçon
*/
function rechargerTroncon(numero)
{
	OpenLayers.loadURL(URL_BASE_SITEWEB+DOSSIER_SITEWEB+'get_troncon.php?troncon='+numero, {}, null, onLoadTroncon, onLoadFailedTroncon);
//	alert(URL_BASE_SITEWEB+DOSSIER_SITEWEB+'get_troncon.php?troncon='+numero);
}

/**
 * 
 */
function commenterTroncon()
{
    commentaire = document.form_notation.commentaireUtilisateur.value;
    troncons = "";
    if($j("#notation_note_selection").attr('checked'))
    {
	for(i = 0; i < listeTroncons.length;i++)
	{
	    if(i > 0)troncons += ",";
	    troncons += listeTroncons[i].numero;
	    listeTroncons[i].commentaire_utilisateur = commentaire;
	}
    }
    else
    {
	troncons = tronconSelectionne;
	for(i = 0; i < listeTroncons.length;i++)
	{
	    if(listeTroncons[i].numero == tronconSelectionne)
	    {
		listeTroncons[i].commentaire_utilisateur = commentaire;
	    }
	}
    }
    xajax_commenterTroncon(troncons,commentaire);
}
