	var cars = new Array();
	var voitures = new Array();
	var categories = new Array();
	var tarif_tour = new Array();
	var tours_mini = new Array();
	var tarif_solos = new Array();
	var tarif_combos = new Array();
	
	var date_en_cours = 0;
	var time_en_cours = 0;
	
	var selections = new Array();
	var tours = new Array();
	var tarifs = new Array();
	
	var total = 0;
	var total_options = 0;
	
	var ajaxGarage = new Object();
	
	function format(valeur, decimal, separateur)
	{
		var deci=Math.round(Math.pow(10,decimal)*(Math.abs(valeur)-Math.floor(Math.abs(valeur)))) ; 
		var val=Math.floor(Math.abs(valeur));
		if((decimal==0)||(deci==Math.pow(10,decimal)))
		{
			val=Math.floor(Math.abs(valeur)); deci=0;
		}
		var val_format=val+"";
		var nb=val_format.length;
		for(var i=1;i<4;i++)
		{
			if (val>=Math.pow(10,(3*i)))
			{
				val_format=val_format.substring(0,nb-(3*i))+separateur+val_format.substring(nb-(3*i));
			}
		}
		if (decimal>0)
		{
			var decim=""; 
			for(var j=0;j<(decimal-deci.toString().length);j++)
			{
				decim+="0";
			}
			deci=decim+deci.toString();
			val_format=val_format+"."+deci;
		}
		if(parseFloat(valeur)<0)
		{
			val_format="-"+val_format;
		}
		return val_format;
	}
	
	function add(id_voiture)
	{
		selections.push(id_voiture);
		tours[id_voiture] = tours_mini[id_voiture];
		tarifs[id_voiture] = tarif_solos[id_voiture];
		
		displayCars(date_en_cours, time_en_cours);
	}
	
	function remove(id_voiture)
	{
		var tmpS = new Array();
		var tmpT = new Array();
		
		for(var i=0; i<selections.length; i++)
		{
			if(selections[i] != id_voiture)
			{
				tmpS.push(selections[i]);
				tmpT[selections[i]] = tours[selections[i]];
			}
		}
		selections = tmpS;
		tours = tmpT;
		
		displayCars(date_en_cours, time_en_cours);
	}
	
	function selectTours(id_voiture, nb)
	{
		for(var i=0; i<selections.length; i++)
		{
			if(selections[i] == id_voiture)
			{
				tours[selections[i]] = nb;
			}
		}
		refreshPrice();
	}
	
	function loadingGarage()
	{
		//une fois que l'ajax est charge, on peut rafraichir le prix
		if(ajaxGarage.readyState != 4)
		{
			setTimeout("loadingGarage()",200);
		}
		else
		{
			refreshPrice();
		}
   	}
	
	function refreshPrice()
	{
		total = 0;
		var tt_tours = 0;
		//var chaine_tours = "";
		var intitule = "";
		var intitulehaut = "";
		
		//on retire les voitures qui sont absentes
		var tmpS = new Array();
		for(var i=0; i<selections.length; i++)
		{
			if(document.getElementById("CUSTOMS_"+selections[i]))
			{
				if(document.getElementById("CUSTOMS_"+selections[i]).options[document.getElementById("CUSTOMS_"+selections[i]).selectedIndex].value > 0)
				{
					tmpS.push(selections[i]);
				}
			}
		}
		selections = tmpS;
		
		if(selections.length)
		{
			if(selections.length == 1)
			{
				total = tarif_solos[selections[0]] + (tours[selections[0]] - tours_mini[selections[0]]) * tarif_tour[selections[0]];
				tt_tours = parseInt(tours[selections[0]]);
				//chaine_tours = tt_tours+"+";
				intitulehaut = intitule = voitures[selections[0]]+" - "+tours[selections[0]]+" laps";
			}
			else
			{
				
				var max_tt = 0;
				var max_car = 0;
				var max_price = 0;
				
				for(var i=0; i<selections.length; i++)
				{
					//recuperer la voiture, le prix de base le plus cher, et le cumul des tours liés
					if(tarif_solos[selections[i]] > max_price)
					{
						max_price = tarif_solos[selections[i]];
						max_tt = (tours[selections[i]] - tours_mini[selections[i]]) * tarif_tour[selections[i]];
						max_car = selections[i];
					}
				}
				total = max_price + max_tt;
				for(var i=0; i<selections.length; i++)
				{
					tt_tours+= parseInt(tours[selections[i]]);
					intitule+= voitures[selections[i]]+" - "+parseInt(tours[selections[i]])+" laps<br />";
					
					//on zappe la voiture de reference
					if(selections[i] == max_car) continue;
					total+= tours[selections[i]] * tarif_tour[selections[i]];
				}
				//intitule = intitule.substring(0, intitule.length-2)+"= "+tt_tours+" laps<br />";
				intitulehaut = intitule = "COMBO "+selections.length+" = "+tt_tours+" laps";
			}
		}
		
		document.getElementById("total_selection_top").innerHTML = "$"+format(total+total_options, 2, ",");
		document.getElementById("total_selection").innerHTML = "$"+format(total+total_options, 2, ",");
		
		if(tt_tours > 0)
		{
			document.getElementById("intitule").innerHTML = intitulehaut;
			document.getElementById("intitule_bas").innerHTML = intitule;
			document.getElementById("experience_price").innerHTML = " - $"+format(total, 2, ",");
			//document.getElementById("total_tours").innerHTML = (chaine_tours)+"="+(tt_tours)+" laps";
		}
		else
		{
			document.getElementById("intitule").innerHTML = "0 CAR - 0 lap";
			document.getElementById("intitule_bas").innerHTML = "0 CAR - 0 lap";
			document.getElementById("experience_price").innerHTML = "";
			//document.getElementById("total_tours").innerHTML = "0 laps";
		}
	}

	function disableDate()
	{
		if(document.getElementById('TYPEDATE').checked == true)
		{
			document.getElementById('IDSELECTDATE').disabled=false;
			displayPeriodes(document.getElementById('IDSELECTDATE').options[document.getElementById('IDSELECTDATE').selectedIndex].value);
		}
		else
		{
			document.getElementById('IDSELECTDATE').disabled=true;
			displayPeriodes();
		}
		displayCars();
	}
	
	function displayPeriodes(id_date)
	{
		getFile("/include/optionsAjax.php?date="+id_date+"&custom=1&cars="+cars,"selecteur_periodes", "null", "null", "null");
		displayCars(id_date);
	}
	
	function displayCars(id_date, id_time, decalage)
	{
		date_en_cours = id_date;
		time_en_cours = id_time;
		ajaxGarage = getFile("/include/customAjax.php?date="+id_date+"&time="+id_time+"&decalage="+decalage+"&cars="+cars+"&selections="+selections+"&tours="+tours+"&tarifs="+tarifs,"partie-haut", "null", "null", "null");
		
		// on attend le chargement complet des elements avant de rafraichir prix et tours
		loadingGarage();
	}
	
	function displayFirst(carFirst, lapFirst)
	{
		//alert(carFirst.join(";"));
		//alert(lapFirst.join(";"));
		
		selections = carFirst;
		tours = lapFirst;
		
		ajaxGarage = getFile("/include/customAjax.php?cars="+cars+"&selections="+selections+"&tours="+tours+"&tarifs="+tarifs,"partie-haut", "null", "null", "null");
		
		// on attend le chargement complet des elements avant de rafraichir prix et tours
		loadingGarage();
	}
	
	function updateTotal()
	{
		total_options = 0;
		//on board video
		if(document.getElementById('OPTION_0').checked)
		{
			total_options+= 79;
		}
		//nb ride along
		total_options+= 99 * document.getElementById('OPTION_1').selectedIndex;
		//nb ride along
		total_options+= 20 * document.getElementById('OPTION_2').selectedIndex;
		
		refreshPrice();
	}

