/*
 *
 *	@titre: url.
 *	@description: javascript ajax url - Le Cidre.
 *	@auteur: neov - http://www.neov.net.
 *	@creation: 20100621.
 *	@modification: 20100621.
 *
*/

$.fn.setMenu = function (index)
{
	$('#header li').removeClass('active') ;
	$('#header li').eq(index).addClass('active') ;
}

var zUrlHashGlobal ;
$.fn.loadAjaxContent = function (url)
{
	
	$('#content-inner').addClass('loading') ;
	$('#content-inner *').css({visibility: 'hidden'}) ;
	
	/*
	var zUrl = url ;
	var tzMatchedTarget = zUrl.match (/^[^#]+[#]([^#]+)$/i) ;
	var zUrlHash = '' ;
	if (tzMatchedTarget)
	{
		if (tzMatchedTarget.length > 1)
		{
			zUrlHash = tzMatchedTarget[1] ;
			if (zUrlHash != '')
			{	
				zUrlHashGlobal = zUrlHash ;
				// document.location.href = document.location.host + j_basepath + zUrlHash ;
				document.location.hash = "#" + zUrlHash ;
			}
		}
	}
	*/

	$.ajax(
		{
			type:		'GET' ,
			url:		url ,
			dataType:	{} ,
			success:	function(response)
			{

				var zMatched = response.match (/<title>(.*)<\/title>/ig) ;

				if (zMatched)
				{
					if (zMatched.length > 0)
					{
						zMatched[0] = zMatched[0].replace (/<\/?title>/ig, '') ;
						zMatched[0] = zMatched[0].replace (/&Agrave;/ig, 'À') ;
						document.title = zMatched[0] ;
					}
				}
				
				var contenu = $(response).find('div#conteneur-large')[0] ;
				var indexMenu = $(response).find('p#index-menu')[0];
				var menuIndex = parseInt($(indexMenu).text()) ;

				$('#header li').removeClass('active') ;
				$('#header li#topMenu' + menuIndex).addClass('active') ;

				$('#content-inner')
					.empty()
					.removeClass('loading')
					.removeClass('empty')
					.append(contenu) ;
				
				$.getScript(j_basepath + 'design/js/form.js') ;


				var cnt = 0 ;
				var nbrItem = $('#content-inner').find('img').length ;

				if (nbrItem > 0)
				{
					$('#content-inner *').css({visibility: 'hidden'});
					$('#content-inner').find('img').each(
						function()
						{
							var imagePreloader = new Image() ;
						
							imagePreloader.onload = function ()
							{
								cnt++; 
								// alert (cnt + ':' + $(this).attr('src')) ;
								// action a la fin du preload.
								if(cnt == nbrItem) {
									$('#content-inner *').css({visibility: 'visible'});
									$().setSize(500) ;

                                    popupOnLoadActions () ;
								}
								imagePreloader.onload = null ;
							};
							imagePreloader.src = $(this).attr('src') ;
						}
					);
				}
				else
				{
					$('#content-inner *').css({visibility: 'visible'});
					$().setSize(500) ;
				}
				onLoadActions () ;

			}
		}
	) ;
}

$.fn.loadAjaxContentInDoc = function (doc, url)
{

	var oContentInner = $(doc).find('#conteneur-large-data') ;

	$(oContentInner).addClass('loading') ;
	$('*', oContentInner).css({visibility: 'hidden'}) ;

	$.ajax(
		{
			type:		'GET',
			url:		url,
			dataType:	{},
			success:	function(response)
			{
				
				var contenu = $(response).find('div#conteneur-large')[0];
				
				$(oContentInner)
					.empty()
					.removeClass('loading')
					.removeClass('empty')
					.append(eval (contenu))
                    .css('font-size', '0.9em') ;
				
				// onLoadActions () ;

			}
		}
	) ;

}

$(
	function()
	{
		$('a').not('.confirmLink').each(
			function()
			{
				if ($(this).attr('target') != '_blank')
				{
					if ($(this).attr('href') != '#' && !(/#$/).test ($(this).attr('href')) && !(/^mailto[:]/).test ($(this).attr('href')) && !(/^javascript[:]/).test ($(this).attr('href')))
					{
						$(this).click(
							function()
							{
								if (!$(this).hasClass ('confirmLink'))
								{
									$('#header li').removeClass('active') ;
									$(this).parent().addClass('active') ;
									
									var zUrl = $(this).attr('href') ;
									
									$().loadAjaxContent(zUrl) ;
									
									
								}
								return false ;
							}
						);
					}
				}
			}
		) ;

		$('#content-inner a').live(
			'click',
			function()
			{
				if ($(this).attr('target') != '_blank')
				{
					if ($(this).attr('href') != '#' && !(/#$/).test ($(this).attr('href')) && !(/^mailto[:]/).test ($(this).attr('href')) && !(/^javascript[:]/).test ($(this).attr('href')))
					{
						if (!$(this).hasClass ('confirmLink'))
						{
							var zUrl = $(this).attr('href') ;
							$().loadAjaxContent(zUrl) ;
							return false ;
						}
					}
				}
			}
		) ;
		
		onLoadActions () ;
	
	}
) ;

function callJeu()
{
	var zUrl = j_basepath + 'cidre.php?module=jeu&action=FoJeu:form' ;
	$().loadAjaxContent(zUrl) ;
}

function openStaticPage (_zStaticPageURL)
{
	var zUrl = j_basepath + 'design/pages/' + _zStaticPageURL ;
	$().loadAjaxContent (zUrl) ;
}

// --- Validateurs particulièrs et Fonctions utilitaires

String.prototype.trim = function() { return this.replace (/^\s+|\s+$/, '') ; } ;

function isEmail (_zInputStr)
{
	var oMailRegEx = new RegExp ("^[^\\.][\\w\\.=-]*[^\\.]@[^\\.][\\w\\.-]+\\.[\\w]{2,4}$") ;
	return oMailRegEx.test (_zInputStr) ;
}

function checkComptePersoEmailUnicity (_zEmail)
{
	
	var bRes = true ;

	$.ajax ({
		url: j_basepath + 'cidre.php?module=aclfo&action=FoComptePerso:checkEmailUnicity',
		data: {zEmail: _zEmail},
		type: 'post',
		dataType: 'json',
		async: false,
		success: function (_iRespContent)
		{
			bRes = (_iRespContent == 1) ;
		}
	}) ;

	return bRes ;

}

function checkComptePersoPseudoUnicity (_zPseudo)
{
	
	var bRes = true ;

	$.ajax ({
		url: j_basepath + 'cidre.php?module=aclfo&action=FoComptePerso:checkPseudoUnicity',
		data: {zPseudo: _zPseudo},
		type: 'post',
		dataType: 'json',
		async: false,
		success: function (_iRespContent)
		{
			bRes = (_iRespContent == 1) ;
		}
	}) ;

	return bRes ;

}


// --- Ensemble des actions à traiter au chargement

function onLoadActions ()
{
	// --- Suppression de tous les gestionnaires d'événements
	$('.backHome').unbind ('click') ;
	$('.star-notifier').unbind ('click') ;
	$('#envoyer-ami-valider').unbind ('click') ;
	$('#post-commentaire').unbind ('submit') ;
	$('#compte-perso-login').unbind ('submit') ;
	$('#compte-perso-incription').unbind ('submit') ;
	$('#compte-perso-edit').unbind ('submit') ;
	$('#compte-pro-login').unbind ('submit') ;
	$('#compte-pro-new').unbind ('submit') ;
	$('#inscription-pro').unbind ('submit') ;
	$('#form-carrement_cidre').unbind ('submit') ;
	$('#form-depot-recette').unbind ('submit') ;
	$('#form-recherche').unbind ('submit') ;

    $('a[class != anchor]').click (
        function ()
        {
			var zHref = $(this).attr ('href') ;
			if (zHref != '#' && zHref != '')
			{
				$.address.value (zHref) ;
			}
			else
			{
				if ($(this).hasClass ('backHome'))
				{
					$.address.value ('') ;
				}
			}
        }
    ) ;
	
	$('.backHome').click(
		function ()
		{
			$('#header li').removeClass('active') ;
			
			$('#content-inner')
				.empty()
				.removeClass('loading')
				.addClass('empty') ;
			
			$().setSize(250) ;

			$().setMenu (0) ;
		}
	);

	$('.star-notifier').click (
		function ()
		{
			var zHtmlId = $(this).attr ('id') ;
			$.ajax ({
				url: j_basepath + 'cidre.php?module=content&action=FoRecetteActions:addNote',
				data: {zHtmlId: zHtmlId},
				type: 'post',
				dataType: 'json',
				async: false,
				success: function (_oRespContent)
				{
					if (_oRespContent.iCodeRet == 0)
					{
						alert ('Merci, votre vote a bien été pris en compte.') ;
						$('.recette-bottom-bar').html (_oRespContent.zHtmlContent) ;
						onLoadActions () ;
					}
					else
					{
						alert ('Vous avez déjà voté pour cette recette. Un seul vote est accepté. Merci.') ;
					}
				}
			}) ;
			return false ;
		}
	) ;
	
	// --- ENVOYER A UN AMI POPUP ---
	$('#envoyer-ami-valider').click (
		function ()
		{
			var zEnvoyerAmiSenderPrenom = $('#zEnvoyerAmiSenderPrenom').val () ;
			var zEnvoyerAmiSenderMail = $('#zEnvoyerAmiSenderMail').val () ;
			var zEnvoyerAmiDestEmail = $('#zEnvoyerAmiDestEmail').val () ;
			var zEnvoyerAmiMessage = $('#zEnvoyerAmiMessage').val () ;
			var iEnvoiAmiRecetteContentObjectId = $('#iEnvoiAmiRecetteContentObjectId').val () ;
			
			var zErrorMessage = '' ;
			
			if (zEnvoyerAmiSenderPrenom == '')
			{
				zErrorMessage += 'Veuillez renseigner le nom de votre ami(e)<br/>'
			}
			if (zEnvoyerAmiSenderMail == '')
			{
				zErrorMessage += 'Veuillez renseigner votre adresse e-mail<br/>'
			}
			else
			{
				if (!checkEmailFormat(zEnvoyerAmiSenderMail))
				{
					zErrorMessage += 'Le format de votre adresse e-mail est invalide<br/>'
				}
			}
			if (zEnvoyerAmiDestEmail == '')
			{
				zErrorMessage += 'Veuillez renseigner l\'adresse e-mail de votre ami(e)<br/>'
			}
			else
			{
				if (!checkEmailFormat(zEnvoyerAmiDestEmail))
				{
					zErrorMessage += 'Le format de l\'adresse e-mail de votre ami(e) est invalide<br/>'
				}
			}
			
			if (zErrorMessage == '')
			{
				$.ajax ({
					url: j_basepath + 'cidre.php?module=content&action=FoRecetteActions:envoiAmi',
					data: 	{
								zSenderPrenom :				zEnvoyerAmiSenderPrenom,
								zSenderMail : 				zEnvoyerAmiSenderMail,
								zDestEmail : 				zEnvoyerAmiDestEmail,
								zMessage : 					zEnvoyerAmiMessage,
								iRecetteContentObjectId : 	iEnvoiAmiRecetteContentObjectId
							},
					type: 'post',
					dataType: 'json',
					async: false,
					success: function (_iResp)
					{
						if (_iResp == 0)
						{
							$('#evoyer-ami-error').html ('') ;
							$('#envoyer-ami-close').trigger ('click') ;
							$('.pop-envoyer-ami-success').trigger ('click') ;
							/*$('#popMessage').find ('.pop-text-message').html ('La recette  et votre message a correctement été envoyé à votre ami(e).') ;*/
							$('#popMessage').find ('.pop-text-message').html ('Votre message a correctement été envoyé à votre ami(e).') ;
						}
						else
						{
							$('#evoyer-ami-error').html ('Il y a eu un problème lors de l\'envoi de votre message, veuillez recommencer') ;
						}
					}
				}) ;
			}
			else
			{
				$('#evoyer-ami-error').html (zErrorMessage) ;
			}
			
			return false ;
		}
	) ;
	// --- END ENVOYER A UN AMI POPUP ---
	
	// --- OUBLI MOT DE PASSE POPUP ---
	$('#oubli-pass-valider').click (
		function ()
		{
			var zOubliPassEmail = $('#zOubliPassMail').val () ;
			var iOubliPassComptePro = $('#iComptePro').val () ;
			
			var zErrorMessage = '' ;
			
			if (zOubliPassEmail == '')
			{
				zErrorMessage += 'Veuillez renseigner votre adresse e-mail<br/>'
			}
			else
			{
				if (!checkEmailFormat(zOubliPassEmail))
				{
					zErrorMessage += 'Le format de votre adresse e-mail est invalide<br/>'
				}
			}
			
			if (zErrorMessage == '')
			{
				$.ajax ({
					url: j_basepath + 'cidre.php?module=aclfo&action=FoComptesActions:sendPassByMail',
					data: 	{
								zMembreEmail :	zOubliPassEmail,
								iComptePro : 	iOubliPassComptePro
							},
					type: 'post',
					dataType: 'json',
					async: false,
					success: function (_iResp)
					{
						if (_iResp == 0)
						{
							$('#oubli-pass-error').html ('') ;
							$('#oubli-pass-close').trigger ('click') ;
							$('.pop-oubli-pass-success').trigger ('click') ;
							$('#popMessage').find ('.pop-text-message').html ('Votre mot de passe vous a été envoyé par e-mail') ;
						}
						else if (_iResp == 1)
						{
							$('#oubli-pass-error').html ('Aucun membre n\'est enregistré avec cette adresse e-mail') ;
						}
						else if (_iResp == 3)
						{
							$('#oubli-pass-error').html ('Vous ne possédez pas de compte pro') ;
						}
						else
						{
							$('#oubli-pass-error').html ('Il y a eu un problème lors de l\'envoi de l\'email, veuillez recommencer') ;
						}
					}
				}) ;
			}
			else
			{
				$('#oubli-pass-error').html (zErrorMessage) ;
			}
			
			return false ;
		}
	) ;
	// --- END OUBLI MOT DE PASSE POPUP ---

	$('#post-commentaire').submit (
		function ()
		{
			postComments () ;
			return false ;
		}
	) ;

	// --- Compte perso

	$('#compte-perso-login').submit (
		function ()
		{
			postComptePersoLogin () ;
			return false ;
		}
	) ;

	$('#compte-perso-incription').submit (
		function ()
		{
			postComptePersoInscription ('inscription') ;
			return false ;
		}
	) ;

	$('#compte-perso-edit').submit (
		function ()
		{
			postComptePersoInscription ('edit') ;
			return false ;
		}
	) ;

	// --- Compte PRO

	$('#compte-pro-login').submit (
		function ()
		{
			postCompteProLogin () ;
			return false ;
		}
	) ;

	$('#compte-pro-new').submit (
		function ()
		{
			postCompteProCheckCode () ;
			return false ;
		}
	) ;

	$('#inscription-pro').submit (
		function ()
		{
			return postInscriptionPro () ;
		}
	) ;

	// --- Carrément cidre
	
	$('#form-carrement_cidre').submit (
		function ()
		{
			postCarrementCidre () ;
			return false ;
		}
	) ;

	// --- Dépôt de recette

	$('#form-depot-recette').submit (
		function ()
		{
			return postRecette () ;
		}
	) ;
	
	var bExecutedOnce = false ;
	// --- Recherche
	$('#form-recherche').submit (
		function ()
		{
			if (!bExecutedOnce)
			{
				postSearchEngine (1, true) ;
				bExecutedOnce = true ;
			}
			return false ;
		}
	) ;	
}

/**
 * Retour accueil
 *
 */
function backHome ()
{
    $('#header li').removeClass('active') ;

    $('#content-inner')
        .empty()
        .removeClass('loading')
        .addClass('empty') ;
    
    $().setSize(250) ;

    $().setMenu (0) ;

    $.address.value ('') ;

     return false ;
}

// ============= Contrôle de formulaire =============

/**
 * Recette : Post commentaire
 *
 */
function postComments ()
{
	var iId = $('#iCommentObjectId').val () ;
	var zPseudo = $('#commentaire-nom').val () ;
	var zEmail = $('#commentaire-email').val () ;
	var zComment = $('#commentaire-texte').val () ;
	var bError = false ;
	if (zPseudo.trim () == '')
	{
		bError = true ;
		$('#commentaire-nom').addClass ('invalid') ;
	}
	else
	{
		$('#commentaire-nom').removeClass ('invalid') ;
	}
	if (zEmail.trim () == '' || !isEmail (zEmail))
	{
		bError = true ;
		$('#commentaire-email').addClass ('invalid') ;
	}
	else
	{
		$('#commentaire-email').removeClass ('invalid') ;
	}
	if (zComment.trim () == '')
	{
		bError = true ;
		$('#commentaire-texte').addClass ('invalid') ;
	}
	else
	{
		$('#commentaire-texte').removeClass ('invalid') ;
	}
	if (bError)
	{
		$('#laisser-commentaire .erreur-post-comment').show () ;
	}
	else
	{
		$('#laisser-commentaire .erreur-post-comment').hide () ;
		$.ajax ({
			url: j_basepath + 'cidre.php?module=content&action=FoRecetteActions:addComment',
			data:	{
						iId: iId,
						zPseudo: zPseudo,
						zEmail: zEmail,
						zComment: zComment
					},
			type: 'post',
			dataType: 'json',
			async: false,
			success: function (_oRespContent)
			{
				$('#post-commentaire').hide () ;
				$('#confirmation-commentaire').show () ;
			}
		}) ;
	}
}

/**
 * COMPTE PERSO - LOGIN
 *
 */
function postComptePersoLogin ()
{
	var zLogin = $('#login-email').val () ;
	var zPassword = $('#login-password').val () ;
	var zMsgErr = '' ;
	if (zLogin.trim () == '' || !isEmail (zLogin))
	{
		zMsgErr += '<br />- Veuillez fournir une adresse email valide' ;
	}
	if (zPassword.trim () == '')
	{
		zMsgErr += '<br />- Veuillez renseigner votre mot de passe' ;
	}
	if (zMsgErr != '')
	{
		$('#iLoginMsgError').html (zMsgErr) ;
		$('#iLoginMsgError').show () ;
		$('#login-email').focus ()
	}
	else
	{
		$.ajax ({
			url: j_basepath + 'cidre.php?module=aclfo&action=FoComptePerso:postLogin',
			data:	{
						zLogin: zLogin,
						zPassword: zPassword
					},
			type: 'post',
			dataType: 'json',
			async: false,
			success: function (_iRespContent)
			{
				if (_iRespContent == 1)
				{
					$('#iDivFlyBoxNonLogge').hide () ;
					$('#iDivFlyBoxLogge').show () ;
					$().loadAjaxContent (j_basepath + 'cidre.php?module=aclfo&action=FoComptePerso:accueil') ;
				}
				else
				{
					$('#iLoginMsgError').html ('Adresse email ou mot de passe incorrect !') ;
					$('#iLoginMsgError').show () ;
				}
			}
		}) ;
	}
}

/**
 * COMPTE PERSO - LOGIN
 *
 */
function postComptePersoInscription (_zMode)
{
	var zNom = $('#inscription-nom').val () ;
	var zPrenom = $('#inscription-prenom').val () ;
	var zPseudo = $('#inscription-pseudo').val () ;
	var zEmail = $('#inscription-email').val () ;
	var zConfirmEmail = $('#inscription-confirm-email').val () ;
	var zPassword = $('#inscription-password').val () ;
	var iCgu = $('#inscription-cgu').attr ('checked') ? 1 : 0 ;
	var iOptIn = $('#inscription-optin').attr ('checked') ? 1 : 0 ;
	var zMsgErr = '' ;
	var bError = false ;
	if (zNom.trim () == '')
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez renseigner votre nom' ;
	}
	if (zPrenom.trim () == '')
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez renseigner votre prénom' ;
	}
	if (zPseudo.trim () == '')
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez renseigner votre pseudo' ;
	}
	if (zEmail.trim () == ''  || !isEmail (zEmail))
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez renseigner correctement votre email' ;
	}
	if (zConfirmEmail.trim () == ''  || !isEmail (zConfirmEmail))
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez confirmer correctement votre email' ;
	}
	if (zPassword.trim () == '')
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez renseigner votre mot de passe' ;
	}
	if (iCgu == 0)
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez accepter les conditions générales d\'utilisation' ;
	}
	if (!bError)
	{
		if (zEmail != zConfirmEmail)
		{
			zMsgErr += '<br />- Les 2 adresses emails doivent être identiques' ;
		}
		else
		{
			// Vérification de l'unicité de l'email
			if (!checkComptePersoEmailUnicity (zEmail))
			{
				zMsgErr += '<br />- Cette adresse email est déjà utilisée' ;
				$('#inscription-email').focus () ;
			}
			else
			{
				// Vérification de l'unicité du pseudo
				if (!checkComptePersoPseudoUnicity (zPseudo))
				{
					zMsgErr += '<br />- Ce pseudo est déjà utilisé' ;
					$('#inscription-pseudo').focus () ;
				}
				else
				{
					var zUrl = j_basepath + 'cidre.php?module=aclfo&action=FoComptePerso:postInscription' ;
					if (_zMode == 'edit')
					{
						zUrl = j_basepath + 'cidre.php?module=aclfo&action=FoComptePerso:postEdit' ;
					}
					$.ajax ({
						url: zUrl,
						data:	{
									zNom: zNom,
									zPrenom: zPrenom,
									zPseudo: zPseudo,
									zEmail: zEmail,
									zPassword: zPassword,
									iOptIn: iOptIn
								},
						type: 'post',
						dataType: 'json',
						async: false,
						success: function (_iRespContent)
						{
							
							if (_zMode == 'inscription')
							{
								
								// Affichage de la confirmation
								$('.deux-colonnes').hide () ;
								$('#iDivConfirmationInscription').show () ;
								
								// Modification de l'état du box flottant
								$('#iDivFlyBoxNonLogge').hide () ;
								$('#iDivFlyBoxLogge').show () ;
								
								// Actions de chargement
								onLoadActions () ;

							}
							else
							{
								alert ('Vos informations ont été mises à jour avec succès') ;
							}

						}
					}) ;
				}
			}
		}
	}
	
	if (zMsgErr != '')
	{
		$('#iInscriptionMsgError').html (zMsgErr) ;
		$('#iInscriptionMsgError').show () ;
	}

}

/**
 * Compte perso LOGOUT
 *
 */
function comptePersoLogout ()
{
	if (confirm ('Voulez-vous vous déconnecter ?'))
	{
		$('#iDivFlyBoxLogge').hide () ;
		$('#iDivFlyBoxNonLogge').show () ;
		return true ;
	}
	else return false ;
}

/**
 * Compte perso DELETE
 *
 */
function comptePersoDelete (_zUrl)
{
	if (confirm ('Etes-vous certains de vouloir supprimer votre compte ?'))
	{
		$('#iDivFlyBoxLogge').hide () ;
		$('#iDivFlyBoxNonLogge').show () ;
		document.location.href = _zUrl ;
		return true ;
	}
	return false ;
}

/**
 * Compte perso DELETE
 *
 */
function compteProDelete ()
{
	$('#iDivFlyBoxLogge').hide () ;
	$('#iDivFlyBoxNonLogge').show () ;
	return true ;
}

/**
 * COMPTE PRO - CHECK CODE
 *
 */
function postCompteProCheckCode ()
{
	var zCode = $('#new-identifiant').val () ;
	var zMsgErr = '' ;
	if (zCode.trim () == '')
	{
		zMsgErr += 'Veuillez renseigner un identifiant correct' ;
	}
	if (zMsgErr != '')
	{
		$('#iCheckCodeMsgError').html (zMsgErr) ;
		$('#iCheckCodeMsgError').show () ;
		$('#new-identifiant').focus ()
	}
	else
	{
		$.ajax ({
			url: j_basepath + 'cidre.php?module=aclfo&action=FoComptePro:postCheckCode',
			data:	{
						zCode: zCode
					},
			type: 'post',
			dataType: 'json',
			async: false,
			success: function (_iRespContent)
			{
				if (_iRespContent == 1)
				{
					$().loadAjaxContent (j_basepath + 'cidre.php?module=aclfo&action=FoComptePro:inscription') ;
				}
				else
				{
					$('#iCheckCodeMsgError').html ('L\'identifiant renseigné n\'est pas correct, merci de réessayer') ;
					$('#iCheckCodeMsgError').show () ;
				}
			}
		}) ;
	}
}

/**
 * COMPTE PRO - LOGIN
 *
 */
function postCompteProLogin ()
{
	var zLogin = $('#login-email').val () ;
	var zPassword = $('#login-password').val () ;
	var zMsgErr = '' ;
	if (zLogin.trim () == '' || !isEmail (zLogin))
	{
		zMsgErr += '<br />- Veuillez fournir une adresse email valide' ;
	}
	if (zPassword.trim () == '')
	{
		zMsgErr += '<br />- Veuillez renseigner votre mot de passe' ;
	}
	if (zMsgErr != '')
	{
		$('#iLoginMsgError').html (zMsgErr) ;
		$('#iLoginMsgError').show () ;
		$('#login-email').focus ()
	}
	else
	{
		$.ajax ({
			url: j_basepath + 'cidre.php?module=aclfo&action=FoComptePro:postLogin',
			data:	{
						zLogin: zLogin,
						zPassword: zPassword
					},
			type: 'post',
			dataType: 'json',
			async: false,
			success: function (_iRespContent)
			{
				if (_iRespContent == 1)
				{
					$('#iDivFlyBoxNonLogge').hide () ;
					$('#iDivFlyBoxLogge').show () ;
					$().loadAjaxContent (j_basepath + 'cidre.php?module=aclfo&action=FoComptePro:accueil') ;
				}
				else
				{
					$('#iLoginMsgError').html ('Adresse email ou mot de passe incorrect !') ;
					$('#iLoginMsgError').show () ;
				}
			}
		}) ;
	}
}

/**
 * COMPTE - PRO - INSCRIPTION
 *
 */
function postInscriptionPro ()
{
	
	var zNom = $('#inscription-nom').val () ;
	var zPrenom = $('#inscription-prenom').val () ;
	var zEtablissement = $('#inscription-etablissement').val () ;
	var zAdresse = $('#inscription-adresse').val () ;
	var zCodePostal = $('#inscription-codep').val () ;
	var zVille = $('#inscription-ville').val () ;
	var zTel = $('#inscription-tel').val () ;
	var zEmail = $('#inscription-email').val () ;
	var zEmailConfirm = $('#inscription-email-confirm').val () ;
	var zPassword = $('#inscription-password').val () ;
	var zPasswordConfirm = $('#inscription-password-confirm').val () ;
	var iCgu = $('#inscription-cgu').attr ('checked') ? 1 : 0 ;
	var zMsgErr = '' ;
	var bError = false ;
	if (zNom.trim () == '')
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez renseigner votre nom' ;
	}
	if (zPrenom.trim () == '')
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez renseigner votre prénom' ;
	}
	if (zEtablissement.trim () == '')
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez renseigner le nom de votre établissement' ;
	}
	if (zAdresse.trim () == '')
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez renseigner votre adresse' ;
	}
	if (zCodePostal.trim () == '')
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez renseigner votre code postal' ;
	}
	if (zVille.trim () == '')
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez renseigner votre ville' ;
	}
	if (zTel.trim () == '')
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez renseigner votre N° de Téléphone' ;
	}
	if (zEmail.trim () == ''  || !isEmail (zEmail))
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez renseigner correctement votre email' ;
	}
	if (zEmailConfirm.trim () == ''  || !isEmail (zEmailConfirm))
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez confirmer correctement votre email' ;
	}
	if (zPassword.trim () == '')
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez renseigner votre mot de passe' ;
	}
	if (zPasswordConfirm.trim () == '')
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez confirmer votre mot de passe' ;
	}
	if (iCgu == 0)
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez accepter les conditions générales d\'utilisation' ;
	}
	if (!bError)
	{
		if (zEmail != zEmailConfirm)
		{
			zMsgErr += '<br />- Les 2 adresses emails doivent être identiques' ;
		}
		else
		{
			if (zPassword != zPasswordConfirm)
			{
				zMsgErr += '<br />- Les 2 mots de passe doivent être identiques' ;
			}
			else
			{
				// Vérification de l'unicité de l'email
				if (!checkComptePersoEmailUnicity (zEmail))
				{
					zMsgErr += '<br />- Cette adresse email est déjà utilisée' ;
					$('#inscription-email').focus () ;
				}
				else
				{
					return true ;
				}
			}
		}
	}
	
	if (zMsgErr != '')
	{
		$('#iInscriptionMsgError').html (zMsgErr) ;
		$('#iInscriptionMsgError').show () ;
	}

	return false ;

}

// --- Carrément cidre

function postCarrementCidre ()
{
	var zCodePostal = $('#zCodePostal').val () ;
	var zMsgErr = '' ;
	var bError = false ;
	$().loadAjaxContent (j_basepath + 'cidre.php?module=carrementcidre&action=FoCarrementCidre:resultat&cp=' + zCodePostal) ;
}

// --- Post recette

/**

<label for="recette-titre">Titre de la recette*</label><br/><input type="text" id="recette-titre" name="zTitre" />
<label for="recette-temps-prepa">Temps de préparation*</label><br/><input type="text" id="recette-temps-prepa" class="petit" name="zTempsPrepa" /> minutes
<label for="recette-temps-cuisson">Temps de cuisson*</label><br/><input type="text" id="recette-temps-cuisson" class="petit" name="zTempsCuisson" /> minutes
<label for="recette-nb-personnes">Nb. de personnes</label><br/>
<label for="recette-photo">Attacher une photo</label><br/><input type="file" id="recette-photo" name="zPhoto" />
<label for="recette-ingredients">Ingrédients* <em>(un ingrédient par ligne)</em></label><br/>
<textarea id="recette-ingredients" cols="50" rows="8" name="zIngredients" ></textarea>
<label for="recette-prepa">Préparation*</label>
<textarea id="recette-prepa" cols="50" rows="15" name="zPrepa"></textarea>
<p><input type="checkbox" id="recette-cgu" class="case"> <label for="recette-cgu">J'accepte les</label> <a 

*/

/**
 * COMPTE - PRO - INSCRIPTION
 *
 */
function postRecette ()
{
	
	var zTitre = $('#recette-titre').val () ;
	var zTempsPrepa = $('#recette-temps-prepa').val () ;
	var zTempsCuisson = $('#recette-temps-cuisson').val () ;
	var zIngredients = $('#recette-ingredients').val () ;
	var zPrepa = $('#recette-prepa').val () ;
	var iCgu = $('#recette-cgu').attr ('checked') ? 1 : 0 ;
	var zMsgErr = '' ;
	var bError = false ;
	if (zTitre.trim () == '')
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez renseigner le titre de votre recette' ;
	}
	if (zTempsPrepa.trim () == '')
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez renseigner le temps de préparation' ;
	}
	if (zTempsCuisson.trim () == '')
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez renseigner le temps de cuisson' ;
	}
	if (zIngredients.trim () == '')
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez renseigner les ingredients nécessaires' ;
	}
	if (zPrepa.trim () == '')
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez décrire la préparation' ;
	}
	if (iCgu == 0)
	{
		bError = true ;
		zMsgErr += '<br />- Veuillez accepter les conditions générales d\'utilisation' ;
	}

	if (!bError)
	{
		return true ;
	}
	
	if (zMsgErr != '')
	{
		$('#iRecetteMsgErreur').html (zMsgErr) ;
		$('#iRecetteMsgErreur').show () ;
	}

	return false ;

}

// --- Recherche
function postSearchEngine (_iCurrentPage, _bNewSearch)
{
	var zMotCle = $('#zRechercheMotCle').val () ;
	var zMsgErr = '' ;
	var bError = false ;
	
	var iNewSearch = _bNewSearch ? 1 : 0 ;
	$().loadAjaxContent (j_basepath + 'cidre.php?module=searchengine&action=FoSearchEngine:search&zKeyword=' + zMotCle + '&iCp=' + _iCurrentPage + '&iNewSearch=' + iNewSearch) ;
	
	return false ;
}


// --- pagination Recette
function postPageRecette (_iNodeId, _iPage, _iCId)
{	
	var zUrl = j_basepath + 'index.php?module=content&action=FoPageCategorieRecette:renderContent&iCId=' + _iCId + '&iCp=' + _iPage + '&iNodeId=' + _iNodeId ;
    $().loadAjaxContent (zUrl) ;
	return false ;
}
