/*

gestion jquery du formulaire

*/
// dès que le document html est ready = $(function() { … });
// ah c'est beau jquery
$(function(){
	// si ya un changement d'état sur zone, jour, horaire : on affiche ligne3, 4…
	
	$("#zone").change(function() { 
		$("#lazone").append('<p>('+$("#zone").val()+')</p>');
		$("#lazone").show("slow");
		$("#ligne4").show("slow");
		$("#ligne2").hide("fast");
	});
	
	// idem au focus ou click
	$("#arrive").focus(function() {
		$("#ligne7").show("slow");
		$('#depart').flushCache();
	});
	$("#depart").focus(function() {
		$('#arrive').flushCache();
	});
	
	$("#arrive").click(function() { 
		$('#arrive').flushCache();
	});
	$("#depart").click(function() { 
		$('#depart').flushCache();
	});
	
	// autocomplete por depart et arrivé
	// passage des variables champ, horiare, zone etc à inc.ajax.ph
	$("#depart").autocomplete("inc.ajax.php",{
		delay:100,autoFill:true,extraParams:{
			champ:"depart",
			zone:function() { return $("#zone").val(); },
			type_transport:function() { return $("#type_transport").val(); }
		}
	});
	$("#arrive").autocomplete("inc.ajax.php",{
		delay:100,autoFill:true,extraParams:{
			champ:"arrive",
			zone:function() { return $("#zone").val(); },
			type_transport:function() { return $("#type_transport").val(); },
			depart:function() { return $("#depart").val(); }
		}
	});


});



// si on click chercher ca lance les var depart arrive (des id du formulaire correspondant) à inc.ajax-results.php
// envoi du resultat à l'id ds le form #resultat
//  $("#arrive").val().substr(0, $("#arrive").val().length-8),
// permet de recuperer "Erize la Petite - 08:16" et de virer l'heure et les ' - ' avant… pour recup le nom de ville et le rechercher.
function results() {

	$("#resultat").html('');
	$("#resultat").hide("fast");
	
	bodyContent = $.ajax({
		url: "inc.ajax-results.php",
		global: false,
		type: "POST",
		data: ({
		   depart:$("#depart").val(),
		   arrive:$("#arrive").val(),
		   zone:$("#zone").val(),
		   type_transport:function() { return $("#type_transport").val(); }
		}),
		dataType: "html",
		success: function(result){
			$("#resultat").append(result);
		}
	}).responseText;	 
}

// nettoyage
/*function clear_results() {
	$("#resultat").html('');
	$("#ligne8").hide("fast");

}*/

