// source --> https://www.spinfamily.fr/wp-content/themes/hello-elementor-child/js/MSW_ajax.js?ver=1.07 

jQuery(document).ready(function($) {

	var show_notice = function( html_element, $target ) {
		if ( ! $target ) {
			$target = $( '.woocommerce-notices-wrapper:first' ) || $( '.cart-empty' ).closest( '.woocommerce' ) || $( '.woocommerce-cart-form' );
		}
		$target.prepend( html_element );
	};

	//Fonctionnalité d'ajout au panier en AJAX
	$(document).on("click", ".single_add_to_cart_button" , function( e ) {

		if ( $( ".woocommerce .cart_empty_suggestion" ).length > 0 ) var cart_was_empty = true;
		else var cart_was_empty = false;
		
		e.preventDefault();

		$('#MSW_overlay').css({'z-index':'9999','background-color':'rgba(0,0,0,0.25)','max-height': '2000px'});

		var bouton_produit = e.target;

		var id_produit = $(this).attr('id');
		//Pour single product
		if (typeof id_produit === typeof undefined || id_produit === false) id_produit = $(this).attr('value');

		var quantite_produit = 1;
		
		//On vérifie les champs personnalisés
		var txt_error_champ_personnalise = '';
		

		if ( $( "#MSW_code_pt4 input[name=code_pt4]" ).length )
		{
			var code_pt4 = $( "#MSW_code_pt4 input[name=code_pt4]" ).val();
			if (code_pt4 == '') txt_error_champ_personnalise+= 'Le champ <strong>Code Poker Tracker</strong> est obligatoire.<br />';
		}
		else var code_pt4 = '';
		
		if ( $( "#MSW_email_pt4 input[name=email_pt4]" ).length )
		{
			var email_pt4 = $( "#MSW_email_pt4 input[name=email_pt4]" ).val();
			if (email_pt4 == '') txt_error_champ_personnalise+= 'Le champ <strong>E-mail Poker Tracker</strong> est obligatoire.<br />';
		}
		else var email_pt4 = '';
		

		if ( txt_error_champ_personnalise != '' )
		{
			$( ".woocommerce-notices-wrapper" ).html( '<ul class="woocommerce-error" role="alert"><li>'+txt_error_champ_personnalise+'</li></ul>' );
			if ( $( "#woosq-popup").length == 0) $('#MSW_overlay').css({'z-index':'3','background-color':'transparent','max-height': '0px'});
			else
			{
				$("body .mfp-woosq .mfp-close").attr("disabled", false);
				$("body .mfp-woosq .mfp-close").attr('style' , 'background-color:#fff;');
				$( "#woosq-popup #MSW_wooqs_overlay").remove();
			}
			return false;
		}

		
		var data = {
				action: 'MSW_ajax_add_to_cart',
				security : MSW_nonce_URL.nonce,
				product_id: id_produit,
				product_sku: '',
				quantity: quantite_produit,
				code_pt4: code_pt4,
				email_pt4: email_pt4,
			};

		$(document.body).trigger('adding_to_cart', [$(bouton_produit), data]);

		$.ajax({
			type: 'post',
			dataType: 'json',
			url: MSW_nonce_URL.url,
			data: data,
			success: function (response) {
			
			// alert('got success');
			// alert(response.error);
			// alert(response.achat_doublon);
			// alert(response.already_isset);
			// alert(response.quantite);
			// alert(response.quantite_panier);
			// alert(response.array_tmp);
			// alert(response.error);
			// alert(response.variations);
			// alert(id_produit);

			$('#MSW_overlay').css({'z-index':'3','background-color':'transparent','max-height': '0px'});
			
			if (response.error==true) 
			{
				if (response.already_isset == true) var error_message = '<ul class="woocommerce-error" role="alert"><li>Tu ne peux pas ajouter un autre « '+response.nom+' » à ton panier.</li></ul>';
				else var error_message = '<ul class="woocommerce-error" role="alert"><li>Une erreur s\'est produite lors de l\'ajout de « '+response.nom+' » à ton panier.</li></ul>';
				$( ".woocommerce-notices-wrapper" ).html( error_message );
			} 
			else 
			{
				//Si page panier et panier était vide, on reload la page
				if ( cart_was_empty == true)
				{
					window.location = 'https://www.spinfamily.fr/panier/';
					return false;
				}
				
				//Si on est sur la page panier on trigger update cart
				if ($("form.woocommerce-cart-form [name='update_cart']").length > 0 )
				{
					$("form.woocommerce-cart-form [name='update_cart']").removeAttr('disabled');
					$("form.woocommerce-cart-form [name='update_cart']").trigger("click");
					$("html, body").animate({ scrollTop: $('#container_panier').offset().top }, 500);
				}
				//Sinon animation + MAJ mini cart + MAJ data-counter nb items
				else 
				{
					if ( $( "#MSW_popup_add_to_cart").length > 0)
					{
						var popup_clone = $( "#MSW_popup_add_to_cart").clone().css('display','block');

						// var content_product = '<h2>'+response.nom+'</h2><p>a bien été ajouté à ton panier.</p>';
						
						if (response.variations != '') var variations_html = response.variations;
						else
						{
							//Cart item du HUD
							if (id_produit == 6083)
							{
								var variations_html = '<dl class="variation"><dt class="variation-Code">Code:</dt><dd class="variationCode"><p>'+code_pt4+'</p></dd><dt class="variation-E-mail">E-mail:</dt><dd class="variation-E-mail"><p>'+email_pt4+'</p></dd></dl>';
							}
							else var variations_html = '';
						}
						
						
						var content_product = '<h2>'+response.nom+'</h2>'+variations_html+'<p>a bien été ajouté à ton panier.</p>';
	

						$.magnificPopup.open({
							items: {
								src: popup_clone,
								type: 'inline',
								
							},

							mainClass: 'mfp-zoom-in',
							removalDelay: 160,
							fixedContentPos: true,
							callbacks: {
								open: function() {
									//Insertion du contenu
									$( "#MSW_popup_add_to_cart .thumbnail").html( '<img src='+response.thumbmail_popup+' />' );
									$( "#MSW_popup_add_to_cart .content .product").html( content_product );
									$( "button.mfp-close" ).attr('title' , '');
									$( "button.mfp-close" ).html('');
								},
								close: function() {
									popup_clone.remove();
								}
							}
						});	
					}

					
					//Mise à jour du mini cart
					if ( typeof woocommerce_params !== 'undefined' )
					{					
						$.post(
							woocommerce_params.ajax_url,
							{'action': 'MSW_ajax_update_mini_cart'},
							function(response_mini_cart) {
								$('.widget_shopping_cart_content').html(response_mini_cart);
							}
						);
					}

					//Quantité data-counter icône
					$( ".elementor-menu-cart__toggle .elementor-button-icon-qty" ).attr('data-counter', response.nb_items);	 
					$( ".elementor-menu-cart__toggle .elementor-button-icon-qty" ).html(response.nb_items);	 
				}
			}
		},
		});	
	});
	
	//Fonctionnalité d'espress checkout en AJAX
	$(document).on("click", ".express_checkout" , function( e ) {

		e.preventDefault();

		$('#MSW_overlay').css({'z-index':'9999','background-color':'rgba(0,0,0,0.25)','max-height': '2000px'});

		var bouton_produit = e.target;

		var id_produit = $(this).attr('id');
		var quantite_produit = 1;

		var data = {
				action: 'MSW_ajax_express_checkout',
				security : MSW_nonce_URL.nonce,
				product_id: id_produit,
				product_sku: '',
				quantity: quantite_produit,
			};

		$(document.body).trigger('adding_to_cart', [$(bouton_produit), data]);

		$.ajax({
			type: 'post',
			dataType: 'json',
			url: MSW_nonce_URL.url,
			data: data,
			success: function (response) {

			$('#MSW_overlay').css({'z-index':'3','background-color':'transparent','max-height': '0px'});
			
			if (response.error==true) 
			{
				var error_message = '<ul class="woocommerce-error" role="alert"><li>Une erreur s\'est produite lors de l\'ajout de « '+response.nom+' » à ton panier.</li></ul>';
				$( ".woocommerce-notices-wrapper" ).html( error_message );
			} 
			else 
			{
				window.location = 'https://www.spinfamily.fr/commander/';
				return false;

				//Affichage du checkout
				$('#MSW_express_checkout').css('display' , 'block');
				
				//Trigger update total on change pour être sur que le récapitulatif de commande soit ok
				$('body').trigger('update_checkout');

				//Scroll to checkout
				$("html, body").animate({ scrollTop: $('#MSW_express_checkout').offset().top }, 400);
		
				//Mise à jour du mini cart
				if ( typeof woocommerce_params !== 'undefined' )
				{					
					$.post(
						woocommerce_params.ajax_url,
						{'action': 'MSW_ajax_update_mini_cart'},
						function(response_mini_cart) {
							$('.widget_shopping_cart_content').html(response_mini_cart);

							//Update du mini cart sous total en HT pour les pros
							if (response.is_magasin == true || response.is_grossiste == true) $(".elementor-menu-cart__main .elementor-menu-cart__subtotal").html( '<strong>Sous Total HT :</strong> <span class="woocommerce-Price-amount amount"><bdi>'+response.sous_total_formatted+'<span class="woocommerce-Price-currencySymbol">€</span></bdi></span>' );
						}
					);
				}

				//Quantité data-counter icône
				$( ".elementor-menu-cart__toggle .elementor-button-icon-qty" ).attr('data-counter', 1);

			}
		},
		});	
	});

	//Fonctionnalité de suppression du panier en AJAX
	$(document).on("click", ".elementor-menu-cart__product-remove a" , function( e ) {

		e.preventDefault();
		
		$('#MSW_overlay_cart').css({'background-color':'rgba(0,0,0,0.5)','max-height': '2000px'});
		
		var cart_item_key = $(this).attr("data-cart_item_key");

		$.ajax({
			type: 'POST',
			dataType: 'json',
			url: MSW_nonce_URL.url,
			data: {
				action: "MSW_ajax_product_remove",
				security : MSW_nonce_URL.nonce,
				cart_item_key: cart_item_key
			},
			success: function(response) {

				if ( ! response || response.removed == false )
				{
					$( ".woocommerce-notices-wrapper" ).html( '<ul class="woocommerce-error" role="alert"><li>Une erreur s\'est produite. Merci de réessayer.</li></ul>' );
					$('#MSW_overlay_cart').css({'background-color':'transparent','max-height': '0px'});
				}
				else
				{
					//Mise à jour du mini cart
					if ( typeof woocommerce_params !== 'undefined' )
					{
						$.post(
							woocommerce_params.ajax_url,
							{'action': 'MSW_ajax_update_mini_cart'},
							function(response) {
								$('.widget_shopping_cart_content').html(response);
								$('#MSW_overlay_cart').css({'background-color':'transparent','max-height': '0px'});
							}
						);
					}

					//Quantité data-counter icône
					$( ".elementor-menu-cart__toggle .elementor-button-icon-qty" ).attr('data-counter', response.nb_items);	 
					$( ".elementor-menu-cart__toggle .elementor-button-icon-qty" ).html(response.nb_items);	 
				}
			}
		});
	});
	
});
// source --> https://www.spinfamily.fr/wp-content/plugins/msw-plugin/assets/js/MSW_plugin_script.js?ver=1.52 

jQuery(document).ready(function($) {

	//Ne pas mettre en invalide par défaut l'input de mot de passe à la création de compte pendant le checkout
	$( "#createaccount" ).on( 'click' , function(e) {
		setTimeout(function () {
			$( "#account_password_field" ).removeClass('woocommerce-invalid woocommerce-invalid-required-field').addClass('woocommerce-validated');
		} , 50);
	});
	
	// Animate prend compte du header sticky on Error blur champ Stripe checkout
	$( document.body ).on( 'stripeError', function(){
		setTimeout(function() {
			var minus_offset = 30;
			if ( $( 'header.elementor-section' ).hasClass('elementor-sticky--active') ) minus_offset += $( 'header.elementor-sticky--active' ).innerHeight();
			$( 'html, body' ).animate({ scrollTop: $( '.wpmc-step-payment #wc-stripe-cc-form' ).offset().top - minus_offset, }, 100);
		}, 0);
	});
	
	//Validation de la dernière étape du multi step checkout on place order (stripe et CGV)
	$( document.body ).on( 'click' , '.wpmc-step-payment #payment #place_order' , function(e) {

		var txt_error = '';

		if ( $( "input#payment_method_stripe" ).length && $( "input#payment_method_stripe" ).is( ':checked') )
		{
			if ( $( "div#stripe-card-element" ).hasClass('empty') )
			{
				txt_error+='Le <strong>numéro de carte</strong> est obligatoire.<br />';
				$( "div#stripe-card-element" ).addClass('invalid')
			}
			else if ( $( "div#stripe-card-element" ).hasClass('invalid') ) txt_error+='Le <strong>numéro de carte</strong> est incomplet ou invalide.<br />';

			if ( $( "div#stripe-exp-element" ).hasClass('empty') )
			{
				txt_error+='La <strong>date d\'expiration</strong> de la carte est obligatoire.<br />';
				$( "div#stripe-exp-element" ).addClass('invalid')
			}
			else if ( $( "div#stripe-exp-element" ).hasClass('invalid') ) txt_error+='La <strong>date d\'expiration</strong> de la carte est incomplète ou invalide.<br />';
			
			if ( $( "div#stripe-cvc-element" ).hasClass('empty') )
			{
				txt_error+='Le <strong>code de sécurité</strong> de la carte est obligatoire.<br />';
				$( "div#stripe-cvc-element" ).addClass('invalid')
			}
			else if ( $( "div#stripe-cvc-element" ).hasClass('invalid') ) txt_error+='Le <strong>code de sécurité</strong> de la carte est incomplet ou invalide.<br />';

			if (txt_error != '')
			{
				txt_error+='<br />Merci de vérifier les données saisies.<br />';
				var scroll_to_anim = true;
			}
		}
		
		if ( $( ".wpmc-step-payment #payment input#terms" ).length && ! $( ".wpmc-step-payment #payment input#terms" ).is( ':checked') )
		{
			$( ".wpmc-step-payment #payment input#terms" ).closest('p').addClass('woocommerce-invalid woocommerce-invalid-required-field').removeClass('woocommerce-validated');
			if (txt_error != '') txt_error+='<br />';
			txt_error+='Merci d\'accepter les <strong>conditions générales de vente</strong> pour valider la commande.<br />';
					
		}
		else $( ".wpmc-step-payment #payment input#terms" ).closest('p').removeClass('woocommerce-invalid woocommerce-invalid-required-field').addClass('woocommerce-validated');

		//Affichage des erreurs
		if (txt_error != '')
		{
			$( ".woocommerce-notices-wrapper" ).prepend( '<ul class="woocommerce-error" role="alert"><li>'+txt_error+'</li></ul>');
			if (scroll_to_anim)
			{
				var minus_offset = 30;
				if ( $( 'header.elementor-section' ).hasClass('elementor-sticky--active') ) minus_offset += $( 'header.elementor-sticky--active' ).innerHeight();
				$( 'html, body' ).animate({ scrollTop: $( '.wpmc-step-payment #wc-stripe-cc-form' ).offset().top - minus_offset, }, 400);
			}
			return false;
		}
	});
	
	//Reorganiser le form checkout au changement de pays (tous les pays n'ont pas besoin des memes champs)
	$( document.body ).on( 'country_to_state_changing', function(e) {
		MSW_reorder_form_billing_shipping();
	});
	
	//Reorganiser le form edit adress au changement de pays (tous les pays n'ont pas besoin des memes champs)
	$( document.body ).on( 'change' , 'form .woocommerce-address-fields #billing_country , form .woocommerce-address-fields #shipping_country', function(e) {
		MSW_reorder_form_billing_shipping();
	});
	
	function MSW_reorder_form_billing_shipping()
	{
		setTimeout(function () {
				if ( $( "p#billing_postcode_field" ).length ) $( "p#billing_postcode_field" ).insertAfter( "p#billing_address_2_field");
				if ( $( "p#billing_postcode_field" ).css('display') == 'none' ) $( "p#billing_city_field" ).removeClass('form-row-last').addClass('form-row-wide');
				else $( "p#billing_city_field" ).removeClass('form-row-wide').addClass('form-row-last');
				
				if ( $( "p#billing_state_field" ).length ) $( "p#billing_state_field" ).insertAfter( "p#billing_country_field");
				if ( $( "p#billing_city_field" ).length ) $( "p#billing_city_field" ).insertAfter( "p#billing_postcode_field");
				if ( $( "p#billing_country_field" ).length ) $( "p#billing_country_field" ).insertAfter( "p#billing_city_field");

				if ( $( "p#billing_postcode_field" ).length ) $( "p#billing_postcode_field" ).removeClass('form-row-wide').addClass('form-row-first');
				
				if ( $( "p#billing_state_field" ).length ) $( "p#billing_state_field" ).removeClass('form-row-wide').addClass('form-row-last');

				if ( $( "p#shipping_postcode_field" ).length ) $( "p#shipping_postcode_field" ).insertAfter( "p#shipping_address_2_field");
				if ( $( "p#shipping_postcode_field" ).css('display') == 'none' )  $( "p#shipping_city_field" ).removeClass('form-row-last').addClass('form-row-wide');
				else $( "p#shipping_city_field" ).removeClass('form-row-wide').addClass('form-row-last');
				
				if ( $( "p#shipping_state_field" ).length ) $( "p#shipping_state_field" ).insertAfter( "p#shipping_country_field");
				if ( $( "p#shipping_city_field" ).length ) $( "p#shipping_city_field" ).insertAfter( "p#shipping_postcode_field");
				if ( $( "p#shipping_country_field" ).length ) $( "p#shipping_country_field" ).insertAfter( "p#shipping_city_field");
				
				if ( $( "p#shipping_postcode_field" ).length ) $( "p#shipping_postcode_field" ).removeClass('form-row-wide').addClass('form-row-first');
				
				if ( $( "p#shipping_state_field" ).length ) $( "p#shipping_state_field" ).removeClass('form-row-wide').addClass('form-row-last');
			} , 50);
	}
	
	//Fermer le menu mobile Elementor on touch s'il est ouvert
	if (window.matchMedia("(max-width: 1024px)").matches)
	{
		$(document).on('touchstart', '#MSW_overlay , #MSW_overlay_sticky_header, .elementor-menu-dropdown__close-button', function (e) {
		// $( "#MSW_overlay , #MSW_overlay_sticky_header, .elementor-menu-dropdown__close-button" ).on("touchstart", function(e) {

			if ( $( ".elementor-location-header .menu_header.menu_left .elementor-menu-toggle" ).hasClass('elementor-active') )
			{
				$( ".elementor-location-header .menu_header.menu_left .elementor-menu-toggle" ).removeClass('elementor-active');
				
				if ( ! $( ".elementor-location-header .menu_header.menu_left" ).hasClass('is_sticky_mobile') )
				{
					$('#MSW_overlay').css({'background-color':'transparent'});
					setTimeout(function() { $('#MSW_overlay').css({'z-index':'3','max-height': '0px'}); $('#MSW_overlay').removeClass('nobefore'); }, 300);
				}
				else
				{
					$('#MSW_overlay_sticky_header').css({'background-color':'transparent'});
					setTimeout(function() { $('#MSW_overlay_sticky_header').css({'z-index':'3','max-height': '0px'}); }, 300); 
				}
				return false;
			}
		});
	}
	
	//Fermer le menu mobile Elementor on touch sur le bouton de fermeture
	// $(document).on("touchstart", ".elementor-menu-dropdown__close-button" , function() {
		
		// alert('got it bouton');
		// $( ".elementor-location-header .menu_header.menu_left .elementor-menu-toggle" ).removeClass('elementor-active');
		
		// if ( ! $( ".elementor-location-header .menu_header.menu_left" ).hasClass('is_sticky_mobile') )
		// {
			// $('#MSW_overlay').css({'z-index':'3','background-color':'transparent','max-height': '0px'});
			// $('#MSW_overlay').removeClass('nobefore');
		// }
		// else
		// {
			// $('#MSW_overlay_sticky_header').css({'z-index':'3','background-color':'transparent','max-height': '0px'});
		// }
	// });

	//Ajouter un bouton de fermeture au menu Elementor sur mobile
	$( "nav.elementor-nav-menu--dropdown.elementor-nav-menu__container" ).prepend('<div class="elementor-menu-dropdown__close-button"></div>');

	//Ajouter une div #MSW_overlay_sticky_header dans le header s'il est sticky (pour palier au problème de z-index)
	if ( window.matchMedia("(max-width: 1024px)").matches ) $( ".elementor-location-header .container_header" ).append('<div id="MSW_overlay_sticky_header"></div>');
	
	//Faire apparaître le menu Elementor par la gauche et afficher un overlay sur mobile
	$( ".elementor-location-header .menu_header.menu_left .elementor-menu-toggle" ).on("touchstart", function(e) {

		e.preventDefault();
		
		if ( $( ".elementor-location-header .menu_header.menu_left .elementor-menu-toggle" ).hasClass('elementor-active') )
		{
			$( ".elementor-location-header .menu_header.menu_left .elementor-menu-toggle" ).removeClass('elementor-active');
			if ( $( ".elementor-location-header .menu_header.menu_left" ).hasClass('is_sticky_mobile') ) $( ".elementor-location-header .container_header #MSW_overlay_sticky_header" ).remove();
			
			return false;
		}
		else $( ".elementor-location-header .menu_header.menu_left .elementor-menu-toggle" ).addClass('elementor-active');

		if ( ! $( ".elementor-location-header .menu_header.menu_left" ).hasClass('is_sticky_mobile') )
		{
			if ( $('#MSW_overlay').css('max-height') == '0px' )
			{
				$('#MSW_overlay').css({'z-index':'9999','background-color':'rgba(0,0,0,0.5)','max-height': '2000px'});
				$('#MSW_overlay').addClass('nobefore');
			}
			else 
			{
				$('#MSW_overlay').css({'background-color':'transparent'});
				setTimeout(function() { $('#MSW_overlay').css({'z-index':'3','max-height': '0px'}); $('#MSW_overlay').removeClass('nobefore'); }, 300);
				
			}
		}
		else
		{
			$('#MSW_overlay_sticky_header').css({'z-index':'9999','background-color':'rgba(0,0,0,0.5)','max-height': '2000px'});
		}
	});
	
	//Si une seule méthode d'expédition est disponible (page panier), pas d'input radio, on adapte le CSS
	if ( $("body ul#shipping_method li input").attr('type') == 'hidden' )
	{
		$("body ul#shipping_method li label").css('width' , '100%');
		// $(".woocommerce .sidebar_cart .cart_totals table.shop_table tr.woocommerce-shipping-totals.shipping th").attr('style' , 'min-width:unset; width:98px;');
	}
	
	if ( $( "#MSW_tab_product" ).length > 0 )
	{
		//Actualiser le tableau on event resize pour le responsive
		$( window ).resize(function() {
			if ( window.matchMedia("(max-width: 767px)").matches )
			{
				$( "#MSW_tab_product .tabs div.tab" ).each(function( e ) { var id = e+1; $( "#MSW_tab_product .content div#contenu_"+id ).insertAfter( $( "#MSW_tab_product .tabs div#tab_"+id ) ); });
				$( "#MSW_tab_product .content" ).remove();
			}
			else
			{
				if ( ! $( "#MSW_tab_product .content" ).length )
				{
					$( "#MSW_tab_product" ).append('<div class="content"></div>');
					$( "#MSW_tab_product .tabs div.contenu" ).each(function( e ) { $( this ).appendTo('#MSW_tab_product .content'); });
				}
			}

			if ( window.matchMedia("(max-width: 767px)").matches ) $( "#MSW_tab_product .tabs div.tab" ).attr('style' , 'width:auto; display:block;');
			else if ( window.matchMedia("(min-width: 768px)").matches && window.matchMedia("(max-width: 1024px)").matches ) $( "#MSW_tab_product .tabs div.tab" ).attr('style' , 'width:'+100/$( "#MSW_tab_product .tabs div.tab" ).length +'%; display:table-cell;');
			else $( "#MSW_tab_product .tabs div.tab" ).attr('style' , 'width:auto; display:table-cell;');
			
		});
		
		//Gestion du tableau sur mobile
		if ( window.matchMedia("(max-width: 767px)").matches )
		{
			$( "#MSW_tab_product .tabs div.tab" ).each(function( e ) { var id = e+1; $( "#MSW_tab_product .content div#contenu_"+id ).insertAfter( $( "#MSW_tab_product .tabs div#tab_"+id ) ); });
			$( "#MSW_tab_product div#contenu_1" ).addClass('active');
			$( "#MSW_tab_product .content" ).remove();
		}

		if ( window.matchMedia("(max-width: 767px)").matches ) $( "#MSW_tab_product .tabs div.tab" ).attr('style' , 'width:auto; display:block;');
		else if ( window.matchMedia("(min-width: 768px)").matches && window.matchMedia("(max-width: 1024px)").matches ) $( "#MSW_tab_product .tabs div.tab" ).attr('style' , 'width:'+100/$( "#MSW_tab_product .tabs div.tab" ).length +'%; display:table-cell;');
		else $( "#MSW_tab_product .tabs div.tab" ).attr('style' , 'width:auto; display:table-cell;');

		//Fonction pour actualiser le tableau d'onglet fiche produit en fonction des clics utilisateur
		$( "#MSW_tab_product .tabs div.tab" ).click(function( e ) {

			e.preventDefault();
			
			//Si click sur le lien, on cherche la div
			if (e.target.nodeName=='A') var div_id = e.target.closest('div').id;
			else if (e.target.nodeName=='DIV') var div_id = e.target.id;
			
			id = div_id.split('_');

			if (div_id && div_id!='')
			{
				$( "#MSW_tab_product div" ).removeClass('active');
				$( "#MSW_tab_product #tab_"+id[1] ).addClass('active');
				$( "#MSW_tab_product #contenu_"+id[1] ).addClass('active');
			}
		});
		
		//Ajouter une classe active au premier onglet
		$( "#MSW_tab_product .tabs div:first-child" ).addClass('active');
		$( "#MSW_tab_product .content div:first-child" ).addClass('active');
		
		//Afficher le custom tab product si il n'est pas vide
		// if ( $( "#MSW_tab_product" ).length > 0 ) $( "#MSW_container_tab_product" ).css('display','block');
	}
	
	//Afficher le champ Email pour être averti du retour de stock sur un produit variable
	$(document).on( 'found_variation', '.single-product', function( event, variation ) {
		if ( ! $( "body" ).hasClass('logged-in') ) $( ".single-product .cwginstock-subscribe-form .cwgstock_email" ).css('display','inline-block');
	});

	//Ajoute une div overlay au panier flottant Elementor
	$( ".elementor-menu-cart__main" ).append('<div id="MSW_overlay_cart"></div>');

	//Supprimer la notice Wishlist ajoutée a la popup lorsqu'on la ferme
	$(document).on("xoo_el_popup_toggled" , function(e , type) {
		if ( type == 'hide' ) setTimeout(function() { $( ".xoo-el-main .xoo_notice_wishlist" ).remove(); }, 400);
	});

	//Modifier l'icone réinitialisation du mot de passe + Email connexion form login / register popup
	if ( $( ".xoo-el-container").length || $( ".xoo-el-form-container").length )
	{
		$( "form.xoo-el-form-lostpw .xoo-aff-input-group span.xoo-aff-input-icon" ).removeClass('fas fa-key');
		$( "form.xoo-el-form-lostpw .xoo-aff-input-group span.xoo-aff-input-icon" ).addClass('fas fa-at');
		
		var icon_email_login = $( "form.xoo-el-form-login .xoo-aff-input-group span.xoo-aff-input-icon.far.fa-user" );
		icon_email_login.removeClass('far fa-user');
		icon_email_login.addClass('fas fa-at');
	}

	//Afficher le container code promo page panier
	$( ".container_coupon #coupon_panier" ).click(function(){
		if ( $('.container_coupon .coupon').hasClass('active') ) $('.container_coupon .coupon').removeClass('active');
		else $('.container_coupon .coupon').addClass('active');
    });
	
	//Afficher le container points fidélité page panier
	$( ".container_coupon_fidelite #coupon_fidelite" ).click(function(){
		if ( $('.container_coupon_fidelite .fidelite').hasClass('active') )
		{
			$('.container_coupon_fidelite .fidelite').removeClass('active');
			$('.container_coupon_fidelite .fidelite .notice_fidelite').removeClass('active');
		}
		else $('.container_coupon_fidelite .fidelite').addClass('active');
    });
	
	//Afficher le container points fidélité page panier
	$( ".container_coupon_fidelite .fidelite a:not(.button)" ).click(function(){
		if ( $('.container_coupon_fidelite .fidelite .notice_fidelite').hasClass('active') ) $('.container_coupon_fidelite .fidelite .notice_fidelite').removeClass('active');
		else $('.container_coupon_fidelite .fidelite .notice_fidelite').addClass('active');
    });

	//Ajouter un bouton submit au search form header full screen
	$( ".MSW_search_form_mobile .elementor-search-form__container" ).append('<button class="elementor-search-form__submit" type="submit" title="Rechercher " aria-label="Rechercher "><i class="fa fa-search" aria-hidden="true"></i><span class="elementor-screen-only">Rechercher </span></button>');
	
	//Cacher les autres dropdown on touch search form header
	$( ".elementor-location-header .elementor-search-form__toggle").on("touchstart", function() {
		if ( $( ".elementor-location-header .container_account_popup").hasClass('active') )
		{
			$( ".elementor-location-header .container_account_popup" ).removeClass('active');
			$( ".elementor-location-header .icone_account i").removeClass('fa-times').addClass('fa-user');
		}
	});
	
	
	//Cacher les autres dropdown on touch mini cart
	$( ".woocommerce_header .elementor-widget-woocommerce-menu-cart").on("touchstart", function() {
		if ( $( ".elementor-location-header .menu_header .elementor-menu-toggle").hasClass('elementor-active') )
		{
			$( ".elementor-location-header .menu_header .elementor-menu-toggle").removeClass('elementor-active');
		}
		
		if ( $( ".elementor-location-header .container_account_popup").hasClass('active') )
		{
			$( ".elementor-location-header .container_account_popup" ).removeClass('active');
			$( ".elementor-location-header .icone_account i").removeClass('fa-times').addClass('fa-user');
		}
	});
	
	//Cacher les autres dropdown on touch menu principal
	$( ".elementor-location-header .menu_header .elementor-menu-toggle" ).on("touchstart", function() {
		if ( $( ".elementor-location-header .container_account_popup").hasClass('active') )
		{
			$( ".elementor-location-header .container_account_popup" ).removeClass('active');
			setTimeout(function() {
			$( ".elementor-location-header .icone_account i").removeClass('fa-times').addClass('fa-user');
			}, 400); 
			
		}
	});
	
	function MSW_DisplayOverlay()
	{
		$('#MSW_overlay').css({'z-index':'1','background-color':'rgba(0,0,0,0.5)','max-height': '2000px'});
	}
	
	//Rétablir l'icône du compte à l'ouverture de la popup
	$('.elementor-location-header .container_account_popup a').on("touchstart", function (e) {
		$( ".elementor-location-header .icone_account i").removeClass('fa-times').addClass('fa-user');
	});
	
	//Faire apparaître les infos du compte on touchstart mon compte header
	$('.elementor-location-header .icone_account').on("touchstart", function (e) {
		"use strict";
		
		e.preventDefault();

		var delay_show = 0;
		
		if ( $( ".elementor-location-header .menu_header .elementor-menu-toggle").hasClass('elementor-active') )
		{
			$( ".elementor-location-header .menu_header .elementor-menu-toggle").removeClass('elementor-active');
			// $( ".elementor-location-header .menu_header .elementor-nav-menu--dropdown").css('display' , 'none');
			delay_show=300;
		}

		if ( $( ".elementor-location-header .container_account_popup").hasClass('active') )
		{
			$( ".elementor-location-header .container_account_popup" ).removeClass('active');
			setTimeout(function() {
			$( ".elementor-location-header .icone_account i").removeClass('fa-times').addClass('fa-user');
			$( ".elementor-location-header .icone_account").removeClass("active");
			}, 400); 
		}
		else 
		{
			setTimeout(function() {
			$( ".elementor-location-header .container_account_popup").addClass("active");
			$( ".elementor-location-header .icone_account i").removeClass('fa-user').addClass('fa-times');
			$( ".elementor-location-header .icone_account").addClass("active");
			}, delay_show); 
			
			
			return false;
		}
	});

	//Faire apparaître les infos du compte au survol de l'icone mon compte header
	$( ".elementor-location-header .icone_account, .elementor-location-header .container_account_popup" ).hover(function() {
		$( ".elementor-location-header .container_account_popup" ).addClass("active");
	}, function(){
		$( ".elementor-location-header .container_account_popup" ).removeClass("active");
    });
	
	//Fermer la popup d'ajout au panier onclick sur bouton poursuivre mes achats
	$(document).on("click", "a.continuer_achats" , function() {
		$.magnificPopup.close();
		$( "#MSW_popup_add_to_cart").css('display' , 'none');
	});
	
	//Supprimer le title du bouton close de la popup quick view
	$( document.body ).on( 'woosq_loaded', function(){
		$( "button.mfp-close" ).attr('title' , '');
	});
	
	//Ajuster le height des images product en fonction du width du grid
	if ( $( ".woocommerce ul.products li" ).length )
	{
		var width_li_grid = $( ".woocommerce ul.products li" ).innerWidth();
		if (width_li_grid > 0) $( ".woocommerce ul.products li .container_image" ).css('height', width_li_grid);

		$( window ).resize(function() {
			var width_li_grid = $( ".woocommerce ul.products li" ).innerWidth();
			if (width_li_grid > 0) $( ".woocommerce ul.products li .container_image" ).css('height', width_li_grid);
		});
	}

	//Smooth scroll anchor link
	jQuery(".smooth_scroll").click(function(){

		var height_minus = 15;
		
		if ( $( "body header" ).hasClass('elementor-sticky') ) height_minus = height_minus + $( "body header" ).outerHeight();
		if ( $( "div.elementor-location-header section.elementor-sticky" ).length > 0 ) height_minus = height_minus + $( "div.elementor-location-header section.elementor-sticky" ).outerHeight();

		var section = jQuery(this).attr('href');
		jQuery('html, body').animate({
			scrollTop: jQuery(section).offset().top - height_minus
		});  
	});
	
	//History back button
	$('#history_back').on('click', function(e){
		e.preventDefault();
		window.history.go(-1);
	});
	
	//Scroll to top button
	$(window).scroll(function(){
        if ($(this).scrollTop() > 100) $('#MSW_scroll_to_top').fadeIn();
        else  $('#MSW_scroll_to_top').fadeOut();
    });

    $('#MSW_scroll_to_top').click(function(){
        $('html, body').animate({scrollTop : 0},500);
        return false;
    });

	//Montrer le password au clic sur la classe MSW-show-password
	$(document).on("click", ".MSW_show_password" , function( e ) {
		if ( $( this ).parent().find('input').attr('type') == 'password' ) $( this ).parent().find('input').attr('type' , 'text');
		else $( this ).parent().find('input').attr('type' , 'password');
	});
	
	//Permettre a l'utilisateur de visualiser les champs mot de passe on login / register
		//Popup login register
		if ( $( ".xoo-el-container").length || $( ".xoo-el-form-inline").length ) $( "form .xoo-aff-group .xoo-aff-password").closest('.xoo-aff-input-group').append('<span class="MSW_show_password"></span>');
		//My account
		if ( $( ".woocommerce-Input--password").length ) $( ".woocommerce-Input--password").closest('.woocommerce-form-row').append('<span class="MSW_show_password"></span>');
		//Page checkout création compte
		if ( $( "body.woocommerce-checkout #account_password_field").length )
		{
			var checkInputPasswordIsLoad = setInterval(function() {
				if ($('.password-input .show-password-input').length ) 
				{
					clearInterval(checkInputPasswordIsLoad);

					$( "#account_password_field .password-input .show-password-input").remove();
					var input_password = $( "#account_password_field .password-input").html();
					$( "#account_password_field .password-input").remove();
					$( "#account_password_field").append(input_password+'<span class="MSW_show_password"></span>');
			   }
		
			}, 200); // check every 200ms
		}

	//Supprimer les show password input par défaut de Woocommerce
	if ( $( "body").hasClass('woocommerce-account') )
	{
		var checkDisplayPasswordInputIsLoad = setInterval(function() {
			if ($('.password-input .show-password-input').length ) 
			{
				clearInterval(checkDisplayPasswordInputIsLoad);
				$( ".show-password-input").remove();	
		   }
	
		}, 200); // check every 200ms
	}

	//Nettoyer les champs invalides à la fermeture de la popup login / register
	$(document).on("xoo_el_popup_closed", function() {
		$( ".xoo-error-notice").remove();
		$( "div.xoo-aff-group").removeClass('invalide');
	});
	
	//Pour la nouvelle version de Easy login
	$('body').on("xoo_el_popup_toggled", function( e , type ) {
		if (type == 'hide' || type == 'show')
		{
			$( ".xoo-error-notice").remove();
			$( "div.xoo-aff-group").removeClass('invalide');
		}
	});
	
	//Vérifier les champs des adresses de facturation et livraison on edit adress
	$(document).on('click', 'form .woocommerce-address-fields button[name="save_address"]' , function( e ) {

		if ( $('#billing_first_name_field').length ) var type_adress = 'billing';
		else if ( $('#shipping_first_name_field').length ) var type_adress = 'shipping';
		if (type_adress) var result = $.CheckAdressForm ( type_adress , 'edit-adress' );
		
		if ( result == 'true' ) return true;
		else
		{
			e.preventDefault();
			return false;
		}
	});
	
	//Vérifier les champs des adresses de facturation et livraison on edit adress (on blur Event)
	$(document).on('keyup change', 'form .woocommerce-address-fields p.validate-required input, form .woocommerce-address-fields p.validate-required select' , function() {
		if ( $(this).val() == '' || ( $(this).prop('nodeName') == 'SELECT' && $(this).val() == 'default' ) )
		{
			var label = '<strong>'+ $(this).closest('p').find('label').html().replace(/&nbsp;/g, '').replace('<abbr class="required" title="obligatoire">*</abbr>', '').replace('<span class="optional">(facultatif)</span>', '') + '</strong>';
			$(this).closest('p').addClass('woocommerce-invalid woocommerce-invalid-required-field').removeClass('woocommerce-validated');
		}
		else $(this).closest('p').removeClass('woocommerce-invalid woocommerce-invalid-required-field').addClass('woocommerce-validated');
	});
	
	//Fonction qui vérifie les éléments du formulaire d'adresse (fonctionne pour edit-adress et pour checkout)
	$.CheckAdressForm = function( type_adress , page ) {

		var txt_error = '';

		if ( type_adress == 'billing' && page == 'checkout') var container = '.wpmc-step-billing ';
		else if ( type_adress == 'shipping' && page == 'checkout') var container = '.wpmc-step-shipping ';
		else var container = '';
		
		
		$( container+"p.form-row" ).each(function() {

			if ( $(this).find('input').length ) var elem_id = '#' + $(this).find('input').attr('id');
			else if ( $(this).find('select').length ) var elem_id = '#' + $(this).find('select').attr('id');

			//Vérification des input vide
			if ( $(this).hasClass('validate-required') && elem_id != '#account_password' && $(this).find(elem_id).val() == '' )
			{
				var label = '<strong>'+ $(this).find('label').html().replace(/&nbsp;/g, '').replace('<abbr class="required" title="obligatoire">*</abbr>', '').replace('<span class="optional">(facultatif)</span>', '') + '</strong>';
				txt_error+='Le champ '+label+' est obligatoire.<br />';
				$(this).addClass('woocommerce-invalid woocommerce-invalid-required-field').removeClass('woocommerce-validated');
			}
			//Vérification des select vide
			else if ( $(this).hasClass('validate-required') && $(this).find('select').length && $(this).find(elem_id).val() == 'default' )
			{
				var label = '<strong>'+ $(this).find('label').html().replace(/&nbsp;/g, '').replace('<abbr class="required" title="obligatoire">*</abbr>', '').replace('<span class="optional">(facultatif)</span>', '') + '</strong>';
				txt_error+='Le champ '+label+' est obligatoire.<br />';
				$(this).addClass('woocommerce-invalid woocommerce-invalid-required-field').removeClass('woocommerce-validated');
			}
			//Vérification des input non vide mais a analyser plus en profondeur
			else if ( $(this).hasClass('validate-required') && elem_id != '#account_password' && $(this).find(elem_id).val() != '' )
			{
				// if ( elem_id == '#billing_postcode' || elem_id == '#shipping_postcode' )
				// {
					// var codepostal = new RegExp("^(([0-8][0-9])|(9[0-5])|(2[ab]))[0-9]{3}$");
					// if ( ! codepostal.test( $(this).find(elem_id).val() ) )
					// {
						// var label = '<strong>'+ $(this).find('label').html().replace(/&nbsp;/g, '').replace('<abbr class="required" title="obligatoire">*</abbr>', '').replace('<span class="optional">(facultatif)</span>', '') + '</strong>';
						// txt_error+='Le champ '+label+' est incorrect.<br />';
						// $(this).addClass('woocommerce-invalid woocommerce-invalid-required-field').removeClass('woocommerce-validated');
					// }
				// }
				if ( elem_id == '#billing_email' )
				{
					var email = new RegExp(/^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[0-9a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i);
					if ( ! email.test( $(this).find(elem_id).val() ) )
					{
						var label = '<strong>'+ $(this).find('label').html().replace(/&nbsp;/g, '').replace('<abbr class="required" title="obligatoire">*</abbr>', '').replace('<span class="optional">(facultatif)</span>', '') + '</strong>';
						txt_error+='Le champ '+label+' est incorrect.<br />';
						$(this).addClass('woocommerce-invalid woocommerce-invalid-required-field').removeClass('woocommerce-validated');
					}
				}
				else if ( elem_id == '#billing_phone' )
				{
					var telephone = new RegExp(/^((\+)33|0)[0-9]([-/. ]?[0-9]{2}){4}$/g);
					if ( ! telephone.test( $(this).find(elem_id).val() ) )
					{
						var label = '<strong>'+ $(this).find('label').html().replace(/&nbsp;/g, '').replace('<abbr class="required" title="obligatoire">*</abbr>', '').replace('<span class="optional">(facultatif)</span>', '') + '</strong>';
						txt_error+='Le champ '+label+' est incorrect.<br />';
						$(this).addClass('woocommerce-invalid woocommerce-invalid-required-field').removeClass('woocommerce-validated');
					}
				}
			}
			//Vérification du mot de passe create account on checkout
			else if ( $(this).hasClass('validate-required') && elem_id == '#account_password' &&  ( $( "#createaccount" ).is(':checked') || ! $( "#createaccount" ).length ) )
			{
				if ( $(this).find(elem_id).val() == '' )
				{
					txt_error+='Le champ <strong>mot de passe</strong> est obligatoire.<br />';
					$(this).addClass('woocommerce-invalid woocommerce-invalid-required-field').removeClass('woocommerce-validated');
				}
				else if ( $(this).find(elem_id).val().length < 8 )
				{
					txt_error+='Votre <strong>mot de passe</strong> doit contenir au minimum 8 caractères.<br />';
					$(this).addClass('woocommerce-invalid woocommerce-invalid-required-field').removeClass('woocommerce-validated');
				}
			}

		});
		
		

		if (txt_error != '')
		{
			$( ".woocommerce-notices-wrapper" ).prepend( '<ul class="woocommerce-error" role="alert"><li>'+txt_error+'</li></ul>');
			var resultat = 'false';
		}
		else var resultat = 'true';
		
		return resultat;

	}
	

	//Vérifier les champs de la popup login / register avant la soumission du formulaire de connexion
	$(document).on("click", ".xoo-el-action-btn.xoo-el-login-btn" , function( e ) {

		$( ".xoo-el-form-login .xoo-error-notice-login").remove();
		$( ".xoo-el-form-login div.xoo-aff-group").removeClass('invalide');
		
		//On défini si le form est inline ou en popup pour afficher sur les bons champs et trigger MSW_add_custom_validation plus bas
		if ( $(this).closest('.xoo-el-form-container').hasClass('xoo-el-form-inline') ) var target = '.xoo-el-form-inline ';
		else var target = '.xoo-el-inmodal ';

		if ( $( target+"form.xoo-el-action-form input[name='xoo-el-username']" ).val() == '' )
		{
			$( target+"form.xoo-el-action-form .xoo-aff-group.xoo-el-username_cont" ).addClass('invalide').append('<div class="xoo-error-notice-login">L\'E-mail est obligatoire.</div>');
		}
		else $( target+"form.xoo-el-action-form .xoo-aff-group.xoo-el-username_cont" ).removeClass('invalide');
		
		if ( $( target+"form.xoo-el-action-form input[name='xoo-el-username']" ).val() != '' )
		{
			var email = new RegExp(/^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[0-9a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i);
			
			if ( ! email.test( $( target+"form.xoo-el-action-form input[name='xoo-el-username']" ).val() ) )
			{
				$( target+"form.xoo-el-action-form .xoo-aff-group.xoo-el-username_cont" ).addClass('invalide').append('<div class="xoo-error-notice-login">L\'E-mail est invalide.</div>');
			}
			else $( target+"form.xoo-el-action-form .xoo-aff-group.xoo-el-username_cont" ).removeClass('invalide');
		}

		if ( $( target+"form.xoo-el-action-form input[name='xoo-el-password']" ).val() == '' )
		{
			$( target+"form.xoo-el-action-form .xoo-aff-group.xoo-el-password_cont" ).addClass('invalide').append('<div class="xoo-error-notice-login">Le mot de passe est obligatoire.</div>');
		}
		else $( target+"form.xoo-el-action-form .xoo-aff-group.xoo-el-password_cont" ).removeClass('invalide');
		
		if ( $( ".xoo-el-form-login .xoo-error-notice-login" ).length > 0 )
		{
			e.preventDefault();
			e.stopPropagation();
		}
	});

	//Vérifier les champs de la popup login / register avant la soumission du formulaire d'inscription
	$(document).on("click", ".xoo-el-action-btn.xoo-el-register-btn" , function( e ) {

		$( ".xoo-el-form-register .xoo-error-notice").remove();
		$( ".xoo-el-form-register div.xoo-aff-group").removeClass('invalide');
		
		//On défini si le form est inline ou en popup pour afficher sur les bons champs et trigger MSW_add_custom_validation plus bas
		if ( $(this).closest('.xoo-el-form-container').hasClass('xoo-el-form-inline') ) var target = '.xoo-el-form-inline ';
		else var target = '.xoo-el-inmodal ';

		if ( $( target+"form.xoo-el-action-form input[name='xoo_el_reg_email']" ).val() == '' )
		{
			$( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_email_cont" ).addClass('invalide').append('<div class="xoo-error-notice">L\'E-mail est obligatoire.</div>');
		}
		else $( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_email_cont" ).removeClass('invalide');

		if ( $( target+"form.xoo-el-action-form input[name='xoo_el_reg_email']" ).val() != '' )
		{
			var email = new RegExp(/^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[0-9a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i);
			
			if ( ! email.test( $( target+"form.xoo-el-action-form input[name='xoo_el_reg_email']" ).val() ) )
			{
				$( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_email_cont" ).addClass('invalide').append('<div class="xoo-error-notice">L\'E-mail est invalide.</div>');
			}
			else $( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_email_cont" ).removeClass('invalide');
		}
		
		if ( $( target+"form.xoo-el-action-form input[name='xoo_el_reg_fname']" ).val() == '' )
		{
			$( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_fname_cont" ).addClass('invalide').append('<div class="xoo-error-notice">Le prénom est obligatoire.</div>');
		}
		else $( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_fname_cont" ).removeClass('invalide');
		
		if ( $( target+"form.xoo-el-action-form input[name='xoo_el_reg_lname']" ).val() == '' )
		{
			$( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_lname_cont" ).addClass('invalide').append('<div class="xoo-error-notice">Le nom est obligatoire.</div>');
		}
		else $( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_lname_cont" ).removeClass('invalide');
		
		if ( $( target+"form.xoo-el-action-form input[name='xoo_el_reg_pass']" ).val() == '' )
		{
			$( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_pass_cont" ).addClass('invalide').append('<div class="xoo-error-notice">Le mot de passe est obligatoire.</div>');
		}
		else $( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_pass_cont" ).removeClass('invalide');
		
		if ( $( target+"form.xoo-el-action-form input[name='xoo_el_reg_pass_again']" ).length )
		{
			if ( $(this).closest( "form.xoo-el-action-form").find( "input[name='xoo_el_reg_pass_again']" ).val() == '' )
			{
				$( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_pass_again_cont" ).addClass('invalide').append('<div class="xoo-error-notice">La confirmation du mot de passe est obligatoire.</div>');
			}
			else $( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_pass_again_cont" ).removeClass('invalide');
		}

		if ( ! $( target+"form.xoo-el-action-form .xoo_el_reg_pass_cont .xoo-error-notice" ).length )
		{
			if ( $( target+"form.xoo-el-action-form input[name='xoo_el_reg_pass']" ).val().length < 8 )
			{
				$( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_pass_cont" ).addClass('invalide').append('<div class="xoo-error-notice">Le mot de passe doit contenir au moins 8 caractères.</div>');
			}
			else $( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_pass_cont" ).removeClass('invalide');
		}
		
		if ( $( target+"form.xoo-el-action-form input[name='xoo_el_reg_pass_again']" ).length )
		{
			if ( ! $( target+"form.xoo-el-action-form .xoo_el_reg_pass_again_cont .xoo-error-notice" ).length )
			{
				if ( $( target+"form.xoo-el-action-form input[name='xoo_el_reg_pass_again']" ).val().length < 8 )
				{
					$( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_pass_again_cont" ).addClass('invalide').append('<div class="xoo-error-notice">Le mot de passe doit contenir au moins 8 caractères.</div>');
				}
				else $( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_pass_again_cont" ).removeClass('invalide');
			}
		}
		
		if ( $( target+"form.xoo-el-action-form input[name='xoo_el_reg_pass_again']" ).length )
		{
			if ( ! $( target+"form.xoo-el-action-form .xoo_el_reg_pass_cont .xoo-error-notice" ).length && ! $( target+"form.xoo-el-action-form .xoo_el_reg_pass_again_cont .xoo-error-notice" ).length )
			{
				if ( $( target+"form.xoo-el-action-form input[name='xoo_el_reg_pass']" ).val() != $( target+"form.xoo-el-action-form input[name='xoo_el_reg_pass_again']" ).val() )
				{
					$( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_pass_cont" ).addClass('invalide')
					$( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_pass_again_cont" ).addClass('invalide').append('<div class="xoo-error-notice">Les mots de passe ne correspondent pas.</div>');
				}
				else
				{
					$( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_pass_cont" ).removeClass('invalide');
					$( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_pass_again_cont" ).removeClass('invalide');
				}
			}
		}
		
		if ( ! $( target+"form.xoo-el-action-form input[name='xoo_el_reg_terms']" ).is(':checked') )
		{
			if ( $( "body" ).hasClass('msw_tu') ) $( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_terms_cont" ).addClass('invalide').append('<div class="xoo-error-notice">Tu dois accepter notre politique de confidentialité.</div>');
			else $( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_terms_cont" ).addClass('invalide').append('<div class="xoo-error-notice">Vous devez accepter notre politique de confidentialité.</div>');
		}
		else $( target+"form.xoo-el-action-form .xoo-aff-group.xoo_el_reg_terms_cont" ).removeClass('invalide');

		//Trigger les champs additionnels
		$( '.xoo-el-form-register' ).trigger( 'MSW_add_custom_validation' , [ target ]  );
		
		if ( $( ".xoo-el-form-register .xoo-error-notice" ).length > 0 )
		{
			e.preventDefault();
			e.stopPropagation();
		}
		else
		{
			//Call en AJAX pour inscrire l'utilisateur a la newsletter si checkbox cochée
			if ( $( ".xoo-el-form-register input[name='xoo_el_reg_newsletter']" ).is(':checked') )
			{
				var fname = $(this).closest( "form.xoo-el-action-form").find( "input[name='xoo_el_reg_fname']" ).val();
				var lname = $(this).closest( "form.xoo-el-action-form").find( "input[name='xoo_el_reg_lname']" ).val();
				var email = $(this).closest( "form.xoo-el-action-form").find( "input[name='xoo_el_reg_email']" ).val();

				$.ajax({
						type:     'POST',
						dataType: 'json',
						url:      MSW_nonce_URL.url,
						data: {
							action: "MSW_ajax_subscribe_user_to_mailchimp_on_register",
							security : MSW_nonce_URL.nonce,
							fname : fname,
							lname : lname,
							email : email
						}
				});
			}
		}
	});
	
	//Vérifier les champs de la popup login / register avant la soumission du formulaire de login
	$(document).on("click", ".xoo-el-action-btn.xoo-el-login-btn" , function( e ) {

		$( ".xoo-el-form-login .xoo-error-notice").remove();
		
		if ( $(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-login input[name='xoo-el-username']" ).val() == '' )
		{
			$(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-login input[name='xoo-el-username']" ).closest('div.xoo-aff-group').addClass('invalide');
			$(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-login input[name='xoo-el-username']" ).closest('div.xoo-aff-group').append('<div class="xoo-error-notice">Le champ E-mail est obligatoire.</div>');
		}
		else $(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-login input[name='xoo-el-username']" ).closest('div.xoo-aff-group').removeClass('invalide');
		
		if ( $(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-login input[name='xoo-el-username']" ).val() != '' )
		{
			var email = new RegExp(/^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[0-9a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i);
			
			if ( ! email.test( $(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-login input[name='xoo-el-username']" ).val() ) ) 
			{
				$(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-login input[name='xoo-el-username']" ).closest('div.xoo-aff-group').addClass('invalide');
				$(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-login input[name='xoo-el-username']" ).closest('div.xoo-aff-group').append('<div class="xoo-error-notice">Le champ E-mail est invalide.</div>');
			}
			else $(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-login input[name='xoo-el-username']" ).closest('div.xoo-aff-group').removeClass('invalide');
		}

		if ( $(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-login input[name='xoo-el-password']" ).val() == '' )
		{
			$(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-login input[name='xoo-el-password']" ).closest('div.xoo-aff-group').addClass('invalide');
			$(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-login input[name='xoo-el-password']" ).closest('div.xoo-aff-group').append('<div class="xoo-error-notice">Le mot de passe est obligatoire.</div>');
		}
		else $(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-login input[name='xoo-el-password']" ).closest('div.xoo-aff-group').removeClass('invalide');

		if ( $( ".xoo-el-form-login .xoo-error-notice" ).length > 0 )
		{
			e.preventDefault();
			e.stopPropagation();
		}
	});
	
	//Vérifier les champs de la popup login / register avant la soumission du formulaire de mot de passe oublié
	$(document).on("click", ".xoo-el-action-btn.xoo-el-lostpw-btn" , function( e ) {

		$( ".xoo-el-form-lostpw .xoo-error-notice").remove();
		
		if ( $(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-lostpw input[name='user_login']" ).val() == '' )
		{
			$(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-lostpw input[name='user_login']" ).closest('div.xoo-aff-group').addClass('invalide');
			$(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-lostpw input[name='user_login']" ).closest('div.xoo-aff-group').append('<div class="xoo-error-notice">Le champ E-mail est obligatoire.</div>');
		}
		else $(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-lostpw input[name='user_login']" ).closest('div.xoo-aff-group').removeClass('invalide');
		
		if ( $(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-lostpw input[name='user_login']" ).val() != '' )
		{
			var email = new RegExp(/^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[0-9a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i);
			
			if ( ! email.test( $(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-lostpw input[name='user_login']" ).val() ) ) 
			{
				$(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-lostpw input[name='user_login']" ).closest('div.xoo-aff-group').addClass('invalide');
				$(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-lostpw input[name='user_login']" ).closest('div.xoo-aff-group').append('<div class="xoo-error-notice">Le champ E-mail est invalide.</div>');
			}
			else $(this).closest( "form.xoo-el-action-form").find( ".xoo-el-form-lostpw input[name='user_login']" ).closest('div.xoo-aff-group').removeClass('invalide');
		}

		if ( $( ".xoo-el-form-lostpw .xoo-error-notice" ).length > 0 )
		{
			e.preventDefault();
			e.stopPropagation();
		}
	});
});