/*********************************************************************************************************/
// Fonction pour la confirmation d'action
// NB : pensez à addslashes les quotes \' dans le texte du message
// exemple d'uilisation : <a href="javascript:securit('Etes vous sur de vouloir supprimer le thème <?php echo addslashes($theme_nom); ?> ?','theme1.php?theme_id=<?php echo "$theme_id"; ?>&action=supprimer');">
function securit(message,action)
{

	if(confirm(message))
		window.location = action;
		

}
/*********************************************************************************************************/


/*********************************************************************************************************/
// fonction des vérification du nom de fichier dans un formulaire
// Utilisation : <form method="post" action="fileaction.php" enctype="multipart/form-data" onSubmit="return testnomfile(this.nomchampsfile)" >
function testnomfile(fichier) {
	
	
	//if(fichier.value=="") { alert('Le fichier est vide !');fichier.focus();return false }
	

	if (navigator.appVersion.indexOf("Mac",0)>0)
	{
			//alert("C'est un MAC");
			
			// TEST du nom de fichier pour MAC
			var chaine = fichier.value;
			
			var tableau=chaine.split("/");
		
			var num = tableau.length-1;
			
			for(i = 0; i < tableau[num].length; i++) 
			{
				if ((tableau[num].substr(i,1) != "a") && (tableau[num].substr(i,1) != "b") && (tableau[num].substr(i,1) != "c") && 
					(tableau[num].substr(i,1) != "d") && (tableau[num].substr(i,1) != "e") && (tableau[num].substr(i,1) != "f") &&
					(tableau[num].substr(i,1) != "g") && (tableau[num].substr(i,1) != "h") && (tableau[num].substr(i,1) != "i") &&
					(tableau[num].substr(i,1) != "j") && (tableau[num].substr(i,1) != "k") && (tableau[num].substr(i,1) != "l") &&
					(tableau[num].substr(i,1) != "m") && (tableau[num].substr(i,1) != "n") && (tableau[num].substr(i,1) != "o") &&
					(tableau[num].substr(i,1) != "p") && (tableau[num].substr(i,1) != "q") && (tableau[num].substr(i,1) != "r") &&
					(tableau[num].substr(i,1) != "s") && (tableau[num].substr(i,1) != "t") && (tableau[num].substr(i,1) != "u") &&
					(tableau[num].substr(i,1) != "v") && (tableau[num].substr(i,1) != "w") && (tableau[num].substr(i,1) != "x") &&
					(tableau[num].substr(i,1) != "y") && (tableau[num].substr(i,1) != "z") && (tableau[num].substr(i,1) != "A") &&
					(tableau[num].substr(i,1) != "B") && (tableau[num].substr(i,1) != "C") && (tableau[num].substr(i,1) != "D") &&
					(tableau[num].substr(i,1) != "E") && (tableau[num].substr(i,1) != "F") && (tableau[num].substr(i,1) != "G") &&
					(tableau[num].substr(i,1) != "H") && (tableau[num].substr(i,1) != "I") && (tableau[num].substr(i,1) != "J") &&
					(tableau[num].substr(i,1) != "K") && (tableau[num].substr(i,1) != "L") && (tableau[num].substr(i,1) != "M") && 
					(tableau[num].substr(i,1) != "N") && (tableau[num].substr(i,1) != "O") && (tableau[num].substr(i,1) != "P") &&
					(tableau[num].substr(i,1) != "Q") && (tableau[num].substr(i,1) != "R") && (tableau[num].substr(i,1) != "S") &&
					(tableau[num].substr(i,1) != "T") && (tableau[num].substr(i,1) != "U") && (tableau[num].substr(i,1) != "V") &&
					(tableau[num].substr(i,1) != "W") && (tableau[num].substr(i,1) != "X") && (tableau[num].substr(i,1) != "Y") &&
					(tableau[num].substr(i,1) != "Z") && (tableau[num].substr(i,1) != "0") && (tableau[num].substr(i,1) != "1") &&
					(tableau[num].substr(i,1) != "2") && (tableau[num].substr(i,1) != "3") && (tableau[num].substr(i,1) != "4") &&
					(tableau[num].substr(i,1) != "5") && (tableau[num].substr(i,1) != "6") && (tableau[num].substr(i,1) != "7") &&
					(tableau[num].substr(i,1) != "8") && (tableau[num].substr(i,1) != "9") && (tableau[num].substr(i,1) != "-") &&
					(tableau[num].substr(i,1) != "_") && (tableau[num].substr(i,1) != ".") && (tableau[num].substr(i,1) != " ") &&
					(tableau[num].substr(i,1) != "\\") && (tableau[num].substr(i,1) != ":") && (tableau[num].substr(i,1) != "/")
					)
				{
					alert('Le nom du fichier est incorrect !');fichier.focus();return false
				}
				
			}//fin du for test nom de fichier

	}//fin de test si mac
	else
	{
		//alert("Ce n'est pas un MAC");
	
		// TEST du nom di fichier pour window
		var chaine = fichier.value;
		
		var tableau=chaine.split("\\");
	
		var num = tableau.length-1;
		
		for(i = 0; i < tableau[num].length; i++) 
		{
			if ((tableau[num].substr(i,1) != "a") && (tableau[num].substr(i,1) != "b") && (tableau[num].substr(i,1) != "c") && 
				(tableau[num].substr(i,1) != "d") && (tableau[num].substr(i,1) != "e") && (tableau[num].substr(i,1) != "f") &&
				(tableau[num].substr(i,1) != "g") && (tableau[num].substr(i,1) != "h") && (tableau[num].substr(i,1) != "i") &&
				(tableau[num].substr(i,1) != "j") && (tableau[num].substr(i,1) != "k") && (tableau[num].substr(i,1) != "l") &&
				(tableau[num].substr(i,1) != "m") && (tableau[num].substr(i,1) != "n") && (tableau[num].substr(i,1) != "o") &&
				(tableau[num].substr(i,1) != "p") && (tableau[num].substr(i,1) != "q") && (tableau[num].substr(i,1) != "r") &&
				(tableau[num].substr(i,1) != "s") && (tableau[num].substr(i,1) != "t") && (tableau[num].substr(i,1) != "u") &&
				(tableau[num].substr(i,1) != "v") && (tableau[num].substr(i,1) != "w") && (tableau[num].substr(i,1) != "x") &&
				(tableau[num].substr(i,1) != "y") && (tableau[num].substr(i,1) != "z") && (tableau[num].substr(i,1) != "A") &&
				(tableau[num].substr(i,1) != "B") && (tableau[num].substr(i,1) != "C") && (tableau[num].substr(i,1) != "D") &&
				(tableau[num].substr(i,1) != "E") && (tableau[num].substr(i,1) != "F") && (tableau[num].substr(i,1) != "G") &&
				(tableau[num].substr(i,1) != "H") && (tableau[num].substr(i,1) != "I") && (tableau[num].substr(i,1) != "J") &&
				(tableau[num].substr(i,1) != "K") && (tableau[num].substr(i,1) != "L") && (tableau[num].substr(i,1) != "M") && 
				(tableau[num].substr(i,1) != "N") && (tableau[num].substr(i,1) != "O") && (tableau[num].substr(i,1) != "P") &&
				(tableau[num].substr(i,1) != "Q") && (tableau[num].substr(i,1) != "R") && (tableau[num].substr(i,1) != "S") &&
				(tableau[num].substr(i,1) != "T") && (tableau[num].substr(i,1) != "U") && (tableau[num].substr(i,1) != "V") &&
				(tableau[num].substr(i,1) != "W") && (tableau[num].substr(i,1) != "X") && (tableau[num].substr(i,1) != "Y") &&
				(tableau[num].substr(i,1) != "Z") && (tableau[num].substr(i,1) != "0") && (tableau[num].substr(i,1) != "1") &&
				(tableau[num].substr(i,1) != "2") && (tableau[num].substr(i,1) != "3") && (tableau[num].substr(i,1) != "4") &&
				(tableau[num].substr(i,1) != "5") && (tableau[num].substr(i,1) != "6") && (tableau[num].substr(i,1) != "7") &&
				(tableau[num].substr(i,1) != "8") && (tableau[num].substr(i,1) != "9") && (tableau[num].substr(i,1) != "-") &&
				(tableau[num].substr(i,1) != "_") && (tableau[num].substr(i,1) != ".") && (tableau[num].substr(i,1) != " ") &&
				(tableau[num].substr(i,1) != "\\") && (tableau[num].substr(i,1) != ":") && (tableau[num].substr(i,1) != "/")
				)
			{
				alert('Le nom du fichier est incorrect !');fichier.focus();return false
			}
			
		}//fin du for test nom de fichier

	}//fin du else test

	return true;
}
/*********************************************************************************************************/



/*********************************************************************************************************/
function MM_preloadImages() { //v3.0
  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 MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
/*********************************************************************************************************/


/*********************************************************************************************************/
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
/*********************************************************************************************************/

/*********************************************************************************************************/
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/*********************************************************************************************************/


/*********************************************************************************************************/
function openWin(theURL,winName,features)
{
    newWin = window.open('',winName,features);;
    newWin.document.write("<p align=center>");
    newWin.document.write("<img src=" + theURL + ">");
    newWin.document.write("</p>");
    newWin.document.write("<p align=center>");
    newWin.document.write("<a href=\"JavaScript:window.close()\">Fermer la fenêtre</a>");
    newWin.document.write("</p>");
}
/*********************************************************************************************************/




/*********************************************************************************************************/
// JavaScript Document
// This script is (c) copyright 2006 Jim Tucek under the
// GNU General Public License (http://www.gnu.org/licenses/gpl.html)
// For more information, visit www.jracademy.com/~jtucek/email/ 
// Leave the above comments alone!

var decryption_cache = new Array();

function decrypt_string(crypted_string,n,decryption_key,just_email_address) {
	var cache_index = "'"+crypted_string+","+just_email_address+"'";

	if(decryption_cache[cache_index])					// If this string has already been decrypted, just
		return decryption_cache[cache_index];				// return the cached version.

	if(addresses[crypted_string])						// Is crypted_string an index into the addresses array
		var crypted_string = addresses[crypted_string];			// or an actual string of numbers?

	if(!crypted_string.length)						// Make sure the string is actually a string
		return "Error, not a valid index.";

	if(n == 0 || decryption_key == 0) {					// If the decryption key and n are not passed to the
		var numbers = crypted_string.split(' ');			// function, assume they are stored as the first two
		n = numbers[0];	decryption_key = numbers[1];			// numbers in crypted string.
		numbers[0] = ""; numbers[1] = "";				// Remove them from the crypted string and continue
		crypted_string = numbers.join(" ").substr(2);
	}

	var decrypted_string = '';
	var crypted_characters = crypted_string.split(' ');

	for(var i in crypted_characters) {
		var current_character = crypted_characters[i];
		var decrypted_character = exponentialModulo(current_character,n,decryption_key);
		if(just_email_address && i < 7)				// Skip 'mailto:' part
			continue;
		if(just_email_address && decrypted_character == 63)	// Stop at '?subject=....'
			break;
		decrypted_string += String.fromCharCode(decrypted_character);
	}
	
	decryption_cache[cache_index] = decrypted_string;			// Cache this string for any future calls

	return decrypted_string;
}
/*********************************************************************************************************/

/*********************************************************************************************************/
function decrypt_and_email(crypted_string,n,decryption_key) {
	if(!n || !decryption_key) { n = 0; decryption_key = 0; }
	if(!crypted_string) crypted_string = 0;

	var decrypted_string = decrypt_string(crypted_string,n,decryption_key,false);
	parent.location = decrypted_string;
}
/*********************************************************************************************************/

/*********************************************************************************************************/
function decrypt_and_echo(crypted_string,n,decryption_key) {
	if(!n || !decryption_key) { n = 0; decryption_key = 0; }
	if(!crypted_string) crypted_string = 0;

	var decrypted_string = decrypt_string(crypted_string,n,decryption_key,true);
	document.write(decrypted_string);
	return true;
}
/*********************************************************************************************************/

/*********************************************************************************************************/
// Finds base^exponent % y for large values of (base^exponent)
function exponentialModulo(base,exponent,y) {
	if (y % 2 == 0) {
		answer = 1;
		for(var i = 1; i <= y/2; i++) {
			temp = (base*base) % exponent;
			answer = (temp*answer) % exponent;
		}
	} else {
		answer = base;
		for(var i = 1; i <= y/2; i++) {
			temp = (base*base) % exponent;
			answer = (temp*answer) % exponent;
		}
	}
	return answer;
}
/*********************************************************************************************************/

/*********************************************************************************************************/
// Fonction permettant d'afficher une information dans une boite flottante.
// Utilistation : onmouseover="Box.show('TITRE','texte',event);" onmouseout="Box.hide();"
Box = function() { }
Box.__name__ = ["Box"];
Box.Box = null;
Box.showTop = function(title,content,evt) {
	if( (title != '') && (content != '') ) content = "<div class='BoxTitle'>" + title + "</div>" + "<div class='BoxContent'>" + content + "</div>";
	else if( (title == '') && (content != '') )content = "<div class='BoxContent'>" + content + "</div>";
	else if( (title != '') && (content == '') ) content = "<div class='BoxTitle'>" + title + "</div>";
	else content = "";
	document.getElementById("BoxContent").innerHTML = content;
	document.onmousemove = closure(Box,"updateTop");
	document.getElementById("Box").style.display = "block";
	Box.update(evt);
}
Box.show = function(title,content,evt) {
	if( (title != '') && (content != '') ) content = "<div class='BoxTitle'>" + title + "</div>" + "<div class='BoxContent'>" + content + "</div>";
	else if( (title == '') && (content != '') )content = "<div class='BoxContent'>" + content + "</div>";
	else if( (title != '') && (content == '') ) content = "<div class='BoxTitle'>" + title + "</div>";
	else content = "";
	document.getElementById("BoxContent").innerHTML = content;
	document.onmousemove = closure(Box,"update");
	document.getElementById("Box").style.display = "block";
	Box.update(evt);
}
Box.hide = function() {
	document.getElementById("Box").style.display = "none";
	document.onmousemove = null;
}
Box.getMouse = function(e) {
	if(e == null) e = window.event;
	if(e != null)
	{
		if( e.pageX != null) return { x : e.pageX, y : e.pageY}
		else if(e.clientX != null) return { x : e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft, y : e.clientY + document.body.scrollTop + document.documentElement.scrollTop}
	}
	else return { x : null, y : null}
}
Box.update = function(e) {
	var tip = document.getElementById("Box");
	var mouse = Box.getMouse(e);
	var x = (mouse.x - tip.offsetWidth / 2);
	var y = (mouse.y + 20);
	var innerWidth = document.documentElement.clientWidth + document.documentElement.scrollLeft;
	x = (Math.min(x,innerWidth - tip.offsetWidth - 10));
	tip.style.left = x + "px";
	tip.style.top = y + "px";
}
Box.updateTop = function(e) {
	var tip = document.getElementById("Box");
	var mouse = Box.getMouse(e);
	var x = (mouse.x - tip.offsetWidth / 2);
	var y = (mouse.y + 20);
	var innerWidth = document.documentElement.clientWidth + document.documentElement.scrollLeft;
	x = (Math.min(x,innerWidth - tip.offsetWidth - 10));
	tip.style.left = x + "px";
	tip.style.top = (y - 30 - tip.clientHeight) + "px";
}
closure = function(o,f) {
	var m = o[f];
	if(m == null) return null;
	var f1 = function() {
		return m.apply(o,arguments);
	}
	f1.scope = o;
	f1.method = m;
	return f1;
}
/*********************************************************************************************************/
/* Fonction permettant d'afficher un secteur */
/*********************************************************************************************************/
var idtoclose = -1; //variable globale l'id a fermer.

function displaySector(id){
	if($(id).style.display == "none"){
		// Fermeture du secteur ouvert
		if(idtoclose != -1 && idtoclose != id)
		{
			$(idtoclose + '_img').src ="../images/fleche-inactive.gif";
			$(idtoclose + '_lien').style.color = "#668220";
			new Effect.BlindUp(idtoclose);
		}
		
		// Ouverture du secteur
		$(id + '_img').src ="../images/fleche-active.gif";
		$(id + '_lien').style.color = "#F48A04";
		new Effect.BlindDown(id,{duration:0.5}); //ouverture du secteur demandé
		idtoclose = id;
	}
	else{
		$(id + '_img').src ="../images/fleche-inactive.gif";
		$(id + '_lien').style.color = "#668220";
		new Effect.BlindUp(id);
	}
}
/***********************************************************************************************************/
/* Fonction affichant la liste des checkbox (page besoin) */
/**********************************************************************************************************/
function dispCheckboxList(){
	if($('listbesoin').style.display=="none"){
		new Effect.BlindDown('listbesoin',{duration:0.5}); //affichage on pour la liste
		$('dispbuttoncl').src = '../images/fleche_roll.gif'
	}
	else{
		new Effect.BlindUp('listbesoin',{duration:0.5}); //affichage off
		$('dispbuttoncl').src = '../images/fleche.gif';
	}
}

/*********************************************************************************************************/
/* Fonction permettant de masquer la photo d'un bloc, et d'afficher le suivant */
/*********************************************************************************************************/

function change_bloc( bloc_a_masquer, bloc_a_afficher )
{
	// Effet d'ouverture (apparition) :
	//  1 : Flou
	//  2 : Le bloc descend
	//  3 : Le bloc monte
	//  4 : Le bloc s'ouvre vers le bas
	var effet_ouverture = 1;
	
	// Effet de fermeture (disparition) :
	//  1 : Flou
	//  2 : Le bloc monte
	//  3 : Le bloc descend
	//  4 : Le bloc se ferme vers le haut
	var effet_fermeture = 1;
	
	bloc = $(bloc_a_masquer);
	if(bloc.style.display == "none")
	{
		bloc = $(bloc_a_afficher);
		switch ( effet_ouverture )
		{
			case 1 :
				new Effect.Appear(bloc);
				break;
			case 2 :
				new Effect.SlideDown(bloc);
				break;
			case 3 :
				new Effect.ReverseSlideDown(bloc);
				break;
			case 4 :
				new Effect.BlindDown(bloc);
				break;
			default :
				new Effect.Appear(bloc);
		}
	}
	else
	{
		switch ( effet_fermeture )
		{
			case 1 :
				new Effect.Fade(bloc);
				break;
			case 2 :
				new Effect.SlideUp(bloc);
				break;
			case 3 :
				new Effect.ReverseSlideUp(bloc);
				break;
			case 4 :
				new Effect.BlindUp(bloc);
				break;
			default :
				new Effect.Fade(bloc);
		}
		bloc = $(bloc_a_afficher);
		switch ( effet_ouverture )
		{
			case 1 :
				setTimeout("new Effect.Appear(bloc);", 1000);
				break;
			case 2 :
				setTimeout("new Effect.SlideDown(bloc);", 1000);
				break;
			case 3 :
				setTimeout("new Effect.ReverseSlideDown(bloc);", 1000);
				break;
			case 4 :
				setTimeout("new Effect.BlindDown(bloc);", 1000);
				break;
			default :
				setTimeout("new Effect.Appear(bloc);", 1000);
		}
	}
}

