$(function() {
		
		//au chargement de la page, on teste avant quelle est la valeur dans select pour calculer les prix à afficher
		$("#tableau_choix_commande .duree").each(function() {
			
			var duree=$(this).val().split(':');
			var identifiant=duree[0];
			var nouveau_prix=duree[1];
			
			$(this).parent('td').parent('tr').children('td').children('span').children('.lien_panier').attr('href','#');
			$(this).parent('td').parent('tr').children('td').children('.prix').html(nouveau_prix+"<span> €</span>");
			
			var qte=$(this).blur().parent('td').parent('tr').children('td').children('.qte').val();
			var nouveau_total=Math.round((nouveau_prix*qte)*100)/100;
			$(this).blur().parent('td').parent('tr').children('td').children('.total').html(nouveau_total+"<span> €</span>");
			$(this).parent('td').parent('tr').children('td').children('span').children('.lien_panier').attr('href','formulaire_commande/'+identifiant+'/ajout_produit.html');
			
		});
		
		//si on change la durée
		$("#tableau_choix_commande .duree").change(function() {
			var ancien_prix=$(this).blur().parent('td').parent('tr').children('td').children('.prix').html();
			var duree=$(this).blur().val().split(':');
			var identifiant=duree[0];
			var nouveau_prix=duree[1];
			var qte=$(this).blur().parent('td').parent('tr').children('td').children('.qte').val();
			var qte=Math.round(qte);
			
			//on met toujours au minimum 1 à la qté 
			if(qte<1) {
				$(this).blur().parent('td').parent('tr').children('td').children('.qte').val(1);
				qte=1;
			} 
			
			var is_numeric=new RegExp("^[0-9]+$","g");
			
			if(!is_numeric.test(qte)) {
				$(this).blur().parent('td').parent('tr').children('td').children('.qte').val(1);
				qte=1;
			}
			
			var nouveau_total=Math.round((nouveau_prix*qte)*100)/100;
			
			$(this).parent('td').parent('tr').children('td').children('span').children('.lien_panier').attr('href','#');

			$(this).blur().parent('td').parent('tr').children('td').children('.prix').html(nouveau_prix+"<span> €</span>");
			$(this).blur().parent('td').parent('tr').children('td').children('.total').html(nouveau_total+"<span> €</span>");
			$(this).parent('td').parent('tr').children('td').children('span').children('.lien_panier').attr('href','formulaire_commande/'+identifiant+'/ajout_produit.html');

			

		});
 	
		//si on change la quantité 
		$("#tableau_choix_commande .qte").change(function() {
			var ancien_prix=$(this).blur().parent('td').parent('tr').children('td').children('.prix').html();
			var duree=$(this).blur().parent('td').parent('tr').children('td').children('.duree').val().split(':');
			var nouveau_prix=duree[1];
			var qte=$(this).blur().val();
			var qte=Math.round(qte);

			//on met toujours au minimum 1 à la qté 
			if(qte<1) {
				$(this).blur().val(1);
				qte=1;
			} 
			
			
			var is_numeric=new RegExp("^[0-9]+$","g");

			if(!is_numeric.test(qte)) {
				$(this).blur().parent('td').parent('tr').children('td').children('.qte').val(1);
				qte=1;
			}
			

			var nouveau_total=Math.round((nouveau_prix*qte)*100)/100;

			$(this).blur().parent('td').parent('tr').children('td').children('.prix').html(nouveau_prix+"<span> €</span>");
			$(this).blur().parent('td').parent('tr').children('td').children('.total').html(nouveau_total+"<span> €</span>");

		});
		
		
		
	});
	
/* pour les popups descriptives des produits */	
$().ready(function() {

	var i=0;
	var nomDiv=new Array();
	var nomTrigger=new Array();
	var nomParam=new Array();
	
	$("#tableau_caddie td.nom_produit a").each(function() {

			var valueTrigger=$(this).attr("class");
			var tab_retour=valueTrigger.split('_');
			var paramAjax=tab_retour[2];
			var element=tab_retour[3];
			
			nomDiv[i]='#box_'+paramAjax+'_'+element;
			nomTrigger[i]=valueTrigger;
			nomParam[i]=paramAjax;
			i++;
	});
	
	for(i=0; i<nomDiv.length; i++) {
		
		$(nomDiv[i]).jqm({
			
				trigger: 'a.'+nomTrigger[i],
				ajax: '/php_v4/ajax/description_produit.php?quoi='+nomParam[i],
				ajaxText: '<div align="center">Chargement en cours...<br /><br /><img src="/images/common/ajax-loader.gif" /><br /><br /><br /></div>',
				target: 'div.reponseContenu'
		});
		
	}

});

$().ready(function() {

	var i=0;
	var nomDiv=new Array();
	var nomTrigger=new Array();
	var nomParam=new Array();
	
	$("#tableau_choix_commande td.nom_produit a").each(function() {

			var valueTrigger=$(this).attr("class");
			var tab_retour=valueTrigger.split('_');
			var paramAjax=tab_retour[2];
			var element=tab_retour[3];
			
			nomDiv[i]='#box_'+paramAjax+'_'+element;
			nomTrigger[i]=valueTrigger;
			nomParam[i]=paramAjax;
			i++;
	});
	
	for(i=0; i<nomDiv.length; i++) {
		
		$(nomDiv[i]).jqm({
			
				trigger: 'a.'+nomTrigger[i],
				ajax: '/php_v4/ajax/description_produit.php?quoi='+nomParam[i],
				ajaxText: '<div align="center">Chargement en cours...<br /><br /><img src="/images/common/ajax-loader.gif" /><br /><br /><br /></div>',
				target: 'div.reponseContenu'
		});
		
	}

});





////////////////////////////////////////////////////////////////////////////////////////
///////////////////////// Catalogue de la librairie ////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////


 
$(function() {
		

		$("#tableau_choix_librairie .qte").each(function() {
			$(this).removeAttr("disabled");
		});
		
		//si on change la quantité 
		$("#tableau_choix_librairie .qte").change(function() {
			
			var prix=$(this).blur().parent('td').parent('tr').children('td').children('.prix').html();
			//alert(prix+' €');
			var qte=$(this).blur().val();
			var qte=Math.round(qte);

			var is_numeric=new RegExp("^[0-9]+$","g");

			var nouveau_total=Math.round((prix*qte)*100)/100;
			$(this).blur().parent('td').parent('tr').children('td').children('.total').html(nouveau_total);
			
			
			var temp=0;
			
			var ttotal=0;
			$("#tableau_choix_librairie .qte").each(function() {
				temp=$(this).blur().parent('td').parent('tr').children('td').children('.total').html();
				//alert((i++)+" total => "+ttotal+" prix => "+temp);
				ttotal=parseInt(ttotal)+parseInt(temp);
				
			});
			
			$("#ttotal").html(ttotal);
			
			if(ttotal > 0) {
				$("#img_poursuivre_commande").attr("src","/images/recrut/boutons/poursuivre_commande.png");
			} else {
				$("#img_poursuivre_commande").attr("src","/images/recrut/boutons/poursuivre_commande_off.png");
			}
			

		});
		
		
		
		
		
		
});


$(function() {
		

		$("#img_poursuivre_commande").click(function() {
			
			if($("#img_poursuivre_commande").attr("src")=="/images/recrut/boutons/poursuivre_commande_off.png") {
				alert("Vous devez mettre au moins un article dans votre panier avant de poursuivre votre commande.");
				return false;
			} else {
				return true;
			}
			

		});
		
		
	
});




$().ready(function() {

	var i=0;
	var nomDiv=new Array();
	var nomTrigger=new Array();
	var nomParam=new Array();
	
	$("#tableau_choix_librairie .description a").each(function() {
	
			var valueTrigger=$(this).attr("class");
			var tab_retour=valueTrigger.split('_');
			var paramAjax=tab_retour[2];
			var element=tab_retour[3];
			nomDiv[i]='#box_'+paramAjax+'_'+element;
			nomTrigger[i]=valueTrigger;
			nomParam[i]=paramAjax;
			i++;
			
	});
	
	for(i=0; i<nomDiv.length; i++) {
		
		$(nomDiv[i]).jqm({
			
				trigger: 'a.'+nomTrigger[i],
				ajax: '/php_v4/ajax/description_produit.php?quoi='+nomParam[i],
				ajaxText: '<div align="center">Chargement en cours...<br /><br /><img src="/images/common/ajax-loader.gif" /><br /><br /><br /></div>',
				target: 'div.reponseContenu'
		});
		
		
		
		$(nomDiv[i]).css('opacity',1).jqDrag();
  

		
	}

});
