$(function() {
	if(typeof(dateFormat)=='undefined') {
		var regional = 'fr';
		var dateFormat = 'dd/mm/yy';
	}
		$( "#dates" ).datepicker({ dateFormat: dateFormat, altField: "#date", altFormat: "yy-mm-dd", minDate: new Date(), maxDate: new Date(2012, 3, 20)});
	$( "#datesejour" ).datepicker({ dateFormat: dateFormat, altField: "#sejourdate", altFormat: "yy-mm-dd", minDate: new Date(), maxDate: new Date(2012, 3, 20)});
	$( ".datesejour" ).datepicker( "option", $.datepicker.regional[ regional ] );
	$( ".datesejour" ).datepicker( "option", "dateFormat", dateFormat );
	
	$('#menu-categories a').click(function(){
				var link = $(this);
				$("#lesarticles").load(this.href, function(){
					$("#menu-categories li a").each(function(){
						$(this).removeClass('select');
					});
					link.addClass('select');
				});
				return false;
		});
	
});

function supprime(cle){
	var nbrArticles = $("input[name=nbrArticles]").val();
	var prixSelection = $("input[name=prixSelection]").val();
	$.ajax({
		type: "POST",
		url: "/supprime",
		data: "cle="+cle+"&nbrArticles="+nbrArticles+"&prixSelection="+prixSelection,
		dataType: 'json',
		success: function(reponse){
			$("input[name=prixReservation]").val(reponse.prixReservation);
			$("input[name=prixSelection]").val(reponse.prixSelection);
			$("input[name=nbrArticles]").val(reponse.nbrArticles);

			$("#article_"+reponse.cle).slideUp("slow", function(){
				$("#detailsArticles").text(reponse.nbrArticles + " article" + (parseInt(reponse.nbrArticles) > 1 ? "s" : "") + " | total : " + parseFloat(reponse.prixReservation).toFixed(2) + " €");
				$("#totalSelection").html("<strong>"+parseFloat(reponse.prixSelection).toFixed(2)+" €</strong>");
				$("#totalReservation").html("<strong>"+parseFloat(reponse.prixReservation).toFixed(2)+" €</strong>");	
			});

		}
	});
}
