/**********************************************************************************
*
*   JQUERY FUNCTIONS
*
**********************************************************************************/

$(document).ready(function() {
	
													 
	// pour afficher les familles de produits											 
	$("a.fam-link").livequery("click", function(){
		idV = ($(this).attr("id"));	
		//alert(idV);
		$(".produits-tables-div").css("display","none");
		$("#"+idV+"div").css("display","block");
		return false;
	}); 
 
 
 
 	// pour afficher la commande en cours	on hover									 
	$("#conditionsButton").hover(	
		function(){
			//alert("hover");																						 
			$("#conditions").css("display","block");
			//alert($("#basketbutton").position("top")); 
			return false;
		},			
		""
	); 
	
	
	
	// pour cacher la commande en cours off hover								 
	$("#conditions").hover(	
		"",			
		function(){
			//alert("out");																						 
			$("#conditions").css("display","none");
			return false;
		}	
	); 
 
 
 
});



/**********************************************************************************
*
*   FUNCTION FOR ADDING PRODUCT PRICES IN PALC PAGE *ONLY*
*
**********************************************************************************/

function addUpPALC(){

	var numFields=((document.forms['products'].elements.length)-2)/5
	var val;
	var sum = 0;
	var consNum;
	var valsPanTot = 0;
	var added = 0;
	var fam;
	




		if(jsClientId &&(jsClientId!='')){ // si client loggé
			
			for(i=1;i<=numFields;i++){	
				//alert("fam = " + document.forms['products'].elements['fam' + i].value);				
				fam = document.forms['products'].elements['fam' + i].value;
	
				if(fam == "01PANI"){ // si la famille est de type qui nécessite 1 consigne
					val = Number(document.forms['products'].elements['num' + i].value);	
					if(val>0){
						valsPanTot += val;						
					}
				}				
				if(document.forms['products'].elements['fam' + i].value == "40CONS"){
					consNum = document.forms['products'].elements['count' + i].value;
					//consNum = 0;
				}
			}
			
			//alert(valsPanTot);
			
			if(valsPanTot>consigne){				
				//if(document.forms['products'].elements['num' + consNum].value==""){
					
					var consToAdd = (valsPanTot-consigne);
					
					document.forms['products'].elements['num' + consNum].value = consToAdd;
					alert("Actuellement vous avez " + consigne + " consigne(s).\nNous allons donc ajouter " + consToAdd + " consigne(s) à votre règlement");
				//}
			}else{
				document.forms['products'].elements['num' + consNum].value = "";		
			}
		}	// fin si client loggé

	

	
	// adding
	for(i=1;i<=numFields;i++){		
		if(document.forms['products'].elements['fam' + i].value != "40CONS"){
			val = Number(document.forms['products'].elements['val' + i].value);
			sum = (sum + (Number(document.forms['products'].elements['num' + i].value)*val));
		}
	}
	document.forms['products'].elements['total'].value = sum.toFixed(2);
}

