toutou.require("toutou.js.ajax", "toutou.html.dom", "toutou.html.event", "toutou.utils.browser", "toutou.event.manager", "toutou.utils.strings");

if(typeof(js) == "undefined") 
{
	js = {};
}


js.articles = function() 
{
	this.nbEtape = 0;
	
	this.form 	= tt$('formVotreRecette');
	
	this.nom_recette		= tt$('nom_recette');
	this.preparation		= tt$('description_etape_1');
	this.mail_newsletter	= tt$('mail_newsletter');
	this.CGV				= tt$('CGV');
	
	this.etape 				= tt$('addEtape');
	this.modele				= tt$('modele'); 
	this.divEtapes 			= tt$('previsualise_etapes');
	this.descriptionEtape 	= tt$('description_etape');
	this.descriptionTitle 	= tt$('descriptionTitle');
	this.visuelTitle		= tt$('visuelTitle');
	this.numEtape			= tt$('numEtape');
	this.visuelEtape		= tt$('srcImg');
	this.visuelEtapeImg		= tt$('img_etape');
	this.boutonSupprime		= tt$('bouton_supprime');
	
	closure 	= toutou.js.closure.bind(this, this.addEtape);
	toutou.html.event.addEventListener(this.etape, "click", closure);
	
	closure 	= toutou.js.closure.bind(this, this.supprimePhoto);
	toutou.html.event.addEventListener(this.boutonSupprime, "click", closure);
	
	this.addImageEtape();
	return this;
}

js.articles.prototype.valide = function () 
{
	var msg = '';
	var field = '';
	if (!this.CGV.checked) {
		msg = 'Vous devez prendre connaissance des CONDITIONS DE PUBLICATION\n' + msg;
		field = this.CGV;
	}
	if (toutou.utils.strings.isEmpty(this.mail_newsletter.value)) 
	{
		msg = 'Vous devez saisir le champ EMAIL\n' + msg;
		field = this.mail_newsletter;
	}
	else if (!toutou.utils.strings.isValidEmail(this.mail_newsletter.value)) 
	{
		msg = 'Votre adresse e-mail n\'est pas valide\n' + msg;
		field = this.mail_newsletter;
	}
	if (!tt$('texte_etape_1') || (tt$('texte_etape_1').value == 'NO_VALUE')) 
	{
		msg = 'Vous devez saisir au moins une PAGE\n' + msg;
		field = this.preparation;
	}
	
	if (toutou.utils.strings.isEmpty(this.nom_recette.value)) 
	{
		msg = 'Vous devez saisir le champ TITRE\n' + msg;
		field = this.nom_recette;
	}

	if (msg) 
	{ 
		alert(msg); 
		if (field) { field.focus(); }
		return false;
	}
	return true;
}

js.articles.prototype.addEtape = function () 
{
	if (this.numEtape.value <= this.nbEtape)	// on est en train de modifier une étape déjà créée
	{
		var descriptionTmp = htmlentities (this.descriptionEtape.value,1);
		
		if (toutou.utils.strings.isEmpty(descriptionTmp))
		{
			alert('Vous devez remplir la description de l\'étape');
			return;
		}
		else
		{
			descriptionTmp2 = descriptionTmp.replace(/\n/g, '<br />');
			tt$('p_texte_etape_'+this.numEtape.value).innerHTML = descriptionTmp2;//this.descriptionEtape.value;
			tt$('texte_etape_'+this.numEtape.value).value 		= descriptionTmp;//this.descriptionEtape.value;
		}
		
		if (this.visuelEtape.value != '')
		{
			if (tt$('img_'+this.numEtape.value))
			{
				tt$('img_'+this.numEtape.value).src = this.visuelEtape.value;
			}
			else
			{
				var img = document.createElement('img');
				img.setAttribute('id','img_'+this.numEtape.value);
				img.src = this.visuelEtape.value;
				tt$('bloc_img_etape_'+this.numEtape.value).appendChild(img);
			}
			tt$('img_etape_'+this.numEtape.value).value = this.visuelEtape.value;
		}
		else
		{
			if (tt$('img_'+this.numEtape.value))
			{
				tt$('bloc_img_etape_'+this.numEtape.value).removeChild(tt$('img_'+this.numEtape.value));
			}
			tt$('img_etape_'+this.numEtape.value).value = 'NO_VALUE';
		}
		
		if (this.nbEtape < 10)
		{
			this.visuelEtapeImg.src = 'imgT/sample_visuel_etape.jpg';
			this.visuelEtape.value = '';
			this.descriptionEtape.value 	= '';
			this.descriptionTitle.innerHTML	= this.nbEtape + 1;
			this.visuelTitle.innerHTML		= this.nbEtape + 1;
			this.numEtape.value				= this.nbEtape + 1;
			this.descriptionEtape.focus();
		}
	}
	else
	{
		var descriptionTmp = this.descriptionEtape.value;
		
		if (toutou.utils.strings.isEmpty(descriptionTmp))
		{
			alert('Vous devez remplir le texte de la page');
			return;
		}
	
		this.nbEtape++;
		descriptionTmp = htmlentities (descriptionTmp,1);
		descriptionTmp2 = descriptionTmp.replace(/\n/g, '<br />');

		// div principal
		var div = document.createElement('div');
		div.className = 'recette_etape';
		
		// div numero d'etape
		var divNumero = document.createElement('div');
		divNumero.className = 'recette_etape_numero';
		var spanNumero = document.createElement('span');
		spanNumero.innerHTML = this.nbEtape;
		divNumero.appendChild(spanNumero);
		div.appendChild(divNumero);
		
		// div principal de description
		var divDescription = document.createElement('div');
		divDescription.className = 'recette_etape_desc';
		
		// div image
		var divImage = document.createElement('div');
		divImage.id = 'bloc_img_etape_' + this.nbEtape;
		divImage.className = 'recette_etape_image';
		if (this.visuelEtape.value != '')
		{
			divImage.innerHTML = '<img id="img_'+this.nbEtape+'" src="'+tt$('srcImg').value+'">';
		}
		divDescription.appendChild(divImage);
		
		// paragraphe de description
		var paraDescription = document.createElement('p');
		paraDescription.id = 'p_texte_etape_' + this.nbEtape;
		paraDescription.innerHTML= descriptionTmp2;
		divDescription.appendChild(paraDescription);
		div.appendChild(divDescription);
		
		// les inputs
		var inputTexte = document.createElement('input');
		inputTexte.type = 'hidden';
		inputTexte.name = 'texte_etape_' + this.nbEtape;
		inputTexte.id = 'texte_etape_' + this.nbEtape;
		inputTexte.value = descriptionTmp;
		
		var inputImage = document.createElement('input');
		inputImage.type = 'hidden';
		inputImage.name = 'img_etape_' + this.nbEtape;
		inputImage.id = 'img_etape_' + this.nbEtape;
		
		if (this.visuelEtape.value != '')
		{
			inputImage.value = tt$('srcImg').value;
		}
		else
		{
			inputImage.value = 'NO_VALUE';
		}
		var inputButton = document.createElement('input');
		inputButton.type = 'button';
		inputButton.name = 'updateEtape_' + this.nbEtape;
		inputButton.id = 'updateEtape_' + this.nbEtape;
		//inputButton.onclick = 'recette.updateEtape(\'' + this.nbEtape + '\');';
		inputButton.className = 'input_submit floatleft';
		inputButton.value = 'modifier';
			
		div.appendChild(inputTexte);
		div.appendChild(inputImage);
		div.appendChild(inputButton);
		
		
		// spacer
		var divSpacer = document.createElement('div');
		divSpacer.className = 'spacer';
		div.appendChild(divSpacer);
		

		this.divEtapes.appendChild(div);

		
		var closure 	= toutou.js.closure.bind(this, this.updateEtape,this.nbEtape);
		toutou.html.event.addEventListener(tt$('updateEtape_' + this.nbEtape), "click", closure);	
		if (this.nbEtape < 10)
		{
			this.visuelEtapeImg.src = 'imgT/sample_visuel_etape.jpg';
			this.visuelEtape.value = '';
			this.descriptionEtape.value 	= '';
			this.descriptionTitle.innerHTML	= this.nbEtape + 1;
			this.visuelTitle.innerHTML		= this.nbEtape + 1;
			this.numEtape.value				= this.nbEtape + 1;
			this.descriptionEtape.focus();
		}
	}

}

js.articles.prototype.updateEtape = function (numEtape) 
{
	var descriptionTmp = html_entity_decode (tt$('texte_etape_'+numEtape).value,1);
	
	if (descriptionTmp == 'NO_VALUE')
	{
		this.descriptionEtape.value 	= '';
	}
	else
	{
		//descriptionTmp = descriptionTmp.replace(/<br \/>/g, '\n');
		this.descriptionEtape.value 	= descriptionTmp;
	}
	this.descriptionTitle.innerHTML	= numEtape;
	
	if (tt$('img_etape_'+numEtape).value != 'NO_VALUE')
	{
		this.visuelEtapeImg.src = tt$('img_etape_'+numEtape).value;
		this.visuelEtape.value = tt$('img_etape_'+numEtape).value;
	}
	this.visuelTitle.innerHTML		= numEtape;
	this.numEtape.value				= numEtape;
	this.descriptionEtape.focus();

}



js.articles.prototype.addImageEtape = function()
{
	User = this.user;
	this.settings_su = {
		button_width: "122",
		button_height: "16",
		button_placeholder_id: "spanButtonPlaceHolderSU",
		button_image_url: "/imgT/btn_etape_recette_ajouter.png",
		
		file_size_limit : "10 MB",
		file_types : "*.gif;*.jpg;*.png;*.bmp;",
		file_types_description : "ImgEtape",
		file_upload_limit : 0,
		file_queue_limit : 0,
		lang : "fr",
		ajax_method : "addImageEtape",
		additionnal_fields : ["numEtape","session_id"]		
	};

	var closure = toutou.js.closure.bind(this, this.loadMultiupload);
	toutou.addOnLoad(closure);
}

js.articles.prototype.supprimePhoto = function()
{
	
	this.visuelEtapeImg.src = 'imgT/sample_visuel_etape.jpg';
	this.visuelEtape.value = '';
}

js.articles.prototype.loadMultiupload = function()
{
	this.su = new oos.multiupload(this.settings_su);
	
	parentForm = this;
	this.su.onCustomUploadSuccess = function(file) 
	{
		try {
			var tab = file.name.split('.');
			var filename2 = 'origine_etape_' + tt$('numEtape').value + '.' + tab[1];
			tt$('img_etape').src = '/img_tmp/' + tt$('session_id').value + '/' + filename2;
			tt$('srcImg').value = '/img_tmp/' + tt$('session_id').value + '/' + filename2;

		} catch(e) {
			alert(e.name + "\n" + e.message + "\n" + " on line : " + e.lineNumber);
			return;
		} finally {
			;
		}
	}

}




if(typeof(js) == "undefined") {
	js = {};
}

js.connexion = function() 
{
	// url de validation ajax
	this.checkUri = 'php/ajax/checkConnection.php';
	
	// construction du frame
	var titre = "Formulaire de connexion";
	var texte = '' +
		'<div class="depot_recette">' +
		'	<form id="form_connexion" method="post" action="">' +
		'		<fieldset>' +
		'	<legend></legend>' +
		'	<p>' +
		'		<label for="connexion_pseudo"><strong>Pseudo</strong> <span class="important">*</span> :</label>' +
		'		<input class="input_text" type="text" name="connexion_pseudo" id="connexion_pseudo" tabindex="1001" />' +
		'	</p>' +
		'	<p>' +
		'		<label for="connexion_password"><strong>Mot de passe</strong> <span class="important">*</span> :</label>' +
		'		<input class="input_text" type="password" name="connexion_password" id="connexion_password" tabindex="1002" />' +
		'	</p>' +
		'	<p>' +
		'		<label for="connexion_submit">&nbsp;</label>' +
		'		<input value="Valider" class="input_submit" type="submit" name="connexion_submit" id="connexion_submit" tabindex="1003" />' +
		'	</p>' +
		'	</form>' +
		'</div>' +
		'';
	
	
	this.frame = new oos.frame(titre, texte);
	
	// initialisation du forumlaire
	this.form 		= tt$('form_connexion');
	this.pseudo 	= tt$('connexion_pseudo');
	this.password	= tt$('connexion_password');
	
	var closure = toutou.js.closure.bind(this, this.onFormSubmit);
	this.form.onsubmit = closure;
}

js.connexion.prototype.onFormSubmit = function()
{
	// requête ajax de validation
	var options = {
		method: "post",
		parameters: encodeURI("login=" + this.pseudo.value + "&password=" + this.password.value)
	}
	
	var response = toutou.js.ajax.request(this.checkUri, options);
	response = eval("(" + response + ")");
	
	// traitement de la réponse
	if(!response.ok)
	{
		alert('Votre login est inconnu ou votre mot de passe érroné');
		return false;
	}
	else
	{
		window.location.replace("mon_compte.htm");	
		return false;
	}
}
toutou.require("toutou.js.ajax", "toutou.html.dom", "toutou.html.event", "toutou.utils.browser", "toutou.event.manager");

if(typeof(js) == "undefined") {
	js = {};
}

js.coverflow = function() 
{
	this.links = new Array();
	this.pages = new Array();

	this.limit = 10;

	for(var i = 1; i < this.limit; i++)
	{
	 	var link = tt$('coverflow_link_' + i);
		if(!link) {break;}

		this.links[i] = link;
		this.pages[i] = tt$('coverflow_page_' + i);

		var closure = toutou.js.closure.bind(this, this.changePage, i);
		toutou.html.event.addEventListener(this.links[i], "click", closure);
	}
}

js.coverflow.prototype.changePage = function(num)
{
	for(var i = 1; i < this.limit; i++)
	{
		if(!this.links[i]) { break; }

		if(i == num)
		{
			this.links[i].className = 'png btn_coverflow on';
			this.pages[i].style.display = 'block';
			continue;
		}

		this.links[i].className = 'png btn_coverflow';
		this.pages[i].style.display = 'none';
	}
}
toutou.require("toutou.js.ajax", "toutou.html.dom", "toutou.html.event", "toutou.utils.browser", "toutou.event.manager");

if(typeof(js) == "undefined") 
{
	js = {};
}

js.diaporama = function(tabDiaporama,nbDiaporama)
{
	this.diaporamaImg 	= tt$('diaporama_img');
	this.diaporamaUrl 	= tt$('diaporama_url');
	this.diaporamaTitre = tt$('diaporama_titre');
	this.diaporamaPrec 	= tt$('diaporama_prec');
	this.diaporamaSuiv 	= tt$('diaporama_suiv');
	
	this.tabDiaporama	= tabDiaporama;
	this.numDiaporama	= 0;
	this.maxDiaporama	= nbDiaporama;
	
	var closure 	= toutou.js.closure.bind(this, this.precedent);
	toutou.html.event.addEventListener(this.diaporamaPrec, "click", closure);
	
	closure 	= toutou.js.closure.bind(this, this.suivant);
	toutou.html.event.addEventListener(this.diaporamaSuiv, "click", closure);
	
	return this;
}

js.diaporama.prototype.suivant = function()
{
	var precedent = this.numDiaporama;
	if (this.numDiaporama == this.maxDiaporama)
	{
		this.numDiaporama = 0;
		var suivant = 1;	
	}
	else
	{
		this.numDiaporama++;
		if (this.numDiaporama == this.maxDiaporama)
		{
			var suivant = 0;	
		}
		else
		{
			var suivant = this.numDiaporama+1;
		}
	}
	
	this.diaporamaImg.src 					= this.tabDiaporama[this.numDiaporama].img;
	this.diaporamaImg.title	= 'Diaporama ' + this.tabDiaporama[this.numDiaporama].titre_complet;
	this.diaporamaImg.alt 	= 'Diaporama ' + this.tabDiaporama[this.numDiaporama].titre_complet;
	this.diaporamaUrl.href 	= this.tabDiaporama[this.numDiaporama].url;
	this.diaporamaUrl.title	= 'Diaporama ' + this.tabDiaporama[this.numDiaporama].titre_complet;
	this.diaporamaTitre.innerHTML 			= this.tabDiaporama[this.numDiaporama].titre;
	
	this.diaporamaPrec.title	= 'Diaporama précédent : ' + this.tabDiaporama[precedent].titre_complet;
	this.diaporamaSuiv.title	= 'Diaporama suivant : ' + this.tabDiaporama[suivant].titre_complet;
	
	return false;
}

js.diaporama.prototype.precedent = function()
{
	var suivant = this.numDiaporama;
	if (this.numDiaporama == 0)
	{
		this.numDiaporama = this.maxDiaporama;
		var precedent = this.numDiaporama-1;	
	}
	else
	{
		this.numDiaporama--;
		if (this.numDiaporama == 0)
		{
			var precedent = this.maxDiaporama;	
		}
		else
		{
			var precedent = this.numDiaporama-1;
		}
	}
	
	this.diaporamaImg.src 					= this.tabDiaporama[this.numDiaporama].img;
	this.diaporamaImg.title	= 'Diaporama ' + this.tabDiaporama[this.numDiaporama].titre_complet;
	this.diaporamaImg.alt 	= 'Diaporama ' + this.tabDiaporama[this.numDiaporama].titre_complet;
	this.diaporamaUrl.href 	= this.tabDiaporama[this.numDiaporama].url;
	this.diaporamaUrl.getAttribute.title	= 'Diaporama ' + this.tabDiaporama[this.numDiaporama].titre_complet;
	this.diaporamaTitre.innerHTML 			= this.tabDiaporama[this.numDiaporama].titre;
	
	this.diaporamaPrec.href		= this.tabDiaporama[precedent].url;
	this.diaporamaPrec.title	= 'Diaporama précédent : ' + this.tabDiaporama[precedent].titre_complet;
	this.diaporamaSuiv.href		= this.tabDiaporama[suivant].url;
	this.diaporamaSuiv.title	= 'Diaporama suivant : ' + this.tabDiaporama[suivant].titre_complet;
	
	return false;
}


if(typeof(js) == "undefined") {
	js = {};
}

js.frigo = function(nbDefaultItems, previousItems) 
{
	if(!nbDefaultItems) { nbDefaultItems = 2; }
	
	this.modele 	= tt$('modele_item_frigo');
	this.cptItems	= 0;
	this.maxItems	= 10;
	
	// pré-remplissage des champs
	for(var key in previousItems)
	{
		this.addItem(previousItems[key]);
	}
	
	if(previousItems.length && previousItems.length != 0) { nbDefaultItems = 1; }
	
	// champs vide par défaut
	for(var i = 0; i < nbDefaultItems; i++)
	{
		this.addItem();
	}
	
	// initialisation du forumlaire
	this.form 	= tt$('formFrigo');
	
	var closure = toutou.js.closure.bind(this, this.onFormSubmit);
	this.form.onsubmit = closure;
}

js.frigo.prototype.onFormSubmit = function()
{
	var ingredients = new Array();
	
	for(var i = 1; i <= this.cptItems; i++)
	{
		var libelle = tt$('ingredients_' + i).value.replace(/"/, "");
		if(libelle.length < 3) { continue; }
		
		var last_char = libelle.substr(-1, 1);
		if(last_char == "x" || last_char == "s")
		{
			libelle = libelle.substr(0, libelle.length-1);
		}
		
		libelle = escape(libelle);
		libelle = libelle.replace(/\s+/g, "_");
		
		ingredients.push(libelle);
	}
	
	ingredients.sort();
	
	var url = "recettes_frigo_" + ingredients.join("-") + ".htm";	
	window.location.replace(url);
	
	return false;
}

js.frigo.prototype.addItem = function(value)
{	
	if(this.cptItems >= this.maxItems) { return; }
	
	this.cptItems++;
	
	var html = this.modele.innerHTML;
	html = html.replace(/##NUM##/g, this.cptItems);
	
	var p = document.createElement('p');
	p.className = this.modele.className;
	p.innerHTML = html;
	
	this.modele.parentNode.appendChild(p);
	
	var parent = this;
	new js.frigoItem(this.cptItems, parent);
	
	if(value)
	{
		tt$('ingredients_' + this.cptItems).value = value;	
	}
}

js.frigoItem = function(id, parent)
{
	this.id		= id;
	this.item 	= tt$('ingredients_' + id);
	this.parent	= parent;
	
	var closure = toutou.js.closure.bind(this, this.onItemBlur);
	toutou.html.event.addEventListener(this.item, "keyup", closure);
}

js.frigoItem.prototype.onItemBlur = function() 
{
	if(this.item.value == '') { return; }
	if(this.id == this.parent.cptItems)
	{
		this.parent.addItem();
	}
}
toutou.require("toutou.utils.strings");
if(typeof(js) == "undefined") {
	js = {};
}

js.inscription = function() 
{
	// url de validation ajax
	this.checkUri = 'php/ajax/checkInscription.php';
	
	// champs du formulaires
	this.prenom	= tt$('prenom');
	this.nom	= tt$('nom');
	this.pseudo	= tt$('pseudo');
	this.email				= tt$('email');
	this.email_confirm		= tt$('email2');
	this.password			= tt$('password');
	this.password_confirm	= tt$('password2');
	
	// initialisation du forumlaire
	this.form 	= tt$('form_inscription');
	
	var closure = toutou.js.closure.bind(this, this.onFormSubmit);
	this.form.onsubmit = closure;
}

js.inscription.prototype.onFormSubmit = function()
{
	var msg 	= '';
	var field 	= '';
	
	// requêtes ajax de validation
	var options = {
		method: "post",
		parameters: "email=" + this.email.value + "&pseudo=" + this.pseudo.value
	}
	
	var response = toutou.js.ajax.request(this.checkUri, options);
	response = eval("(" + response + ")");
	
	// on regarde si l'email est déjà connu en premier lieu
	if(!response.ok && response.erreurs.EMAIL_KNOWN)
	{
		if(confirm("Cet email est deja connu. Voulez-vous rendre sur la page de contact pour redemander votre mot de passe ?"))
		{
			window.location.replace("contactez-nous.htm");
			return false;
		}
		else
		{
			msg = 'Cet email est déjà utilisé\n';
		}
	}
	
	// validation des nom et prénom
	if(toutou.utils.strings.isEmpty(this.nom.value))
	{
		msg = 'Vous devez saisir le champ NOM\n' + msg;
		if(!field) { field = this.nom; }
	}
	if(toutou.utils.strings.isEmpty(this.prenom.value))
	{
		msg = 'Vous devez saisir le champ PRENOM\n' + msg;
		if(!field) { field = this.prenom; }
	}
	
	// validation en ligne du pseudo
	if(toutou.utils.strings.isEmpty(this.pseudo.value))
	{
		msg = 'Vous devez saisir le champ PSEUDO\n' + msg;
		if(!field) { field = this.pseudo; }
	}
	else if(this.pseudo.value.length < 4)
	{
		msg = 'Votre PSEUDO doit comporter au moins 4 caracteres\n' + msg;
		if(!field) { field = this.pseudo; }
	}
	else if(!response.ok && response.erreurs.LOGIN_NOT_AVAILABLE)
	{
		msg = 'Ce PSEUDO est deja utilise\n' + msg;
		if(!field) { field = this.pseudo; }
	}
	
	// validation des emails
	if (toutou.utils.strings.isEmpty(this.email.value)) 
	{
		msg = 'Vous devez saisir le champ EMAIL\n' + msg;
		if(!field) { field = this.email; }
	}
	else if (toutou.utils.strings.isEmpty(this.email_confirm.value)) 
	{
		msg = 'Vous devez saisir le champ de confirmation d\'EMAIL\n' + msg;
		if(!field) { field = this.email_confirm; }
	}
	else if (!toutou.utils.strings.isValidEmail(this.email.value)) 
	{
		msg = 'Votre EMAIL n\'est pas valide\n' + msg;
		if(!field) { field = this.email; }
	}
	else if (this.email.value != this.email_confirm.value) 
	{
		msg = 'Les EMAILS ne sont pas identiques\n' + msg;
		if(!field) { field = this.email_confirm; }
	}
	
	// validation des passwords
	if (toutou.utils.strings.isEmpty(this.password.value) || toutou.utils.strings.isEmpty(this.password_confirm.value)) 
	{
		msg = 'Vous devez saisir le champ MOT DE PASSE\n' + msg;
		if(!field) { field = this.password; }
	}
	else if (this.password.value != this.password_confirm.value) 
	{
		msg = 'Les MOTS DE PASSE ne sont pas identiques\n' + msg;
		if(!field) { field = this.password_confirm; }
	}

	if (msg) 
	{ 
		alert(msg); 
		if (field) { field.focus(); }
		return false;
	}
	
	return true;
}

if(typeof(js) == "undefined") 
{
	js = {};
}

js.recherches = new function() 
{
	this.requestUri		 = "/ajaxRequests/lib_tags.inc";
}

js.recherches.submit = function (/* Form Object */ f) 
{
	if (f.kw.value == null || f.kw.value.length < 3) 
	{
		alert("Vous devez saisir un mot-clé");
		f.kw.focus();
		return false;
	}
	
	if(f.ingredients) 	var val_ingr = f.ingredients.value;
	if(f.difficulte) 	var val_diff = f.difficulte.options[f.difficulte.selectedIndex].value;
	if(f.tattente) 		var val_tatt = f.tattente.options[f.tattente.selectedIndex].value;
	if(f.cout) 			var val_cout = f.cout.options[f.cout.selectedIndex].value;
	if(f.rubrique) 		var val_rubr = f.rubrique.options[f.rubrique.selectedIndex].value;	

	var querystring = "";
	if(val_ingr || val_diff || val_tatt || val_cout || val_rubr) 
	{
		if(!val_ingr) var val_ingr = "";
		if(!val_diff) var val_diff = "";
		if(!val_tatt) var val_tatt = "";
		if(!val_cout) var val_cout = "";
		if(!val_rubr) var val_rubr = "";
		
		querystring += "?ingredients="+val_ingr;
		querystring += "&difficulte="+val_diff;
		querystring += "&tattente="+val_tatt;
		querystring += "&cout="+val_cout;
		querystring += "&rubrique="+val_rubr;
	}
	
	libelle = f.kw.value.replace(/"/, "");
	if(libelle.length < 3) 
	{
		f.kw.focus();
		return false;
	}

	libelle = escape(libelle);
	
	string = "http://www.750g.com/recettes_"+libelle+".htm"+querystring;	
	window.location.replace(string);
	return false;
}

js.recherches.frigoSubmit = function(/* Form Object */ f) 
{
		
}
toutou.require("toutou.utils.strings");
if(typeof(js) == "undefined") {
	js = {};
}

js.newsletters = function(champMail) 
{
	if(!champMail) { champMail = 'EMAIL'; }
	
	// champs du formulaires
	this.email = tt$(champMail);
	
	return this;
}

js.newsletters.prototype.onFormSubmit = function()
{
	var msg = '';
	var field;
	// validation des emails
	if (toutou.utils.strings.isEmpty(this.email.value) || this.email.value == 'votrenom@email.com') 
	{
		msg+= 'Vous devez saisir le champ EMAIL\n';
		if(!field) { field = this.email; }
	}
	else if (!toutou.utils.strings.isValidEmail(this.email.value)) 
	{
		msg+= 'Votre EMAIL n\'est pas valide\n';
		if(!field) { field = this.email; }
	}
	
	if (tt$('OFFRES_PARTENAIRES_OUI').checked == false && tt$('OFFRES_PARTENAIRES_NON').checked == false)
	{
		msg+= 'Vous n\'avez pas indique si vous souhaitiez recevoir les offres partenaires';
		if(!field) { field = tt$('OFFRES_PARTENAIRES_OUI'); }
	}

	if (msg != '') 
	{ 
		alert(msg); 
		if (field) { field.focus(); }
		return false;
	}
	
	return true;
}

js.newsletters.prototype.videChamps = function()
{
	if (this.email.value == 'votrenom@email.com')
	{
		this.email.value = '';
	}
	else if(this.email.value == '')
	{
		this.email.value = 'votrenom@email.com';
	}
}
toutou.require("toutou.html.dom", "toutou.js.ajax");

if(typeof(js) == "undefined") {
	js = {};
}

js.tag = function(tag,nbRecettes,typeRecherche) 
{
	this.nbRecettes			= nbRecettes;
	this.tag				= tag;
	this.typeRecherche		= typeRecherche;
			
	if (this.nbRecettes != 0)
	{
		this.recette 			= tt$('bloc_recette');
		this.membre 			= tt$('bloc_membre');
		this.titre 				= tt$('bloc_titre');
		
//		this.recette_precedente = tt$('lien_recette_precedente');
//		this.recette_suivante 	= tt$('lien_recette_suivante');
		this.envie_du_jour		= tt$('envie_du_jour');
	}
}

//js.tag.prototype.trier = function(type,sens)
//{
//	switch(type)
//	{
//		case 'note' :
//			this.tri = 'NOTE';
//			break;
//		case 'difficulte' :
//			this.tri = 'DIFFICULTE';
//			break;
//		case 'cout' :
//			this.tri = 'COUT';
//			break;
//		case 'tps_prepa' :
//			this.tri = 'TEMPS_PREPARATION';
//			break;
//	}
//	
//	switch(sens)
//	{
//		case null	:
//			if (this.sens == 'ASC')	{ this.sens = 'DESC';}
//			else					{ this.sens = 'ASC';}					
//		case 'asc'	:
//			this.sens = 'ASC';
//			break;
//		case 'desc' :
//			this.sens = 'DESC';
//			break;				
//	}	
//	
//	var urlPart = '/php/ajax/triRecettes.php?tag=' + this.tag + '&tri=' + this.tri + '&sens=' + this.sens + '&typeR=' + this.typeRecherche;
//	var html = toutou.js.ajax.request(urlPart);
//	html =  eval( '(' + html + ')' );
//	
//	if (this.nbRecettes > 3)
//	{
//		this.envie_du_jour				= tt$('envie_du_jour');
//		var envieDuJour 				= this.envie_du_jour.innerHTML;
//		this.recette.innerHTML 			= html.recette;
//		this.membre.innerHTML 			= html.membre;
//		this.titre.innerHTML			= html.titre;
//		
//		this.envie_du_jour				= tt$('envie_du_jour');
//		this.envie_du_jour.innerHTML	= envieDuJour;
//	}
//	
//	this.liste_recette.innerHTML	= html.liste;
//	
//	this.suggestions.innertHTML		= html.suggestion;
//	
//}

js.tag.prototype.recetteSuivantePrecedente = function(idRecette)
{
	
	
	var urlPart = '/php/ajax/recetteSuivPrec.php?recette=' + idRecette + '&tag=' + this.tag + '&typeR=' + this.typeRecherche;
	var html = toutou.js.ajax.request(urlPart);
	html =  eval( '(' + html + ')' );
	
	var envieDuJour 				= this.envie_du_jour.innerHTML;
	
	this.recette.innerHTML 			= html.recette;
	this.membre.innerHTML 			= html.membre;
	this.titre.innerHTML			= html.titre;
	
	this.envie_du_jour				= tt$('envie_du_jour');
	this.envie_du_jour.innerHTML	= envieDuJour;
}

toutou.require("toutou.js.ajax", "toutou.html.dom", "toutou.html.event", "toutou.utils.browser", "toutou.event.manager");

if(typeof(js) == "undefined") 
{
	js = {};
}


js.membres = function() 
{

	this.addAvatar();
	return this;
}

js.membres.prototype.addAvatar = function()
{
	User = this.user;
	this.settings_su = {
		button_width: "122",
		button_height: "16",
		button_placeholder_id: "spanButtonPlaceHolderSU",
		button_image_url: "/imgT/btn_etape_recette_ajouter.png",
		
		file_size_limit : "10 MB",
		file_types : "*.gif;*.jpg;*.png;*.bmp;",
		file_types_description : "ImgEtape",
		file_upload_limit : 0,
		file_queue_limit : 0,
		lang : "fr",
		ajax_method : "updateAvatar",
		additionnal_fields : ["user_id"]		
	};



	var closure = toutou.js.closure.bind(this, this.loadMultiupload);
	toutou.addOnLoad(closure);
}

js.membres.prototype.supprimePhoto = function()
{
	var donnees = toutou.js.ajax.request('/php/ajax/supprimeAvatar.php?user=' + tt$('user_id').value);
	tt$('img_avatar').src = '/imgT/img_default_avatar_' + donnees + '_l.png';
}

js.membres.prototype.loadMultiupload = function()
{
	this.su = new oos.multiupload(this.settings_su);
	
	parentForm = this;
	this.su.onCustomUploadSuccess = function(file) 
	{
		try {
			tt$('img_avatar').src = '/img_tmp/origine_avatar_' + tt$('user_id').value + '.png';
			/*var tab = file.name.split('.');
			var filename2 = 'origine_etape_' + tt$('numEtape').value + '.' + tab[1];
			tt$('img_etape').src = '/img_tmp/' + tt$('session_id').value + '/' + filename2;*/
			

		} catch(e) {
			alert(e.name + "\n" + e.message + "\n" + " on line : " + e.lineNumber);
			return;
		} finally {
			;
		}
	}

}




toutou.require("toutou.js.ajax", "toutou.html.dom", "toutou.html.event", "toutou.utils.browser", "toutou.event.manager", "toutou.utils.strings");

if(typeof(js) == "undefined") 
{
	js = {};
}

js.impressionRecette = function(page,idRecette)
{
	this.idRecette = idRecette;
	this.page = page;
	this.form = tt$('formImpressionRecette');
	var closure 	= toutou.js.closure.bind(this, this.popup);
	toutou.html.event.addEventListener(this.form, "submit", closure);
	
}
js.impressionRecette.prototype.popup = function()
{
	var ingredient	= (tt$('INGREDIENTS').checked)?1:0;
	var preparation	= (tt$('PREPARATION').checked)?1:0;
	var conseil		= (tt$('CONSEILS').checked)?1:0;
	var photo		= (tt$('PHOTOGRAPHIE').checked)?1:0;
	var commentaire	= (tt$('COMMENTAIRES').checked)?1:0;
	
	url = this.page + '?impression=1&ingredient='+ingredient+'&preparation='+preparation+'&conseil='+conseil+'&photo='+photo+'&commentaire='+commentaire;
	window.open(url,'_blank');
	
	return false;
}

js.recettes = function() 
{
	this.nbEtape = 0;
	
	this.form 	= tt$('formVotreRecette');
	
	this.nom_recette		= tt$('nom_recette');
	this.description		= tt$('descriptionRecette');
	this.ingredients		= tt$('ingredients');
	this.preparation		= tt$('description_etape_1');
	this.mail_newsletter	= tt$('mail_newsletter');
	this.CGV				= tt$('CGV');
	
	this.etape 				= tt$('addEtape');
	this.modele				= tt$('modele'); 
	this.divEtapes 			= tt$('previsualise_etapes');
	this.descriptionEtape 	= tt$('description_etape');
	this.descriptionTitle 	= tt$('descriptionTitle');
	this.visuelTitle		= tt$('visuelTitle');
	this.numEtape			= tt$('numEtape');
	this.visuelEtape		= tt$('srcImg');
	this.visuelEtapeImg		= tt$('img_etape');
	this.boutonSupprime		= tt$('bouton_supprime');
	
	this.difficulte			= tt$('difficulte');
	this.cout				= tt$('cout');
	
	var closure 	= toutou.js.closure.bind(this, this.addEtape);
	toutou.html.event.addEventListener(this.etape, "click", closure);
	
	closure 	= toutou.js.closure.bind(this, this.supprimePhoto);
	toutou.html.event.addEventListener(this.boutonSupprime, "click", closure);
	
	this.addImageEtape();
	return this;
}

js.recettes.prototype.valide = function () 
{
	var msg = '';
	var field = '';
	if (!this.CGV.checked) {
		msg = 'Vous devez prendre connaissance des CONDITIONS DE PUBLICATION\n' + msg;
		field = this.CGV;
	}
	if(this.difficulte.options[this.difficulte.selectedIndex].value == "")
	{
		msg = 'Vous devez saisir le champ DIFFICULTE\n' + msg;
		field = this.difficulte;		
	}
	if(this.cout.options[this.cout.selectedIndex].value == "")
	{
		msg = 'Vous devez saisir le champ COUT\n' + msg;
		field = this.cout;		
	}
	
	if (toutou.utils.strings.isEmpty(this.mail_newsletter.value)) 
	{
		msg = 'Vous devez saisir le champ EMAIL\n' + msg;
		field = this.mail_newsletter;
	}
	else if (!toutou.utils.strings.isValidEmail(this.mail_newsletter.value)) 
	{
		msg = 'Votre adresse e-mail n\'est pas valide\n' + msg;
		field = this.mail_newsletter;
	}
	
	if (!tt$('texte_etape_1') || (tt$('texte_etape_1').value == 'NO_VALUE')) 
	{
		msg = 'Vous devez saisir au moins une ETAPE\n' + msg;
		field = this.preparation;
	}
	if (toutou.utils.strings.isEmpty(this.ingredients.value)) 
	{
		msg = 'Vous devez saisir le champ INGREDIENTS\n' + msg;
		field = this.ingredients;
	}
	if (toutou.utils.strings.isEmpty(this.description.value)) 
	{
		msg = 'Vous devez saisir le champ DESCRIPTION\n' + msg;
		field = this.description;
	}
	if (toutou.utils.strings.isEmpty(this.nom_recette.value)) 
	{
		msg = 'Vous devez saisir le champ LIBELLE\n' + msg;
		field = this.nom_recette;
	}

	if (msg) 
	{ 
		alert(msg); 
		if (field) { field.focus(); }
		return false;
	}
	return true;
}

js.recettes.prototype.addEtape = function () 
{
	if (this.numEtape.value <= this.nbEtape)	// on est en train de modifier une étape déjà créée
	{
		var descriptionTmp = htmlentities (this.descriptionEtape.value,1);
		
		if (toutou.utils.strings.isEmpty(descriptionTmp))
		{
			alert('Vous devez remplir la description de l\'étape');
			return;
		}
		else
		{
			descriptionTmp2 = descriptionTmp.replace(/\n/g, '<br />');
			tt$('p_texte_etape_'+this.numEtape.value).innerHTML = descriptionTmp2;//this.descriptionEtape.value;
			tt$('texte_etape_'+this.numEtape.value).value 		= descriptionTmp;//this.descriptionEtape.value;
		}
		
		if (this.visuelEtape.value != '')
		{
			if (tt$('img_'+this.numEtape.value))
			{
				tt$('img_'+this.numEtape.value).src = this.visuelEtape.value;
			}
			else
			{
				var img = document.createElement('img');
				img.setAttribute('id','img_'+this.numEtape.value);
				img.src = this.visuelEtape.value;
				tt$('bloc_img_etape_'+this.numEtape.value).appendChild(img);
			}
			tt$('img_etape_'+this.numEtape.value).value = this.visuelEtape.value;
		}
		else
		{
			if (tt$('img_'+this.numEtape.value))
			{
				tt$('bloc_img_etape_'+this.numEtape.value).removeChild(tt$('img_'+this.numEtape.value));
			}
			tt$('img_etape_'+this.numEtape.value).value = 'NO_VALUE';
		}
		
		if (this.nbEtape < 10)
		{
			this.visuelEtapeImg.src = 'imgT/sample_visuel_etape.jpg';
			this.visuelEtape.value = '';
			this.descriptionEtape.value 	= '';
			this.descriptionTitle.innerHTML	= this.nbEtape + 1;
			this.visuelTitle.innerHTML		= this.nbEtape + 1;
			this.numEtape.value				= this.nbEtape + 1;
			this.descriptionEtape.focus();
		}
	}
	else
	{
		var descriptionTmp = this.descriptionEtape.value;
		
		if (toutou.utils.strings.isEmpty(descriptionTmp))
		{
			alert('Vous devez remplir la description de l\'étape');
			return;
		}
	
		this.nbEtape++;
		descriptionTmp = htmlentities (descriptionTmp,1);
		descriptionTmp2 = descriptionTmp.replace(/\n/g, '<br />');

		// div principal
		var div = document.createElement('div');
		div.className = 'recette_etape';
		
		// div numero d'etape
		var divNumero = document.createElement('div');
		divNumero.className = 'recette_etape_numero';
		var spanNumero = document.createElement('span');
		spanNumero.innerHTML = this.nbEtape;
		divNumero.appendChild(spanNumero);
		div.appendChild(divNumero);
		
		// div principal de description
		var divDescription = document.createElement('div');
		divDescription.className = 'recette_etape_desc';
		
		// div image
		var divImage = document.createElement('div');
		divImage.id = 'bloc_img_etape_' + this.nbEtape;
		divImage.className = 'recette_etape_image';
		if (this.visuelEtape.value != '')
		{
			divImage.innerHTML = '<img id="img_'+this.nbEtape+'" src="'+tt$('srcImg').value+'">';
		}
		divDescription.appendChild(divImage);
		
		// paragraphe de description
		var paraDescription = document.createElement('p');
		paraDescription.id = 'p_texte_etape_' + this.nbEtape;
		paraDescription.innerHTML= descriptionTmp2;
		divDescription.appendChild(paraDescription);
		div.appendChild(divDescription);
		
		// les inputs
		var inputTexte = document.createElement('input');
		inputTexte.type = 'hidden';
		inputTexte.name = 'texte_etape_' + this.nbEtape;
		inputTexte.id = 'texte_etape_' + this.nbEtape;
		inputTexte.value = descriptionTmp;
		
		var inputImage = document.createElement('input');
		inputImage.type = 'hidden';
		inputImage.name = 'img_etape_' + this.nbEtape;
		inputImage.id = 'img_etape_' + this.nbEtape;
		
		if (this.visuelEtape.value != '')
		{
			inputImage.value = tt$('srcImg').value;
		}
		else
		{
			inputImage.value = 'NO_VALUE';
		}
		var inputButton = document.createElement('input');
		inputButton.type = 'button';
		inputButton.name = 'updateEtape_' + this.nbEtape;
		inputButton.id = 'updateEtape_' + this.nbEtape;
		//inputButton.onclick = 'recette.updateEtape(\'' + this.nbEtape + '\');';
		inputButton.className = 'input_submit floatleft';
		inputButton.value = 'modifier';
			
		div.appendChild(inputTexte);
		div.appendChild(inputImage);
		div.appendChild(inputButton);
		
		
		// spacer
		var divSpacer = document.createElement('div');
		divSpacer.className = 'spacer';
		div.appendChild(divSpacer);
		
//		var myTemplate = this.modele.innerHTML;
//		myTemplate = myTemplate.replace(/##NUM##/g, this.nbEtape);
//		
//		descriptionTmp = htmlentities (descriptionTmp,1);
//		descriptionTmp2 = descriptionTmp.replace(/\n/g, '<br />');
//
//		myTemplate = myTemplate.replace(/##TEXTE_INPUT##/g, descriptionTmp);
//		myTemplate = myTemplate.replace(/##TEXTE##/g, descriptionTmp2);
//		
//		
//		if (this.visuelEtape.value != '')
//		{
//			myTemplate = myTemplate.replace(/##IMG##/g, '<img id="img_'+this.nbEtape+'" src="'+tt$('srcImg').value+'">');
//			myTemplate = myTemplate.replace(/##IMG_INPUT##/g, tt$('srcImg').value);
//		}
//		else
//		{
//			myTemplate = myTemplate.replace(/##IMG##/g, '');
//			myTemplate = myTemplate.replace(/##IMG_INPUT##/g, 'NO_VALUE');
//		}
//		div.innerHTML = myTemplate;
//	
		this.divEtapes.appendChild(div);
//		tt$('p_texte_etape_'+this.numEtape.value).innerHTML = descriptionTmp2;//this.descriptionEtape.value;
//		tt$('texte_etape_'+this.numEtape.value).value 		= descriptionTmp;//this.descriptionEtape.value;
		
		var closure 	= toutou.js.closure.bind(this, this.updateEtape,this.nbEtape);
		toutou.html.event.addEventListener(tt$('updateEtape_' + this.nbEtape), "click", closure);	
		if (this.nbEtape < 10)
		{
			this.visuelEtapeImg.src = 'imgT/sample_visuel_etape.jpg';
			this.visuelEtape.value = '';
			this.descriptionEtape.value 	= '';
			this.descriptionTitle.innerHTML	= this.nbEtape + 1;
			this.visuelTitle.innerHTML		= this.nbEtape + 1;
			this.numEtape.value				= this.nbEtape + 1;
			this.descriptionEtape.focus();
		}
	}
	//<img src="imgmodeles/sample_visuel_etape.jpg" title="" />	
}

js.recettes.prototype.updateEtape = function (numEtape) 
{
	var descriptionTmp = html_entity_decode (tt$('texte_etape_'+numEtape).value,1);
	
	if (descriptionTmp == 'NO_VALUE')
	{
		this.descriptionEtape.value 	= '';
	}
	else
	{
		//descriptionTmp = descriptionTmp.replace(/<br \/>/g, '\n');
		this.descriptionEtape.value 	= descriptionTmp;
	}
	this.descriptionTitle.innerHTML	= numEtape;
	
	if (tt$('img_etape_'+numEtape).value != 'NO_VALUE')
	{
		this.visuelEtapeImg.src = tt$('img_etape_'+numEtape).value;
		this.visuelEtape.value = tt$('img_etape_'+numEtape).value;
	}
	this.visuelTitle.innerHTML		= numEtape;
	this.numEtape.value				= numEtape;
	this.descriptionEtape.focus();
}



js.recettes.prototype.addImageEtape = function()
{
	User = this.user;
	this.settings_su = {
		button_width: "122",
		button_height: "16",
		button_placeholder_id: "spanButtonPlaceHolderSU",
		button_image_url: "/imgT/btn_etape_recette_ajouter.png",
		
		file_size_limit : "2 MB",
		file_types : "*.jpg;*.jpeg;*.png;*.bmp;",
		file_types_description : "ImgEtape",
		file_upload_limit : 0,
		file_queue_limit : 0,
		lang : "fr",
		ajax_method : "addImageEtape",
		additionnal_fields : ["numEtape","session_id"]		
	};

	var closure = toutou.js.closure.bind(this, this.loadMultiupload);
	toutou.addOnLoad(closure);
}

js.recettes.prototype.supprimePhoto = function()
{
	
	this.visuelEtapeImg.src = 'imgT/sample_visuel_etape.jpg';
	this.visuelEtape.value = '';
}

js.recettes.prototype.loadMultiupload = function()
{
	this.su = new oos.multiupload(this.settings_su);
	
	parentForm = this;
	this.su.onCustomUploadSuccess = function(file) 
	{
		try {
			var tab = file.name.split('.');
			var filename2 = 'origine_etape_' + tt$('numEtape').value + '.' + tab[1];
			tt$('img_etape').src = '/img_tmp/' + tt$('session_id').value + '/' + filename2;
			tt$('srcImg').value = '/img_tmp/' + tt$('session_id').value + '/' + filename2;

		} catch(e) {
			alert(e.name + "\n" + e.message + "\n" + " on line : " + e.lineNumber);
			return;
		} finally {
			;
		}
	}

}




