					// Quelques variables

display_form_admin="none"; 	// la variable qui cache / montre le menu administrateur, pour se connecter en admin

opac=new Array();
opac_max=new Array();		// opacité des calques

opacity=100; 			// opacité par défaut des menus, lors de leur affichage
//opac['affiche_photo']=80;
zindex=2; 			// z-index des menus

var inc;			// Variable de temps (setinterval...) pour fadeoutmenu
var inc2;			// idem pour fadeinmenu





function montre(theID){				// fonction du menu déroulant
 if (document.getElementById){
  myID = document.getElementById(theID);
  if (myID.style.display == "none"){		// Si display = caché (none), alors on affiche le morceau du menu correspondant
   myID.style.display = "block";
  }
  else{						// Sinon, on le cache.
   myID.style.display = "none";
  }
 }
}

function montre_photo(theID){			// fonction pour montrer les photos
 if (document.getElementById){
  myID = document.getElementById(theID);
   myID.style.display = "block";
 }
}

function cache_photo(theID){			// fonction pour cacher les photos
 if (document.getElementById){
   myID.style.display = "none";
 }
}



function fadeoutMenu(calque,thephoto) { 
// clearTimeout(inc1);

	if(opac[calque]> 5){
		 if (opac[calque]<5){opac[calque]=5;} // si l'opacité est trop faible, on met à 0
		 else{opac[calque]-=0.2*opac[calque];} // sinon, on met une opacité moins élevée, et on applique
		 if(document.all) document.getElementById(calque).filters.alpha.opacity = opac[calque]; 
		 else document.getElementById(calque).style.MozOpacity = opac[calque]/100; 

		// Puis on relance la fonction

		 menu_tmp=calque;
		 the_photo=thephoto;

		 inc = setTimeout('fadeoutMenu(menu_tmp,the_photo)', 10); 
	} 
	else{ // Si l'opacité =0, alors on cache le calque

//	document.getElementById(calque).style.visibility = "hidden"; 
	clearTimeout(inc);

		if (calque=="affiche_photo"){

			document.getElementById(calque).innerHTML="";
			menu('affiche_photo','addons/affiche_photo.php', thephoto);

		}

	} // if opac>0
} // function

function fadeinMenu(calque) { 

// document.getElementById(calque).style.visibility = "visible"; 


 if(opac[calque]< opac_max[calque]){
 if (opac[calque]>95){opac[calque]=opac_max[calque];} 
 opac[calque]+=0.2*opac[calque]; 
 if(document.all) document.getElementById(calque).filters.alpha.opacity = opac[calque]; 
 else document.getElementById(calque).style.MozOpacity = opac[calque]/100; 

 menu_tmp=calque;

 inc2 = setTimeout('fadeinMenu(menu_tmp)', 10); 

 } 
 else{
//  myElementzoom=document.getElementById("menu"+calque);
//  myElementzoom.innerHTML="";
    clearTimeout(inc2);
 }
}



					//Fonction d'appel d'Ajax


		// La fonction du menu que l'on appelle par : 
		// calque = calque en jeu, généralement le nom du menu
		// contenu : contenu à modifier (ouvre un fichier php du type web2-contenu.php
		// variable : s'il y a lieu (sinon "0") -> ouvre un fichier php avec la variable en get
		
		// Appel d'une fonction XHR.sendAndLoad AJAX que l'on retrouve dans js-ajax.js

function menu(calque,fichier,variable){

		// Création de l'objet
		var XHR = new XHRConnection();		
		// Zone à remplir
		XHR.setRefreshArea(calque);
		// Chargement de la page
		// Natures des paramètres			
		// 	+ string, fichier à charger
		// 	+ string, GET ou POST
		// 	+ ref, nom de la fonction de callBack
		XHR.sendAndLoad(fichier+"?var="+variable, "GET");

		if (calque=="affiche_photo"){
			fadeinMenu('affiche_photo');
		}
		
		return true;

}

					// Fonction qui place le menu sélectionné :

function place_menu(calque){

	if(curX){	// si ce sont les menus

		if(curX<(largeur_ecran*1/2)){

	    pos_menu_x=curX+100+"px";
	    pos_menu_y=curY+30+"px";

		}
		else{

	    pos_menu_x=curX-300+"px";
	    pos_menu_y=curY+30+"px";

		}

	}
	else{

	    pos_menu_x=300+"px";
	    pos_menu_y=100+"px";

	}

	document.getElementById(calque).style.left = pos_menu_x; 
	document.getElementById(calque).style.top = pos_menu_y; 


} // function place_menu






					// Fonction de détermination de position du curseur, redim des calques etc.

/*
	Réalisé par oli.
	http://blog.oli-web.com
*/

var isClicked = false;
var objectToDrag;
var ecartX;
var ecartY;
var curX;
var curY;
var initialHeight;
var initialWidth;
var initialCurX;
var initialCurY;
var theAction;
var minWidth 	= 40;
var minHeight 	= 40;
var thePadding 	= 20;

var _MOVE_ 	= 0;
var _RESIZE_N_ 	= 1;
var _RESIZE_S_ 	= 2;
var _RESIZE_W_ 	= 3;
var _RESIZE_E_ 	= 4;
var _RESIZE_NW_ = 5;
var _RESIZE_NE_ = 6;
var _RESIZE_SW_ = 7;
var _RESIZE_SE_ = 8;

function positionne(p_id, p_posX, p_pos_Y){
	document.getElementById(p_id).style.left = p_posX;
	document.getElementById(p_id).style.top = p_pos_Y;
	document.getElementById(p_id).style.zIndex = 0;
}

function getPositionCurseur(e){
	//ie
	if(document.all){
		curX = event.clientX;
		curY = event.clientY;
	}
	
	//netscape 4
	if(document.layers){
		curX = e.pageX;
		curY = e.pageY;
	}
	
	//mozilla
	if(document.getElementById){
		curX = e.clientX;
		curY = e.clientY;
	}
}

function downAction(p_obj,e){
	isClicked = true;
	objectToDrag = p_obj;
	getPositionCurseur(e);
	ecartX = curX - parseInt(objectToDrag.style.left);
	ecartY = curY - parseInt(objectToDrag.style.top);
	objectToDrag.style.zIndex = 100;
	
	initialWidth = objectToDrag.offsetWidth;
	initialHeight = objectToDrag.offsetHeight;
	initialCurX = curX;
	initialCurY = curY;
	theAction = modifCurseur(p_obj, e);
}

function moveAction(p_obj, e){
	var newPosX;
	var newPosY;

	if(isClicked == true){
		getPositionCurseur(e);
		switch (theAction){
			case _MOVE_ :
				newPosX = curX - ecartX;
				newPosY = curY - ecartY;
				objectToDrag.style.left = newPosX + 'px';
				objectToDrag.style.top = newPosY + 'px';
				break;
			case _RESIZE_N_ :
				resizeByTop(curY);
				break;
			case _RESIZE_S_ :
				resizeByBottom(curY);
				break;
			case _RESIZE_W_ :
				resizeByLeft(curX);
				break;
			case _RESIZE_E_ :
				resizeByRight(curX);
				break;
			case _RESIZE_NW_ :
				resizeByTop(curY);
				resizeByLeft(curX);
				break;
			case _RESIZE_NE_ :
				resizeByTop(curY);
				resizeByRight(curX);
				break;
			case _RESIZE_SW_ :
				resizeByBottom(curY);
				resizeByLeft(curX);
				break;
			case _RESIZE_SE_ :
				resizeByBottom(curY);
				resizeByRight(curX);
				break;
		}
	}else{
		modifCurseur(p_obj, e);
	}
}

function leaveAction(p_obj){
	
	if(p_obj == objectToDrag){
		isClicked = false;
		p_obj.style.zIndex = 0;
	}
}

function modifCurseur(p_obj, e){
	getPositionCurseur(e);
	
	// haut gauche
	if(((curY - parseInt(p_obj.style.top)) < thePadding) &&
		((curX - parseInt(p_obj.style.left)) < thePadding )){
			p_obj.style.cursor = 'nw-resize';
			return _RESIZE_NW_;
		}
	
	// haut droit
	if(((curY - parseInt(p_obj.style.top)) < thePadding) &&
		(((parseInt(p_obj.style.left) +  p_obj.offsetWidth) - curX) < thePadding)){
			p_obj.style.cursor = 'ne-resize';
			return _RESIZE_NE_;
		}
		
	// bas gauche
	if((((parseInt(p_obj.style.top) +  p_obj.offsetHeight) - curY) < thePadding) &&
		((curX - parseInt(p_obj.style.left)) < thePadding )){
			p_obj.style.cursor = 'sw-resize';
			return _RESIZE_SW_;
		}
		
	// bas droit
	if((((parseInt(p_obj.style.top) +  p_obj.offsetHeight) - curY) < thePadding) &&
		(((parseInt(p_obj.style.left) +  p_obj.offsetWidth) - curX) < thePadding)){
			p_obj.style.cursor = 'se-resize';
			return _RESIZE_SE_;
		}
		
	// cote gauche
	if((curX - parseInt(p_obj.style.left)) < thePadding ){
			p_obj.style.cursor = 'w-resize';
			return _RESIZE_W_;
		}
		
	// cote droit
	if(((parseInt(p_obj.style.left) +  p_obj.offsetWidth) - curX) < thePadding){
			p_obj.style.cursor = 'e-resize';
			return _RESIZE_E_;
		}
		
	// haut
	if((curY - parseInt(p_obj.style.top)) < thePadding){
			p_obj.style.cursor = 'n-resize';
			return _RESIZE_N_;
		}
		
	// bas
	if(((parseInt(p_obj.style.top) +  p_obj.offsetHeight) - curY) < thePadding){
			p_obj.style.cursor = 's-resize';
			return _RESIZE_S_;
		}
		
	p_obj.style.cursor = 'move';
	return _MOVE_;
}

function resizeByTop(p_curY){
	var newPosY;
	var newHeight;
	newHeight = (initialHeight + (initialCurY - p_curY));
	if(newHeight > minHeight){
		newPosY = p_curY - ecartY;
		objectToDrag.style.top = newPosY + 'px';
		objectToDrag.style.height = newHeight + 'px';
	}
}

function resizeByBottom(p_curY){
	var newHeight;
	newHeight = (initialHeight - (initialCurY - p_curY));
	if(newHeight > minHeight)
		objectToDrag.style.height = newHeight + 'px';
}

function resizeByLeft(p_curX){
	var newPosX;
	var newWidth;
	newWidth = (initialWidth + (initialCurX - p_curX));
	if(newWidth > minWidth){
		newPosX = p_curX - ecartX;
		objectToDrag.style.left = newPosX + 'px';
		objectToDrag.style.width = newWidth + 'px';
	}
}

function resizeByRight(p_curX){
	var newWidth;
	newWidth = (initialWidth - (initialCurX - p_curX));
	if(newWidth > minWidth)
		objectToDrag.style.width = newWidth + 'px';
}

function fadein(calque) { 

 if(opac[calque]< opacity){
 if (opac[calque]>95){opac[calque]=opacity;} 
 opac[calque]+=0.2*opac[calque]; 
 if(ie5) document.getElementById("menu"+calque).filters.alpha.opacity = opac[calque]; 
 if(ns6) document.getElementById("menu"+calque).style.MozOpacity = opac[calque]/100; 

 menu_tmp=calque;

 inc2 = setTimeout('fadeinMenu(menu_tmp)', 10); 

 } 
}


// + --------------------------------------------------------------------------------------
// + XHRConnection
// + V1.3
// + Thanh Nguyen, http://www.sutekidane.net
// + 20.10.2005
// + http://creativecommons.org/licenses/by-nc-sa/2.0/fr/deed.fr
// + --------------------------------------------------------------------------------------
function XHRConnection() {
	
	// + ----------------------------------------------------------------------------------
	var conn = false;
	var debug = false;
	var datas = new String();
	var areaId = new String();
	// Objet XML
	var xmlObj;
	// Type de comportement au chargement du XML
	var xmlLoad;
	
	// + ----------------------------------------------------------------------------------
	try {
		conn = new XMLHttpRequest();		
	}
	catch (error) {
		if (debug) { alert('Erreur lors de la tentative de création de l\'objet \nnew XMLHttpRequest()\n\n' + error); }
		try {
			conn = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (error) {
			if (debug) { alert('Erreur lors de la tentative de création de l\'objet \nnew ActiveXObject("Microsoft.XMLHTTP")\n\n' + error); }
			try {
				conn = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (error) {
				if (debug) { alert('Erreur lors de la tentative de création de l\'objet \nnew ActiveXObject("Msxml2.XMLHTTP")\n\n' + error); }
				conn = false;
			}
		}
	}

	// + ----------------------------------------------------------------------------------
	// + setDebugOff
	// + Désactive l'affichage des exceptions
	// + ----------------------------------------------------------------------------------
	this.setDebugOff = function() {
		debug = false;
	};

	// + ----------------------------------------------------------------------------------
	// + setDebugOn
	// + Active l'affichage des exceptions
	// + ----------------------------------------------------------------------------------
	this.setDebugOn = function() {
		debug = true;
	};
	
	// + ----------------------------------------------------------------------------------
	// + resetData
	// + Permet de vider la pile des données
	// + ----------------------------------------------------------------------------------
	this.resetData = function() {
		datas = new String();
		datas = '';
	};
	
	// + ----------------------------------------------------------------------------------
	// + appendData
	// + Permet d'empiler des données afin de les envoyer
	// + ----------------------------------------------------------------------------------
	this.appendData = function(pfield, pvalue) {
		datas += (datas.length == 0) ? pfield+ "=" + escape(pvalue) : "&" + pfield + "=" + escape(pvalue);
	};
	
	// + ----------------------------------------------------------------------------------
	// + setRefreshArea
	// + Indique quel elment identifié par id est valoris lorsque l'objet XHR reoit une réponse
	// + ----------------------------------------------------------------------------------
	this.setRefreshArea = function(id) {
		areaId = id;
	};
	
	// + ----------------------------------------------------------------------------------
	// + createXMLObject
	// + Méthode permettant de créer un objet DOM, retourne la réfrence
	// + Inspiré de: http://www.quirksmode.org/dom/importxml.html
	// + ----------------------------------------------------------------------------------
	this.createXMLObject = function() {
		try {
			 	xmlDoc = document.implementation.createDocument("", "", null);
				xmlLoad = 'onload';
		}
		catch (error) {
			try {
				xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
				xmlLoad = 'onreadystatechange ';
			}
			catch (error) {
				if (debug) { alert('Erreur lors de la tentative de création de l\'objet XML\n\n'); }
				return false;
			}
		}
		return xmlDoc;
	}
	
	// + ----------------------------------------------------------------------------------
	// + Permet de définir l'objet XML qui doit être valorisé lorsque l'objet XHR reoit une réponse
	// + ----------------------------------------------------------------------------------
	this.setXMLObject = function(obj) {
		if (obj == undefined) {
				if (debug) { alert('Paramètre manquant lors de l\'appel de la méthode setXMLObject'); }
				return false;
		}
		try {
			//xmlObj = this.createXMLObject();
			xmlObj = obj;
		}
		catch (error) {
				if (debug) { alert('Erreur lors de l\'affectation de l\'objet XML dans la méthode setXMLObject'); }
		}
	}
	
	// + ----------------------------------------------------------------------------------
	// + loadXML
	// + Charge un fichier XML
	// + Entrées
	// + 	xml			String		Le fichier XML à charger
	// + ----------------------------------------------------------------------------------
	this.loadXML = function(xml, callBack) {
		if (!conn) return false;
		// Chargement pour alimenter un objet DOM
		if (xmlObj && xml) {
			if (typeof callBack == "function") {
				if (xmlLoad == 'onload') {
					xmlObj.onload = function() {
						callBack(xmlObj);
					}
				}
				else {
					xmlObj.onreadystatechange = function() {
						if (xmlObj.readyState == 4) callBack(xmlObj)
					}
				}
			}
			xmlObj.load(xml);
			return;
		}		
	}

	// + ----------------------------------------------------------------------------------
	// + sendAndLoad
	// + Connexion à la page désirée avec envoie des données, puis mise en attente de la réponse
	// + Entrées
	// + 	Url			String		L'url de la page à laquelle l'objet doit se connecter
	// + 	httpMode		String		La méthode de communication HTTP : GET, HEAD ou POST
	// + 	callBack		Objet		Le nom de la fonction de callback
	// + ----------------------------------------------------------------------------------
	this.sendAndLoad = function(Url, httpMode, callBack) {
		httpMode = httpMode.toUpperCase();
		conn.onreadystatechange = function() {
			if (conn.readyState == 4 && conn.status == 200) {
				// Si une fonction de callBack a été définie
				if (typeof callBack == "function") {
					callBack(conn);
					return;
				}
				// Si une zone destinée à récupérer le résultat a été définie
				else if (areaId.length > 0){
					try {
						document.getElementById(areaId).innerHTML = conn.responseText;
					}
					catch(error) {
						if (debug) { alert('Echec, ' + areaId + ' n\'est pas un objet valide'); }
					}
					return;
				}
			}
		};
		switch(httpMode) {
			case "GET":
				try {
					Url = (datas.length > 0) ? Url + "?" + datas : Url;
					conn.open("GET", Url);
					conn.send(null);
				}
				catch(error) {
					if (debug) { alert('Echec lors de la transaction avec ' + Url + ' via la méthode GET'); }
					return false;
				}
			break;
			case "POST":
				try {
					conn.open("POST", Url); 
					conn.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
					conn.send(datas);
				}
				catch(error) {
					if (debug) { alert('Echec lors de la transaction avec ' + Url + ' via la mthode POST'); }
					return false;
				}
			break;
			default :
				return false;
			break;
		}
		return true;
	};
	return this;
}
