// JavaScript Document

function litnombre(aChaineNombre)
{
	// retire les espaces les points et autres caractères différents des nombres
	var li=0;
	var lChaine=""+aChaineNombre;
	while (li<eval(lChaine.length))
	{
		if (lChaine.charCodeAt(li)<48 || lChaine.charCodeAt(li)>57)
		{
			lChaine=lChaine.substring(0,li)+lChaine.substring(li+1,lChaine.length);
			li--;
		}
		li++;
	}
	return lChaine;
}


function litnombreCompte(aChaineNombre)
{
	var li=0;
	var lNb;
	var lChaine=""+aChaineNombre;

	while (li<eval(lChaine.length))
	{
		if (lChaine.charCodeAt(li)<48 || lChaine.charCodeAt(li)>57)
		{
			if (lChaine.charCodeAt(li)>=65 || lChaine.charCodeAt(li)<=90)
			{
				lNb=lChaine.charCodeAt(li)-64;
				if (lNb>9)
				{
					lNb=lNb-9;
				}

				if (lNb>9)
				{
					lNb=lNb-8;
				}

				lChar=""+lNb;
				lChaine=lChaine.substring(0,li)+lChar+lChaine.substring(li+1,lChaine.length);
			}
			else
			{
				if (lChaine.charCodeAt(li)>=97 || lChaine.charCodeAt(li)<=122)
				{
					lNb=lChaine.charCodeAt(li)-96;
					if (lNb>9)
					{
						lNb=lNb-9;
					}

					if (lNb>9)
					{
						lNb=lNb-8;
					}
	
					lChar=""+lNb;
					lChaine=lChaine.substring(0,li)+lChar+lChaine.substring(li+1,lChaine.length);
				}
				else
				{	
					// on retire le caractère indésirable
					lChaine=lChaine.substring(0,li)+lChaine.substring(li+1,lChaine.length);
					li--;
				}
			}
		}

		li++;
	}
	return lChaine;
}

function litnombreIBAN(aChaineNombre)
{
	// retire les espaces les points et autres caractères différents des nombres
	// pour les lettres A à Z, remplacement par un nombre :
	// A remplacé par 10 ... Z remplacé par 35
	var li=0;
	var lNb;
	var lChaine=""+aChaineNombre;
	var lChaineRes="";

	while (li<eval(lChaine.length))
	{
		if (lChaine.charCodeAt(li)<48 || lChaine.charCodeAt(li)>57)
		{
			if (lChaine.charCodeAt(li)>=65 || lChaine.charCodeAt(li)<=90)
			{
				lNb=lChaine.charCodeAt(li)-55;

				lChar=""+lNb;
				lChaineRes=lChaineRes+lChar;
			}
			else
			{
				if (lChaine.charCodeAt(li)>=97 || lChaine.charCodeAt(li)<=122)
				{
					lNb=lChaine.charCodeAt(li)-87;
					lChar=""+lNb;
					lChaineRes=lChaineRes+lChar;
				}
				else
				{	
					// on retire le caractère indésirable
				}
			}
		}
		else
		{
			lChaineRes=lChaineRes+lChaine.substring(li,li+1);
		}
		li++;
	}
	return lChaineRes;
}

function fCalcRib(aCodeBanque, aCodeGuichet, aNoCompte)
{
	var lCodeBanque, lCodeGuichet, lNoCompte;
	var lint ;
	var lCompteNum;
	var lCompteStr;
	var lA,	lB, lC, lD, lE, lF, lG, lH, lI, lLength, lLoop,	lAsc, lNb;

	// retire les espaces les points et autres caractères différents des nombres
	lCodeBanque=litnombre(aCodeBanque);
	lCodeGuichet=litnombre(aCodeGuichet);
	lNoCompte=litnombreCompte(aNoCompte);

	if (lCodeBanque.length!=5)
	{
		return 0;
	}

	if (lCodeGuichet.length!=5)
	{
		return 0;
	}

	if (lNoCompte.length>11)
	{
		return 0;
	}

	lA=parseFloat(lCodeBanque);
	lB=parseFloat(lCodeGuichet);
	lC=parseFloat(lNoCompte);

	lD=8*lA;

	lA=lD % 97;

	lE=15*lB;
	lB=97-(lE % 97);
	lF=3*lC;
	lC=97-(lF % 97);
	lG=lA+lB+lC;
	lI=lG % 97;

	if (lI==0)
	{
		return 97;
	}
	else
	{
		return lI;
	}
}

function fCalcIBAN(acodepays, aRIB)
{

	var lcodepays, lRIB, lConcat, lNb, lIBAN, lCodeNum, lCodeStr, li, lRetenue, lCle, lNbInterm, lStrInterm;

	lRIB=litnombreIBAN(aRIB);
	lcodepays=litnombreIBAN(acodepays);

	if ((acodepays.length!=2) || (lcodepays.length!=4))
	{
		return "";
	}

	lConcat=lRIB+lcodepays+"00";
	
	// découpage par bloc de 9 chiffres pour calculer le modulo (pb de précision)
	li=0;
	lRetenue="";
	while (li<eval(lConcat.length))
	{
		lStrInterm=lRetenue+lConcat.substring(li, li+9);
		lNbInterm=parseFloat(lStrInterm);
		lCle=lStrInterm % 97;
		lRetenue=""+lCle;
		
		li=li+9;
	}

	lCodeNum=98-(lCle % 97);

	if (lCodeNum<10)
	{
		lCodeStr="0"+lCodeNum;
	}
	else
	{
		lCodeStr=""+lCodeNum;
	}
	
	lIBAN=acodepays+lCodeStr+aRIB;


	return lIBAN;

}

function fCopierRib(aCodeBanque, aCodeGuichet, aNoCompte, aCleRib)
{
	var lCodeBanque, lCodeGuichet, lNoCompte, lCleRib, lCodeStr, lRib, lNbCleRib;

	lCodeBanque=litnombre(aCodeBanque);
	lCodeGuichet=litnombre(aCodeGuichet);
	lNoCompte=aNoCompte;
	lCleRib=litnombre(aCleRib);


	if (lCodeBanque.length!=5)
	{
		return 0;
	}

	if (lCodeGuichet.length!=5)
	{
		return 0;
	}

	if (lNoCompte.length!=11)
	{
		return 0;
	}
	
        if ((lCleRib.length>2)||(lCleRib.length==0))
	{
		return 0;
	}

	lNbCleRib=parseFloat(lCleRib) % 100;

        if ((lNbCleRib<1) || (lNbCleRib>97))
	{
		return 0;
	}

	if (lCleRib<10)
	{
		lCodeStr="0"+lNbCleRib;
	}
	else
	{
		lCodeStr=""+lNbCleRib;
	}

	lRib=lCodeBanque+lCodeGuichet+lNoCompte+lCodeStr;

	return lRib;
}

function cliqueaffiliation()
	{
	document.rib.clerib.value=fCalcRib(document.rib.codebanque.value, document.rib.codeguichet.value, document.rib.nocompte.value) ;
	document.rib.submit() ;
	}

function arrondir(nombre, decimales) // affiliation
	{
	  if (isNaN(nombre)) return "";
	  if (decimales == 0) 
		{
		 var n = Math.round(nombre);
		 return n.toString();
	  }
  else if (decimales > 0) 
	{
	 if (document.all) 
		var undefined; // Netscape 4 ne connaît pas la constante undefined
	 var p10 = Math.pow(10, decimales);
	 var n = Math.round(nombre * p10);
	 n = n.toString();
	 var point = n.length - decimales;
	 if (point >= 0) 
		n = n.substring(0, point) + "." + n.substring(point);
	 else 
		n = "0." + formater(n, decimales);
	  }
  else 
	{
	 var p10 = Math.pow(10, -decimales);
	 var n = Math.round(nombre / p10) * p10;
	 n = n.toString();
	  }
  if (nombre.signe_decimal == undefined) 
	return n;
  else 
	return n.replace(".", nombre.signe_decimal);
	}	




function recommander(article)
	{
	window.open ('recommander.php?artid='+article+'', 'Recommander', 'Width=600, Height=450, toolbar=no, directories=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no') ;
	}



/*
function agrandir(article, largeur, hauteur, photoid)
	{
	alert('hello');
	var newlargeur = largeur * 3.3 ;
	var newhauteur = hauteur * 2.7 ;
	//var newlargeur = 700 ;
	//var newhauteur = 700 ;
	window.open ('photos.php?artid='+article+'', 'Photos', 'Width='+newlargeur+', Height='+newhauteur+', toolbar=no, directories=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no') ;
	}
*/

function agrandir(article, largeur, hauteur, photoid)
	{
	var newlargeur = largeur * 3.3 ;
	var newhauteur = hauteur * 2.7 ;
	if (photoid == undefined)
		{
	window.open ('photos.php?artid='+article+'', 'Photos', 'Width='+newlargeur+', Height='+newhauteur+', toolbar=no, directories=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no') ;
		}
	else 
		{
			if(photoid !='0' && photoid != 'undefined')
				window.open ('photos.php?artid='+article+'&articlephotoid='+photoid+'', 'Photos', 'Width='+newlargeur+', Height='+newhauteur+', toolbar=no, directories=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no') ;
		}
	}
	
function agrandir2(article, largeur, hauteur, photoid)
	{
	var newlargeur = largeur * 3.3 ;
	var newhauteur = hauteur * 2.7 ;
	if (photoid == undefined)
		{
	window.open ('photos.php?artid='+article+'', 'Photos', 'Width='+newlargeur+', Height='+newhauteur+', toolbar=no, directories=no, location=no, menubar=no, resizable=no, scrollbars=yes, status=no') ;
		}
	else 
		{
			if(photoid !='0' && photoid != 'undefined')
				window.open ('photos.php?artid='+article+'&articlephotoid='+photoid+'', 'Photos', 'Width='+newlargeur+', Height='+newhauteur+', toolbar=no, directories=no, location=no, menubar=no, resizable=no, scrollbars=yes, status=no') ;
		}
	}
	
	
function recalculer() 
	{
	document.formu.submit();
	}

function etape2() 
	{
	document.formu.action='cde2.php';
	document.formu.submit();
	}


function continuer() 
{
	window.location = 'cde1.php?action=delpanier_complet' ;
}



function ferme(menu) 
	 {
	 document.getElementById(menu).style.display='none';
	 }

function ouvre(afermer, menu) 
	 {
	 if (afermer != '')
		{
		ferme(afermer) ;
		}
	 document.getElementById(menu).style.display='block';
	 }


function voir(article) 
	 {
	 document.getElementById(article).style.display = 'block';
	 }

function cacher(article) 
	 {
	 document.getElementById(article).style.display = 'none';
	 }



function MM_preloadImages() 
		{
		var d=document ;
		if (d.images)
			{
			if (!d.MM_p)
				d.MM_p=new Array();
			var i, j = d.MM_p.length, a = MM_preloadImages.arguments ;
			for (i = 0 ; i < a.length ; i++)
			if (a[i].indexOf("#") != 0)
				{
				d.MM_p[j] = new Image ; 
				d.MM_p[j++].src = a[i] ;
				}
			}	
		}

/*function changeImgAnnonce(srcImg,imagesize0,imagesize1)
	{
	var largeur_en_cours = imagesize0 ;
	var hauteur_en_cours = imagesize1 ;
	if (imagesize0 > 600 || imagesize1 > 600)
		{
		if (largeur_en_cours > 600) // si largeur > 112
			{
			var width = 600 ; // largeur = 112
			var height = Math.floor (600 * hauteur_en_cours / largeur_en_cours) ; // hauteur = 112 * (768/1024)
			largeur_en_cours = width ;
			hauteur_en_cours = height ;
			} 
		if (hauteur_en_cours > 600) 
			{
			var width = Math.floor(largeur_en_cours * 600 / hauteur_en_cours) ;
			var height = 600 ;
			largeur_en_cours = width ;
			hauteur_en_cours = height ;
			}
		}
	document.getElementById('diapo').innerHTML = '<img src='+srcImg+' width='+largeur_en_cours+' name=big>'; // height='+hauteur_en_cours+'
	}
*/	
	
	
function changeImgAnnonce(srcImg,imagesize0,imagesize1,largeurphotos,hauteurphotos)
	{
		
	var largeur_en_cours = parseInt(imagesize0) ;
	var hauteur_en_cours = parseInt(imagesize1) ;
	var largeur_photos = parseInt(largeurphotos) ;
	var hauteur_photos = parseInt(hauteurphotos) ;

	if (isNaN(largeur_photos) == true && isNaN(hauteur_photos) == true)
		{
		if (largeur_en_cours > 600 || hauteur_en_cours > 600)
			{
			if (largeur_en_cours > 600) // si largeur > 112
				{
				var width = 600 ; // largeur = 112
				var height = Math.floor (600 * hauteur_en_cours / largeur_en_cours) ; // hauteur = 112 * (768/1024)
				largeur_en_cours = width ;
				hauteur_en_cours = height ;
				} 
			if (hauteur_en_cours > 600) 
				{
				var width = Math.floor(largeur_en_cours * 600 / hauteur_en_cours) ;
				var height = 600 ;
				largeur_en_cours = width ;
				hauteur_en_cours = height ;
				}
			}
		}
	else
		{
		if (largeur_en_cours > largeur_photos || hauteur_en_cours > hauteur_photos)
			{
			if (largeur_en_cours > largeur_photos) // largeur_photos <= 600 pixels max
				{
				var width = largeur_photos ;
				var height = Math.floor (largeur_photos * hauteur_en_cours / largeur_en_cours) ; // hauteur = 112 * (768/1024)
				largeur_en_cours = width ;
				hauteur_en_cours = height ;
				} 
			if (hauteur_en_cours > hauteur_photos) // hauteur_photos <= 600 pixels max
				{
				var width = Math.floor(largeur_en_cours * hauteur_photos / hauteur_en_cours) ;
				var height = hauteur_photos ;
				largeur_en_cours = width ;
				hauteur_en_cours = height ;
				}
				
			}
		
		}
	document.getElementById('diapo').innerHTML = '<img src='+srcImg+' width='+largeur_en_cours+' name=big>'; // height='+hauteur_en_cours+'
	}	


function changeImgAnnoncenew(srcImg)
	{
	document.getElementById('diapo').innerHTML = '<img src='+srcImg+' name=big>'; // height='+hauteur_en_cours+'
	}	

function toggle(id,p)
	{
	var myChild = document.getElementById(id);
	if(myChild.style.display!='block')
		{
		myChild.style.display='block';
		document.getElementById(p).className='folderOpen';
		}
	else
		{
		myChild.style.display='none';
		document.getElementById(p).className='folder';
		}
	}

function vider(objet)
	{
	if (objet.value == "recherche" || objet.value == "Adresse mail" || objet.value == "passe" || objet.value == "Votre e-mail" || objet.value == "Mot de passe")
		{
		objet.value = "" ;
		}
	}

function viderpanier()
	{
	window.location = 'cde1.php?action=delpanier_complet' ;
	}
	
function changeImgAnnonce2(srcImg)
	{
	document.getElementById('big').src = srcImg ;
	}	


function clic_onglet(mon_onglet) {
	switch(mon_onglet){
		case'cdc':
			document.getElementById('promo').style.color='#808080';
			document.getElementById('top_vente').style.color='#808080';
			document.getElementById('nouveaute').style.color='#808080';
			document.getElementById('cdc').style.color='#A5CB32';
			document.getElementById('tops_contents').className = 'tops_contents0' ;
			affiche(0);
			break;
		case 'promo':
			document.getElementById('cdc').style.color='#808080';
			document.getElementById('top_vente').style.color='#808080';
			document.getElementById('nouveaute').style.color='#808080';
 			document.getElementById('promo').style.color='#A5CB32';
			document.getElementById('tops_contents').className = 'tops_contents1' ;
			affiche(1);
			break;
		case'top_vente':
			document.getElementById('cdc').style.color='#808080';
			document.getElementById('promo').style.color='#808080';
			document.getElementById('nouveaute').style.color='#808080';
 			document.getElementById('top_vente').style.color='#A5CB32';
			document.getElementById('tops_contents').className = 'tops_contents2' ;
			affiche(2);
			break;
		case'nouveaute':
			document.getElementById('cdc').style.color='#808080';
			document.getElementById('promo').style.color='#808080';
			document.getElementById('top_vente').style.color='#808080';
 			document.getElementById('nouveaute').style.color='#A5CB32';
			document.getElementById('tops_contents').className = 'tops_contents3' ;
			affiche(3);
			break;
		}
	
}

// Début script pour le menu horizontal déroulant 
window.onload=montre;
function montre(id) {
	var d = document.getElementById(id);
	var tabdd = document.getElementsByTagName('dd');
	for (var i=0;i<tabdd.length;i++) {
		document.getElementById(tabdd[i].id).style.display='none';
		}
/*


	alert(tabdd);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {
			document.getElementById('smenu'+i).style.display='none';
			}
		}*/
	if (d) {
		d.style.display='block';
	}
}

function affiche(id) {
	for(i=0;i<4;i++){
		valeur = "calque" + i;
		document.getElementById(valeur).style.display="none";
	}
	valeur = "calque" + id;
	document.getElementById(valeur).style.display="block";
}


	
function poplink(msg)
	{
		//alert(document.body.scrollLeft);
		//alert(msg);
	var content = '<img src="'+msg+'">';
	if (domok)
		{
	  	document.getElementById("topdecklink").innerHTML = content;
	  	document.getElementById("topdecklink").style.border="1px solid black";
	  	skn.visibility = "visible";
		skn.display = "block";
  		}
	}

function get_mouse(e){
	var x = (navigator.appName.substring(0,3) == "Net") ? e.pageX : event.x+document.documentElement.scrollLeft;
	var y = (navigator.appName.substring(0,3) == "Net") ? e.pageY : event.y+document.documentElement.scrollTop;
	skn.left = x + 30 +"px";//15
	skn.top = y - 255 +"px";
	
}
function killlink()
	{
	if (domok)
  		skn.display = "none";
	}

function imprimer(article) {
	window.open ('imprimer.php?artid='+article+'', 'Impression', 'Width=800, Height=600, toolbar=no, directories=no, location=no, menubar=no, resizable=no, scrollbars=yes, status=no') ;
	}

