/**************************************************************************/
/*************** FICHIER CONTENANT LES FONCTIONS JAVASCRIPT ***************/
/**************************************************************************/

function trim(string)
{
	return string.replace(/(^\s*)|(\s*$)/g,'');
}
function urlencode(ch) {
   ch = ch.replace(/[ ]/g,"+");
   return escape(ch);
}
function urldecode(ch) {
   ch = ch.replace(/[+]/g," ");
   return unescape(ch);
}
function searchANDreplace(chaine,mySearch,myReplace)
{
	var reg = new RegExp("(" + mySearch + ")", "g");
	chaine = chaine.replace(reg,myReplace);
	
	return chaine;
}

//Permettant de trier des nombres
function tri_nombres(a,b)
{
	return a-b;
}

//Accéder au flash
function getMovieName(movieName)
{
	if (navigator.appName.indexOf("Microsoft") != -1)
	{
		return window[movieName];
	}
	else
	{
		return document[movieName];
	}
}

//Fonction pour changer la page
function changePage(direction,numMiniature)
{
	//On remet le pageflip en mode zoom défault
	flashZoom("default");
	
	numPageMax = parseInt(document.getElementById("pagesTotales").innerHTML);
	if(numPageMax != 1)
	{
		//Portrait
		if (Gformat == "portrait")
		{	
				//var numPage = document.getElementById("numPageGauche").innerHTML;
				//numPage = parseInt(numPage.replace(" - ",""));
				var numPage = GcurrentPage;
				
				switch(direction)
				{
					case "gauche" : 
						if(numPage < 1 || !numPage)
						{
							return false;
						}
						else
						{
							numPage = numPage - 1;
							
							if(GmodeVisu == "double")
							{
								numPage = numPage - 1;	
							}
						}				
					break;
						
					case "droite" :
						if(numPage == numPageMax)
						{
							return false;
						}
						else
						{
							numPage = numPage + 2;
						}
					break;
						
					case "choixuser" :
						//numPage = parseInt(document.getElementById("goTO").numPage.value);
						numPage = parseInt($("#champschoixpage").val());
						
						if(GmodeVisu == "double")
						{
							numPage = numPage - 1;	
						}
					break;
						
					case "miniAndSearch" :
						numPage = parseInt(numMiniature);
						
						if(GmodeVisu == "double")
						{
							numPage = numPage - 1;	
						}
					break;
						
					default :
						alert("Erreur fonction \"changePage()\" !");
						return false;
					break;
				}
		}
		//Paysage
		else
		{
				//var numPage = parseInt(document.getElementById("numPageDroite").innerHTML);
				//var numPage = parseInt($("#champschoixpage").val());
				var numPage = GcurrentPage;
				
				switch(direction)
				{
					case "gauche" : 
						if(numPage < 1 || !numPage)
						{
							return false;
						}
						else
						{	
							// mode paysage
							numPage = numPage * 2 - 3;
						}				
					break;
						
					case "droite" :
						// mode paysage
						numPage = numPage * 2;
					break;
						
					case "choixuser" :
						//numPage = parseInt(document.getElementById("goTO").numPage.value);
						var numPage = parseInt($("#champschoixpage").val());
						
						// mode paysage
						numPage = numPage * 2 - 1;
					break;
						
					case "miniAndSearch" :
						numPage = parseInt(numMiniature);
						
						// mode paysage
						numPage = numPage * 2 - 1;
					break;
						
					default :
						alert("Erreur fonction \"changePage()\" !");
						return false;
					break;
				}
		}
		
		//On mémorise la page choisie
		GcurrentPage = numPage;
		if(GcurrentPage == 0){ GcurrentPage = 1; }
		
		//Appel de la fonction permettant de tourner les pages dans le flash
		//if(document.getElementById("contenuBas").style.display == "block")
		if(document.getElementById("zoneworkmilieu").style.display == "block")
		{
			getMovieName("pageflip").tournerpage(numPage);
		}
		else
		{
			if(direction == "miniAndSearch" || direction == "choixuser")
			{
				showHideFlash("show", numPage, false, false, false);
			}
		}
		
		//On enregistre la stat de consultation de la page
		if(direction == "miniAndSearch" || direction == "choixuser")
		{
			var pageInsert = numPage.toString();
			if(Gformat == "portrait")
			{
				//Pour le format portrait
				if(numPage != 1 && numPage != numPageMax)
				{
					if(numPage%2 == 0){ pageInsert = numPage.toString() + " - " + (numPage + 1) }
					else{ pageInsert = (numPage - 1) + " - " + numPage.toString(); }
				}
			}
			else
			{
				//Pour le format paysage
				pageInsert = (numPage + 1) / 2;
			}
			
			saveStat("page", pageInsert);
		}
	}
	else
	{
		ajaxGetTradAlert("Vous ne pouvez pas changer de page.");
	}
	
	getMovieName("pageflip").focus();
	
	return false;
}

//Fonction de synchronisation entre le flash et la page
function synchroFlashHtml(numPageG,numPageD)
{
	//Le pageflip donnant l'index 0 à la première page, on se met en accord
	var numPageG = parseInt(numPageG);
	var numPageD = parseInt(numPageD);
	
	//Portrait
	if (Gformat == "portrait"){
		if (numPageG < 1 || !numPageG)
		{
			numPageG = 0;
			//document.getElementById("numPageDroite").style.visibility ="visible";
			if(GmodeVisu == "normal")
			{
				//document.getElementById("numPageGauche").style.visibility ="hidden";
				//document.getElementById("numPageGauche").innerHTML = numPageG.toString();
				$("#champschoixpage").val("1");
				//document.getElementById("numPageDroite").innerHTML = "1";
			}
			else
			{
				/*document.getElementById("numPageGauche").style.visibility ="visible";
				document.getElementById("numPageGauche").innerHTML = "1 - ";
				document.getElementById("numPageDroite").innerHTML = "2";*/
			}
		}
		else
		{
			//Si le nombre de page totales est égale à 1
			if (parseInt(document.getElementById("pagesTotales").innerHTML) == 1)
			{
				numPageG = 1;	
			}
			
			if(GmodeVisu == "double")
			{
				numPageG = numPageG + 1;
				numPageD = numPageD + 1;
			}
			
			//document.getElementById("numPageGauche").style.visibility ="visible";
			//document.getElementById("numPageGauche").innerHTML = numPageG.toString() + " - ";
			$("#champschoixpage").val(numPageG.toString());
			//document.getElementById("numPageDroite").style.visibility ="visible";
			if(numPageD > parseInt(document.getElementById("pagesTotales").innerHTML) || !numPageD)
			{
				//document.getElementById("numPageDroite").style.visibility ="hidden";
				//document.getElementById("numPageDroite").innerHTML = "&nbsp;";
				//document.getElementById("numPageGauche").innerHTML = document.getElementById("numPageGauche").innerHTML.replace(" - ","");
			}
			else
			{
				//document.getElementById("numPageDroite").innerHTML = numPageD.toString();
			}
		}
		numPage = numPageG;
		
		//On mémorise la page actuelle
		GcurrentPage = numPage;
		if(GcurrentPage == 0){ GcurrentPage = 1; }
	}
	//Paysage
	else
	{
		numPage = (parseInt(numPageD) + 1)/2;
		
		if (numPage >= 1)
		{
			//document.getElementById("numPageGauche").style.visibility ="hidden";
			//document.getElementById("numPageGauche").innerHTML = numPage.toString();
			//document.getElementById("numPageDroite").innerHTML = ""  + numPage;
			$("#champschoixpage").val(numPage.toString());
		}
		numPage = parseInt(numPageD);
		
		//On mémorise la page actuelle
		GcurrentPage = numPage;
		GcurrentPage = (parseInt(GcurrentPage) + 1)/2;
		if(GcurrentPage == 0){ GcurrentPage = 1; }
		
		//On cré le lien pour l'impression
		if(GisAdmin != "true")
		{
			var zeros = "";
			var i = 1;
			var printPage = document.getElementById("numPageDroite").innerHTML;
			if(document.getElementById("blockTools").style.display == "none")
			{
				//on recupere le nom du cookie
				var nameCookie = "e-motionbook-select-" + GnameCat;
				
				//on lit le contenu du cookie
				var contentSelect = readCookie(nameCookie);
				
				//Récupération du vrai numéro de page
				var tabContent = contentSelect.split("#");
				printPage = tabContent[printPage-1];
			}
			while( i <= GcatTotalPages.length - printPage.length)
			{
				zeros += "0";
				i++;
			}
			var PDFtoOpen = zeros + printPage + "_" + GPDFname;
			document.getElementById("printPDF").href = "mon-pdf.php?nameCat=" + GnameCat + "&PDFname=" + PDFtoOpen + "&mode=unique&page=" + printPage;
		}
	}
	
	//On réaffiche les marques-pages
	showMP();
}


//Imprimer
function imprimer(cote)
{
	if(GisAdmin != "true")
	{
		var id;
		var printPage;
		if(GcurrentPage == 1)
		{
			printPage = GcurrentPage;	
		}
		else
		{
			if(cote == "gauche")
			{
				//printPage = parseInt(document.getElementById("numPageGauche").innerHTML.split(" ")[0]);
				printPage = GcurrentPage;
				id = "Gprint";
			}
			else
			{
				//printPage = parseInt(document.getElementById("numPageDroite").innerHTML);
				printPage = GcurrentPage+1;
				id = "Dprint";
			}
		}
		
		/*//On regarde si on est en mode "ma selection"
		if(document.getElementById("blockTools").style.display == "none")
		{
			//on recupere le nom du cookie
			var nameCookie = "e-motionbook-select-" + GnameCat;
			
			//on lit le contenu du cookie
			var contentSelect = readCookie(nameCookie);
			
			//Récupération du vrai numéro de page
			var tabContent = contentSelect.split("#");
			if(cote == "gauche")
			{
				printPage = parseInt(tabContent[parseInt(printPage/2)]);	
			}
			else
			{
				printPage = parseInt(tabContent[parseInt((printPage-1)/2)]);
				if(printPage != 1)
				{
					printPage++;
				}
			}
		}*/
		
		printPage = printPage.toString();
		var zeros = "";
		var i = 1;
		while( i <= GcatTotalPages.length - printPage.length)
		{
			zeros += "0";
			i++;
		}
		
		var PDFtoOpen = zeros + printPage + "_" + GPDFname;
		window.open("mon-pdf.php?nameCat=" + GnameCat + "&PDFname=" + PDFtoOpen + "&mode=unique&page=" + printPage, "monPDF");
	}
}

//Envoyer la page par mail
function sendMailPage(cote)
{
	if(GisAdmin != "true")
	{
		var id;
		var emailPage;
		
		if(GcurrentPage == 1)
		{
			emailPage = GcurrentPage;	
		}
		else
		{
		
			if(cote == "gauche")
			{
				
				emailPage = GcurrentPage;
				//emailPage = parseInt(document.getElementById("numPageGauche").innerHTML.split(" ")[0]);
				id = "GEmailPage";
			}
			else
			{
				emailPage = GcurrentPage+1;
				//emailPage = parseInt(document.getElementById("numPageDroite").innerHTML);
				id = "DEmailPage";
			}
		}
		
		//On regarde si on est en mode "ma selection"
		/*if(document.getElementById("blockTools").style.display == "none")
		{
			//on recupere le nom du cookie
			var nameCookie = "e-motionbook-select-" + GnameCat;
			
			//on lit le contenu du cookie
			var contentSelect = readCookie(nameCookie);
			
			//Récupération du vrai numéro de page
			var tabContent = contentSelect.split("#");
			if(cote == "gauche")
			{
				emailPage = parseInt(tabContent[parseInt(printPage/2)]);	
			}
			else
			{
				emailPage = parseInt(tabContent[parseInt((printPage-1)/2)]);
				if(emailPage != 1)
				{
					emailPage++;
				}
			}
		}*/
		
		emailPage = emailPage.toString();
		var zeros = "";
		var i = 1;
		while( i <= GcatTotalPages.length - emailPage.length)
		{
			zeros += "0";
			i++;
		}
		
		var txtTitle = "";
		switch(GmaLangue)
		{
			case "fr":
				txtTitle = "Envoi à un ami";
			break;
			
			case "en":
				txtTitle = "Send to a friend";
			break;
			
			case "it":
				txtTitle = "Send to a friend";
			break;
			
			case "nl":
				txtTitle = "Send to a friend";
			break;
			
			case "es":
				txtTitle = "Enviar a un amigo";
			break;
			
			default:
				alert("Erreur de langue !");
			break;
		}
		
		//var PDFtoOpen = zeros + printPage + "_" + GPDFname;
		//window.open("mon-pdf.php?nameCat=" + GnameCat + "&PDFname=" + PDFtoOpen + "&mode=unique&page=" + printPage, "monPDF");
		
		tb_show(txtTitle, "envoi-ami.php?isthickbox=true&lang=" + GmaLangue + "&page=" + emailPage + "&width=260&height=340", false);
	}
}

function sendMailMP()
{
	if(GisAdmin != "true")
	{
		var txtTitle = "";
		switch(GmaLangue)
		{
			case "fr":
				txtTitle = "Envoi à un ami";
			break;
			
			case "en":
				txtTitle = "Send to a friend";
			break;
			
			case "it":
				txtTitle = "Send to a friend";
			break;
			
			case "nl":
				txtTitle = "Send to a friend";
			break;
			
			case "es":
				txtTitle = "Enviar a un amigo";
			break;
			
			default:
				alert("Erreur de langue !");
			break;
		}
		//var PDFtoOpen = zeros + printPage + "_" + GPDFname;
		//window.open("mon-pdf.php?nameCat=" + GnameCat + "&PDFname=" + PDFtoOpen + "&mode=unique&page=" + printPage, "monPDF");
		
		tb_show(txtTitle, "envoi-mp-ami.php?isthickbox=true&lang=" + GmaLangue + "&width=260&height=340", false);
	}
}

function showHideMaskEmailPage(mode)
{
	if(mode == "show")
	{
		//flashZoom("default");
		
		document.getElementById("GmaskEmailPage").style.visibility = "visible";
		document.getElementById("DmaskEmailPage").style.visibility = "visible";
		//if(parseInt(document.getElementById("numPageDroite").innerHTML) == 1)
		if(GcurrentPage == 1)
		{
			document.getElementById("GmaskEmailPage").style.visibility = "hidden";
		}
		//if(parseInt(document.getElementById("numPageGauche").innerHTML) == parseInt(document.getElementById("pagesTotales").innerHTML))
		if(GcurrentPage == GcatTotalPages)
		{
			document.getElementById("DmaskEmailPage").style.visibility = "hidden";
		}
		
		document.getElementById("mask").style.visibility = "visible";
		document.getElementById("maskEmailPage").style.visibility = "visible";
	}
	else
	{
		document.getElementById("GmaskEmailPage").style.visibility = "hidden";
		document.getElementById("DmaskEmailPage").style.visibility = "hidden";
		document.getElementById("maskEmailPage").style.visibility = "hidden";
		document.getElementById("mask").style.visibility = "hidden";
	}
}

//Zoomer ou dézoomer le pageflip
function flashZoom(action)
{
	
	if(document.getElementById("pageflip"))
	{
		getMovieName("pageflip").flashZoom(action);
	}
}


//Afficher ou masquer les flash
function showHideFlash(state, numPage, nomXML, numPageSearch, texteSearch)
{
	//Création du chemin du fichier XML
	if (nomXML == false || nomXML == "false")
	{
		fichierXML = "imagesPageFlip/" + GnameCat + "/config.xml";
	}
	else
	{
		fichierXML = nomXML;
	}
	
	if(state == "show")
	{
		//On affiche les différents éléments
		/*document.getElementById("bandeauHaut").style.visibility = "visible";
		document.getElementById("numPageGauche").style.visibility = "visible";
		document.getElementById("numPageDroite").style.visibility = "visible";
		document.getElementById("contenuHaut").style.visibility = "visible";
		document.getElementById("contenuSearch").style.display = "none";
		document.getElementById("contenuBas").style.display = "block";*/
		document.getElementById("zoneworkbas").style.display = "block"
		//Affichage du grand flash
		//var so = new SWFObject("pageflip.swf", "pageflip", "808", "571", "9", "#000000");
		//var so = new SWFObject("pageflip.swf", "pageflip", "696", "492", "9", "#000000");
		var so = new SWFObject("pageflip.swf", "pageflip", "738", "522", "9", "#000000");
		so.addParam("quality","High");
		so.addParam("wmode", "transparent");
		so.addParam("allowFullScreen", "true");
		so.addVariable("fichierXML",fichierXML);
		so.addVariable("firstPage",numPage);
		so.addVariable("nameCat",GnameCat);
		so.addVariable("format",Gformat);
		so.addVariable("lang", GmaLangue);
		so.addVariable("numPageSearch",numPageSearch);
		so.addVariable("texteSearch",texteSearch);
		//so.write("contenuBas");
		so.write("zoneworkmilieu");
		
		//On change les boutons retourcat et retour resultats
		/*if(document.getElementById("backToCat").style.display == "inline")
		{
			document.getElementById("backToCat").style.display = "none";
			document.getElementById("backToResults").style.display = "inline"
		}*/
		
		getMovieName("pageflip").focus();
	}
	else
	{
		//On masque la zoombar, le contenu bas, et le grand flash
		/*document.getElementById("bandeauHaut").style.visibility = "hidden";
		document.getElementById("numPageGauche").style.visibility = "hidden";
		document.getElementById("numPageDroite").style.visibility = "hidden";
		document.getElementById("contenuHaut").style.visibility = "hidden";
		document.getElementById("contenuBas").style.display = "none";
		document.getElementById("contenuSearch").style.display = "block";*/
	}
}


//Fonction permettant d'écrire le cookie marque Page
function writeCookieMP(nameCookie,valeur,action)
{
	//On récupère d'abord l'ancienne valeur du cookie
	var oldValeur = readCookie(nameCookie);
	
	switch(action) 
	{
		case "add":
			//On regarde si la page que l'on veut ajouter n'existe pas déjà
			var retour = true;
			if(oldValeur != null)
			{
				var tabOld = oldValeur.split("#");
				for(var j=0 ; j<tabOld.length ; j++)
				{
					if(parseInt(tabOld[j]) == valeur)
					{
						retour = false;
					}
				}
			}
			if(retour)
			{
				//On concatène l'ancienne valeur avec la nouvelle, puis on tri
				var newValeur = oldValeur + valeur + "#";
				var tabNew = newValeur.split("#");
				tabNew.sort(tri_nombres);
				var contentCookie = "";
				for(var i=0 ; i<tabNew.length ; i++)
				{
					contentCookie = contentCookie + tabNew[i] + "#";
				}
				//Initialisation de la durée du cookie à 1 an
				var expires = new Date;
				expires.setFullYear(expires.getFullYear()+1);
				
				//Tous le site
				var path = null;
				
				//Le domaine courant
				var domain = null;
				
				//Pas de sécurité
				var secure = false;
				
				//Ecriture du cookie
				document.cookie = nameCookie + "=" + escape(contentCookie) + ((expires==null) ? "" : ("; expires=" + expires.toGMTString())) + ((path==null) ? "" : ("; path="+path)) + ((domain==null) ? "" : ("; domain="+domain)) + ((secure==true) ? "; secure" : "");
				
				//On lis le cookie pour réafficher les marques-page
				showMP(nameCookie);				
	
				//On enregistre la stat d'ajout du marque-page
				valeur = parseInt(valeur);
				if(valeur != 1 && valeur != GcatTotalPages && Gformat == "portrait")
				{
					valeur = valeur.toString() + " - " + (valeur + 1);	
				}
				saveStat("marquepage", valeur);
				if(document.getElementById("TB_title") != null )
				{
				   ajaxGetTradAlert("Marque-page ajouté.");
				}
				
			}
			else
			{
				ajaxGetTradAlert("Ce marque-page existe déjà.");
			}
		break;
			
		case "remove":
		
			var txtConfirm = "";
			switch(GmaLangue)
			{
				case "fr":
					txtConfirm = "Etes-vous sur de vouloir effacer ce marque-page ?";
				break;
				
				case "en":
					txtConfirm = "Are you sure you want to remove all of your bookmarks ?";
				break;
				
				case "it":
					txtConfirm = "Sei sicuro di voler eliminare tutti gli elementi selezionati ?";
				break;
				
				case "nl":
					txtConfirm = "Wenst u uw volledige selectie te deleten ?";
				break;
				
				case "es":
					txtConfirm = "¿Confirma que desea borrar este marcapágina?";
				break;
				
				default:
					alert("Erreur de langue !");
				break;
			}
		
			if(confirm(txtConfirm))
			{
				var contentCookie = "";
				var tabOld = oldValeur.split("#");
				for(var k=0 ; k<tabOld.length ; k++)
				{
					if(parseInt(tabOld[k]) != valeur)
					{
						contentCookie = contentCookie + tabOld[k] + "#";	
					}
				}
				//Initialisation de la durée du cookie à 1 an
				var expires = new Date;
				expires.setFullYear(expires.getFullYear()+1);
				//Tous le site
				var path = null;
				//Le domaine courant
				var domain = null;
				//Pas de sécurité
				var secure = false;
				//Ecriture du cookie
				document.cookie = nameCookie + "=" + escape(contentCookie) + ((expires==null) ? "" : ("; expires=" + expires.toGMTString())) + ((path==null) ? "" : ("; path="+path)) + ((domain==null) ? "" : ("; domain="+domain)) + ((secure==true) ? "; secure" : "");
				//On lis le cookie pour réafficher les marques-page
				showMP(nameCookie);
			}
		break;
	}
}

function writeCookieMPSilent(nameCookie,valeur,action)
{
	//On récupère d'abord l'ancienne valeur du cookie
	var oldValeur = readCookie(nameCookie);
	
	switch(action) 
	{
		case "add":
			//On regarde si la page que l'on veut ajouter n'existe pas déjà
			var retour = true;
			if(oldValeur != null)
			{
				var tabOld = oldValeur.split("#");
				for(var j=0 ; j<tabOld.length ; j++)
				{
					if(parseInt(tabOld[j]) == valeur)
					{
						retour = false;
					}
				}
			}
			if(retour)
			{
				//On concatène l'ancienne valeur avec la nouvelle, puis on tri
				var newValeur = oldValeur + valeur + "#";
				var tabNew = newValeur.split("#");
				tabNew.sort(tri_nombres);
				var contentCookie = "";
				for(var i=0 ; i<tabNew.length ; i++)
				{
					contentCookie = contentCookie + tabNew[i] + "#";
				}
				//Initialisation de la durée du cookie à 1 an
				var expires = new Date;
				expires.setFullYear(expires.getFullYear()+1);
				
				//Tous le site
				var path = null;
				
				//Le domaine courant
				var domain = null;
				
				//Pas de sécurité
				var secure = false;
				
				//Ecriture du cookie
				document.cookie = nameCookie + "=" + escape(contentCookie) + ((expires==null) ? "" : ("; expires=" + expires.toGMTString())) + ((path==null) ? "" : ("; path="+path)) + ((domain==null) ? "" : ("; domain="+domain)) + ((secure==true) ? "; secure" : "");
				
				//On lis le cookie pour réafficher les marques-page
				showMP(nameCookie);				
	
				//On enregistre la stat d'ajout du marque-page
				valeur = parseInt(valeur);
				if(valeur != 1 && valeur != GcatTotalPages && Gformat == "portrait")
				{
					valeur = valeur.toString() + " - " + (valeur + 1);	
				}
				saveStat("marquepage", valeur)
			}
			else
			{
				//ajaxGetTradAlert("Ce marque-page existe déjà.");
			}
		break;
			
		case "remove":
			if(confirm("Etes-vous sur de vouloir effacer ce marque-page ?"))
			{
				var contentCookie = "";
				var tabOld = oldValeur.split("#");
				for(var k=0 ; k<tabOld.length ; k++)
				{
					if(parseInt(tabOld[k]) != valeur)
					{
						contentCookie = contentCookie + tabOld[k] + "#";	
					}
				}
				//Initialisation de la durée du cookie à 1 an
				var expires = new Date;
				expires.setFullYear(expires.getFullYear()+1);
				//Tous le site
				var path = null;
				//Le domaine courant
				var domain = null;
				//Pas de sécurité
				var secure = false;
				//Ecriture du cookie
				document.cookie = nameCookie + "=" + escape(contentCookie) + ((expires==null) ? "" : ("; expires=" + expires.toGMTString())) + ((path==null) ? "" : ("; path="+path)) + ((domain==null) ? "" : ("; domain="+domain)) + ((secure==true) ? "; secure" : "");
				//On lis le cookie pour réafficher les marques-page
				showMP(nameCookie);
			}
		break;
	}
}


//Fonctions permettant de lire le cookie
function getCookieVal(offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr)); 
}
function readCookie(nameCookie)
{
	var arg = nameCookie + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) return getCookieVal(j);
		i = document.cookie.indexOf(" ",i) + 1;
		if (i == 0) break;
	}
	return null; 
}


//Fonction de d'ajout d'un marque page
function addMP(page)
{
	var nameCookie = "e-motionbook-mp-" + GnameCat;
	//var numPage = document.getElementById("numPageGauche").innerHTML;
	if(page == "gauche")
	{
		numPage = GcurrentPage;
	}
	else
	{
		if(GcurrentPage != 1)
		{
			numPage = GcurrentPage+1;	
		}
		else
		{
			numPage = 1;	
		}
	}
	/*if(numPage == 0)
	{
		numPage = 1;	
	}
	else
	{
		numPage = parseInt(numPage.replace(" - ",""));
	}*/
	
	//On écrit dans le cookie
	writeCookieMP(nameCookie,numPage,"add");
}


//Fonction d'affichage des marques pages en fonction du cookie
function showMP()
{
	if(GisAdmin != "true")
	{
		//if(document.getElementById("blockTools").style.display != "none")
		//{
			var retourGauche = "";
			var retourDroite = "";
			
			numPage = GcurrentPage;
			
			/*var numPage = document.getElementById("numPageGauche").innerHTML;
		
			if((numPage == 0 )||(numPage==""))
			{
				numPage = 1;	
			}
			else
			{
				numPage = parseInt(numPage.replace(" - ",""));	
			}*/
			
			if(!GnameCat.match("^e-motionbook-mp-"))
			{
				var nameCookie = "e-motionbook-mp-" + GnameCat;
			}
			else
			{
				var nameCookie = GnameCat;
			}
			
			var tabMP = readCookie(nameCookie);
			if(tabMP)
			{
				var marquesPage = tabMP.split("#");
				for(var i=0 ; i<marquesPage.length ; i++)
				{
					if(marquesPage[i] != "")
					{
						var titleIMG = "";
						switch(GmaLangue)
						{
							case "fr":
								titleIMG = "Supprimer ce marque-page";
							break;
							
							case "en":
								titleIMG = "Remove this bookmark";
							break;
							
							case "it":
								titleIMG = "Cancella questo segnapagina";
							break;
							
							case "nl":
								titleIMG = "Deze pagina markering deleten";
							break;
							
							case "es":
								titleIMG = "eliminar este marcapáginas";
							break;
							
							default:
								alert("Erreur de langue !");
							break;
						}
						
						var width = "12";
						var height = "13";
						
						//Portrait
						if (Gformat == "portrait")
						{
							if (marquesPage[i] > numPage)
							{
								retourDroite = retourDroite + "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class=\"tabMPD\"><tr><td><a href=\"javascript:void(0);\" onclick=\"writeCookieMP('" + nameCookie + "'," + marquesPage[i] + ",'remove');\"><img src=\"images/efe/mp-gauche.png\" alt=\"" + titleIMG + "\" title=\"" + titleIMG + "\" height=\"" + height + "\" width=\"" + width + "\" /></a></td>";
								retourDroite = retourDroite + "<td class=\"txtMP\"><a href=\"javascript:void(0);\" onclick=\"changePage('miniAndSearch'," + marquesPage[i] + ",'" + GnameCat + "');\">" + marquesPage[i] + "</a></td></tr></table>";
							}
							else
							{
								retourGauche = retourGauche + "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class=\"tabMPG\"><tr><td><a href=\"javascript:void(0);\" onclick=\"writeCookieMP('" + nameCookie + "'," + marquesPage[i] + ",'remove');\"><img src=\"images/efe/mp-gauche.png\" alt=\"" + titleIMG + "\" title=\"" + titleIMG + "\" height=\"" + height + "\" width=\"" + width + "\" /></a></td>";
								retourGauche = retourGauche + "<td class=\"txtMP\"><a href=\"javascript:void(0);\" onclick=\"changePage('miniAndSearch'," + marquesPage[i] + ",'" + GnameCat + "');\">" + marquesPage[i] + "</a></td></tr></table>";
							}					
						}
						else //Paysage
						{
							retourDroite = retourDroite + "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class=\"tabMPD\"><tr><td><a href=\"javascript:void(0);\" onclick=\"writeCookieMP('" + nameCookie + "'," + marquesPage[i] + ",'remove');\"><img src=\"images/efe/mp-gauche.png\" alt=\"" + titleIMG + "\" title=\"" + titleIMG + "\" height=\"" + height + "\" width=\"" + width + "\" /></a></td>";
								retourDroite = retourDroite + "<td class=\"txtMP\"><a href=\"javascript:void(0);\" onclick=\"changePage('miniAndSearch'," + marquesPage[i] + ",'" + GnameCat + "');\">" + marquesPage[i] + "</a></td></tr></table>";
						}
					}
				}
				document.getElementById("mpG").innerHTML = retourGauche;
				document.getElementById("mpD").innerHTML = retourDroite;
		//	}
		}
	}
}

function getAllMP()
{
	if(GisAdmin != "true")
	{
		
			if(!GnameCat.match("^e-motionbook-mp-"))
			{
				var nameCookie = "e-motionbook-mp-" + GnameCat;
			}
			else
			{
				var nameCookie = GnameCat;
			}
			
			var tabMP = readCookie(nameCookie);
			if(tabMP)
			{
				var marquesPage = tabMP.split("#");
				
				var outputHtml = "<ul>";
				
				for(var i=0 ; i<marquesPage.length ; i++)
				{
					if(marquesPage[i] != "")
					{
						outputHtml += '<li><a href="javascript:void(0);" onclick="changePage(\'miniAndSearch\','+marquesPage[i]+');hideMPList();return false;"><img src="imagesPageFlip/'+GnameCat+'/'+GnamePage+"-"+marquesPage[i]+'.png" alt="page '+marquesPage[i]+'" /><br  /><span class="num-page-center">'+marquesPage[i]+'</span></a></li>';
					}
				}
				outputHtml += "</ul>";
				//alert(document.getElementById("conteneurPrincipal").offsetLeft); 
				;
				//var position = $("#conteneurPrincipal").offset();
				//var positionmask = $("#mask").offset();
				
				document.getElementById("mask").style.width = $(window).width()+"px";
				document.getElementById("mask").style.height = $(window).height()+"px";
				document.getElementById("mask").style.left = "-"+maskPosition.left+"px";
				document.getElementById("mask").style.top = "-"+maskPosition.top+"px";
				document.getElementById("mask").style.visibility = "visible";
				document.getElementById("mp-list").style.visibility = "visible";
				document.getElementById("mp-list-content").innerHTML = outputHtml;
			}
			else
			{
				var alerttxt = "";
					switch(GmaLangue)
					{
						case "fr":
							alerttxt = "pas de marque-pages";
						break;
						
						case "en":
							alerttxt = "no bookmark";
						break;
						
						case "it":
							alerttxt = "no bookmark";
						break;
						
						case "nl":
							alerttxt = "no bookmark";
						break;
						
						case "es":
							alerttxt = "no hay marcapáginas";
						break;
						
						default:
							alert("Erreur de langue !");
						break;
					}
				alert(alerttxt);	
			}
	}
}

function getAllMPinArray()
{
	if(GisAdmin != "true")
	{
			var aMp = new Array();
			if(!GnameCat.match("^e-motionbook-mp-"))
			{
				var nameCookie = "e-motionbook-mp-" + GnameCat;
			}
			else
			{
				var nameCookie = GnameCat;
			}
			
			var tabMP = readCookie(nameCookie);
			if(tabMP)
			{
				var marquesPage = tabMP.split("#");
				
				for(var i=0 ; i<marquesPage.length ; i++)
				{
					if(marquesPage[i] != "")
					{
						aMp.push(marquesPage[i]);
					}
				}
				return aMp;
			}
			else
			{
				var alerttxt = "";
					switch(GmaLangue)
					{
						case "fr":
							alerttxt = "pas de marque-pages";
						break;
						
						case "en":
							alerttxt = "no bookmark";
						break;
						
						case "it":
							alerttxt = "no bookmark";
						break;
						
						case "nl":
							alerttxt = "no bookmark";
						break;
						
						case "es":
							alerttxt = "no hay marcapáginas";
						break;
						
						default:
							alert("Erreur de langue !");
						break;
					}
				alert(alerttxt);	
				return false;
			}
	}
}

function printMP()
{
	var aMPList  = new Array();
	var nZero    = GcatTotalPages.length;
	var initPage = "";
	var GoodSelect = "";
	
	for(var i = 0; i<nZero; i++)
	{
		initPage+= "0";	
	}
	
	if(!GnameCat.match("^e-motionbook-mp-"))
	{
		var nameCookie = "e-motionbook-mp-" + GnameCat;
	}
	else
	{
		var nameCookie = GnameCat;
	}
	
	var tabMP = readCookie(nameCookie);
	if(tabMP)
	{
		var marquesPage = tabMP.split("#");
		var nMP         = marquesPage.length;
		for(var j=0; j<nMP; j++)
		{
			if(marquesPage[j] != "")
			{
				var tmpPage = initPage+marquesPage[j].toString();
				tmpPage     = tmpPage.substring(tmpPage.length - 3, tmpPage.length);
				aMPList.push(tmpPage);
				/*if(marquesPage[j] != 1)
				{
					tmpPage = initPage+(parseInt(marquesPage[j])+1).toString();
					tmpPage = tmpPage.substring(tmpPage.length - 3, tmpPage.length);
					aMPList.push(tmpPage);
				}*/
			}
		}
		GoodSelect = aMPList.join("-");
		ajaxGetMyPDF("selection",GoodSelect);	
	}
	
	
	
}

function addSearchToMp()
{
	//alert(aPages);
	var txtConfirm = "";
	var txtAlert   = "";
	switch(GmaLangue)
	{
		case "fr":
			txtConfirm = "Êtes-vous sur de vouloir ajouter l'ensemble de ces pages à vos marques-pages ?";
			txtAlert   = "Pages ajoutées dans les marques pages";
		break;
		
		case "en":
			txtConfirm = "Do you really want to add theses pages to your bookmarks ?";
			txtAlert   = "Pages succefully added to your bookmarks";
		break;
		
		case "it":
			txtConfirm = "Do you really want to add theses pages to your bookmarks ?";
			txtAlert   = "Pages succefully added to your bookmarks";
		break;
		
		case "nl":
			txtConfirm = "Do you really want to add theses pages to your bookmarks ?";
			txtAlert   = "Pages succefully added to your bookmarks";
		break;
		
		case "es":
			txtConfirm = "¿Está seguro de que desea añadir todas las páginas a sus marcapáginas?";
			txtAlert   = "Páginas adjuntadas a su marcapágina";
		break;
		
		default:
			alert("Erreur de langue !");
		break;
	}
	
	if(confirm(txtConfirm))
		{
		var nameCookie = "e-motionbook-mp-" + GnameCat;
		for(var i = 0; i<aPages.length; i++)
		{
			
			writeCookieMPSilent(nameCookie,aPages[i],"add");	
		}
		
		
		
		alert(txtAlert);
	}
}

function getPostit()
{
	//	e-motionbook-pi-efe2010ra	
	if(!GnameCat.match("^e-motionbook-pi-"))
	{
		var nameCookie = "e-motionbook-pi-" + GnameCat;
	}
	else
	{
		var nameCookie = GnameCat;
	}
	
	var tabMP = readCookie(nameCookie);
	//alert(tabMP);
}


//Fonction permettant d'afficher l'anim de loading
function afficheLoading()
{
	var so = new SWFObject("loading.swf", "animloading", "808", "571", "9", "#ffffff");
	so.addParam("quality","High");
	so.addParam("wmode", "transparent");
	so.write("contenuBas");
}


//Fonction appelé depuis le petit flash, permettant de bouger le grand flash quand on drag la cible
function moveCible(xorderPourCent,yorderPourCent)
{
	if(document.getElementById("pageflip"))
	{
		getMovieName("pageflip").movePageFlip(xorderPourCent,yorderPourCent);
	}
}

//Fonction permettant d'ajouter un post-it sur le grand pageflip
function placePostIt()
{
	if(document.getElementById("pageflip"))
	{
		getMovieName("pageflip").placePostIt();
	}
}


//fonction permettant d'afficher les alertes flash
function flashAlert(texte)
{
	alert(texte);
}


//Fonction de d'ajout de pages dans la sÃ©lection
function addSelect()
{
	
	var nameCookie = "e-motionbook-select-" + GnameCat;
	//Portrait
	if (Gformat == "portrait")
	{
		var numPage = document.getElementById("numPageGauche").innerHTML;
	}
	//Paysage
	else
	{
		var numPage = document.getElementById("numPageDroite").innerHTML;
	}	
	if(numPage == 0)
	{
		numPage = 1		
	}
	else
	{
		numPage = parseInt(numPage.replace(" - ",""));	
	}
	
	//On écrit dans le cookie
	writeCookieSelect(nameCookie,numPage);	
}

function writeCookieSelect(nameCookie,valeur)
{
	//On récupère le nombre de pages max
	var numPageMax = parseInt(document.getElementById("pagesTotales").innerHTML);
	
	//On récupère l'ancienne valeur du cookie
	var oldValeur = readCookie(nameCookie);
	
	//On initialise une variable de retour
	var bReturn = true;
	
	if(oldValeur != "" && oldValeur != null)
	{
		//On parse le tableau pour savoir si cette page est déjà présente dans la selection
		var tabOld = oldValeur.split("#");
		for(var i=0 ; i<tabOld.length ; i++)
		{
			if(parseInt(tabOld[i]) == parseInt(valeur))
			{
				//Portrait
				if (Gformat == "portrait")
				{
					ajaxGetTradAlert("Cette double page fait déjà partie de votre sélection.");
				}
				//Paysage
				else
				{
					ajaxGetTradAlert("Cette page fait déjà partie de votre sélection.");
				}
				bReturn = false;
				i = tabOld.length;
			}
		}
	}

	if(bReturn)
	{
		//On concatène l'ancienne valeur avec la nouvelle
		var newValeur = oldValeur + valeur + "#";
		var tabNew = newValeur.split("#");
		
		//On tri ce nouveau tableau de valeurs
		tabNew.sort(tri_nombres);
		
		//init variable contentCookie
		var contentCookie = "";
		
		for(var i=0 ; i<tabNew.length ; i++)
		{
			if (tabNew[i]!="")
			{
				contentCookie = contentCookie + tabNew[i] + "#";
			}
		}
		
		//Initialisation de la durée du cookie à 1 an
		var expires = new Date;
		expires.setFullYear(expires.getFullYear()+1);
		
		//Tous le site
		var path = null;
		
		//Le domaine courant
		var domain = null;
		
		//Pas de sécurité
		var secure = false;
		
		//Ecriture du cookie
		document.cookie = nameCookie + "=" + escape(contentCookie) + ((expires==null) ? "" : ("; expires=" + expires.toGMTString())) + ((path==null) ? "" : ("; path="+path)) + ((domain==null) ? "" : ("; domain="+domain)) + ((secure==true) ? "; secure" : "");
		
		switch(GmaLangue)
		{
			case "fr":
				if (Gformat == "portrait")
				{
					alert("Cette double page a correctement été ajouté à votre sélection.");
				}
				else
				{
					alert("Cette page a correctement été ajouté à votre sélection.");
				}
			break;
			case "en":
				if (Gformat == "portrait")
				{
					alert("This double-page was successfully added to your selection.");
				}
				else
				{
					alert("This page was successfully added to your selection.");
				}
			break;
			case "it":
				if (Gformat == "portrait")
				{
					alert("Queste due pagine sono state aggiunte alla sua selezione con successo.");
				}
				else
				{
					alert("Questa pagina e stata aggiunta alla sua selezione con successo.");
				}
			break;
			case "nl":
				if (Gformat == "portrait")
				{
					alert("Deze dubbele pagina werd correct aan uw selectie toegevoegd.");
				}
				else
				{
					alert("Deze dubbele pagina werd correct aan uw selectie toegevoegd.");
				}
			break;
		}
		
		//On enregistre la stat de "selection"
		valeur = parseInt(valeur);
		if(valeur != 1 && valeur != GcatTotalPages && Gformat == "portrait")
		{
			valeur = valeur.toString() + " - " + (valeur + 1);	
		}
		saveStat("selection", valeur);
	}
}

function removeSelect()
{
	var txtConfirm = "";
	switch(GmaLangue)
	{
		case "fr":
			//Portrait
			if (Gformat == "portrait")
			{
				txtConfirm = "Etes-vous sûr de vouloir supprimer cette double page de votre sélection ?";
			}
			//Paysage
			else
			{
				txtConfirm = "Etes-vous sûr de vouloir supprimer cette page de votre sélection ?";
			}			
		break;
		
		case "en":
			//Portrait
			if (Gformat == "portrait")
			{
				txtConfirm = "Are you sure you want to remove this double-page from your selection ?";
			}
			//Paysage
			else
			{
				txtConfirm = "Are you sure you want to remove this page from your selection ?";
			}
		break;
		
		case "it":
			//Portrait
			if (Gformat == "portrait")
			{
				txtConfirm = "Sei sicuro di voler eliminare queste due pagine dalla selezione ?";
			}
			//Paysage
			else
			{
				txtConfirm = "Sei sicuro di voler eliminare questa pagina dalla selezione ?";
			}
		break;
		
		case "nl":
			//Portrait
			if (Gformat == "portrait")
			{
				txtConfirm = "Deze dubbele pagina is correct aan uw selectie toegevoegd ?";
			}
			//Paysage
			else
			{
				txtConfirm = "Deze dubbele pagina is correct aan uw selectie toegevoegd ?";
			}			
		break;
		
		default:
			alert("Erreur de langue !");
		break;
	}
	
	if(confirm(txtConfirm))
	{
		// nom du cookie
		var nameCookie = "e-motionbook-select-" + GnameCat;
		
		// numéro de la page a supprimer
		//Portrait
		if (Gformat == "portrait")
		{
			var numPage = document.getElementById("numPageGauche").innerHTML;
		}
		//Paysage
		else
		{
			var numPage = document.getElementById("numPageDroite").innerHTML;
		}		
		
		// test si la page est la page de garde
		if(numPage==0  || trim(numPage)=="")
		{
			numPage = 1;
		}
		else
		{
			numPage = parseInt(numPage.replace(" - ",""));
		}
			
		//lit le cookie
		var oldValeur = readCookie(nameCookie);
		
		//on cré un tableau des numéro de page
		tabValeurCookie = oldValeur.split("#"); 
		
		//valeur a supprimer dans le cookie
		ValeurAsupprimer = tabValeurCookie[numPage-1];
		
		//on cherche a reformer le contenu du cookie sans la valeur a supprimer
		contentCookie = "";
		for(var k=0 ; k<tabValeurCookie.length ; k++)
		{
			if (tabValeurCookie[k] != "")
			{
				if(parseInt(tabValeurCookie[k])!= ValeurAsupprimer)
				{
					contentCookie = contentCookie + tabValeurCookie[k] + "#";	
				}
			}
		}
		
		//mise à jour du cookie
		//Initialisation de la durée du cookie à  1 an
		var expires = new Date;
		expires.setFullYear(expires.getFullYear()+1);
		//Tous le site
		var path = null;
		//Le domaine courant
		var domain = null;
		//Pas de sécurité
		var secure = false;
		//Ecriture du cookie
		document.cookie = nameCookie + "=" + escape(contentCookie) + ((expires==null) ? "" : ("; expires=" + expires.toGMTString())) + ((path==null) ? "" : ("; path="+path)) + ((domain==null) ? "" : ("; domain="+domain)) + ((secure==true) ? "; secure" : "");

		//on réaffiche notre nouvelle sélection
		ajaxSeeSelect();
	}
}
function effaceCookieSelec()
{
	var txtConfirm = "";
	switch(GmaLangue)
	{
		case "fr":
			txtConfirm = "Etes-vous sûr de vouloir supprimer votre sélection de page dans son intégralité ?";
		break;
		
		case "en":
			txtConfirm = "Are you sure you want to remove all of your page selection ?";
		break;
		
		case "it":
			txtConfirm = "Sei sicuro di voler eliminare tutti gli elementi selezionati ?";
		break;
		
		case "nl":
			txtConfirm = "Wenst u uw volledige selectie te deleten ?";
		break;
		
		default:
			alert("Erreur de langue !");
		break;
	}
	
	if(confirm(txtConfirm))
	{
		//Création du nom du cookie
		var nameCookie = "e-motionbook-select-" + GnameCat;
		
		//On cré une variable vide
		var contentCookie = "";
		
		//Initialisation de la durée du cookie  1 an
		var expires = new Date;
		expires.setFullYear(expires.getFullYear()+1);
		//Tous le site
		var path = null;
		//Le domaine courant
		var domain = null;
		//Pas de sécurité
		var secure = false;
		//Ecriture du cookie
		document.cookie = nameCookie + "=" + escape(contentCookie) + ((expires==null) ? "" : ("; expires=" + expires.toGMTString())) + ((path==null) ? "" : ("; path="+path)) + ((domain==null) ? "" : ("; domain="+domain)) + ((secure==true) ? "; secure" : "");	

		//On reload la page dans sont état initial
		window.location.reload();
	}
}

//Fonction permettant de rabattre les angles du pageflip
function closeCorners()
{
	/*if(document.getElementById("contenuBas") && document.getElementById("pageflip"))
	{*/
		/*if(document.getElementById("contenuBas").style.display=="block" && document.getElementById("pageflip") && GcanCloseCorners)
		{*/
		if(document.getElementById("pageflip") && GcanCloseCorners)
		{
			try 
			{
				getMovieName("pageflip").flashCloseCorners();
				//getMovieName("pageflip").focus();
			}
			catch (erreur)
			{
				//alert(erreur);
			}
		}
	//}
}

//Fonction permettant de changer la source des images pour over
function imgOver(imgSRC)
{
	if(imgSRC.indexOf("over") == -1)
	{
		//L'image n'est pas en mode over, on la met en mode over
		var newImgSRC = imgSRC.replace(".png","-over.png");
	}
	else
	{
		//L'image est en mode over, on la met en mode normal
		var newImgSRC = imgSRC.replace("-over.png",".png");
	}
	
	return newImgSRC;
}

//Fonction permettant d'ouvrir un pop-up centré dans l'écran
function popupCentrer(page,largeur,hauteur) 
{
	var top = (screen.height-hauteur)/2;
	var left = (screen.width-largeur)/2;
	window.open(page,"","top=" + top + ",left=" + left + ",width=" + largeur + ",height = "+ hauteur + ",menubar=no, status=no, scrollbars=no");
}

//Fonction permettant de changer le contenu de la partie navigation (vignettes, sommaire)
function changeNavig(onglet)
{
	switch(onglet)
	{
		case "vignettes":
			document.getElementById("sommaire").style.display = "none";
			document.getElementById("vignettes").style.display = "block";
			document.getElementById("blockBtnsNavig1").style.display = "inline";
			document.getElementById("blockBtnsNavig2").style.display = "none";
		break;
		
		case "sommaire":
			document.getElementById("vignettes").style.display = "none";
			document.getElementById("sommaire").style.display = "block";
			document.getElementById("blockBtnsNavig2").style.display = "inline";
			document.getElementById("blockBtnsNavig1").style.display = "none";
		break;
		
		default:
			alert("Erreur fonction \"changeNavig\" !");
		break;
	}
}

//Fonction permettant de revenir sur le catalogue à la page où on était ou sur les résultats
function backTo(what,mode)
{
	switch(what)
	{
		case "catalogue":
			if(mode)
			{
				document.getElementById("contenuBas").style.display = "none";
				document.getElementById("contenuSearch").style.display = "block";
			}
			document.getElementById("backToResults").style.display = "none";
			document.getElementById("backToCat").style.display = "inline";
			
			if(document.getElementById("bandeauHaut").style.visibility == "visible")
			{
				document.getElementById("bandeauHaut").style.visibility = "hidden";
				document.getElementById("numPageGauche").style.visibility = "hidden";
				document.getElementById("numPageDroite").style.visibility = "hidden";
			}
		break;
		
		case "resultats":
			if(mode)
			{
				document.getElementById("contenuSearch").style.display = "none";
				document.getElementById("contenuBas").style.display = "block";
			}
			document.getElementById("backToCat").style.display = "none";
			document.getElementById("backToResults").style.display = "inline";
			
					
			if(document.getElementById("bandeauHaut").style.visibility == "hidden")
			{
				document.getElementById("bandeauHaut").style.visibility = "visible";
				document.getElementById("numPageGauche").style.visibility = "visible";
				document.getElementById("numPageDroite").style.visibility = "visible";
			}
		break;
		
		default:
			alert("Erreur fonction \"backTo()\" !");
		break;
	}
}

//Fonction permettant d'afficher la loupe
function flashShowGlass()
{
	//if(document.getElementById("contenuBas").style.display=="block" && document.getElementById("pageflip"))
	if(document.getElementById("zoneworkbas").style.display=="block" && document.getElementById("pageflip"))
	{
		try 
		{
			getMovieName("pageflip").flashShowGlass();
		}
		catch (erreur)
		{
			//alert(erreur);
		}
	}
}

function showHidePostitMenu()
{
	if(document.getElementById("menu-postit").style.display != "block")
	{
		document.getElementById("menu-postit").style.display = "block";	
	}
	else
	{
		document.getElementById("menu-postit").style.display = "none";
	}
}

function showHideToolsMenu()
{
	if(document.getElementById("menu-outils").style.display != "block")
	{
		document.getElementById("menu-outils").style.display = "block";	
	}
	else
	{
		document.getElementById("menu-outils").style.display = "none";
	}
}

//Fonction permettant d'afficher ou masquer le masque d'impression
function showHideMaskPrint(mode)
{
	if(mode == "show")
	{
		flashZoom("default");
		
		document.getElementById("GmaskPrint").style.visibility = "visible";
		document.getElementById("DmaskPrint").style.visibility = "visible";
		
		if(GcurrentPage == 1)
		//if(parseInt(document.getElementById("numPageDroite").innerHTML) == 1)
		{
			document.getElementById("GmaskPrint").style.visibility = "hidden";
		}
		
		if(GcurrentPage == GcatTotalPages)
		//if(parseInt(document.getElementById("numPageGauche").innerHTML) == parseInt(document.getElementById("pagesTotales").innerHTML))
		{
			document.getElementById("DmaskPrint").style.visibility = "hidden";
		}
		
		document.getElementById("mask").style.visibility = "visible";
		document.getElementById("maskPrint").style.visibility = "visible";
	}
	else
	{
		document.getElementById("GmaskPrint").style.visibility = "hidden";
		document.getElementById("DmaskPrint").style.visibility = "hidden";
		document.getElementById("maskPrint").style.visibility = "hidden";
		document.getElementById("mask").style.visibility = "hidden";
	}
}

//Fonction permettant d'afficher ou masquer le masque des PDFs
function showHideMaskPDFs(mode)
{
	if(GisAdmin != "true")
	{
		if(mode == "show")
		{
			flashZoom("default");
			
			document.getElementById("linkPDFPerso").style.display = "inline";
			document.getElementById("linkPDFnotes").style.display = "inline";
			if(document.getElementById("blockMaSelecFirst").style.display != "none")
			{
				document.getElementById("linkPDFPerso").style.display = "none";	
			}
			else
			{
				document.getElementById("linkPDFnotes").style.display = "none";
			}
			
			document.getElementById("mask").style.visibility = "visible";
			document.getElementById("maskPDFs").style.visibility = "visible";
		}
		else
		{
			document.getElementById("maskPDFs").style.visibility = "hidden";
			document.getElementById("mask").style.visibility = "hidden";
		}
	}
}

//Fonction permettant de changer le catalogue à visionner
function changeCat(nameCat)
{
	window.location = "e-motionbook.php?nameCat=" + nameCat + "&lang=" + GmaLangue;
}

//Fonction permettant de vérifier la présence d'un cookie pour les notes, et de lancer la génération du XML pour la création du PDF avec notes
function getMyPDFnotes(type,numsPage)
{
	if(type == "notes")
	{
		//Création du nom du Coookie
		var nameCookie = "e-motionbook-pi-" + GnameCat;
		
		//On va récupérer l'identifiant de la personne dans le Coookie
		var idCookie = readCookie(nameCookie);
		
		if(idCookie != null)
		{
			window.open("mon-pdf.php?type=notes&idCookie=" + idCookie);
		}
		else
		{
			ajaxGetTradAlert("Vous n'avez encore placé aucune note sur le catalogue.");
		}
	}
	
	if(type == "selection")
	{
		window.open("mon-pdf.php?type=selection&numsPage=" + numsPage);
	}
}

//Fonction permettant de créer la chaine de paramètres à envoyer aux fichiers AJAX
function createParametres()
{
	Gparametres = "GnameCat=" + GnameCat + "&GmodeVisu=" + GmodeVisu + "&Gformat=" + Gformat + "&GPDFname=" + GPDFname + "&GcatTotalPages=" + GcatTotalPages + "&GmaLangue=" + GmaLangue + "&GisAdmin=" + GisAdmin + "&GmodeZones=" + GmodeZones;	
}

//Fonction permettant d'afficher ou masquer les menus
function showHideMenu(idMenu,myVisibility)
{
	if(document.getElementById(idMenu))
	{
		document.getElementById(idMenu).style.visibility = myVisibility;
	}	
}

//Fonction permettant de visionner un swf, en mode norma ou en mode zoom
function showMedias(mode, page1, page2, xpos, ypos, myWidth, myHeight, cote, lien)
{
	//On vide le blockMedias
	document.getElementById("blockMedias").innerHTML = "";
	
	var page = GcurrentPage;
	
	if(page != 1 && cote == 'droit')
	{
		page ++;
	}
	
	var coteutilise = cote == "gauche" ? "gauche" : "droite";
	
	var constLink = "<a href='javascript:void(0);' onclick='addMP(\""+coteutilise+"\");return false;' style='color:#000; text-decoration:none;margin-left:10px;' title=''><img src='images/efe/marque-page_"+GmaLangue+".png' alt='Marquer cette page'/></a><a href='javascript:void(0);' onclick='getMovieName(\"pageflip\").flashPrintPage("+page+", false);return false;' style='color:#000; text-decoration:none;margin-left:10px;' title=''><img src='images/efe/imprimer_"+GmaLangue+".png' alt='Imprimer cette page'/></a>";
	
	switch(mode)
	{
		case "zoom":
			//On affiche le zoom
			var so = new SWFObject("show-medias.swf", "showmedias", "820", "510", "9", "#cccccc");
			so.addParam("quality","High");
			so.addVariable("modeShow","zoom");
			so.addVariable("URLpage1",page1);
			so.addVariable("URLpage2",page2);
			so.addVariable("showX",xpos);
			so.addVariable("showY",ypos);
			so.addVariable("showWidth",myWidth);
			so.addVariable("showHeight",myHeight);
			so.addVariable("showCote",cote);
			so.addVariable("format",Gformat);
			so.write("blockMedias");
			
			//tb_show('Zoom','e-motionbook.php#TB_inline?width=820&height=510&inlineId=blockMedias',false);
			
			//Si on a un lien à afficher
			if(lien != "")
			{
				//Hack spécial mail
				if(lien.indexOf("mailto:") == 0)
				{
					lien = "<a href=\"" + lien + "\" target=\"_blank\" style=\"color:#000; text-decoration:none;\">" + lien.replace( "mailto:", "") + "</a>"
				}
				else
				{
					lien = "<a href=\"" + lien + "\" target=\"_blank\" style=\"color:#000; text-decoration:none;\" title=\"S'inscrire\"><img src='images/efe/s-inscrire_"+GmaLangue+".png' alt=''/></a>"
				}
				
				tb_show(lien+constLink, 'e-motionbook.php#TB_inline?width=820&height=510&inlineId=blockMedias', false);
			}
			else
			{
				//C'est un zoom standard	
				//tb_show('Zoom','e-motionbook.php#TB_inline?width=820&height=510&inlineId=blockMedias',false);
				tb_show(constLink,'e-motionbook.php#TB_inline?width=820&height=510&inlineId=blockMedias',false);
			}
		break;
		
		case "media":
			//On affiche le media
			var so = new SWFObject("show-medias.swf", "showmedias", "820", "510", "9", "#cccccc");
			so.addParam("quality","High");
			so.addVariable("modeShow","normal");
			so.addVariable("URLpage1",page1);
			so.addVariable("URLpage2",false);
			so.addVariable("showX",false);
			so.addVariable("showY",false);
			so.addVariable("showWidth",false);
			so.addVariable("showHeight",false);
			so.addVariable("showCote",false);
			so.addVariable("format",false);
			so.write("blockMedias");
			
			tb_show(constLink,'e-motionbook.php#TB_inline?width=820&height=510&inlineId=blockMedias',false);
		break;
		
		default:
			alert("Erreur fonction \"showSWFs()\" !!!");
		break;
	}
}

//Fonction permettant d'aficher ou masquer les dessins
function showHideDrawnings(action)
{
	switch(action)
	{
		case "show":
			document.getElementById("showDrawnings").style.display = "none";
			document.getElementById("hideDrawnings").style.display = "inline";
		break;
		
		case "hide":
			document.getElementById("hideDrawnings").style.display = "none";
			document.getElementById("showDrawnings").style.display = "inline";
		break;
		
		default:
			alert("Erreur fonction \"showHideDrawnings()\" !");
		break;
	}
	
	getMovieName("pageflip").flashShowHideDrawnings(action);
}

function hidePostitList()
{
	document.getElementById("mask").style.visibility = "hidden";
	document.getElementById("postit-list").style.visibility = "hidden";
	document.getElementById("postit-list-content").innerHTML = "";
}

function hideMPList()
{
	document.getElementById("mask").style.visibility = "hidden";
	document.getElementById("mp-list").style.visibility = "hidden";
	document.getElementById("mp-list-content").innerHTML = "";
}

function hideSearchResults()
{
	document.getElementById("mask").style.visibility = "hidden";
	document.getElementById("search-results").style.visibility = "hidden";
	document.getElementById("search-results-content").innerHTML = "";
}

function showsubmenu(num)
{
	if(submenuPrevOpen != num)
	{
		closeSubmenu();
		//document.getElementById("sms-"+num).style.display="block";
		if($("#sms-"+num+" ul li").length > 0)
		{
			$("#sms-"+num).slideDown("normal");
			submenuPrevOpen = num;
		}
		else
		{
			submenuPrevOpen = -1;	
		}
	}
	else
	{
		closeSubmenu();
		submenuPrevOpen = -1;
	}
}

function closeSubmenu()
{
	if(submenuPrevOpen != -1)
	{
		$("#sms-"+submenuPrevOpen).slideUp("normal");
		//document.getElementById("sms-"+submenuPrevOpen).style.display="none";	
	}
}

function tb_show_mask(){
	
	var txtWait = "";
	switch(GmaLangue)
	{
		case "fr":
			txtWait = "Merci de patienter quelques instants...";
		break;
		
		case "en":
			txtWait = "Please wait...";
		break;
		
		case "it":
			txtWait = "Please wait...";
		break;
		
		case "nl":
			txtWait = "Please wait...";
		break;
		
		case "es":
			txtWait = "Por favor, espere un momento…";
		break;
		
		default:
			alert("Erreur de langue !");
		break;
	}
	
	if(document.getElementById("TB_window"))
	{
		document.getElementById("TB_window").style.display = "none";
	}
	if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
		$("body","html").css({height: "100%", width: "100%"});
		$("html").css("overflow","hidden");
		if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
			$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
		}
	}else{//all others
		if(document.getElementById("TB_overlay") === null){
			$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
		}
	}
	
	if(tb_detectMacXFF()){
		$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
	}else{
		$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
	}


	$("body").append("<div id='TB_load'><img src='images/loading3.gif' /><div style=\"color:#FFF; margin:10px 0 0 0;\">"+txtWait+"</div></div>");//add loader to the page
	$('#TB_load').show();//show loader
}
