// 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)
	{
	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 recalculer() 
	{
	document.formu.submit();
	}

function etape2() 
	{
	document.formu.action='cde2.php';
	document.formu.submit();
	}




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)
	{
	document.images['big'].src = srcImg ; 
	if (document.images['big'].width > 600)
		{
		document.images['big'].width = 600 ;
		}
	if (document.images['big'].height > 600)
		{
		document.images['big'].height = 600 ;
		}
	}	

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 affiche_uploads()
	{
	if(document.getElementById('affiche_uploads').style.display=='none')
		{
		document.getElementById('affiche_uploads').style.display = 'block';
		document.getElementById('btn_affiche_uploads').style.display = 'none';
		document.getElementById('affiche_uploads_input').style.display = 'none';
		document.getElementById('btn_affiche_uploads_input').style.display = 'block';		
		document.getElementById('articledesc').style.display = 'none';		
		}
	else
		{
		document.getElementById('affiche_uploads').style.display = 'none';
		document.getElementById('btn_affiche_uploads').style.display = 'block';
		document.getElementById('affiche_uploads_input').style.display = 'none';
		document.getElementById('btn_affiche_uploads_input').style.display = 'block';				
		document.getElementById('articledesc').style.display = 'block';
		}
	}
	
function affiche_uploads_input()
	{
	if(document.getElementById('affiche_uploads_input').style.display=='none')
		{
		document.getElementById('affiche_uploads_input').style.display = 'block';
		document.getElementById('btn_affiche_uploads_input').style.display = 'none';
		document.getElementById('affiche_uploads').style.display = 'none';
		document.getElementById('btn_affiche_uploads').style.display = 'block';		
		document.getElementById('articledesc').style.display = 'none';		
		}
	else
		{
		document.getElementById('affiche_uploads_input').style.display = 'none';
		document.getElementById('btn_affiche_uploads_input').style.display = 'block';
		document.getElementById('affiche_uploads').style.display = 'none';
		document.getElementById('btn_affiche_uploads').style.display = 'block';				
		document.getElementById('articledesc').style.display = 'block';
		}
	}
*/	

function addpaniersansupload()
	{
	document.getElementById('doituploader').value = '0';
	document.formuadd.action='upload.php';
	document.getElementById('myaction').name='action';
	if (document.getElementById('bat').checked)
		var bat = 1;	
	else
		var bat = 0;
	document.getElementById('bat').value=bat;
	document.formuadd.submit();
	}
	
function addpanieruploadinput ()
	{
	document.getElementById('uupload').name='0';	
	document.formuadd.action='uupload.php';
	document.getElementById('myaction').name='action';
	document.formuadd.submit();
	}
	
function lienbtn_upload (div)
	{
	if (div == "0")
		document.getElementById('bouton_upload').href = 'Javascript:addpaniersansupload();';
	else
		document.getElementById('bouton_upload').href = 'Javascript:affiche_upload('+div+');';
	}
	
function affiche_upload (div)
	{
	document.getElementById('upload_'+div).style.display = 'block';	
	if (document.getElementById('contenu_uupload_'+div))
		{
		/**************************************************************** INFOS SAISIES ************************************************************/
		var qte = document.getElementById('qte').value;
		var artid = document.getElementById('artid').value;
		var maliste = '' ;
		var caracteristiques = document.getElementById('listes').value;
		var montableaudecaracteristiques=caracteristiques.split(',');
		var x;
		for (x=1; x<montableaudecaracteristiques.length; x++)  {
			var caractvalid = document.getElementById('lst_'+montableaudecaracteristiques[x]).options[document.getElementById('lst_'+montableaudecaracteristiques[x]).selectedIndex].value ;
			maliste += '&lst_'+montableaudecaracteristiques[x]+'='+caractvalid;
			}
		if (document.getElementById('bat').checked)
			var bat = 1;	
		else
			var bat = 0;	
			
		/**************************************************************** INFOS SAISIES ************************************************************/
		document.getElementById('contenu_uupload_'+div).src = 'http://www.flyers-imprim.com/iframe_uuploadpro.php?artid='+artid+'&qte='+qte+'&bat='+bat+'&listes='+caracteristiques+maliste+'&uupload=1';
		}
	}
		
//for showing popup over orange button
function bind() {
	llinks = $$('a');
//	llinks = document.links;
	for(i in llinks) {
		if ((llinks[i].href != null) && (llinks[i].href.indexOf('int,31,nosreferences.html') != -1) && (llinks[i].innerHTML.indexOf('userfiles/image/Confiance.jpg') != -1)) {
			llinks[i].onmouseover = popUp;
			llinks[i].onmouseout  = popDown;
			break;
		}
  	}
	var div = document.createElement('div');
	div.setAttribute('id', 'img_div');
	document.body.appendChild(div);	
//	$('img_div').innerHTML = "HELLO?";
	$('img_div').style.position = 'absolute';
	$('img_div').style.top      = '130px';
	$('img_div').style.left     = '140px';
	$('img_div').style.zIndex   = '20';
	$('img_div').style.display  = 'none';

	var strHref = window.location.href;
	a = strHref.match(/\/cat,([^,]+),/);
	if (a != null) {
		new Ajax.Updater('img_div', 'ajax.php' , { method: 'post', parameters: { category: a[1]} } );
	        new PeriodicalExecuter(nextPic, 2);
	}
}


function nextPic() {
	children = $('img_div').childNodes;
	for(i = 0; i < children.length; i++) {
		if (children != null && children[i].style.display == '') {
			children[i].style.display = 'none';
			if (i + 1 == children.length)
				children[0].style.display = '';
			else
				children[i + 1].style.display = '';
			break;
		}
	}
}

function popUp() {
	$('img_div').style.display = '';
	children = $('img_div').childNodes;
	flag = true;
	for(i = 0; i < children.length; i++)
		if (children != null && (children[i].style.display != null) && (children[i].style.display == '')) {
			flag = false;
			break;
		}
	if (flag && children)
		children[0].style.display = '';
}

function popDown() {
	$('img_div').style.display = 'none';	
}
document.onLoad = window.setTimeout('bind()', 1000);


//document.onLoad = bind;

