
/************************************************/
/***gestion date livraion par calendrier*********/
/************************************************/
var heure = new Date().getHours();
if(heure > 10){
	var currentDat = new Date().addDays(2);
}
else{
	var currentDat = new Date().addDays(1);
}
var jour = new Date().getDay();
if(jour == '6'){ //samedi
	var currentDat = currentDat.addDays(2);
}
if(jour == '0'){//dimanche
	var currentDat = currentDat.addDays(1);
}
/************************************************/
/**fin gestion date livraion par calendrier******/
/************************************************/
function round(val, dec){ 
	return val.toFixed(dec);
}
function addDays(d, j){
	return new Date(d.getTime() + (1000 * 60 * 60 * 24 * j));
}

/*
function calculLivraison(d){
			date = new Date()
			date = addDays(date, d); // on ajoute deux jours pour la livraison en 48h
			jour = date.getDate(); // aujourd'hui
			mois = date.getMonth(); // mois => janvier = 0, fevrier = 1, etc...
			mois = parseInt(mois)+1;
			annee = date.getFullYear();
			heure = date.getHours();
			nom_jour  = date.getDay();
			alert(nom_jour);
			if(heure>10){ // jusqu'a 11h30 => ok
				plusUnJour = 1;
			}
			else{ //a partir de 12h => plus un jour pour la livraison
				plusUnJour = 0;
			}
			jour = jour+plusUnJour;
			livraison = jour+"/"+mois+"/"+annee;
			return livraison;
}
*/

// poid des canelé en gramme		
poidCG = 60; //gros
poidCL = 30; //lunch
poidCB = 17; //bouchee
poidBa = 27; //emballage ballotin
poidCo = 22; //emballage cone
poidEm = 0; //emballage blanc
poidCartonB = 250;
limitePoidsTotal = 30000;



function optionChrono(){
		poid = document.getElementById("poid_commande").innerHTML; //on recupere les poid tootal de la commande
		poidTotal = (poid.slice(0, -3)*1000); //on enleve le kg
			
		/*desactiver pour tester TNT*/
		/*
		if(document.formFacture.chrono.checked == true){
			//***********************************************
			//***gestion date livraion par calendrier********
			//***********************************************
			var heure = new Date().getHours();
			if(heure > 10){
				var currentDat = new Date().addDays(2);
			}
			else{
				var currentDat = new Date().addDays(1);
			}
			var jour = new Date().getDay();
			if(jour == '6'){ //samedi
				var currentDat = currentDat.addDays(2);
			}
			if(jour == '0'){//dimanche
				var currentDat = currentDat.addDays(1);
			}
			//************************************************
			//**fin gestion date livraion par calendrier******
			//************************************************
			if (poidTotal >=30000) {trans=37.22;}
			if (poidTotal <=30000) {trans=37.22;}
			if (poidTotal <=29000) {trans=36.48;}
			if (poidTotal <=28000) {trans=35.74;}
			if (poidTotal <=27000) {trans=34.99;}
			if (poidTotal <=26000) {trans=34.25;}
			if (poidTotal <=25000) {trans=33.51;}
			if (poidTotal <=24000) {trans=32.77;}
			if (poidTotal <=23000) {trans=32.03;}
			if (poidTotal <=22000) {trans=31.29;}
			if (poidTotal <=21000) {trans=30.55;}
			if (poidTotal <=20000) {trans=29.80;}
			if (poidTotal <=19000) {trans=29.06;}
			if (poidTotal <=18000) {trans=28.32;}
			if (poidTotal <=17000) {trans=27.58;}
			if (poidTotal <=16000) {trans=26.84;}
			if (poidTotal <=15000) {trans=26.10;}
			if (poidTotal <=14000) {trans=25.38;}
			if (poidTotal <=13000) {trans=24.66;}
			if (poidTotal <=12000) {trans=23.94;}
			if (poidTotal <=11000) {trans=23.23;}
			if (poidTotal <=10000) {trans=22.51;}
			if (poidTotal <=9000)  {trans=21.79;}
			if (poidTotal <=8000)  {trans=21.07;}
			if (poidTotal <=7000)  {trans=20.36;}
			if (poidTotal <=6000)  {trans=19.64;}
			if (poidTotal <=5000)  {trans=18.92;}
			if (poidTotal <=2000)  {trans=18.63;}
			if (poidTotal ==250)  {trans=0.00;} // poid de l'embalage blanc
		
			//$("div#info_date .valueInfo").empty().append(calculLivraison(1)); // on affiche la date de livraison
			
		}
		else{
			//************************************************
			//***gestion date livraion par calendrier*********
			//************************************************
			var heure = new Date().getHours();
			if(heure > 10){
				var currentDat = new Date().addDays(3);
			}
			else{
				var currentDat = new Date().addDays(2);
			}
			var jour = new Date().getDay();
			if(jour == '6'){ //samedi
				var currentDat = currentDat.addDays(2);
			}
			if(jour == '0'){//dimanche
				var currentDat = currentDat.addDays(1);
			}
			//************************************************
			//**fin gestion date livraion par calendrier******
			//************************************************
			if (poidTotal >=30000) {trans=24.6;}
			if (poidTotal <=30000) {trans=24.6;}
			if (poidTotal <=15000) {trans=19.3;}
			if (poidTotal <=10000) {trans=17.5;}
			if (poidTotal <=7000)  {trans=14.8;}
			if (poidTotal <=5000)  {trans=13.0;}
			if (poidTotal <=3000)  {trans=11.1;}
			if (poidTotal <=2000)  {trans=10.2;}
			if (poidTotal <=1000)  {trans=9.3;}
			if (poidTotal <=500)   {trans=8.1;}	
			if (poidTotal ==250)  {trans=0.00;}// poid de l'embalage blanc
			
			//$("div#info_date .valueInfo").empty().append(calculLivraison(2)); // on affiche la date de livraison
		}
		*/
			//********************************************************
			//***gestion date livraion par calendrier avec TNT********
			//********************************************************
			var heure = new Date().getHours();
			if(heure > 10){
				var currentDat = new Date().addDays(2);
			}
			else{
				var currentDat = new Date().addDays(1);
			}
			var jour = new Date().getDay();
			if(jour == '6'){ //samedi
				var currentDat = currentDat.addDays(2);
			}
			if(jour == '0'){//dimanche
				var currentDat = currentDat.addDays(1);
			}
			//************************************************
			//**fin gestion date livraion par calendrier******
			//************************************************			
			if (poidTotal >=30000) {trans=34.00;}
			if (poidTotal <=30000) {trans=34.00;} 
			if (poidTotal <=29000) {trans=33.30;} 
			if (poidTotal <=28000) {trans=32.60;} 
			if (poidTotal <=27000) {trans=31.90;} 
			if (poidTotal <=26000) {trans=31.20;} 
			if (poidTotal <=25000) {trans=30.50;} 
			if (poidTotal <=24000) {trans=29.80;} 
			if (poidTotal <=23000) {trans=29.10;} 
			if (poidTotal <=22000) {trans=28.40;} 
			if (poidTotal <=21000) {trans=27.70;} 
			if (poidTotal <=20000) {trans=27.00;} 
			if (poidTotal <=19000) {trans=26.30;} 
			if (poidTotal <=18000) {trans=25.60;} 
			if (poidTotal <=17000) {trans=24.90;} 
			if (poidTotal <=16000) {trans=24.20;} 
			if (poidTotal <=15000) {trans=23.50;} 
			if (poidTotal <=14000) {trans=22.80;} 
			if (poidTotal <=13000) {trans=22.10;} 
			if (poidTotal <=12000) {trans=21.40;} 
			if (poidTotal <=11000) {trans=20.70;} 
			if (poidTotal <=10000) {trans=20.00;} 
			if (poidTotal <=9000)  {trans=19.30;} 
			if (poidTotal <=8000)  {trans=18.60;} 
			if (poidTotal <=7000)  {trans=17.90;} 
			if (poidTotal <=6000)  {trans=17.20;} 
			if (poidTotal <=5000)  {trans=16.50;} 
			if (poidTotal <=4000)  {trans=15.80;}
			if (poidTotal <=3000)  {trans=15.10;}
			if (poidTotal <=2000)  {trans=14.40;} 
			if (poidTotal <=1000)  {trans=13.70;} 
			if (poidTotal ==250)  {trans=0.00;}// poid de l'embalage blanc
		
		
		
		
		
		
		/************************************************/
		/***gestion date livraion par calendrier*********/
		/************************************************/
		currentD = new Date(currentDat.getFullYear(), currentDat.getMonth(), currentDat.getDate(), 12, 0, 0);
		$(function(){
			$('.date-pick').datePicker({clickInput:true})
			$('.date-pick').dpSetStartDate(currentD);
		});
		/************************************************/
		/**fin gestion date livraion par calendrier******/
		/************************************************/
	
		trans = round(trans,2); // on arrondi a deux chiffre apres la virgule
			
		ue = document.getElementById("frais_port").innerHTML; // on recupere les frais de port
		ue = ue.slice(0, -1); // on enleve le sigle €
		
		$("#prixFdp").val(trans); // on met a jour les FDP dans le hidden
		
		$("div#fe .tt").empty().append(trans+" &euro;"); // en affiche les frais de port
		
		total_ttc = document.getElementById("total_ttc").innerHTML; //on recuepere le total TTC
		total_ttc = total_ttc.slice(0, -1);
		total_ttc = parseFloat(total_ttc) - parseFloat(ue) + parseFloat(trans); //parseFloat() sert a transformer une chaine en nombre flotant afin qu ele "+" additionne au lieu de concaténer
		total_ttc = round(total_ttc,2);
		$("div#total .tt").empty().append(total_ttc+" &euro;"); // on affiche le TTC
		
		$("#verifPoidTotal").val(poidTotal); // on met a jour lele poid total de verification
		
		//dateLivraison = document.getElementById("livraison").value;
		//alert(dateLivraison);
}
	
	



function ajoutManuel(id){
	//on recupere lepoid total de verification en grame => max 30kg => 30000g
	verifPoidTotal = document.getElementById("verifPoidTotal").value;
	
	qteGc = document.getElementById("g_canele").value;
	qteLc = document.getElementById("l_canele").value;
	qteBc = document.getElementById("b_canele").value;
	qteBa = document.getElementById("ballotin").value;
	qteCo = document.getElementById("cone").value;
	
	oldQteGc = document.getElementById("oldQteGc").value;
	oldQteLc = document.getElementById("oldQteLc").value;
	oldQteBc = document.getElementById("oldQteBc").value;
	oldQteCo = document.getElementById("oldQteCo").value;
	oldQteBa = document.getElementById("oldQteBa").value;
	
	//alert("=> "+oldQteCo+" "+oldQteBa+" "+oldQteGc+" "+oldQteLc+" "+oldQteBc);;
	//alert(qteGc+" - "+qteLc+" - "+qteBc+" - "+qteBa+" - "+qteCo);
	
	newPoids = (qteGc*poidCG)+(qteLc*poidCL)+(qteBc*poidCB)+(qteBa*poidBa)+(qteCo*poidCo);
	
	//alert(id+" : "+verifPoidTotal+" / "+newPoids);
	
	if(newPoids > limitePoidsTotal){
		if(id == "g_canele"){
			poidsAenlever = (verifPoidTotal-(oldQteGc*poidCG));
			qteGc = Math.floor((limitePoidsTotal-poidsAenlever)/poidCG); 
		}
		if(id == "l_canele"){
			poidsAenlever = (verifPoidTotal-(oldQteLc*poidCL));
			qteLc = Math.floor((limitePoidsTotal-poidsAenlever)/poidCL); 
		}
		if(id == "b_canele"){
			poidsAenlever = (verifPoidTotal-(oldQteBc*poidCB));
			qteBc = Math.floor((limitePoidsTotal-poidsAenlever)/poidCB); 
		}
		if(id == "ballotin"){
			poidsAenlever = (verifPoidTotal-(oldQteBa*poidBa));
			qteBa = Math.floor((limitePoidsTotal-poidsAenlever)/poidBa); 
		}
		if(id == "cone"){
			poidsAenlever = (verifPoidTotal-(oldQteCo*poidCo));
			qteCo = Math.floor((limitePoidsTotal-poidsAenlever)/poidCo); 
		}
	}
	
	
	//alert(qteGc);
	
	
	//if(verifPoidTotal < 30000){
		//on recupere les prix unitaires
		prixBcanel = document.getElementById("prixB").value;
		prixLcanel = document.getElementById("prixL").value;
		prixGcanel = document.getElementById("prixG").value;
		prixBa = document.getElementById("prixBa").value;
		prixCo = document.getElementById("prixCo").value;
		prixFdp = document.getElementById("prixFdp").value;
			
		if(id == "g_canele"){
			$("div#gc").css({"display" : "block"});
			newVal = qteGc;
			$("div#gc span.qte").empty().append(newVal+"&nbsp;"); // on met a jour la quantite
			$("#oldQteGc").val(newVal); // on met a jour lele poid total de verification
			$("#g_canele").val(newVal); // on met a jour lele poid total de verification
			montantGc = (newVal*prixGcanel);
			montantGcA = round(montantGc,2);
			$("div#gc span.tt").empty().append(montantGcA+" &euro;");
			if(newVal < 1){
				$("div#gc").css({"display" : "none"});
			}
		}
		if(id == "b_canele"){
			$("div#bc").css({"display" : "block"}); // on affiche la ligne
			newVal = qteBc;
			$("div#bc span.qte").empty().append(newVal+"&nbsp;");
			$("#oldQteBc").val(newVal); // on met a jour lele poid total de verification
			$("#b_canele").val(newVal); // on met a jour lele poid total de verification
			montantBc = (newVal*prixBcanel);
			montantBcA = round(montantBc,2);
			$("div#bc span.tt").empty().append(montantBcA+" &euro;");
			if(newVal < 1){
				$("div#bc").css({"display" : "none"});
			}
		}
		if(id == "l_canele"){
			$("div#lc").css({"display" : "block"});
			newVal = qteLc;
			$("div#lc span.qte").empty().append(newVal+"&nbsp;");
			$("#oldQteLc").val(newVal); // on met a jour lele poid total de verification
			$("#l_canele").val(newVal); // on met a jour lele poid total de verification
			montantLc = (newVal*prixLcanel);
			montantLcA = round(montantLc,2);
			$("div#lc span.tt").empty().append(montantLcA+" &euro;");
			if(newVal < 1){
				$("div#lc").css({"display" : "none"});
			}
		}
		if(id == "ballotin"){
			$("div#ba").css({"display" : "block"});
			newVal = qteBa;
			$("div#ba span.qte").empty().append(newVal+"&nbsp;"); // on met a jour la quantite
			$("#oldQteBa").val(newVal); // on met a jour lele poid total de verification
			$("#ballotin").val(newVal); // on met a jour lele poid total de verification
			montantBa = (newVal*prixBa);
			montantBaA = round(montantBa,2);
			$("div#ba span.tt").empty().append(montantBaA+" &euro;");
			if(newVal < 1){
				$("div#ba").css({"display" : "none"});
			}
		}
		if(id == "cone"){
			$("div#co").css({"display" : "block"});
			newVal = qteCo;
			$("div#co span.qte").empty().append(newVal+"&nbsp;"); // on met a jour la quantite
			$("#oldQteCo").val(newVal); // on met a jour lele poid total de verification
			$("#cone").val(newVal); // on met a jour lele poid total de verification
			montantCo = (newVal*prixCo);
			montantCoA = round(montantCo,2);
			$("div#co span.tt").empty().append(montantCoA+" &euro;");
			if(newVal < 1){
				$("div#co").css({"display" : "none"});
			}
		}
				
		// poids total des canelés en gramme
		poidTotal = ((qteBc*poidCB)+(qteLc*poidCL)+(qteGc*poidCG)+(qteBa*poidBa)+(qteCo*poidCo)+(poidCartonB*1));
		// poids total des canelés en kg
		poidTotalKg = round((poidTotal/1000),2) 
		//alert(poidTotal);
		
		/*desactiver pour test TNT*/
		/*
		if(document.formFacture.chrono.checked == true){
			if (poidTotal >=30000) {trans=37.22;}
			if (poidTotal <=30000) {trans=37.22;}
			if (poidTotal <=29000) {trans=36.48;}
			if (poidTotal <=28000) {trans=35.74;}
			if (poidTotal <=27000) {trans=34.99;}
			if (poidTotal <=26000) {trans=34.25;}
			if (poidTotal <=25000) {trans=33.51;}
			if (poidTotal <=24000) {trans=32.77;}
			if (poidTotal <=23000) {trans=32.03;}
			if (poidTotal <=22000) {trans=31.29;}
			if (poidTotal <=21000) {trans=30.55;}
			if (poidTotal <=20000) {trans=29.80;}
			if (poidTotal <=19000) {trans=29.06;}
			if (poidTotal <=18000) {trans=28.32;}
			if (poidTotal <=17000) {trans=27.58;}
			if (poidTotal <=16000) {trans=26.84;}
			if (poidTotal <=15000) {trans=26.10;}
			if (poidTotal <=14000) {trans=25.38;}
			if (poidTotal <=13000) {trans=24.66;}
			if (poidTotal <=12000) {trans=23.94;}
			if (poidTotal <=11000) {trans=23.23;}
			if (poidTotal <=10000) {trans=22.51;}
			if (poidTotal <=9000)  {trans=21.79;}
			if (poidTotal <=8000)  {trans=21.07;}
			if (poidTotal <=7000)  {trans=20.36;}
			if (poidTotal <=6000)  {trans=19.64;}
			if (poidTotal <=5000)  {trans=18.92;}
			if (poidTotal <=2000)  {trans=18.63;}
			if (poidTotal ==250)  {trans=0.00;}// poid de l'embalage blanc
		}
		else{
			if (poidTotal >=30000) {trans=24.6;}
			if (poidTotal <=30000) {trans=24.6;}
			if (poidTotal <=15000) {trans=19.3;}
			if (poidTotal <=10000) {trans=17.5;}
			if (poidTotal <=7000)  {trans=14.8;}
			if (poidTotal <=5000)  {trans=13.0;}
			if (poidTotal <=3000)  {trans=11.1;}
			if (poidTotal <=2000)  {trans=10.2;}
			if (poidTotal <=1000)  {trans=9.3;}
			if (poidTotal <=500)   {trans=8.1;}
			if (poidTotal ==250)  {trans=0.00;}// poid de l'embalage blanc
		}
		*/
			if (poidTotal >=30000) {trans=34.00;}
			if (poidTotal <=30000) {trans=34.00;} 
			if (poidTotal <=29000) {trans=33.30;} 
			if (poidTotal <=28000) {trans=32.60;} 
			if (poidTotal <=27000) {trans=31.90;} 
			if (poidTotal <=26000) {trans=31.20;} 
			if (poidTotal <=25000) {trans=30.50;} 
			if (poidTotal <=24000) {trans=29.80;} 
			if (poidTotal <=23000) {trans=29.10;} 
			if (poidTotal <=22000) {trans=28.40;} 
			if (poidTotal <=21000) {trans=27.70;} 
			if (poidTotal <=20000) {trans=27.00;} 
			if (poidTotal <=19000) {trans=26.30;} 
			if (poidTotal <=18000) {trans=25.60;} 
			if (poidTotal <=17000) {trans=24.90;} 
			if (poidTotal <=16000) {trans=24.20;} 
			if (poidTotal <=15000) {trans=23.50;} 
			if (poidTotal <=14000) {trans=22.80;} 
			if (poidTotal <=13000) {trans=22.10;} 
			if (poidTotal <=12000) {trans=21.40;} 
			if (poidTotal <=11000) {trans=20.70;} 
			if (poidTotal <=10000) {trans=20.00;} 
			if (poidTotal <=9000)  {trans=19.30;} 
			if (poidTotal <=8000)  {trans=18.60;} 
			if (poidTotal <=7000)  {trans=17.90;} 
			if (poidTotal <=6000)  {trans=17.20;} 
			if (poidTotal <=5000)  {trans=16.50;} 
			if (poidTotal <=4000)  {trans=15.80;}
			if (poidTotal <=3000)  {trans=15.10;}
			if (poidTotal <=2000)  {trans=14.40;} 
			if (poidTotal <=1000)  {trans=13.70;} 
			if (poidTotal ==250)  {trans=0.00;}// poid de l'embalage blanc
			
		trans=round(trans,2);
		
		qteBa = $("#ballotin").val();
		qteCo = $("#cone").val();
		totalMontant = round(((qteLc*prixLcanel)+(qteBc*prixBcanel)+(qteGc*prixGcanel)+(qteBa*prixBa)+(qteCo*prixCo)+(1*trans)),2);
		
		$("div#fe .tt").empty().append(trans+" &euro;"); // en affiche les frais de port
		$("#prixFdp").val(trans); // on met a jour les FDP dans le hidden
		
		$("div#info_poid .valueInfo").empty().append(poidTotalKg+" kg"); // on affiche le poid total
		
		$("div#total .tt").empty().append(totalMontant+" &euro;"); // on affiche le TTC
		//alert(poidTotal);
		$("#verifPoidTotal").val(poidTotal); // on met a jour lele poid total de verification
		
	//}
}

function chronoCalendrier(){
	if (document.getElementById("livraison").value!=""){
	
		var obj = document.getElementById("livraison")
		var date = obj.value;
		
		//desactivé pour TNT
		/*
		if(document.formFacture.chrono.checked == true){
			var nbJour = -1;	
		}
		else{
			var nbJour = 1;	
		}
		*/
		var nbJour = 1;	
		
		
		explode = date.split('/');
		
		var annee = explode[2];
		var mois = explode[1];
		var jour = explode[0];
		
		var newDate = new Date(annee, mois, jour,0,0,0).addDays(nbJour)
		
		var newJour = newDate.getDate();
		var newMois = newDate.getMonth();
		var newAnnee = newDate.getFullYear();
		
		newDate = newJour+'/'+newMois+'/'+newAnnee;
		
		obj.value=newDate;
	}
}

$(document).ready(function() {
	//on recupere lepoid total de verification en grame => max 30kg => 30000g
	
		//$("div#info_date .valueInfo").empty().append(calculLivraison(2)); // on affiche la date de livraison
		
		// on recuperere les quantites pour le reafichage apres validation si pas pas bon
		$qteReaficheB = document.getElementById("b_canele").value; //
		$qteReaficheL = document.getElementById("l_canele").value; //
		$qteReaficheG = document.getElementById("g_canele").value; //
		$qteReaficheBa = document.getElementById("ballotin").value; //
		$qteReaficheCo = document.getElementById("cone").value; //
		
		
		// on cache les ligne de la facture au depart
		if($qteReaficheB == 0){
			$("div#bc").css({"display" : "none"});
		}
		if($qteReaficheL == 0){
			$("div#lc").css({"display" : "none"});
		}
		if($qteReaficheG == 0){
			$("div#gc").css({"display" : "none"});
		}
		if($qteReaficheBa == 0){
			$("div#ba").css({"display" : "none"});
		}
		if($qteReaficheCo == 0){
			$("div#co").css({"display" : "none"});
		}
		
		//on recupere les prix unitaires
		prixBcanel = document.getElementById("prixB").value;
		prixLcanel = document.getElementById("prixL").value;
		prixGcanel = document.getElementById("prixG").value;
		prixBa = document.getElementById("prixBa").value;
		prixCo = document.getElementById("prixCo").value;
		prixFdp = document.getElementById("prixFdp").value;
		
		
		//on rajoute les boutons
		$("div.btn").append('<div class="incDec"><div class="inc button">+</div><div class="dec button">-</div></div>');
		$("div.btn_emballage").append('<div class="incDec"><div class="inc button">+</div><div class="dec button">-</div></div>');
				
		$(".button").click(function() {
			
			oldQteCo = document.getElementById("oldQteCo").value;
			oldQteBa = document.getElementById("oldQteBa").value;
			oldQteGc = document.getElementById("oldQteGc").value;
			oldQteLc = document.getElementById("oldQteLc").value;
			oldQteBc = document.getElementById("oldQteBc").value;
			//alert("=> "+oldQteCo+" "+oldQteBa+" "+oldQteGc+" "+oldQteLc+" "+oldQteBc);
	
			var verifPoidTotal = document.getElementById("verifPoidTotal").value;
			//alert(verifPoidTotal);
			
			var $button = $(this);
			var oldValue = $button.parent().parent().find("input").val();
			//alert(oldValue);
			var id = $button.parent().parent().find("input").attr("id");
			//alert(id);
			
			if(id == "b_canele"){
				verifPoidTotal = parseInt(verifPoidTotal) + parseInt(poidCB);
			}
			if(id == "l_canele"){
				verifPoidTotal = parseInt(verifPoidTotal) + parseInt(poidCL);
			}
			if(id == "g_canele"){
				verifPoidTotal = parseInt(verifPoidTotal) + parseInt(poidCG);
			}
			if(id == "ballotin"){
				verifPoidTotal = parseInt(verifPoidTotal) + parseInt(poidBa);
			}
			if(id == "cone"){
				verifPoidTotal = parseInt(verifPoidTotal) + parseInt(poidCo);
			}
			//alert(verifPoidTotal);
			
			if ($button.text() == "+") {
				if(verifPoidTotal <= limitePoidsTotal){
					var newVal = parseFloat(oldValue) + 1;
				}
				else{
					var newVal = parseFloat(oldValue);	
				}
			  // AJAX save would go here
			} 
			else {
			  // Don't allow decrementing below zero
			  if (oldValue >= 1) {
				  var newVal = parseFloat(oldValue) - 1;
				  // AJAX save would go here
			  }
			  else{
			  	var newVal = 0;
			  }
			}
			
			$button.parent().parent().find("input").val(newVal); // met a jour les qte dans le input visible et le hidden
			
			//alert(id);
			//alert(newVal);
			if(id == "b_canele"){
				$("div#bc").css({"display" : "block"}); // on affiche la ligne
				$("div#bc span.qte").empty().append(newVal+"&nbsp;"); // on met a jour la quantite
				$("#qteCdeB").val(newVal); // on met a jour la quantite dans le form de validation
				montantBc = (newVal*prixBcanel);
				montantBcA = round(montantBc,2);
				$("div#bc span.tt").empty().append(montantBcA+" &euro;");
				if(newVal < 1){
					$("div#bc").css({"display" : "none"});
				}
			}
			if(id == "l_canele"){
				$("div#lc").css({"display" : "block"});
				$("div#lc span.qte").empty().append(newVal+"&nbsp;"); // on met a jour la quantite
				$("#qteCdeL").val(newVal);
				montantLc = (newVal*prixLcanel);
				montantLcA = round(montantLc,2);
				$("div#lc span.tt").empty().append(montantLcA+" &euro;");
				if(newVal < 1){
					$("div#lc").css({"display" : "none"});
				}
			}
			if(id == "g_canele"){
				$("div#gc").css({"display" : "block"});
				$("div#gc span.qte").empty().append(newVal+"&nbsp;"); // on met a jour la quantite
				$("#qteCdeG").val(newVal);
				montantGc = (newVal*prixGcanel);
				montantGcA = round(montantGc,2);
				$("div#gc span.tt").empty().append(montantGcA+" &euro;");
				if(newVal < 1){
					$("div#gc").css({"display" : "none"});
				}
			}
			if(id == "ballotin"){
				$("div#ba").css({"display" : "block"});
				$("div#ba span.qte").empty().append(newVal+"&nbsp;"); // on met a jour la quantite
				$("#qteCdeBa").val(newVal);
				montantBa = (newVal*prixBa);
				montantBaA = round(montantBa,2);
				$("div#ba span.tt").empty().append(montantBaA+" &euro;");
				if(newVal < 1){
					$("div#ba").css({"display" : "none"});
				}
			}
			if(id == "cone"){
				$("div#co").css({"display" : "block"});
				$("div#co span.qte").empty().append(newVal+"&nbsp;"); // on met a jour la quantite
				$("#qteCdeCo").val(newVal);
				montantCo = (newVal*prixCo);
				montantCoA = round(montantCo,2);
				$("div#co span.tt").empty().append(montantCoA+" &euro;");
				if(newVal < 1){
					$("div#co").css({"display" : "none"});
				}
			}
			
			// quantité de chaque canelé etemballage
			qteBc = $("#b_canele").val();
			qteLc = $("#l_canele").val();
			qteGc = $("#g_canele").val();
			qteBa = $("#ballotin").val();
			qteCo = $("#cone").val();
			
			// poids total des canelés en gramme
			poidTotal = ((qteBc*poidCB)+(qteLc*poidCL)+(qteGc*poidCG)+(qteBa*poidBa)+(qteCo*poidCo)+(poidCartonB*1));
			// poids total des canelés en kg
			poidTotalKg = round((poidTotal/1000),2) 
			//alert(poidTotal+" / "+poidTotalKg);
			
			/*desactiver pour tester TNT*/
			/*
			if(document.formFacture.chrono.checked == true){
				if (poidTotal >=30000) {trans=37.22;} // pour definir quand meme trans
				if (poidTotal <=30000) {trans=37.22;}
				if (poidTotal <=29000) {trans=36.48;}
				if (poidTotal <=28000) {trans=35.74;}
				if (poidTotal <=27000) {trans=34.99;}
				if (poidTotal <=26000) {trans=34.25;}
				if (poidTotal <=25000) {trans=33.51;}
				if (poidTotal <=24000) {trans=32.77;}
				if (poidTotal <=23000) {trans=32.03;}
				if (poidTotal <=22000) {trans=31.29;}
				if (poidTotal <=21000) {trans=30.55;}
				if (poidTotal <=20000) {trans=29.80;}
				if (poidTotal <=19000) {trans=29.06;}
				if (poidTotal <=18000) {trans=28.32;}
				if (poidTotal <=17000) {trans=27.58;}
				if (poidTotal <=16000) {trans=26.84;}
				if (poidTotal <=15000) {trans=26.10;}
				if (poidTotal <=14000) {trans=25.38;}
				if (poidTotal <=13000) {trans=24.66;}
				if (poidTotal <=12000) {trans=23.94;}
				if (poidTotal <=11000) {trans=23.23;}
				if (poidTotal <=10000) {trans=22.51;}
				if (poidTotal <=9000)  {trans=21.79;}
				if (poidTotal <=8000)  {trans=21.07;}
				if (poidTotal <=7000)  {trans=20.36;}
				if (poidTotal <=6000)  {trans=19.64;}
				if (poidTotal <=5000)  {trans=18.92;}
				if (poidTotal <=2000)  {trans=18.63;}
				if (poidTotal ==250)  {trans=0.00;}// poid de l'embalage blanc
			}
			else{
				if (poidTotal >=30000) {trans=24.6;} // pour definir quand meme trans
				if (poidTotal <=30000) {trans=24.6;}
				if (poidTotal <=15000) {trans=19.3;}
				if (poidTotal <=10000) {trans=17.5;}
				if (poidTotal <=7000)  {trans=14.8;}
				if (poidTotal <=5000)  {trans=13.0;}
				if (poidTotal <=3000)  {trans=11.1;}
				if (poidTotal <=2000)  {trans=10.2;}
				if (poidTotal <=1000)  {trans=9.3;}
				if (poidTotal <=500)   {trans=8.1;}
				if (poidTotal ==250)  {trans=0.00;}// poid de l'embalage blanc
			}
			*/
			if (poidTotal >=30000) {trans=34.00;}
			if (poidTotal <=30000) {trans=34.00;} 
			if (poidTotal <=29000) {trans=33.30;} 
			if (poidTotal <=28000) {trans=32.60;} 
			if (poidTotal <=27000) {trans=31.90;} 
			if (poidTotal <=26000) {trans=31.20;} 
			if (poidTotal <=25000) {trans=30.50;} 
			if (poidTotal <=24000) {trans=29.80;} 
			if (poidTotal <=23000) {trans=29.10;} 
			if (poidTotal <=22000) {trans=28.40;} 
			if (poidTotal <=21000) {trans=27.70;} 
			if (poidTotal <=20000) {trans=27.00;} 
			if (poidTotal <=19000) {trans=26.30;} 
			if (poidTotal <=18000) {trans=25.60;} 
			if (poidTotal <=17000) {trans=24.90;} 
			if (poidTotal <=16000) {trans=24.20;} 
			if (poidTotal <=15000) {trans=23.50;} 
			if (poidTotal <=14000) {trans=22.80;} 
			if (poidTotal <=13000) {trans=22.10;} 
			if (poidTotal <=12000) {trans=21.40;} 
			if (poidTotal <=11000) {trans=20.70;} 
			if (poidTotal <=10000) {trans=20.00;} 
			if (poidTotal <=9000)  {trans=19.30;} 
			if (poidTotal <=8000)  {trans=18.60;} 
			if (poidTotal <=7000)  {trans=17.90;} 
			if (poidTotal <=6000)  {trans=17.20;} 
			if (poidTotal <=5000)  {trans=16.50;} 
			if (poidTotal <=4000)  {trans=15.80;}
			if (poidTotal <=3000)  {trans=15.10;}
			if (poidTotal <=2000)  {trans=14.40;} 
			if (poidTotal <=1000)  {trans=13.70;} 
			if (poidTotal ==250)  {trans=0.00;}// poid de l'embalage blanc
			
			trans=round(trans,2);
			
			qteBa = $("#ballotin").val();
			qteCo = $("#cone").val();
			totalMontant = round(((qteLc*prixLcanel)+(qteBc*prixBcanel)+(qteGc*prixGcanel)+(qteBa*prixBa)+(qteCo*prixCo)+(1*trans)),2);
			
			$("div#fe span.tt").empty().append(trans+" &euro;"); // en affiche les frais de port
			
			$("div#info_poid .valueInfo").empty().append(poidTotalKg+" kg"); // on affiche le poid total
			
			$("#verifPoidTotal").val(poidTotal); // on met a jour lele poid total de verification
			
			$("div#total .tt").empty().append(totalMontant+" &euro;"); // on affiche le TTC
			
			$("#prixFdp").val(trans); // on met a jour les FDP dans le hidden
			
	
			
		});
});
