$(function(){
	$("div#menu_fr").load("/inc/menu-fr.html", function(){
		$(this).children("ul.menu").fadeIn(500);
		$("a#logo").fadeIn(500);

		$(this).children("ul.menu").children("li").children("a").hover(function(){
			$(this).animate({color : "#D5D9C2"});
		}, function(){
			$(this).animate({color : "#606E17"});
		});

		$(this).children("ul.menu").children("li").children("ul").children("li").children("a").hover(function(){
			$(this).stop().animate({color : "#D5D9C2"}, 600);
		}, function(){
			$(this).stop().animate({color : "#606E17"}, 600);
		});
		

		$(this).children("ul.menu").children("li").children("ul").children("li").children("ul").children("li").children("a").hover(function(){
			$(this).stop().animate({color : "#D5D9C2"}, 600);
		}, function(){
			$(this).stop().animate({color : "#606E17"}, 600);
		});
	});

	
	$("div#menu_en").load("/inc/menu-en.html", function(){
		$(this).children("ul.menu").fadeIn(500);
		$("a#logo").fadeIn(500);

		$(this).children("ul.menu").children("li").children("a").hover(function(){
			$(this).animate({color : "#D5D9C2"});
		}, function(){
			$(this).animate({color : "#606E17"});
		});

		$(this).children("ul.menu").children("li").children("ul").children("li").children("a").hover(function(){
			$(this).stop().animate({color : "#D5D9C2"}, 600);
		}, function(){
			$(this).stop().animate({color : "#606E17"}, 600);
		});
		

		$(this).children("ul.menu").children("li").children("ul").children("li").children("ul").children("li").children("a").hover(function(){
			$(this).stop().animate({color : "#D5D9C2"}, 600);
		}, function(){
			$(this).stop().animate({color : "#606E17"}, 600);
		});
	});
	
	
	
	////////////////////////////////////////////////////////////////
	// FORM VALIDATION - START
	////////////////////////////////////////////////////////////////
		$("#newAddress").click(function(){
			if($(this).is(":checked")) {
				$("input.newAddress").attr("required", "true");
				$("div#new_address").slideDown(500);
			} else {
				$("div#new_address").slideUp(500);
				$("input.newAddress").attr("required", "false");
			}
		});

		$("input[name=submit]").click(function(){
			var form = $(this).parents("form");
			var msg = "";
			var tableau = new Array( true,"","" );	
			var errors = "";

			form.find("input[required=true], textarea[required=true]").each(function(){
				var id = $(this).attr("id");
				var message = $(this).attr("message");

				est_la(id, tableau, message + " /", id + " /");

				if(id == "courriel" || id == "email")
					est_courriel_valide(id, tableau, $(this).attr("message2") + " /", id + " /");
			});
			

			if($("#newAddress").is(":checked")) {
				form.find("input.newAddress").each(function(){
					var id = $(this).attr("id");
					var message = $(this).attr("message");

					est_la(id, tableau, message + " /", id + " /");
				});
			}


			if(tableau[0]) {
				var formData = form.serialize();
				$.ajax({
					type: "POST",
					url: "/inc/php/post.php",
					data: formData,
					success: function(response) {}
				});

				form.slideUp(500);
				$("div#errors").slideUp(500);
				$("div#success").slideDown(500);
			} else {
				var aMSG = tableau[1].split(" /");
				var aFIELD = tableau[2].split(" /");

				errors += "<p>Le formulaire comporte certaines erreurs :</p>";
				errors += "<ul>";
				for( var i = 0; i < aMSG.length; i++ ) {
					if( aMSG[i] != "" )
						errors += "<li>"+aMSG[i]+"</li>";
				}
				errors += "</ul>";

				$("div#errors")
					.html(errors)
					.slideDown(500);
			}

			return false;
		});
	////////////////////////////////////////////////////////////////
	// FORM VALIDATION - END
	////////////////////////////////////////////////////////////////
});
