// JavaScript Document

/* document Ready */
/*$( function () {
	addEvent(window, "load", tmt_validatorInit);
	doOnLoad($("body"));
});

function doOnLoad(context){

	$('.errorMessage', context).hide();
	
	$(".submit", context).click(function(){
		//$('#errorMessage').html('');									 
		$(this).parents("form").children('.errorMessage').hide();
		if($(this).parents("form")[0].onsubmit()){
			$(this).parents("form")[0].submit();
		}
	});
	
}

//Affichage des erreurs, fonction appellée par TMTValidator
function displayError(frm){
	$('#errorMessage').html('Certaines informations sont incomplètes ou invalides, veuillez les compléter correctement <br>');
	$(frm).children('.errorMessage').show();
}*/


$(document).ready( function () {
	$(".submit").click(function(){
		//$('#errorMessage').html('');									 
		//$(this).parents("form").children('.errorMessage').hide();
		if($(this).parents("form")[0].onsubmit()){
			$(this).parents("form")[0].submit();
		}
	});

	$("#homeBouttonRecherche").click(function(){
		//$('#errorMessage').html('');									 
		//$(this).parents("form").children('.errorMessage').hide();
		var zMotCle = $("#home_zMotCle").val();

		//if (zMotCle != "" && zMotCle.length > 2)
		if ( zMotCle.length > 2 && zMotCle != "Recherchez votre recette par mot clé")
		{
			if($(this).parents("form")[0].onsubmit()) {
			    $.post("index.php", {module:"recette", action:"recette:ajoutSessionCritereHomePage", zMotCle:zMotCle}, function() {
//			        window.location.href = j_basepath+"index.php?module=recette&action=recette:rechercheRecette";
			        window.location.href = j_basepath+"index.php/trouver_recette";
			    }, "json");
			 //$(this).parents("form")[0].submit();
			}
		}else{
			alert("Veuillez saisir un mot-clé ayant au moins trois caractères");
		}
		
	});
	
	// Retour à la page précédente 
	$("a[title=Retour]").click(function() {
	    window.location.href = j_basepath+"index.php/comment_cuisiner_veau";
	});

} ) ;
