// PNG transparent sous internet Explorer
function IE_CorrectAlpha_PNG(){ 
for(i=0; i<document.images.length; i++){ 
img    = document.images[i]; 
imgExt  = img.src.substring(img.src.length-3, img.src.length); 
imgExt  = imgExt.toUpperCase(); 
if (imgExt == "PNG"){ 
imgID    = (img.id) ? "id='" + img.id + "' " : ""; 
imgClass= (img.className) ? "class='" + img.className + "' " : ""; 
imgTitle= (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "; 
imgStyle= "display:inline-block;" + img.style.cssText; 
if (img.align == "left") { imgStyle = "float:left;"  + imgStyle; } else if (img.align == "right"){ imgStyle = "float:right;" + imgStyle; } 
if (img.parentElement.href)   { imgStyle = "cursor:hand;" + imgStyle; }        
strNewHTML    = '<span '+imgID+imgClass+imgTitle+' style="width:'+img.width+'px; height:'+img.height+'px;'+imgStyle+';'+'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+img.src+'\', sizingMethod=\'scale\');"></span>'; 
img.outerHTML = strNewHTML; 
i = i-1; 
}}} 
window.attachEvent("onload", IE_CorrectAlpha_PNG)

function afficheMenu(id) {
	document.getElementById(id).style.display='block';
}

function cacheMenu(id) {
	document.getElementById(id).style.display='none';
}

function cacheTout(nbFam) {
	for (i = 1; i<(nbFam+1); i++){
			document.getElementById("fam"+i+"_dep").style.display="none";
	}
}

function PopupImage(img) {
	titre="Agrandissement";
	w=open("popup-agrandissement.php?img="+img,"image","width=400,height=400,toolbar=no,scrollbars=no,resizable=no,status=no,top=0,left=0");
}
function PopupPhotos(id) {
	titre="Photos";
	w=open("popup-photos.php?exp="+id,"image","width=800,height=550,toolbar=no,scrollbars=yes,resizable=yes,status=no,top=0,left=0");
}
function popupFDP(idp){
	titre="FDP";
	w=open("popup-fdp.php?prod="+idp,"image","width=800,height=550,toolbar=no,scrollbars=yes,resizable=yes,status=no,top=0,left=0");
}

function valider(){
	var erreur="";
	var erreur2;
	erreur2=true;
	if(document.getElementById('nom').value.length==0){
		erreur+="Veuillez renseigner votre nom.\n";
		erreur2=false;
	}
	if(document.getElementById('prenom').value.length==0){
		erreur+="Veuillez renseigner votre prénom.\n";
		erreur2=false;
	}
	if(document.getElementById('mail').value.length>55){
		erreur+="Votre E-mail est trop long.\n";
		erreur2=false;	
	}
	if(document.getElementById('mail').value.length==0){
		erreur+="Veuillez renseigner votre E-mail.\n";	
		erreur2=false;
	}
	var res=arobaceok(document.getElementById('mail').value)
	if(res==false){
		erreur+="Votre E-mail n'est pas correct.\n";
		erreur2=false;	
	}	
	if(erreur2==true){
		document.form1.submit();
	} else {
		alert(erreur);
	}
}

function arobaceok(email){
	var a=document.forms[0].email.value;
	var test="" + a;
	for(var k = 0; k < test.length;k++){
		var c = test.substring(k,k+1);
		if(c == "@"){
			return true;
		}
	}
	return false;
} 

function verifParrainage(){
	if(document.getElementById('add1').value==""){
		if(document.getElementById('add2').value==""){
			if(document.getElementById('add3').value==""){
				if(document.getElementById('add4').value==""){
					alert("Veuillez saisir au moins une adresse email");
					return false;
				}else{
					return true;
				}
			}
		}
	}
} 					

//AJOUT DANS LE PANIER
function ajoutProduitPanier(id_produit,from,lib,variable,lib2,variable2,lib3,variable3,lib4,variable4)
{
		if(lib!=''){str = '&lib=' + lib + '&var=' + variable; }else{str = '';}
		if(lib2!=''){str2 = '&lib2=' + lib2 + '&var2=' + variable2; }else{str2 = '';}
		if(lib3!=''){str3 = '&lib3=' + lib3 + '&var3=' + variable3; }else{str3 = '';}
		if(lib4!=''){str4 = '&lib4=' + lib4 + '&var4=' + variable4; }else{str4 = '';}
		document.getElementById('AddToBasket').setAttribute("src", 'ajout-panier.php?id_prod=' + id_produit + '&from=' + from + str + str2 + str3 + str4);
}

function affichePhot(phot,total){
	for(var i = 1; i < (total+1); i++){
		document.getElementById(i).style.display="none";
	}
	document.getElementById(phot).style.display="block";
}

function afficheCom(id){
	if(document.getElementById("com"+id).style.display == "none"){
		document.getElementById("com"+id).style.display="block";
	} else {
		document.getElementById("com"+id).style.display="none";
	}
}
function afficheCommentaire(id){
	if(document.getElementById("commentaire"+id).style.display == "none"){
		document.getElementById("commentaire"+id).style.display="block";
	} else {
		document.getElementById("commentaire"+id).style.display="none";
	}
}
/* page mon-compte/inscription clic sur la case adresse de livraison */
function clicLivraison(elt){
	if(elt.checked){
		document.getElementById('bloc_livraison').className="display";
	}else{
		document.getElementById('bloc_livraison').className="undisplay";
	}
}
/* page mon-panier changement du pays et du mode de livraison */
function changePaysPort(id){
	document.location.href='mon-panier.php?l_pays='+id;	
}
function changeModePort(id){
	document.location.href='mon-panier.php?l_mode='+id;	
}
function sendCodePromo(code){
	document.location.href='mon-panier.php?code_promo='+code;	
}
/* page mon-panier validation du panier */
function validerPanier(){
	elt1 = document.getElementById('cgv');
	if(elt1){ cgv = elt1.checked; }else{ cgv = false; }
	elt2 = document.getElementById('frais');
	if(elt2){ frais = elt2.value; }else{ frais = 0; }
	
	if(frais==0){
		alert('Vous ne pouvez valider cette commande. La livraison n\'étant pas disponible pour ce pays et ce mode de livraison. ');	
	}else if(!cgv){
		alert('Vous n\'avez pas accepté les Conditions générales de vente. ');	
	}else{
		document.location.href='identification.php';	
	}
}
function suppProduitPanier(id){
	if(confirm("Êtes-vous sur de vouloir supprimer ce produit de votre panier ?")){
		document.location.href = 'mon-panier.php?supp_pdt='+id;
	}
}
/* page paiement validation du paiement */
function cochePaiement(id){
	// on gere le coché décoché
	elt1 = document.getElementById('paiement1');
	elt2 = document.getElementById('paiement2');
	elt3 = document.getElementById('paiement3');
	elt4 = document.getElementById('paiement4');
	if(elt1 && id!=1){ elt1.checked=false; }
	if(elt2 && id!=2){ elt2.checked=false; }
	if(elt3 && id!=3){ elt3.checked=false; }
	if(elt4 && id!=4){ elt4.checked=false; }
	
	// on gere l'affichage d'un message
	elt1 = document.getElementById('div_paiement1');
	elt2 = document.getElementById('div_paiement2');
	elt3 = document.getElementById('div_paiement3');
	elt4 = document.getElementById('div_paiement4');
	
	if(elt1){ elt1.className="undisplay"; }
	if(elt2){ elt2.className="undisplay"; }
	if(elt3){ elt3.className="undisplay"; }
	if(elt4){ elt4.className="undisplay"; }
	
	lib = "div_paiement"+id;	
	document.getElementById(lib).className="display";
}
function validerPaiement(){
	elt1 = document.getElementById('paiement1');
	elt2 = document.getElementById('paiement2');
	elt3 = document.getElementById('paiement3');
	elt4 = document.getElementById('paiement4');
	if(elt1){ paiement1 = elt1.checked; }else{ paiement1 = false; }
	if(elt2){ paiement2 = elt2.checked; }else{ paiement2 = false; }
	if(elt3){ paiement3 = elt3.checked; }else{ paiement3 = false; }
	if(elt4){ paiement4 = elt4.checked; }else{ paiement4 = false; }
	
	if(paiement1){
		document.location.href='script-cmd.php?paiement=Carte bancaire';
	}else if(paiement2){
		document.location.href='script-cmd.php?paiement=Chèque';
	}else if(paiement3){
		document.location.href='script-cmd.php?paiement=Chèque 3X';
	}else if(paiement4){
		document.location.href='script-cmd.php?paiement=Virement';
	}else{
		alert('Vous devez choisir un moyen de paiement.');	
	}
}

/* activation / desactivation des bons */
function activerBon(id_bon){
	if(confirm('Etes vous sur de vouloir activer ce bon ?')){
		document.location.href='mon-panier.php?activerBon='+id_bon;	
	}
}
function desactiverBon(id_bon){
	if(confirm('Etes vous sur de vouloir desactiver ce bon ?')){
		document.location.href='mon-panier.php?desactiverBon='+id_bon;	
	}
}