// JavaScript Document
$(document).ready(function(){
	// ENVOYER A UN AMI
	$("#envoiamiForm").hide();
	$(".envoiamiBouton").click(function(){
		$("#resaForm").hide();
		$("#envoiamiForm").toggle("slow", function(){$("#envoiami_Reload").click();});
		$("#envoiamiMessage").html('');
	});
 	//$("#envoiamiForm").corner("dog tr 20px");
 		// RESERVATION
	$("#resaForm").hide();
	$("#resaBouton").click(function(){
		$("#envoiamiForm").hide();
		$("#resaForm").toggle("slow", function(){$("#resa_Reload").click();});
		$("#resaMessage").html('');
	});
 	//$("#envoiamiForm").corner("dog tr 20px");

	$("#envoiami_formulaire").submit(function(){
		retour=true;
		$(".envoiamiError").html('');
		if ($("#dest01").val()=='' && $("#dest02").val()=='' && $("#dest03").val()=='' && $("#dest04").val()=='') {
			$("#error_general").html("Il faut au moins une adresse e-mail de destinataire");
			retour=false;}
		
		if ($("#dest01").val() !='' && $("#dest01").val() !=$("#dest01").val().match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i)) {
			$("#error_dest01").html("L'adresse e-mail n'est pas valide.");
			retour=false;}
		
		if ($("#dest02").val() !='' && $("#dest02").val() !=$("#dest02").val().match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i)) {
			$("#error_dest02").html("L'adresse e-mail n'est pas valide.");
			retour=false;}
		
		if ($("#dest03").val() !='' && $("#dest03").val() !=$("#dest03").val().match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i)) {
			$("#error_dest03").html("L'adresse e-mail n'est pas valide.");
			retour=false;}
		
		if ($("#dest04").val() !='' && $("#dest04").val() !=$("#dest04").val().match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i)) {
			$("#error_dest04").html("L'adresse e-mail n'est pas valide.");
			retour=false;}

		if ($("#exped").val() =='') {
			$("#error_exped").html("Champs obligatoire.");
			retour=false;}

		if ($("#exped").val() !='' && $("#exped").val() !=$("#exped").val().match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i)) {
			$("#error_exped").html("L'adresse e-mail n'est pas valide.");
			retour=false;}

		if ($("#exped_nom").val() =='') {
			$("#error_exped_nom").html("Champs obligatoire.");
			retour=false;}

		
		if ($("#envoiamiCode").val() =='') {
			$("#code_error").html("Attention vous avez oubli&eacute; de renseigner le champs CODE");
			retour=false;}
		return retour; 
	
	});
	
	function total_place(){
		total = 0;
		if ($("#resa_tarif1").val() > 0)total += Number($("#resa_tarif1").val());
		if ($("#resa_tarif2").val() > 0)total += Number($("#resa_tarif2").val());
		if ($("#resa_tarif3").val() > 0)total += Number($("#resa_tarif3").val());
		if ($("#resa_tarif4").val() > 0)total += Number($("#resa_tarif4").val());
		return total;
	}
	
	function montant_total(){
		total = 0;
		if ($("#resa_tarif1").val() > 0) total += ($("#resa_tarif1").val() * $("#resa_tarif1_prix").val());
		if ($("#resa_tarif2").val() > 0) total += ($("#resa_tarif2").val() * $("#resa_tarif2_prix").val());
		if ($("#resa_tarif3").val() > 0) total += ($("#resa_tarif3").val() * $("#resa_tarif3_prix").val());
		if ($("#resa_tarif4").val() > 0) total += ($("#resa_tarif4").val() * $("#resa_tarif4_prix").val());
		return total;
	}
	
	$("#resa_tarif1").blur(function(){
		$("#resa_total_tarif1").html(($("#resa_tarif1").val() * $("#resa_tarif1_prix").val()) + " &euro;");
		$("#resa_total").html(montant_total() + " &euro;");
		$("#resa_total_place").val(total_place());
	});
	
	$("#resa_tarif2").blur(function(){
		$("#resa_total_tarif2").html(($("#resa_tarif2").val() * $("#resa_tarif2_prix").val()) + " &euro;");
		$("#resa_total").html(montant_total() + " &euro;");
		$("#resa_total_place").val(total_place());
	});
	
	$("#resa_tarif3").blur(function(){
		$("#resa_total_tarif3").html(($("#resa_tarif3").val() * $("#resa_tarif3_prix").val()) + " &euro;");
		$("#resa_total").html(montant_total() + " &euro;");
		$("#resa_total_place").val(total_place());
	});
	
	$("#resa_tarif4").blur(function(){
		$("#resa_total_tarif4").html(($("#resa_tarif4").val() * $("#resa_tarif4_prix").val()) + " &euro;");
		$("#resa_total").html(montant_total() + " &euro;");
		$("#resa_total_place").val(total_place());
	});
	
	$("#resa_formulaire").submit(function(){
		retour=true;
		$(".envoiamiError").html('');
		if ($("#resa_nom").val()=='') {
			$("#error_resa_nom").html("Champs obligatoire");
			retour=false;}
			
		if ($("#resa_prenom").val()=='') {
			$("#error_resa_prenom").html("Champs obligatoire");
			retour=false;}
			
		if ($("#resa_adresse").val()=='') {
			$("#error_resa_adresse").html("Champs obligatoire");
			retour=false;}
			
		if ($("#resa_cp").val()=='') {
			$("#error_resa_cp").html("Champs obligatoire");
			retour=false;}
			
		if ($("#resa_ville").val()=='') {
			$("#error_resa_ville").html("Champs obligatoire");
			retour=false;}
			
		if ($("#resa_mail").val()=='') {
			$("#error_resa_mail").html("Champs obligatoire");
			retour=false;}
		
		if ( $("#resa_total_place").val()=='' || $("#resa_total_place").val()<=0) {
			$("#error_resa_tarif").html("La r&eacute;servation doit comprendre au moins 1 place");
			retour=false;}	
			
		if ($("#resa_mail").val() !='' && $("#resa_mail").val() !=$("#resa_mail").val().match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i)) {
			$("#error_resa_mail").html("L'adresse e-mail n'est pas valide.");
			retour=false;}
		
		if ($("#resaCode").val() =='') {
			$("#resa_code_error").html("Attention vous avez oubli&eacute; de renseigner le champs CODE");
			retour=false;}
		return retour; 
	
	});
});



 
