if($('#choix')){


var content="";
for(i=0;i<13;i++)
	content=content+"<option value='"+i+"'>"+i+"</option>";
	
$('#choix select').each(function(i){
		
	$(this).html(content);
	
});


$('#choix select').change(changechoix12);


} //endif #choix

if($('#choix2')){


	var content="";
	for(i=0;i<4;i++)
		content=content+"<option value='"+i+"'>"+i+"</option>";
		
	$('#choix2 select').each(function(i){
			
		$(this).html(content);
		
	});

	$('#choix2 select').change(changechoix12);

}//endif choix2

function changechoix12(){
	
	var total=0;
	var options="";
	var resteSpecials=3;
	$('#choix select').each(function(i){
		
		valcookies=$(this).val();
		if(valcookies>0){
			total=total+parseInt(valcookies);
			options=options+parseInt(valcookies)+"*"+$(this).prev().html()+";";
		}
	});
	$('#choix2 select').each(function(i){
		
		valcookies=$(this).val();
		if(valcookies>0){
			resteSpecials=parseInt(resteSpecials)-parseInt(valcookies);
			total=total+parseInt(valcookies);
			options=options+parseInt(valcookies)+"*"+$(this).prev().html()+";";
		}
	});
	var diff=12-parseInt(total);
	//on repasse sur les select pour refaire les maximums..
	$('#choix select').each(function(i){
		
		valselect=$(this).val();
		
		if(diff>0){
			valmax=parseInt(valselect)+parseInt(diff);
		}
		else{
			valmax=valselect;
		}
		
		var content="";
		for(i=0;i<=valmax;i++){
			if(valselect==i && valselect>0)
				content=content+"<option value='"+i+"' selected>"+i+"</option>";
			else
				content=content+"<option value='"+i+"'>"+i+"</option>";
		}
		$(this).html(content);
	});
	$('#choix2 select').each(function(i){
		
		valselect=$(this).val();
		
		if(diff<=0){
			valmax=valselect;
		}
		else{
			valmax=parseInt(resteSpecials)+parseInt(valselect);
		}
		if(valmax>3) valmax=3;
		
		var content="";
		for(i=0;i<=valmax;i++){
			if(valselect==i && valselect>0)
				content=content+"<option value='"+i+"' selected>"+i+"</option>";
			else
				content=content+"<option value='"+i+"'>"+i+"</option>";
		}
		$(this).html(content);
	});
	
	
	if(total<=12){
		content="Vous avez choisi "+total+" Cookies";
	}
	if(total>12){
		content="Vous avez choisi "+total+" Cookies<br /><p style='color:#922; font-weight:bold;'>Il y a trop de cookies ! veuillez en sélectionner 12.</p>";
		options="Trop de cookies";
	}
	if(total==1){
		content="Vous avez choisi 1 Cookie";
	}
	//alert(content);
	$('#nb_cookies').html(content);
	//alert(options);
	$('#cookies_choisis').val(options);
	
	if(total==12){
		$('#notsendPanier').hide();
		$('#sendPanier').fadeIn();
		$('#mess_panier').html("");
	}
	else{
		$('#sendPanier').hide();
		$('#notsendPanier').fadeIn();
		$('#mess_panier').html("Encore "+diff+" cookies pour ajouter cette boite à votre panier.");
	}
	
}

