$(document).ready(function(){
	$('#JMessage').hide();
	/**********************************************************************************************
	Formulaire identification
	Header
	*/
});

$(function() {
	// Verification formulaire newsletters
	$('#formNewsMailbooster').submit(function(){
		if($('#NewsMailboosterPrenom').val()==''){
			jAlert('Merci de renseigner votre prénom', 'Information');
			return false;
		}
		if($('#NewsMailboosterEMail').val()==''){
			jAlert('Merci de renseigner votre email', 'Information');
			return false;
		}
	});
			 
	// Tableau une ligne sur deux 
	$('.TabSurligne tbody tr:nth-child(odd)').addClass('TDPair') ;	


	 $('#formIdentificationHeader').submit(function(){
		if($.trim($('#idLoginHeader').val())==''){
			jAlert('Merci de renseigner votre nom d\'utilisateur.', 'Information', function(r){
				$('#idLoginHeader').focus();
			});		
			return false;
		}else if($.trim($('#idPassHeader').val())==''){
			jAlert('Merci de renseigner votre mot de passe.', 'Information', function(r){
				$('#idPassHeader').focus();
			});		
			return false;
		}else{
			$('#JMessage').show("fast",function(){
				$('#JMessagePlus').replaceWith('Vérification en cours...')
				$('#formIdentificationHeader').ajaxSubmit({ 
					url			: '/includes/actions_post.php',    	// override for form's 'action' attribute 
					type			: 'post',	       				// 'get' or 'post', override for form's 'method' attribute 
					success		: function(msg){
						if(msg==1){
							$(location).attr('href',"https://www.mailbooster.com/mon_compte/index.php");
						}else{
							$('#JMessage').hide();
							jAlert(msg, 'Information');
						}
					} 
				});
				return false;				
			});
		}
		return false;				
	});
	/*
	Sur une page
	*/
	$('#formIdentification').submit(function(){
		if($.trim($('#idLogin').val())==''){
			jAlert('Merci de renseigner votre nom d\'utilisateur.', 'Information', function(r){
				$('#idLogin').focus();
			});		
			return false;
		}else if($.trim($('#idPass').val())==''){
			jAlert('Merci de renseigner votre mot de passe.', 'Information', function(r){
				$('#idPass').focus();
			});		
			return false;
		}else{
			$('#JMessage').show("fast",function(){
				$('#JMessagePlus').replaceWith('Vérification en cours...');
				$('#formIdentification').ajaxSubmit({ 
					url			: '/includes/actions_post.php',    	// override for form's 'action' attribute 
					type			: 'post',	       				// 'get' or 'post', override for form's 'method' attribute 
					success		: function(msg){
						if(msg==1){
							$(location).attr('href',"/mon_compte/index.php");
						}else{
							$('#JMessage').hide();
							jAlert(msg, 'Information');
						}
					} 
				});
				return false;				
			});
		}
		return false;				
	});
	
	/*
	Retrouve mot de passe
	*/
	$('#formPassePerdu').submit(function(){
		if($.trim($('#PassPerdu').val())==''){
			jAlert('Merci de renseigner votre Email.', 'Information', function(r){
				$('#PassPerdu').focus();
			});		
			return false;
		}else if($.trim($('#Code').val())==''){
			jAlert('Merci de recopier le code de sécurité.', 'Information', function(r){
				$('#Code').focus();
			});		
			return false;
		}else{
			$('#JMessage').show("fast",function(){
				$('#JMessagePlus').replaceWith('Demande en cour...');
			});
		}
	});
	
	/**********************************************************************************************
	Formulaire de contact
	*/
	$('#formContact').submit(function(){
		$('#JMessage').show("fast",function(){
			$('#JMessagePlus').replaceWith('Vérification en cours...');
			$('#formContact').ajaxSubmit({ 
				url			: '/includes/actions_post.php',    	// override for form's 'action' attribute 
				type			: 'post',	       				// 'get' or 'post', override for form's 'method' attribute 
				success		: function(msg){
					if(msg==1){
						jAlert('Votre message nous est bien parvenu.', 'Information', function(r){
							$(location).attr('href',"/index.php");
						});		
					}else{
						$('#JMessage').hide();
						jAlert(msg, 'Information');
					}
				} 
			});
			return false;				
		});
		return false;				
	});
	
	/**********************************************************************************************
	Formulaire d'inscription
	*/
	$('#formInscription').submit(function(){
		$('#JMessage').show("fast",function(){
			$('#JMessagePlus').replaceWith('Vérification en cours...');
			$('#formInscription').ajaxSubmit({ 
				url			: '/includes/actions_post.php',    	// override for form's 'action' attribute 
				type			: 'post',	       				// 'get' or 'post', override for form's 'method' attribute 
				success		: function(msg){
					if(msg==1){
						jAlert('Un message de confirmation vous a été envoyé.', 'Information', function(r){
							$(location).attr('href',"https://www.mailbooster.com/identification.php");
						});		
					}else{
						$('#JMessage').hide();
						jAlert(msg, 'Information');
					}
				} 
			});
			return false;				
		});
		return false;				
	});
});
