	<!--
	// Page de choix motif et Cie 
	// version 11
	// Indentation : tabulations
	
	
	// 
	// Sélectionne tous les choix de la liste
	//
	function postSelect( strNomListeDestination ) {
		// Sélection de tous les éléments de la liste de sélection
		lstDestination = document.getElementsByName( strNomListeDestination )[0];
		tabOptionsLstDestination = lstDestination.options;
		for( i = 0; i < lstDestination.options.length; ++i ){
			lstDestination.options[i].selected = true;
		}
	
		// Soumission du formulaire
		forumaire = document.getElementsByName("form_cmd")[0];
		forumaire.submit();
	}// postSelect
	
	
	//
	// Met à jour la liste des couleurs en fonction du motif sélectionné
	//
	function choix_motif_clic( strNomListeMotifs, strNomListeCouleurs ) {
		lstMotifs = document.getElementsByName( strNomListeMotifs )[0];
		lstCouleurs = document.getElementsByName( strNomListeCouleurs )[0];
		
		// Récupération de l'option choisie pour le motif
		tabOptionsMotifs = lstMotifs.options;
		tabOptionsCouleurs = lstCouleurs.options;
		option = tabOptionsMotifs[lstMotifs.selectedIndex];
		nbCouleurs_motif = parseInt( option.value );
		
		// Calcul du nombre de couleurs dans la liste des couleurs
		nbCouleurs_liste = lstCouleurs.length;
		/*if ( nbCouleurs_liste == nbCouleurs_motif ) {
			alert("Nb couleurs OK");
		}*/
		// Mise à jour du nombre de couleurs
		// - Trop de couleurs
		if ( nbCouleurs_liste > nbCouleurs_motif ) {
			// effacement à la fin
			nb_a_effacer = nbCouleurs_liste - nbCouleurs_motif;
			for ( i = 0; i < nb_a_effacer; ++i ) {
				//alert("supp. couleur");
				lstCouleurs.remove( nbCouleurs_liste - i - 1 );
			}
			return;
		}
		// - Pas assez de couleurs
		if ( nbCouleurs_liste < nbCouleurs_motif ) {
			// ajout à la fin
			nb_a_ajouter = nbCouleurs_motif - nbCouleurs_liste;
			for ( i = 0; i < nb_a_ajouter; ++i ) {
				//alert("ajout couleur");
				// Création d'une nouvelle option
				option = document.createElement("option");
				
				// Remplissage de l'option
				strTexte_a_ajouter = "#" + (nbCouleurs_liste + i + 1);
				var attrib_option_value = document.createAttribute("value");
				attrib_option_value.nodeValue = strTexte_a_ajouter;
				option.setAttributeNode( attrib_option_value );
				
				var texte_option = document.createTextNode( strTexte_a_ajouter );
				option.appendChild( texte_option );
				
				// Ajout de l'option dans la liste destination
				lstCouleurs.options.add( option );
			}
			return;
		}
	}// choix_motif_clic
	
	
	//
	// Suppression des paranthèses dans une chaine
	//
	function suppr_parentheses( str ) {
		iDeb = str.indexOf("(");
		iFin = str.indexOf(")");
		lg = str.length;
		strDeb = str;
		strFin = str;
		return strDeb.substr(0, iDeb) + strFin.substr( iFin+1, lg );
	}// suppr_parentheses
	
	
	//
	// Copie le choix de tissus de la liste source vers la liste destination
	//
	function bouton_copier_clic( strNomListeMotifs, strNomListeCouleurs, 
	                             strNomListeTissus, strNomTypeDimension, 
	                             strNomListeCoupons, strNomLgTissus,
	                             strNomListeDestination ) {
		// Récupération des éléments à traiter
		lstMotifs = tabLstMotifs = document.getElementsByName( strNomListeMotifs )[0];
		lstCouleurs = document.getElementsByName( strNomListeCouleurs )[0];
		lstDestination = document.getElementsByName( strNomListeDestination )[0];
		lstTissus = document.getElementsByName( strNomListeTissus )[0];
		tab_choix_dimension = document.getElementsByName( strNomTypeDimension );
		lstCoupons = document.getElementsByName( strNomListeCoupons )[0];
		
		// Recuperation du type de dimension (coupon ou au metre)
		nb_choix = tab_choix_dimension.length;
		strTypeDimension = "";
		for ( i = 0; i < nb_choix; ++i ) {
			if (tab_choix_dimension[i].checked ) {
				strTypeDimension = tab_choix_dimension[i].value;
			}
		}
		//alert("type dim = " + strTypeDimension );
		
		// Calcul du prix et de l'aire de référence du tissus
		tabOptionsTissus = lstTissus.options;
		optionTissus = tabOptionsTissus[lstTissus.selectedIndex];
		longueur_ref = 100.0;// cm
		largeur_ref = parseFloat( optionTissus.label );// cm
		aire_ref_prix = longueur_ref * largeur_ref;
		aire_ref_poids = 100.0 * 100.0;
		prix_aire_ref = parseFloat( optionTissus.value );// euros
		poids_aire_ref = parseFloat( optionTissus.title );// g / m^2
		strNomTissus = optionTissus.text;
		strNomTissus = strNomTissus.toLowerCase();
		
		// - calcul de l'aire commandée
		tabOptionsCoupons = lstCoupons.options;
		optionCoupon = tabOptionsCoupons[lstCoupons.selectedIndex];
		aire_cmd = -1.0;
		if ( strTypeDimension == "type_au_coupon" ) {
			var strTailleCoupon = optionCoupon.value;
			var nLargeur_cmd = 1.0;
			var nLg_cmd = 1.0;
			if ( strTailleCoupon == "S" ) {
				nLargeur_cmd = parseFloat( largeur_ref ) / 3.0;// cm
				nLg_cmd = 50.0;// cm
			}
			else {// strTailleCoupon == "L"
				nLargeur_cmd = 2.0 * parseFloat( largeur_ref ) / 3.0;
				nLg_cmd = 100.0;// cm
			}
			nLg_cmd = Math.floor( nLg_cmd );
			nLargeur_cmd = Math.floor( nLargeur_cmd );
			aire_cmd = nLg_cmd * nLargeur_cmd;
			strTexte_coupon = optionCoupon.text;
			//alert( "Taille coupon : lg = " + nLg_cmd + " x " + nLargeur_cmd);
		}
		else { // au mètre
			champLg = document.getElementsByName( strNomLgTissus )[0];
			longueur_cmd = parseFloat( champLg.value );
			if ( longueur_cmd < 100.0 ) {
				alert("Pas de longueurs en dessous de 100 cm, merci." );
				return;
			}
			if ( longueur_cmd % 50 != 0.0 )  {
				alert("Les longueurs doivent être des multiples de 50 cm, merci." );
				return;
			}
			aire_cmd = largeur_ref * longueur_cmd;
		}
		//alert("Aire commandée = " + aire_cmd);
		
		// - calcul du prix correspondant
		prix_cmd = new Number( 0.0 );
		prix_cmd = aire_cmd * prix_aire_ref / aire_ref_prix;
		//alert("prix_cmd = " + prix_cmd);
		if ( strTypeDimension == "type_au_coupon" ) {
			if ( strTailleCoupon == "S" ) {
				if ( strNomTissus.match("popeline") == "popeline") {
					prix_cmd = Math.ceil( 10.0 * prix_cmd ) / 10.0;// arrondi à 1 décimale
				}
				else {
					prix_cmd = Math.ceil( 10.0 * prix_cmd ) / 10.0;// arrondi à 1 décimale
				}
			}
			if ( strTailleCoupon == "L" ) {
				if ( strNomTissus.match("popeline") == "popeline") {
					prix_cmd = 18.80;// arrondi à la con de ma femme... grrr
				}
				else {
					prix_cmd = Math.ceil( 10.0 * prix_cmd ) / 10.0;// arrondi à 1 décimale
				}
			}
		}
		prix_cmd = Math.round(100.0 * prix_cmd ) / 100.0;// arrondi à 2 décimales

		poids_cmd = aire_cmd * poids_aire_ref / aire_ref_poids;
		poids_cmd = Math.round(100.0 * poids_cmd ) / 100.0;
		

		// Remplissage de l'option
		tabOptionsMotifs = lstMotifs.options;
		tabOptionsCouleurs = lstCouleurs.options;
		
		// Calcul du texte à ajouter
		option = tabOptionsMotifs[lstMotifs.selectedIndex];
		strValeur = option.value; 
		strTexte = option.text;

		option = tabOptionsCouleurs[lstCouleurs.selectedIndex];
		strValeur = strValeur + " " + option.value; 
		strTexte = strTexte + " " + option.text;
		
		
		strTexte = strTexte + ", " + optionTissus.text;
		//alert("type dim = " + strTypeDimension );
		if ( strTypeDimension == "type_au_coupon") {
			strTexte = strTexte + ", coupon " + suppr_parentheses( optionCoupon.text );
		}
		if ( strTypeDimension == "type_au_metre") {
			//strTexte = strTexte + ", " + largeur_ref + " x " + longueur_cmd + " cm.";
			strTexte = strTexte + ", " + longueur_cmd + " cm.";
			//strTexte += " " + optionTissus.value + " € le mètre"; 
		}
		strTexte += ", prix " + prix_cmd.toFixed(2) + " €";
		strTexte += ", poids " + poids_cmd + " g";
		//poids_cmd
		
		// Création de l'option à ajouter dans la liste destination
		//var numOk = 1;
		option_copie = document.createElement('option');
		var texte_option_copie = document.createTextNode( strTexte );
		option_copie.appendChild( texte_option_copie );
		
		//Ajout de l'option dans la liste destination
		try {
			lstDestination.options.add( option_copie, null );
		}
		catch( ex ) {// Pour IE
			option_ie = document.createElement('option');
			option_ie.text = strTexte;
			lstDestination.options.add( option_ie );
		}
		
		// Adaptation du nombre de lignes pour qu'il n'y ait pas d'ascenceur
		var nb_lignes_selection_org = 9;
		if ( lstDestination.options.length > nb_lignes_selection_org ) {
			lstDestination.size = lstDestination.options.length;
		}
		calculer_totaux( strNomListeDestination );
	}// bouton_copier_clic
	
	
	
	//
	// Calcule le total du prix et du poids des tissus de la liste de destination
	//
	function calculer_totaux( strNomListeChoix ) {
		champPrix_tissus = document.getElementById( "idPrix_tissus" );
		champPoids_tissus = document.getElementById( "idPoids_tissus" );
		champPrix_affranchissement = document.getElementById( "idPrix_affranchissement" );
		champPrix_emballage = document.getElementById( "idPrix_emballage" );
		champPrix_total = document.getElementById( "idPrix_total" );
		//alert( champPrix_tissus.innerHTML);
		
		lstChoix = document.getElementsByName( strNomListeChoix )[0];
		tabOptionsChoix = lstChoix.options;
		var nPrix_tissus = new Number( 0.0 );
		var nPoids_tissus = new Number( 0.0 );
		for ( i = 0; i < tabOptionsChoix.length; ++i ) {
			strLigne = tabOptionsChoix[i].text;
			strEuro = String.fromCharCode( 8364 );
			strLigne = strLigne.replace( strEuro, "e");
			lg = strLigne.length;			
			
			idx_deb_poids = strLigne.indexOf("poids");	        
			poids = parseFloat( strLigne.substr( idx_deb_poids + 5 ));
			
			idx_deb_prix = strLigne.indexOf("prix");
			prix = parseFloat( strLigne.substr( idx_deb_prix + 4 )); 
			
			nPrix_tissus += prix;
			nPoids_tissus += poids;
		}

		// Calcul du prix d'affranchissement en fonction de nPoids_tissus et du pays
		lst_pays = document.getElementsByName( "lst_pays" )[0];
		tabOptionsPays = lst_pays.options;
		optionPays = tabOptionsPays[lst_pays.selectedIndex];
		//alert("Pays = \"" + optionPays.text + "\"");
		
		tabPoids = new Array();
		tabPrix = new Array();
		tabPoids[0] = 20.0;		
		tabPoids[1] = 50.0;
		tabPoids[2] = 100.0;
		tabPoids[3] = 250.0;
		tabPoids[4] = 500.0;
		tabPoids[5] = 1000.0;
		tabPoids[6] = 2000.0;
		tabPoids[7] = 3000.0;
		tabPoids[8] = 4000.0; 
		tabPoids[9] = 5000.0;
		tabPoids[10] = 6000.0;
		tabPoids[11] = 7000.0;
		tabPoids[12] = 8000.0;
		tabPoids[13] = 9000.0;
		tabPoids[14] = 10000.0;
		tabPoids[15] = 15000.0;
		tabPoids[16] = 20000.0;
		if ( optionPays.text == "France" ) {
			tabPrix[0] = 0.58;
			tabPrix[1] = 0.95;
			tabPrix[2] = 1.40;
			tabPrix[3] = 2.30;
			tabPrix[4] = 3.15;
			tabPrix[5] = 4.05;
			tabPrix[6] = 5.35;
			tabPrix[7] = 6.25;
			tabPrix[8] = 10.60;
			tabPrix[9] = 10.60;
			tabPrix[10] = 12.50;
			tabPrix[11] = 12.50;
			tabPrix[12] = 15.35;
			tabPrix[13] = 15.35;
			tabPrix[14] = 15.35;
			tabPrix[15] = 17.45;
			tabPrix[16] = 23.75;
		}
		else if ( optionPays.text == "Outre-mer zone 1" ) {
			tabPrix[0] = 0.68;
			tabPrix[1] = 1.20;
			tabPrix[2] = 1.90;
			tabPrix[3] = 3.55;
			tabPrix[4] = 5.65;
			tabPrix[5] = 8.80;
			tabPrix[6] = 9.80;
			tabPrix[7] = 10.80;
			tabPrix[8] = 11.80;
			tabPrix[9] = 12.80;
			tabPrix[10] = 13.80;
			tabPrix[11] = 15.35;
			tabPrix[12] = 16.90;
			tabPrix[13] = 18.45;
			tabPrix[14] = 20.00;
			tabPrix[15] = 26.00;
			tabPrix[16] = 32.00;
		}
		else if ( optionPays.text == "Outre-mer zone 2" ) {
			tabPrix[0] = 0.80;
			tabPrix[1] = 1.50;
			tabPrix[2] = 2.50;
			tabPrix[3] = 5.05;
			tabPrix[4] = 8.65;
			tabPrix[5] = 11.75;
			tabPrix[6] = 19.20;
			tabPrix[7] = 26.65;
			tabPrix[8] = 34.10;
			tabPrix[9] = 41.55;
			tabPrix[10] = 49.00;
			tabPrix[11] = 56.45;
			tabPrix[12] = 63.90;
			tabPrix[13] = 71.35;
			tabPrix[14] = 78.80;
			tabPrix[15] = 125.80;
			tabPrix[16] = 172.80;
		}
		else if ( optionPays.text == "Union européenne et Suisse" ) {
			tabPrix[0] = 1.80;
			tabPrix[1] = 1.80;
			tabPrix[2] = 1.80;
			tabPrix[3] = 3.00;
			tabPrix[4] = 4.40;
			tabPrix[5] = 6.50;
			tabPrix[6] = 8.90;
			tabPrix[7] = 21.30;
			tabPrix[8] = 24.95;
			tabPrix[9] = 28.60;
			tabPrix[10] = 32.25;
			tabPrix[11] = 35.90;
			tabPrix[12] = 39.55;
			tabPrix[13] = 43.20;
			tabPrix[14] = 46.85;
			tabPrix[15] = 53.85;
			tabPrix[16] = 60.85;
		}
		else if ( optionPays.text == "Maghreb" ||
		          optionPays.text == "Pays d'Europe de l'Est (hors Union européenne)" ) {
			tabPrix[0] = 2.00;
			tabPrix[1] = 2.00;
			tabPrix[2] = 2.00;
			tabPrix[3] = 3.20;
			tabPrix[4] = 5.00;
			tabPrix[5] = 9.00;
			tabPrix[6] = 13.10;
			tabPrix[7] = 22.00;
			tabPrix[8] = 30.20;
			tabPrix[9] = 34.65;
			tabPrix[10] = 39.10;
			tabPrix[11] = 43.55;
			tabPrix[12] = 48.00;
			tabPrix[13] = 52.45;
			tabPrix[14] = 56.90;
			tabPrix[15] = 67.10;
			tabPrix[16] = 77.30;
		}
		else if ( optionPays.text == "Canada, Etats-unis"  || 
		          optionPays.text == "Pays d'Afrique (hors Maghreb)" ||
		          optionPays.text == "Proche et Moyen-Orient" ) {
			tabPrix[0] = 2.00;
			tabPrix[1] = 2.00;
			tabPrix[2] = 2.00;
			tabPrix[3] = 3.20;
			tabPrix[4] = 5.00;
			tabPrix[5] = 9.00;
			tabPrix[6] = 13.10;
			tabPrix[7] = 22.00;
			tabPrix[8] = 48.90;
			tabPrix[9] = 58.30;
			tabPrix[10] = 67.70;
			tabPrix[11] = 77.10;
			tabPrix[12] = 86.50;
			tabPrix[13] = 95.90;
			tabPrix[14] = 105.30;
			tabPrix[15] = 128.80;
			tabPrix[16] = 152.30;
		}
		
		if ( tabPoids.length == 0 || tabPoids.length != tabPrix.length) {
			alert("Attention, l'affranchissement est mal configuré pour ce pays (" + optionPays.text + ")");
			return;
		}
		
		var nPrix_affranchissement = new Number( 0.0 );
		var nPoids_tissus_plus_emballage = nPoids_tissus * 1.2;// prise en compte de l'emballage pour l'affranchissement
		for ( i = 0; i < tabPoids.length; ++i ) {
			if ( nPoids_tissus_plus_emballage > tabPoids[i] ) {
				nIdx_prix = i + 1;
				if ( nIdx_prix >= tabPrix.length ) {
					nIdx_prix = tabPrix.length - 1;	
					alert("Au-delà de 30 kg, contactez-moi.");
				}
				nPrix_affranchissement = tabPrix[ nIdx_prix ];
			}
		}
		if ( nPrix_affranchissement == 0 && nPoids_tissus_plus_emballage > 0) {// prix minimum
			nPrix_affranchissement = tabPrix[0];
		}
		
		// Calcul total et affichage
		var nPrix_final = new Number();
		nPrix_final = nPrix_tissus + nPrix_affranchissement;
		
		strCodePoids_tissus = "<p>" + nPoids_tissus.toFixed(2) + " g.";
		strCodePoids_tissus += "<input type=\"hidden\" name=\"poids_tissus\" value=\"" + nPoids_tissus.toFixed(0) + "\"></p>";
		champPoids_tissus.innerHTML = strCodePoids_tissus;
		
		strCodePrix_tissus = "<p>" + nPrix_tissus.toFixed(2) + " €";
		strCodePrix_tissus += "<input type=\"hidden\" name=\"prix_tissus\" value=\"" + nPrix_tissus.toFixed(2) + "\"></p>";
		champPrix_tissus.innerHTML = strCodePrix_tissus;
		
		strCodePrix_affranchissement = "<p>" + nPrix_affranchissement.toFixed(2) + " €";
		strCodePrix_affranchissement += "<input type=\"hidden\" name=\"prix_affranchissement\" value=\"" + nPrix_affranchissement.toFixed(2) + "\"></p>";
		champPrix_affranchissement.innerHTML = strCodePrix_affranchissement;
		
		strCodePrix_total = "<p><b>" + nPrix_final.toFixed(2) + " €";
		strCodePrix_total += "<input type=\"hidden\" name=\"prix_total\" value=\"" + nPrix_final.toFixed(2) + "\"></b></p>";
		champPrix_total.innerHTML = strCodePrix_total;
	}// calculer_totaux
	
	
	//
	// Supprime l'élément sélectionné de la liste dont on a reçu le nom
	//
	function bouton_supprimer_clic( strNomListe ) {
		//alert("Supprimer element " + strNomListe );
		tabLst = document.getElementsByName( strNomListe )
		if ( tabLst.length != 1 ) {// la liste doit exister ! 
			alert( "nb lst src = " + tabLst.length );
			return;
		}
		var lst = tabLst[0];
		var tabOptions = lst.options;
		if ( lst.selectedIndex >= 0 ) {
			lst.remove( lst.selectedIndex );
			calculer_totaux("lst_destination[]");
			
			// Resélection du dernier
			if ( lst.options.length > 0 ) {
				lst.options[lst.options.length - 1].selected = true;
			}
			
			// Adaptation du nombre de lignes
			//lstDestination = document.getElementsByName( strNomListe )[0];
			var nb_lignes_selection_org = 9;
			if ( lst.options.length < lstDestination.size ) {
				var nb_lignes = lst.options.length;
				if ( nb_lignes >= nb_lignes_selection_org ) {
					lst.size = nb_lignes;
				}
			}
		}
		else {
			alert( "Vous n'avez pas sélectionné l'élément à supprimer" );
		}
	}// bouton_supprimer_clic


	//
	// Passage en mode "coupon" (selectionne le radio-bouton "au coupon")
	//
	function choix_au_coupon_clic() {
		tab_choix_dimension = document.getElementsByName( "type_dimension" );

		// Recuperation du type de dimension (coupon ou au metre)
		nb_choix = tab_choix_dimension.length;
		for ( i = 0; i < nb_choix; ++i ) {
			if ( tab_choix_dimension[i].value == "type_au_coupon" ) {
				tab_choix_dimension[i].checked = true;
			}
		}
	}// choix_au_coupon_clic


	//
	// Passage en mode "au_metre" (selectionne le radio-bouton "au metre")
	//
	function choix_au_metre_clic() {
		tab_choix_dimension = document.getElementsByName( "type_dimension" );

		// Recuperation du type de dimension (coupon ou au metre)
		nb_choix = tab_choix_dimension.length;
		for ( i = 0; i < nb_choix; ++i ) {
			if ( tab_choix_dimension[i].value == "type_au_metre" ) {
				tab_choix_dimension[i].checked = true;
			}
		}
	}// choix_au_metre_clic
	
	
	//
	// Imprime la page courante
	//
	function imprimer_page() {
		window.print()
	}// imprimer_page
	//-->
