// JavaScript Document
function choixStation(id_station)
{
	$.getJSON('/ajax/getMagasins.php',{id_station : id_station}, function(data) 
	{
		var selectMagasin = $('#id_magasin');
		selectMagasin.find('option').remove().end().append('<option value="0">-----</option>');	
		$.each(data, function(key, val) {
			selectMagasin.change(
				function()
				{
					choix_magasin(selectMagasin.val());	
				}
			);
			selectMagasin.append($("<option></option>").attr("value",key).text(val)); 		
		});		
	});	
}	

function choix_magasin(id_magasin)
{		
	
	$.getJSON('/ajax/getDates.php',{id_magasin : id_magasin}, function(magasin) 
	{						
		$(":date").data("dateinput").setMin(magasin.date_ouverture, true);
		$(":date").data("dateinput").setMax(magasin.date_fermeture, true);			
	});		
}	

function goReservation(lang)
{
	var id_magasin 		= 	$('#id_magasin').val();
	var date_arrivee	= 	$('#date_arrivee').val();
	var code_promo		=	$('#code_promo').val();
	var verif = true;
	$('.formVerify').each(			
		function()
		{
			if($(this).val() == 0)
			{
				$(this).addClass('empty');	
				verif = false;
			}
			else
			{
				$(this).removeClass('empty');	
			}
		}
	);
	if(verif)
	{
		$.ajax({
			type: "POST",
			url: "/ajax/createUrl.php",
			data: {id_magasin:id_magasin,date_arrivee:date_arrivee,code_promo:code_promo,lang:lang} ,
			success:function(reponse){
					location.href = reponse;
			}
		});
	}
}

