			
// Ce fichier contient quelques fonctions relatives à l'application DHTML de l'interface utilisateur pour les sites Internet 

var loaded = false; // état de l'appplication (téléchargée ou pas)
var cursec = "";
var menuCourant = "";
var bw = lib_bwcheck();

var attributMenuDefault = new Array();
attributMenuDefault["CouleurAvantPlan"] = new Array();
attributMenuDefault["CouleurAvantPlan"]["Normal"] = "#000000";
attributMenuDefault["CouleurAvantPlan"]["AuDessus"] = "#000000";
attributMenuDefault["CouleurAvantPlan"]["Selectionne"] = "#000000";
attributMenuDefault["CouleurFond"] = new Array();
attributMenuDefault["CouleurFond"]["Normal"] = "#0000FF";
attributMenuDefault["CouleurFond"]["AuDessus"] = "#00009F";
attributMenuDefault["CouleurFond"]["Selectionne"] = "#0000FF";
attributMenuDefault["SousMenuVisible"] = new Array();
attributMenuDefault["SousMenuVisible"]["Normal"] = false;
attributMenuDefault["SousMenuVisible"]["AuDessus"] = false;
attributMenuDefault["SousMenuVisible"]["Selectionne"] = false;

var tempsAvantTimeoutActif = 500;
var tempsTimeOutMenu = 1000;
// cette fonction est appellée par l'évenement onload de <body> 

function initSect(){
	if (bw) {
		if (bw.bw) {
			loaded=true;	
		}
	}
}

function high(sec, secNom){
	if ((bw.bw)&&(loaded)) {
		this.im = getObj(sec);
		if (!im.selectionne) {
			setCouleurs(secNom, im, "AuDessus");		
		} 

		// substr
		if (getAttribut("SousMenuVisible","AuDessus", secNom)) {
			this.im2 = getObj(secNom+'eSousMenu');
			if (im2) {
				this.im = bw.dom?im2.style:bw.ie4?im2.style:bw.ns4?im2:0;
				im.visibility = 'visible';
			}
		}
		allLow(secNom, secNom.substring(0, (secNom.length-3)));		
		timeOutMenu();
		sectionActive=true;
		menuCourant=secNom;
	}		
}
function low(sec){
	if ((bw.bw)&&(loaded)) {
		this.im = getObj(sec);
		if (!im.selectionne) {
			setCouleurs(sec, im, "Normal");	
		} 
		sectionActive=false;
	}		
}

function downSousSection(oEnsembleSections, nomSection) {
	var i, ok, sousSection, oSousSection, oEnsembleSousSections, im, oSection;
	oSection = getObj(nomSection);
	im = bw.dom?oEnsembleSections.style:bw.ie4?oEnsembleSections.style:bw.ns4?oEnsembleSections:0;
	if (!oSection.selectionne) {
		if (!getAttribut("SousMenuVisible","Normal", nomSection)) {
			im.visibility = 'hidden';
		}
	} else  {
		if (!getAttribut("SousMenuVisible","Selectionne", nomSection)) {
			im.visibility = 'hidden';
		}
	}
	ok = true;
	i = 1;
	while(ok) {
		sousSection = nomSection + 'e' + preZero(i);
		oEnsembleSousSections = getObj(sousSection+'eSousMenu');
		if (oEnsembleSousSections) {
			downSousSection(oEnsembleSousSections, sousSection);
		}
		oSousSection = bw.dom?document.getElementById(sousSection):bw.ie4?document.all[sousSection]:bw.ns4?eval('document.'+nomSection+'eSousMenu.layers.'+sousSection):0
		ok = oSousSection?1:0
		i++;
	}
}

// fonction qui désactive chacune des section du menu sauf si c'est la section courante
function allDown(cursec) {
	// get no menu
	if (cursec) {
		var noMenu = cursec.substring(0, 3);
		allLow("", noMenu);
	}
}

// fonction qui désactive chacune des section du menu sauf si c'est la section courante
function allLow(nomSousSectionCourante, nomSection) {
	var i, ok, sousSection, oSousSection, oEnsembleSousSections;
	ok = true;
	i = 1;
	while(ok) {
		sousSection = nomSection + 'e' + preZero(i);
		if (sousSection!= nomSousSectionCourante) {
			oEnsembleSousSections = getObj(sousSection+'eSousMenu');
			if (oEnsembleSousSections) {
				downSousSection(oEnsembleSousSections, sousSection);
			}
			oSousSection = bw.dom?document.getElementById(sousSection):bw.ie4?document.all[sousSection]:bw.ns4?eval('if (document.'+nomSection+'eSousMenu) document.'+nomSection+'eSousMenu.layers.'+sousSection + '; else 0;'):0
			ok = oSousSection?1:0
		}
		i++;
	//	if (i>10) ok = false;
	}
}

var timeOutActif;
function timeOutMenu() {
	if (!timeOutActif) {
	    timeOutActif = true;
		if (bw.ns4) {
			setTimeout(tempsHorsSection, tempsAvantTimeoutActif);
		} else {
			setTimeout("tempsHorsSection()", tempsAvantTimeoutActif);
		}
	}
}

function tempsHorsSection() {
	if (!sectionActive) {
		if (bw.ns4) {
			setTimeout(horsSection, tempsTimeOutMenu);
		} else {
			setTimeout("horsSection()", tempsTimeOutMenu);
		}
	} else {
		timeOutActif = false;
		timeOutMenu();
	}
}
function horsSection() {
	if (!sectionActive) {
		allDown(menuCourant);
		timeOutActif = false;
	} else {
		timeOutActif = false;
		timeOutMenu();
	}
}
function clickAutour(url) {	if (bw.dom) location.href=document.getElementById('base').href + url; }

function setCouleurUp(obj, couleur) {
	obj.couleurUp = couleur;
}
function setCouleurDown(obj, couleur) {
	obj.couleurDown = couleur;
}


//fonction qui va chercher une référence à un objet selon le DOM du browser
function getObj(nObj) {
	return bw.dom?document.getElementById(nObj):bw.ie4?document.all[nObj]:bw.ns4?eval('document.' + nObj):0;
}

function activeSectionUrl(noMenu) {
    var oMov = new Object();
    oMov.Y= 0;
    if (!bw.opera6) {
    	trouveSelectionDansMenu(location.href.toLowerCase(), noMenu, oMov, true, true);
		moveObjPosition(oMov.X, oMov.Y, noMenu+'PadApres');
		moveObjPosition(oMov.X, oMov.Y, 'SOS');	
    } else	{
    	trouveSelectionDansMenu(location.href.toLowerCase(), noMenu, oMov, false, true);
		moveObjPosition(oMov.X, oMov.Y, noMenu+'PadApres');
		moveObjPosition(oMov.X, oMov.Y, 'SOS');	
    	trouveSelectionDansMenu(location.href.toLowerCase(), noMenu, oMov, true, false);		
	}	
}


function trouveSelectionDansMenu(url, nomSection, oMov, visibilty, movObject) {
	var i, ok, sousSection, oSousSection, oEnsembleSousSections, urlSection, oUrlSection;
	var selectionne = false;
	var elementSousSectionSelectionne = false;
	ok = true;
	i = 1;
	if (isElement(nomSection)&&movObject) moveObjPosition(oMov.X, oMov.Y, nomSection);
	while(ok) {
		selectionne = false;
		sousSection = nomSection + 'e' + preZero(i);
		if (movObject) moveObjPosition(oMov.X, oMov.Y, sousSection)			
		urlSection = 'l' + sousSection;
		oUrlSection = getObj(urlSection);
		if (oUrlSection) {
			selectionne=compareUrl(oUrlSection, url);
			elementSousSectionSelectionne = elementSousSectionSelectionne || selectionne;
			oEnsembleSousSections = getObj(sousSection+'eSousMenu');
			if (oEnsembleSousSections) {
				selectionne = (trouveSelectionDansMenu(url, sousSection, oMov, visibilty, movObject) || selectionne);
				if (selectionne) {
					if (getAttribut("SousMenuVisible","Selectionne", sousSection)&&visibilty) {				
						if (!bw.ns4) {
							oEnsembleSousSections.style.visibility = 'visible';
						} else {						
							oEnsembleSousSections.visibility = 'visible';					
						}
					}
					oMov.Y = oMov.Y + getAttribut("DeplaceMenuApresY","Selectionne", sousSection);
					oMov.X = oMov.X + getAttribut("DeplaceMenuApresX","Selectionne", sousSection);					
					if (!oMov.Y) oMov.Y = 0;
					if (!oMov.X) oMov.X = 0;
					
				}				
			}
			oSousSection = bw.dom?document.getElementById(sousSection):bw.ie4?document.all[sousSection]:bw.ns4?eval('if (document.'+nomSection+'eSousMenu) document.'+nomSection+'eSousMenu.layers.'+sousSection + '; else 0;'):0
			oSousSection.selectionne = selectionne;
			if (selectionne) {
				setCouleurs(sousSection, oSousSection, "Selectionne")
			}
			ok = oSousSection?1:0
		} else {
			ok = false;
		}
		i++;
	}
	var oSection = getObj(nomSection);
	if (!oSection.selectionne) {
		oSection.selectionne = elementSousSectionSelectionne;
		if (oSection.selectionne) {
			if (isElement(nomSection)) setCouleurs(nomSection, oSection, "Selectionne");				
		}	
	}
	return elementSousSectionSelectionne;
}

function compareUrl(oUrlSection, url) {
	var lUrl = oUrlSection.href.toLowerCase();
//	if (url.indexOf(lUrl)>-1) {
	if (url==lUrl) {
		return true;
	} else {
		return false;
	}
}


function getAttributPourObj(nomAttribut,evenementUtilisateur, obj) {
	try {
		if (obj.attributMenu[nomAttribut][evenementUtilisateur]) {
			return obj.attributMenu[nomAttribut][evenementUtilisateur];
		} else {
			return false;
		}
	}
	catch(e) {
	
	}		
} 

function getAttribut(nomAttribut,evenementUtilisateur, nomObj) {
// si l'objet a un attribut specifique, on renvoie cet attribut
// sinon on prend l'objet parent dont le nom de substr(0,3)
// sinon on prend l'attribut par defaut 
	var attribut;
	objDeLAttribut = getObj(nomObj);
	attribut = getAttributPourObj(nomAttribut,evenementUtilisateur, objDeLAttribut);
	if (!attribut) {
		nomObj = nomObj.substring(0, 3);
		objDeLAttribut = getObj(nomObj);
		attribut = getAttributPourObj(nomAttribut,evenementUtilisateur, objDeLAttribut);
		if (!attribut) {
			try {
				attribut = attributMenuDefault[nomAttribut][evenementUtilisateur];
			} catch (e) {
				// l'attribute n'existe pas, on renvoit 0
				attribut = 0;
			}
		}
	}
	return attribut;
} 

function setCouleurs(nomSection, oSection, etat) {
	var	urlSection = 'l' + nomSection;
	var oUrlSection = getObj(urlSection);
	if (!oUrlSection) oUrlSection = oSection;
	if (bw.ns4) {
			oSection.bgColor =  getAttribut("CouleurFond",etat, nomSection);
			oUrlSection.color =  getAttribut("CouleurAvantPlan",etat, nomSection);			
		} else {
			oSection.style.backgroundColor = getAttribut("CouleurFond",etat, nomSection);
			oUrlSection.style.color = getAttribut("CouleurAvantPlan",etat, nomSection);
		}	
}

function isElement(nomObj) {
	return ((nomObj.length>3)&&(!nomObj.indexOf("Sous")));
}

function moveObjPosition(OffSetX, OffSetY, nomObjet) {
	// les objets doivent avoir position:relative pour que ca marche !!!!
	if ((OffSetX)||(OffSetY)){
		document.write('<style type="text/css">' +
					'#' + 	nomObjet + '{' +
					'top:' + OffSetY + 
					';left:' + OffSetX +
					'}</style>');
	}
}


