// Top des ventes 
// Change element class with id and classname
function fnchangecss(sId, sCSS)
{
    if(!document.getElementById) return;

    var oElem = document.getElementById(sId);
    if(!oElem) return;
    
    oElem.className = sCSS;
}

var idCurrent = "tdvProductContainer1";
var idCurrentLink = "lnktdv1";
var idCurrentNum = "tdvNum1";

// Top des ventes 
//Display the right DIV on mouse over
function showTdv(tdvId)
{
    if(!document.getElementById) return;
    if(isNaN(tdvId)) return;
    
    var idContainer = "tdvProductContainer"+tdvId;
    var idLink = "lnktdv"+tdvId;
    var idNum = "tdvNum"+tdvId;
    var oContainer = document.getElementById(idContainer);
    var oCurrent = document.getElementById(idCurrent);
    
    if(!oContainer || !oCurrent) return;
    
    fnchangecss(idCurrentLink,"lnktdv");
    fnchangecss(idLink,"lnktdvhov");
    fnchangecss(idCurrentNum,"tdvNum");
    fnchangecss(idNum,"tdvNumhov");
    
    oCurrent.style.display = "none";
    oContainer.style.display = "block";
    
    idCurrent = idContainer;
    idCurrentLink = idLink;
    idCurrentNum = idNum;
    
    
}


// Affiche mode de paiement
function div1(){
	document.getElementById("div1Oui").style.display="block";
	document.getElementById("div1Non").style.display="none";
}
function div2(){
	document.getElementById("div2Oui").style.display="block";
	document.getElementById("div2Non").style.display="none";
}
function div3(){
	document.getElementById("div3Oui").style.display="block";
	document.getElementById("div3Non").style.display="none";
}
function div4(){
	document.getElementById("div4Oui").style.display="block";
	document.getElementById("div4Non").style.display="none";
}
function div5(){
	document.getElementById("div5Oui").style.display="block";
	document.getElementById("div5Non").style.display="none";
}

// Affiche contact
function afficheContact(){
	document.getElementById("tabContact").className="fondContactForm";
	document.getElementById("formContact").style.display="block";

}


// 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);

/*Popup paiement*/
function PopupInfoPaiement() {
	titre="Info_Paiement";
	w=open("popup-info-paiement.php","image","width=500,height=500,toolbar=no,scrollbars=yes,resizable=yes,top=0,left=0");
	w.document.close();
}

/*Popup envoie panier*/
function PopupEnvoiePanier() {
	titre="Envoyer_ce_panier_par_e-mail";
	w=open("popup-envoie-panier.php","Envoie_Panier","width=500,height=500,toolbar=no,scrollbars=yes,resizable=yes,top=0,left=0");
	w.document.close();
}

/*Popup envoie Info Dispo*/
function PopupDemandeInfoDispo(prod) {
	titre="Etre informé dés sa disponibilité";
	w=open("popup-demande-dispo-prod.php?prod="+prod,"dispo_prod","width=500,height=650,toolbar=no,scrollbars=yes,resizable=yes,top=0,left=0");
	w.document.close();
}

/* Popup image centré + lien fermer */
function PopupImage(img) {
	titre="Agrandissement";
	w=open("popup-agrandissement.php?img="+img,"image","width=400,height=400,toolbar=no,scrollbars=no,resizable=no,top=0,left=0");
	w.document.close();
}
/* Contenu description du détail produit */
function contenuDescription(qui, combien) {
	for(i = 1; i<= combien; i++ ){
		if (qui=="cont-"+i){
			document.getElementById("layer"+i).style.display="block";
			document.getElementById("case"+i).className="contenuCellSelection";
		}else{
			document.getElementById("layer"+i).style.display="none";
			document.getElementById("case"+i).className="contenuCellAutres";
		}
	}
}
/* Affichage des divs des popups */
function afficheDiv(qui){
	for(i = 1; i<= 5; i++ ){
		document.getElementById(i).style.display="none";
	}
	document.getElementById(qui).style.display="block";
}
/* Popup comparateur */
function popupComparer(){
	titre="Comparateur";
	prod1 = document.getElementById('prod1').value;
	prod2 = document.getElementById('prod2').value;
	prod3 = document.getElementById('prod3').value;
	prod4 = document.getElementById('prod4').value;
	typeComp = document.getElementById('typeComp').value;
	idType = document.getElementById('idType').value;
	w=open("popup-comparateur.php?prod1="+prod1+"&prod2="+prod2+"&prod3="+prod3+"&prod4="+prod4+"&typeComp="+typeComp+"&idType="+idType,"comparateur","width=400,height=400,toolbar=no,scrollbars=yes,resizable=yes,top=0,left=0");
	w.document.close();
}
/* Popup impression produit */
function popupPdtImprimer(prod){
	titre="Impression";
	w=open("popup-imprimer-produit.php?prod="+prod,"impression","width=400,height=400,toolbar=no,scrollbars=yes,resizable=no,top=0,left=0");
	w.document.close();
}

/* Popup envoie produit mail*/
function popupPdtEnvoieMail(prod){
	titre="Envoie_Mail";
	w=open("popup-envoie-produit-mail.php?prod="+prod,"Envoie_produit_mail","width=400,height=400,toolbar=no,scrollbars=yes,resizable=no,top=0,left=0");
	w.document.close();
}


/* Popup de calcul des frais de port */
function popupCalculFraisPort(prod){
	w=open("popup-frais-port.php?prod="+prod,"calcul_frais_de_port","width=400,height=400,toolbar=no,scrollbars=yes,resizable=no,top=0,left=0");
	w.document.close();
}
/*Popup "ce que vous pouvez voir avec" */
function popupCQVPVA(prod){
	titre="Avec";
	w=open("popup-CQVPVA.php?prod="+prod,"avec","width=600,height=400,toolbar=no,scrollbars=yes,resizable=no,top=0,left=0");
	w.document.close();
}
//fonction aller à la page x
function allerA(page){
	if(page!=""){
		document.location = page;
	}
}
//fonction aller à la page x
function parentAllerA(page){
	if(page!=""){
		window.opener.document.location = page;
		window.close();
	}
}
/*Popup "plus de photos" */
function popupPlusDePhotos(prod){
	titre="Avec";
	w=open("popup-photos.php?prod="+prod,"avec","width=600,height=400,toolbar=no,scrollbars=yes,resizable=no,top=0,left=0");
	w.document.close();
}
/* contact */
function valider()
{
	//variable contenant le message d'erreur
	var erreur="";
	
	//variable permettant de savoir si il on a rencontré une erreur
	var erreur2;
	
	erreur2=true;
	
	//test du nom
	if(document.getElementById('leNom').value.length==0)
	{
		erreur+="Veuillez renseigner votre nom.\n";
		erreur2=false;	
	}
	
	//test du prenom
	if(document.getElementById('lePrenom').value.length==0)
	{
		erreur+="Veuillez renseigner votre prénom.\n";
		erreur2=false;	
	}
	//test du mail
	if(document.getElementById('lAdresseDeMessagerie').value.length>55)
	{
		erreur+="Votre E-mail est trop long.\n";
		erreur2=false;	
	}
	if(document.getElementById('lAdresseDeMessagerie').value.length==0)
	{
		erreur+="Veuillez renseigner votre E-mail.\n";	
		erreur2=false;
	}
	var res=arobaceok(document.getElementById('lAdresseDeMessagerie').value)
	if(res==false)
	{
		erreur+="Votre E-mail n'est pas correct.\n";
		erreur2=false;
	}	
	
	//si aucune erreur on submit le formulaire
	if(erreur2==true)
	{
		document.formulaire.submit();
	}
	else
	{
		//sinon affichage des erreurs
		alert(erreur);
		return false;
	}
}
//test si le champ mail contient un @
function arobaceok(email)
{
	var a=document.formulaire.lAdresseDeMessagerie.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;
} 
//coher un produit a comparer
function checkComparer(elt){
	nb = parseInt(document.getElementById('nbCheck').value);
	prod = "prod" + (nb+1);
	
	if(elt.checked){
		if(nb<4){
			elt.checked=true;
			document.getElementById('nbCheck').value = nb+1;
			document.getElementById(prod).value = elt.value;
		}else{
			alert("Vous avez déjà selectionné 4 articles");
			elt.checked=false;
		}
	}else{
		document.getElementById('nbCheck').value = nb-1;
		for(i=1;i<=4;i++){
			prod = "prod" + i;
			if(document.getElementById(prod).value == elt.value){
				document.getElementById(prod).value = "";
			}
		}
		for(i=1;i<4;i++){
			prod = "prod" + i;
			if(document.getElementById(prod).value == ""){
				for(j=i;j<4;j++){
					prod1 = "prod" + j;
					prod2 = "prod" + (j+1);
					document.getElementById(prod1).value = document.getElementById(prod2).value;
				}
				document.getElementById('prod4').value = '';
			}
		}
		elt.checked=false;
	}
}
// decompte du temps
// id : id de la balise dans laquelle le temps restant sera affiché
// d : nombre de jour
// h : nombre d'heure
// m : nombre de minutes
// s : nombre de seconde
function decompte(id,d,h,m,s){
	t = 1000;
	
	if(h==0 && m==0 && s==0 && d==0){location.reload();}
	
	//construction du texte
	txt = "";
	if(d==1){ txt += "1 jour ";}
	if(d>1){ txt += d+" jours ";}
	if(d<1){
		if(h==1){ txt += "1 heure ";}
		if(h>1){ txt += h+" heures ";}
		if(m==1){ txt += "1 minute ";}
		if(m>1){ txt += m+" minute ";}
		if(h<1){
			if(s==1 || s==0){ txt += s+" seconde ";}
			if(s>1){ txt += s+" secondes ";}
		}
		
	}
	
	//affichage
	document.getElementById(id).innerHTML = txt;
	
	//decompte
	s--;
	if(s==-1 && m>0){s=59;m--;}
	if(m==-1 && h>0){m=59;h--;}
	if(h==-1 && d>0){h=23;d--;}
	
	//on relance la fonction
	fct = "decompte('"+id+"','"+d+"','"+h+"','"+m+"','"+s+"')";
	//alert(fct);
	setTimeout(fct,t);
}
// decompte du temps avec affichage complet
// id : id de la balise dans laquelle le temps restant sera affiché
// d : nombre de jour
// h : nombre d'heure
// m : nombre de minutes
// s : nombre de seconde
function decompteComplet(id,d,h,m,s){
	t = 1000;
	
	if(h==0 && m==0 && s==0 && d==0){location.reload();}
	
	//construction du texte
	txt = "";
	if(d==1){ txt += "1 jour ";}
	if(d>1){ txt += d+" jours ";}
	if(h==1){ txt += "1 heure ";}
	if(h>1){ txt += h+" heures ";}
	if(m==1){ txt += "1 minute ";}
	if(m>1){ txt += m+" minute ";}
	if(s==1 || s==0){ txt += s+" seconde ";}
	if(s>1){ txt += s+" secondes ";}
	
	//affichage
	document.getElementById(id).innerHTML = txt;
	
	//decompte
	s--;
	if(s==-1 && m>0){s=59;m--;}
	if(m==-1 && h>0){m=59;h--;}
	if(h==-1 && d>0){h=23;d--;}
	
	//on relance la fonction
	fct = "decompteComplet('"+id+"','"+d+"','"+h+"','"+m+"','"+s+"')";
	//alert(fct);
	setTimeout(fct,t);
}


// REMPLACE L'IMAGE PRINCIPALE PAR UNE AUTRE
function imagePrincipale(img,id){
	urlp = document.getElementById('img1').src;
	nurlp = urlp.replace("moyennes","minis");
		
	dirg = 'images/produits/grandes/';
	dirm = 'images/produits/moyennes/';
	dirp = 'images/produits/minis/';
	
	pos1 = urlp.indexOf(dirm);
	len = urlp.length;
	subu = urlp.substr(pos1,len);
	imgp = subu.replace(dirm,"");
	
	urln = dirm+img;
	lienp = "javascript:imagePrincipale('"+imgp+"','"+id+"')";
	lienn = "javascript:PopupImage('"+dirg+img+"');";
	
	document.getElementById('img1').src = urln;
	document.getElementById('img'+id).src = nurlp;
	document.getElementById('aimg1').href = lienn;
	document.getElementById('azoom').href = lienn;
	document.getElementById('aimg'+id).href = lienp;
}


// fonction de roll-over menu
function rollover(ligne,id){
	var cla1 = "coteGaucheMenu";
	var cla2 = "coteGaucheMenuB";
	var cla3 = "separateurMenu";
	var cla4 = "separateurMenuB";
	var cla5 = "coteDroitMenu";
	var cla6 = "coteDroitMenuB";
	lib = "c-"+ligne+"-"+id;
	lien = "lienMenu-"+ligne+"-"+id;
	ida = parseInt(id)-1;
	idp = parseInt(id)+1;
	liba = "c-"+ligne+"-"+(ida);
	libp = "c-"+ligne+"-"+(idp);
	droite = document.getElementById(libp);
	gauche = document.getElementById(liba);
	
	document.getElementById(lib).className="celluleMenu-1-B";
	document.getElementById(lien).className="lienMenu-1-B";
	
	if(gauche.className==cla1){
		gauche.className=cla2;
	}else if(gauche.className==cla3){
		gauche.className=cla4;
	}
	if(droite.className==cla5){
		droite.className=cla6;
	}else if(droite.className==cla3){
		droite.className=cla4;
	}
}


function rollout(ligne,id){
	var cla1 = "coteGaucheMenu";
	var cla2 = "coteGaucheMenuB";
	var cla3 = "separateurMenu";
	var cla4 = "separateurMenuB";
	var cla5 = "coteDroitMenu";
	var cla6 = "coteDroitMenuB";
	lib = "c-"+ligne+"-"+id;
	lien = "lienMenu-"+ligne+"-"+id;
	ida = parseInt(id)-1;
	idp = parseInt(id)+1;
	liba = "c-"+ligne+"-"+(ida);
	libp = "c-"+ligne+"-"+(idp);
	droite = document.getElementById(libp);
	gauche = document.getElementById(liba);
	
	if(!l[ligne][id]){
		document.getElementById(lib).className="celluleMenu-1";
		document.getElementById(lien).className="lienMenu-1";
		
		if(!l[ligne][ida]){
			//alert(id+" : "+ida);
			//alert(l[ligne][id]+" : "+l[ligne][ida]);
			if(gauche.className==cla2){
				gauche.className=cla1;
			}else if(gauche.className==cla4){
				gauche.className=cla3;
			}
		}
		if(!l[ligne][idp]){
			if(droite.className==cla6){
				droite.className=cla5;
			}else if(droite.className==cla4){
				droite.className=cla3;
			}
		}
	}
}


//AJOUT DANS LE PANIER
function ajoutProduitPanier(id_produit)
{
	sizePanier();
	from = document.location.href;
	document.getElementById('AddToBasket').setAttribute("src", 'ajout-panier.php?id_produit=' + id_produit + '&from=' + from);
}
function poursuivreCommande(){
		document.location = "identification.php";
}
function confirmerCommande(){
	r1 = document.getElementById('radio1');
	r2 = document.getElementById('radio2');
	r3 = document.getElementById('radio3');
	//r4 = document.getElementById('radio4');
	r5 = document.getElementById('radio5');
	r6 = document.getElementById('radio6');
	r7 = document.getElementById('radio7');
	r8 = document.getElementById('radio8');
	
	id_cmd = document.getElementById('id_commande').value;
	
	if(r1 && r1.checked){ // PAIMENT PAR CARTE BANCAIRE
		document.location = "laposte_request.php?num_commande="+id_cmd;
	}else if(r2 && r2.checked){ // PAIEMENT PAR CHEQUE
		document.location = "recapitulatif-commande.php?num_commande="+id_cmd+"&paiement=Chèque";
	}else if(r3 && r3.checked){ // PAIEMENT PAR CHEQUE 2X
		document.location = "recapitulatif-commande.php?num_commande="+id_cmd+"&paiement=Chèque 2X sans frais";
	/*}else if(r4 && r4.checked){ // PAIEMENT 1EUROCOM
		document.location = "uneurocom_request.php?num_commande="+id_cmd;
		//alert ("Le système de paiement en ligne \"1euro.com\" est en cours d'installation.");
	*/
	}else if(r5 && r5.checked){ // PAIELENT RECEIVE AND PAY 1 FOIS
		document.location = "fianet-requete.php?num_commande="+id_cmd+"&type_IHM=1";
		document.formFIA.submit();
	}else if(r8 && r8.checked){ // PAIELENT RECEIVE AND PAY PLUSIEURS FOIS
		document.location = "fianet-requete.php?num_commande="+id_cmd+"&type_IHM=2";
		document.formFIA.submit();	
	}else if(r6 && r6.checked){ // PAIEMENT PAR VIREMENT
		document.location = "recapitulatif-commande.php?num_commande="+id_cmd+"&paiement=Virement";
	}else if(r7 && r7.checked){ // PAIEMENT PAR PAYPAL
		document.forms.validationPaypal.submit();
	}else{
		alert ("Vous devez choisir un mode de paiement.");
	}
}


/* affichage des coordonnées de livraison */
function coordonneesLivraison(){
	bt = document.getElementById('livraison');
	table = document.getElementById('tableLivraison');
	if(bt.checked){
		table.className="display_none";
		document.getElementById('civL1').checked=false;
		document.getElementById('civL2').checked=false;
		document.getElementById('civL3').checked=false;
		document.getElementById('nomL').value="";
		document.getElementById('prenomL').value="";
		document.getElementById('adresseL').value="";
		document.getElementById('adresseL2').value="";
		document.getElementById('cpL').value="";
		document.getElementById('villeL').value="";
	}else{
		table.className="display";
	}
}


//////////////////////////////////////////////////
// Fonctions roll over et roll out du menu
function menuOver(k){
	d = "cd"+k;
	g = "cg"+k;
	c = "cc"+k;
	document.getElementById(d).className="coteDroitMenuOver";
	document.getElementById(g).className="coteGaucheMenuOver";
	document.getElementById(c).className="fondMenuOver";
}
function menuOut(k){
	d = "cd"+k;
	g = "cg"+k;
	c = "cc"+k;
	document.getElementById(d).className="coteDroitMenuOff";
	document.getElementById(g).className="coteGaucheMenuOff";
	document.getElementById(c).className="fondMenuOff";
}
function sousMenuOver(k){
	c = "cellS"+k;
	document.getElementById(c).className="cellTabSousOver";
}
function sousMenuOut(k){
	c = "cellS"+k;
	document.getElementById(c).className="cellTabSousOff";
}