function number_format(number, decimals, dec_point, thousands_sep) {
    var n = !isFinite(+number) ? 0 : +number, 
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }    return s.join(dec);
}


function showLayer(nom_layer){
   document.getElementById(nom_layer).style.display = 'block';
}
function hideLayer(nom_layer){
   document.getElementById(nom_layer).style.display = 'none';
}
function repartir(nom_layer){
	
	if(document.getElementById(nom_layer).style.display == 'block'){
		 document.getElementById(nom_layer).style.display = 'none';
	}
	else if(document.getElementById(nom_layer).style.display == "none"){
		document.getElementById(nom_layer).style.display = 'block';
	}
}

function impFichedetailProduit(){
	window.print();
}



//SERT A VALIDER LA LECTURE DES CGV AVANT DE VALIDER LE PANIER}
function validerCGV(){
	if(document.forms["form_cgv"].elements['cgv'].checked==false)  {
		jAlert("Vous devez validez les CGV!","");
		return false;
	}
	return true;

}




//fonction écouteur sur bouton radio, change le BG du module de choix paiement
function affFond(id) {
    var lth = document.forms["choix_paiement"].moyen.length;
    var isVal = false; 
    for(i=0;i<lth;i++){
        if(document.forms["choix_paiement"].moyen[i].checked==true){
            isVal=true;
			document.getElementById(i).className="choix-paiement-fleche-actif";
        }
		if(document.forms["choix_paiement"].moyen[i].checked==false){
			document.getElementById(i).className="choix-paiement-fleche-inactif";
        }
    }
}



//fonction écouteur sur bouton radio, rafraichi les frais de port dans le module total panier
function refreshFDP(fdp) {
    var lth = document.forms["zone_livraison"].choix_zone_de_livraison.length;
    for(i=0;i<lth;i++){
        if(document.forms["zone_livraison"].choix_zone_de_livraison[i].checked==true){
			document.getElementById("montant-fdp").innerHTML= number_format(fdp,2,".","")+"&nbsp;&euro;";
			var valeur=i;
 			document.cookie = "fdp_ck=" + escape(valeur+1)
			calculMontantTotalPanier(fdp);
		}
    }
}




//fonction écouteur sur bouton radio, rafraichi les frais de port dans le module total panier
function calculMontantTotalPanier(fdp) {
	//alert(fdp);
		if(fdp==undefined){
			//alert("ici");
			var fdp=parseFloat(document.getElementById("fdp_total").value);
			//alert ("fdp=" + fdp);
	
		}
		document.getElementById("montant-fdp").innerHTML= fdp + "&euro;";
		//alert("fdp="+fdp);
		
		//je récupère tout les montants à additionner	
		//var prixttc_total=parseFloat(document.forms["total-panier"].prixttc_total.value);
		var prixttc_total=parseFloat(document.getElementById("prixttc_total").value);
		fdp=parseFloat(fdp);
		//alert("prixttc_total="+prixttc_total+" - fdp="+fdp);
		//je met à jour le montant total du panier
		var montantTotal=Math.round((prixttc_total + fdp)*100)/100;
		//alert(montantTotal);
		document.getElementById("montant-total").innerHTML= montantTotal + "&euro;";

}


function verifSubscribeNl(){
	var email=document.getElementById("email").value;
	var tabA=email.split("@");
		if(tabA.length!=2){
			alert("Votre email est mal renseigné.");
			return false;
		}
	var tabP=tabA[1].split(".");
		if(tabP.length<2){
			alert("Votre email est mal renseigné.");
			return false;
		}
	return true;			
}


