


$(document).ready(function(){



	function megaHoverOver(){
	    $(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
	    (function($) {
	        //Function to calculate total width of all ul's
	        jQuery.fn.calcSubWidth = function() {
	            rowWidth = 0;
	            //Calculate row
	            $(this).find("ul").each(function() { //for each ul...
	                rowWidth += $(this).width(); //Add each ul's width together
	            });
	        };
	    })(jQuery); 
	
	    if ( $(this).find(".row").length > 0 ) { //If row exists...
	
	        var biggestRow = 0;	
	
	        $(this).find(".row").each(function() {	//for each row...
	            $(this).calcSubWidth(); //Call function to calculate width of all ul's
	            //Find biggest row
	            if(rowWidth > biggestRow) {
	                biggestRow = rowWidth;
	            }
	        });
	
	        $(this).find(".sub").css({'width' :biggestRow}); //Set width
	        $(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin
	
	    } else { //If row does not exist...
	
	        $(this).calcSubWidth();  //Call function to calculate width of all ul's
	        $(this).find(".sub").css({'width' : rowWidth}); //Set Width
	
	    }
	}
	//On Hover Out
	function megaHoverOut(){
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
	      $(this).hide();  //after fading, hide it
	  });
	}
	
	
	var config = {
	     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
	     interval: 100, // number = milliseconds for onMouseOver polling interval
	     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
	     timeout: 500, // number = milliseconds delay before onMouseOut
	     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
	};
	
	if ($("ul#menuTopbloc").size()>0)
	{
		$("ul#menuTopbloc li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
		$("ul#menuTopbloc li").hoverIntent(config); //Trigger Hover intent with custom configurations
	}
});

function Verifmail(elm)
		{
			if (
				elm != '' &&
				elm.length >= 5 &&
				elm.indexOf("@") != "-1" && 
				elm.indexOf("@") != "0" &&   
				elm.indexOf("@") != elm.length - 1 &&
				elm.indexOf("@",elm.indexOf("@")+1)==-1 &&
				elm.indexOf(".") != "-1" &&
				elm.indexOf(".") != "0" && 
				elm.indexOf(".") != elm.length - 1 &&
				elm.indexOf("@")!=elm.indexOf(".") + 1 && 
				elm.indexOf("@")!=elm.indexOf(".") - 1){
				return true;
				}
			else{
				return false;
			}
		}
	function fnVerif(){
		
		if (document.contact.nom.value==""){
			alert("Renseignez votre Nom");
			return  false;
			}
		if (document.contact.message.value==""){
			alert("N'oubliez pas votre message");
			return  false;
		     }
		var email=document.contact.email.value;
		if (""==email){
			alert("Renseignez votre Email");
			return false;
		}else if (    ( -1== email.indexOf( '@' ,0)  )  ||  ( -1==email.indexOf('.',0 )  )    ) {
			// l'adresse entrée est incorrecte
			alert("adresse Email incorrecte");
			return false;
		}
	}
	
	function verifFormConx(mail,mdp){
		if(mail==""){
			alert('Renseigner l\'adresse E-mail');
			return false;
		}
		else if(mdp==""){
			alert('Renseigner le mot de passe');
			return false;
		}
		else if(Verifmail(mail)==false){
			alert('E-mail incorrect !');
			return false;
		}
		else{
			return true;	
		}
	}
function verifInfosPers(){
	if (document.inscription.nom.value==""){
		alert("Renseignez votre nom !");
		document.inscription.nom.focus();
		return  false;
		}
	if (document.inscription.prenom.value==""){
		alert("Renseignez votre prénom !");
		document.inscription.prenom.focus();
		return  false;
		}
	if (document.inscription.adresse.value==""){
		alert("Renseignez votre adresse !");
		document.inscription.adresse.focus();
		return  false;
		}
	if (document.inscription.cp.value==""){
		alert("Renseignez votre code postal !");
		document.inscription.cp.focus();
		return  false;
		}
	if (document.inscription.ville.value==""){
		alert("Renseignez votre ville !");
		document.inscription.ville.focus();
		return  false;
		}
	if (document.inscription.pays.value==""){
		alert("Renseignez votre pays !");
		document.inscription.pays.focus();
		return  false;
		}
	if (document.inscription.telephone.value=="" && document.inscription.portable.value==""){
		alert("Renseignez au moins un numéro de téléphone !");
		document.inscription.telephone.focus();
		return  false;
		}
	var email = document.inscription.mail_compte.value;
	if (email==""){
		alert("Renseignez votre E-mail !");
		document.inscription.mail_compte.focus();
		return  false;
	}
	else if(Verifmail(email)==false){
		alert("E-mail incorrect !");
		document.inscription.mail_compte.focus();
		return  false;
	}
}

function verifChangeMdp(mdp,new_mdp,conf_mdp){
		if(mdp==""){
			alert("Renseigner le mot de passe actuel!");
			return false;
		}
		if(new_mdp==""){
			alert("Renseigner le nouveau mot de passe !");
			return false;
		}
		if(new_mdp.length<6){
			alert("Le nouveau mot de passe doit être de 6 caractères minimum !");
			return false;
		}
		else if(new_mdp!=conf_mdp){
			alert("Confirmation du mot de passe erronée !");
			return false;
		}
}

function affiche_livraison(){

	if (document.getElementById){
		if(document.getElementById("check_livraison").checked == true){
			document.getElementById("ad_livraison").style.display = 'block'; 
			document.getElementById("span_liv").style.display = 'none'; 
		}else {
			document.getElementById("ad_livraison").style.display = 'none';
			document.getElementById("span_liv").style.display = 'inline'; 
		}
	}else if(document.all){
		if(document.all["check_livraison"].checked == true) {
			document.all["ad_livraison"].style.display = 'block'; 
			document.all["span_liv"].style.display = 'none'; 
		}else {
			document.all["ad_livraison"].style.display = 'none';
			document.all["span_liv"].style.display = 'inline';
		}
	}else if(document.layers){
		if(document.layers["check_livraison"].checked == true) {
			document.layers["ad_livraison"].display = 'block'; 
			document.layers["span_liv"].display = 'none'; 
		}else {
			document.layers["ad_livraison"].display = 'none';
			document.layers["span_liv"].display = 'inline'; 
		}
	}
}

