/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \
|		
|		Copyright (c) 2005 IDEP
|		Design + Intégration + Dev : Smart Agence
|		http://www.smartagence.com/
|		
\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */




/* ______________________[ 01 | Interactivité du menu principal (menu horizontal) ]________________________ */

/* A special thanks goes to Eric Shepherd for his ALA article about “Hybrid CSS Dropdowns”: http://www.alistapart.com/articles/hybrid/ 
and to Patrick Griffiths and Dan Webb for their htmldog.com article “Sons of Suckerfish”: http://www.htmldog.com/articles/suckerfish/ */
/* Ce script est nécessaire à MSIE pour mimer le comportement de la pseudo-classe « :hover » sur un élément « <li/> ».
Il est péférable d’attribuer des liens aux items de premier niveau, ainsi dans le cas d’un non support de Javascript par le navigateur client, la navigation reste possible. Il s’agira sûrement d’attribuer à ces items de premier niveau le lien de leur premier sous-item. Typo3 knows. */

function SmartHover() {
	if (document.all&&document.getElementById&&document.getElementById("NavigationPrincipale")) {
		navRoot=document.getElementById("NavigationPrincipale");
		for (i=0;i<navRoot.childNodes.length;i++) {
			node=navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {this.className+=" over";}
				node.onmouseout=function() {this.className=this.className.replace(" over", "");}
			}
		}
	}
}


/* ______________________[ 02 | Gestion de la taille du texte d’un article ]________________________ */

/* Ce script modifie la taille du texte contenu dans <td id="ColB"/>. Si JavaScript n’est pas activé ou si les méthodes 
ne sont pas supportés, il ne se passera rien mais cela ne provoquera pas d’erreur. */
/* A special thanks goes to Eric Shepherd for his ALA article about “Hybrid CSS Dropdowns”: http://www.alistapart.com/articles/hybrid/ 
and to Patrick Griffiths and Dan Webb for their htmldog.com article “Sons of Suckerfish”: http://www.htmldog.com/articles/suckerfish/ */
/* Ce script est nécessaire à MSIE pour mimer le comportement de la pseudo-classe « :hover » sur un élément « <li/> ».
Il est péférable d’attribuer des liens aux items de premier niveau, ainsi dans le cas d’un non support de Javascript par le navigateur client, la navigation reste possible. Il s’agira sûrement d’attribuer à ces items de premier niveau le lien de leur premier sous-item. Typo3 knows. */

/* A special thanks goes to Eric Shepherd for his ALA article about “Hybrid CSS Dropdowns”: http://www.alistapart.com/articles/hybrid/ 
and to Patrick Griffiths and Dan Webb for their htmldog.com article “Sons of Suckerfish”: http://www.htmldog.com/articles/suckerfish/ */
/* Ce script est nécessaire à MSIE pour mimer le comportement de la pseudo-classe « :hover » sur un élément « <li/> ».
Il est péférable d’attribuer des liens aux items de premier niveau, ainsi dans le cas d’un non support de Javascript par le navigateur client, la navigation reste possible. Il s’agira sûrement d’attribuer à ces items de premier niveau le lien de leur premier sous-item. Typo3 knows. */
function SmartSize() {
	if (document.getElementById&&document.getElementById("TaillePlus")&&document.getElementById("TailleMoins")&&document.getElementById("ColB")) {
		var cibleplus=document.getElementById("TaillePlus");
		var ciblemoins=document.getElementById("TailleMoins");
		var cibletxt=document.getElementById("ColB");
		cibleplus.onclick=function() {
			var sizestr=cibletxt.style.fontSize.substring(0,cibletxt.style.fontSize.length-2);
			var sizeinter=cibletxt.style.lineHeight.substring(0,cibletxt.style.lineHeight.length-2);
			sizestr=sizestr!=""?parseInt(sizestr):12;
			sizeinter=sizeinter!=""?parseInt(sizeinter):15;
			cibletxt.style.fontSize=sizestr+1+"px";
			cibletxt.style.lineHeight=sizeinter+1+"px";
		}
		ciblemoins.onclick=function() {
			var sizestr=cibletxt.style.fontSize.substring(0,cibletxt.style.fontSize.length-2);
			var sizeinter=cibletxt.style.lineHeight.substring(0,cibletxt.style.lineHeight.length-2);
			sizestr=sizestr!=""?parseInt(sizestr):12;
			sizeinter=sizeinter!=""?parseInt(sizeinter):15;
			cibletxt.style.fontSize=sizestr-1+"px";
			cibletxt.style.lineHeight=sizeinter-1+"px";
		}
	}
}

/* ______________________[ 03 | Ajout de la page courante aux favoris de Microsoft Internet Explorer ]________________________ */

/* Mettre la page courante en favoris — MSIE only */
function AddBookmark(btn) {
	if (document.getElementById&&document.getElementById(btn)) {
		var el=document.getElementById(btn);
		var operaStr="« Ctrl + T » pour ajouter aux favoris.";
		var firefoxStr="« Ctrl + D » pour ajouter aux favoris.";
		if (document.all&&navigator.userAgent.indexOf("Opera")==-1) {
			el.onclick=function() {
				window.external.AddFavorite(document.location,document.title);
			}
		} else if (navigator.userAgent.indexOf("Opera")!=-1) {
			el.title=operaStr;
			window.status=operaStr;
		} else if (navigator.userAgent.indexOf("Firefox")!=-1) {
			el.title=firefoxStr;
			for(a=0;a<el.childNodes.length;a++) {
				el.childNodes[a].title=el.childNodes[a].nodeName=="A"?firefoxStr:"";
			}
		}
	}
}


/* ______________________[ 04 | Lancement d’une impression pour les navigateurs compatibles ]________________________ */

/* Les utilisateur de MacOS ne peuvent bénéficier de cette fonctionnalité : il peut être intéressant de prévoir une explication 
à ces utilisateurs sur la page d’aide par exemple. */

function DirectPrint() {
	if (window.print) self.print();
}


/* ______________________[ 05 | « Rollover » à l’ancienne, quelque peu rafraîchi ]________________________ */

/* Rollover: Thanks goes to Chris Heilmann from http://www.onlinetools.org/ */

/* Il suffit d’ajouter l’attribut class="roll" à une image et de générer une image de survol dont le nom est le même que celui 
de l’image non survolée mais avec le suffixe « _on ». ex. : « bouton_validation.gif » et « bouton_validation_on.gif ». Encore une fois, 
si JavaScript n’est pas activé c&ocirc;té client ou mal supporté, l’effet au survol n’aura pas lieu mais ne provoquera pas d’erreur. */

function findimg() {
	var imgs,i;
	imgs=document.getElementsByTagName('img');
	for(i=0;i<imgs.length;i++) {
		if (/roll/.test(imgs[i].className)) {
			imgs[i].onmouseover=function(){roll(this);};
			imgs[i].onmouseout=function(){roll(this);};
		}
	}
}

function roll(o) {
	var src,ftype,newsrc;
	src=o.src;
	ftype=src.substring(src.lastIndexOf('.'), src.length);
	if (/_on/.test(src)) {newsrc=src.replace('_on','');} else {newsrc=src.replace(ftype, '_on'+ftype);}
	o.src=newsrc;
}


/* ______________________[ 06 | Gestion de l’ouverture/fermeture d’une liste « <dl/> » ]________________________ */

/* Ce script est utilisé lorsque chaque « <dt/> » à l’intérieur d’un onglet doit ouvrir/fermer le « <dd/> » correspondant.
Il y a une gestion d’état « on ». Deux fonctionnalités cohabitent : par exemple « SmartDL("listeDynamique",0,"FAQ",0,"Guides",1); » 
le premier argument de cette fonction est l’ID de la <dl/> à rendre interactive, le chiffre qui suit (0 ou 1) définit le type de fonctionnalité :
pour « 0 », un clic sur un <dt/> provoque l’ouverture du <dd/> associé ET la fermeture de tous les autres <dd/>. Pour « 1 », un clic sur
un <dt/> provoque l’ouverture/fermeture du <dd/> associé selon son état au moment du clic, les autres <dd/> ne bougent pas. */

function SmartDL() {
	var args=SmartDL.arguments;
	for (n=0;n<args.length;n+=2) {
		var ClickFx=args[n+1];
		if (document.getElementById&&document.getElementById(args[n])) {
			var root=document.getElementById(args[n]).childNodes;
			for (a=0;a<root.length;a++) {
				if (root[a].nodeName=="DT"&&root[a].className!="on") {
					if (root[a].nextSibling.nodeName=="DD") {var Sister=root[a].nextSibling;}
					else if (root[a].nextSibling.nextSibling.nodeName=="DD") {var Sister=root[a].nextSibling.nextSibling;}
					Sister.className="off";
				}
				if (root[a].nodeName=="DT"&&root[a].className=="on") {
					if (root[a].nextSibling.nodeName=="DD") {var Sister=root[a].nextSibling;}
					else if (root[a].nextSibling.nextSibling.nodeName=="DD") {var Sister=root[a].nextSibling.nextSibling;}
					Sister.className="on";
				} 
			}
			for (a=0;a<root.length;a++) {
				if (root[a].nodeName=="DT") {SmartOpenClose(root[a],root,ClickFx);}
			}
		}
	}
}

function SmartOpenClose(who,Brothers,ClickFx) {
	if (who.nextSibling.nodeName=="DD") {var Sister=who.nextSibling;}
	else if (who.nextSibling.nextSibling.nodeName=="DD") {var Sister=who.nextSibling.nextSibling;}
	if (ClickFx==1) {
		who.onclick=function() {
			who.className=who.className=="on"?"off":"on";
			Sister.className=Sister.className=="on"?"off":"on";
		}
	} else {
		who.onclick=function() {
			for (a=0;a<Brothers.length;a++) {
				if (Brothers[a].nodeName=="DT") {Brothers[a].className="";}
				else if (Brothers[a].nodeName=="DD") {Brothers[a].className="off";}
			}
			who.className="on";
			Sister.className=(Sister.className=="on"||Sister.className==" on")?"":"on";
		}
	}
}


/* ______________________[ 07 | Plan du site ]________________________ */

function RnkFolder(element) {
	var el=document.getElementById(element);
	var es=el.parentNode.style;
	var et=el.parentNode.parentNode.firstChild.style;
	el.parentNode.parentNode.firstChild.blur();
	es.display=es.display=="none"||es.display==""||!es.display?"block":"none";
	et.backgroundImage=et.backgroundImage=="url(../../img/fd_on.gif)"?"url(../../img/fd_off.gif)":"url(../../img/fd_on.gif)";
}


/* ______________________[ 08 | Miscellaneous ]________________________ */

function OpenPopup(url,nom,option) {
	window.open(url,nom,option);
}

navvers=navigator.appVersion.substring(0,1);
if (navvers>3)
	navok=true;
else
	navok=false;
today=new Date;
jour=today.getDay();
numero=today.getDate();
if (numero<10)
	numero="0"+numero;
mois=today.getMonth();
if (navok)
	annee=today.getFullYear();
else
	annee=today.getYear();
TabJour=new Array("Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi");
TabMois=new Array("janvier","février","mars","avril","mai","juin","juillet","aout","septembre","octobre","novembre","décembre");
messageDate=TabJour[jour]+" "+numero+" "+TabMois[mois]+" "+annee;

function OpenReactions() {
	var args=OpenReactions.arguments;
	for (n=0;n<args.length;n++) {
		if (document.getElementById&&document.getElementById("Commentaires")) {
			var cible=document.getElementById("Commentaires");
			if (document.getElementById(args[n])) {
				var root=document.getElementById(args[n]);
				root.onclick=function() {
					cible.className="on";
				}				
			}
		}
		var location=window.location.href;
		var thisPage=location.substring(location.lastIndexOf("#")+1);
		if (thisPage=="reactions") {
			var cible=document.getElementById("Commentaires");
			cible.className="on";			
		}
	}
}


/* ______________________[ 09 | Plan du site ]________________________ */

/*
aqtree3clickable.js

Converts an unordered list to an explorer-style tree, with clickable
icons

To make this work, simply add one line to your HTML:
<script type="text/javascript" src="aqtree3clickable.js"></script>

and then make the top UL of your nested unordered list of class
"aqtree3clickable".

That's it. No registration function, nothing.

http://www.kryogenix.org/code/browser/aqlists/

Stuart Langridge, November 2002
sil@kryogenix.org

Inspired by Aaron's labels.js (http://youngpup.net/demos/labels/) and Dave Lindquist's menuDropDown.js (http://www.gazingus.org/dhtml/?id=109)

*/

addEvent(window, "load", makeTreesC);

function makeTreesC() {
    // We don't actually need createElement, but we do
    // need good DOM support, so this is a good check.
    if (!document.createElement) return;
    
    uls = document.getElementsByTagName("ul");
    for (uli=0;uli<uls.length;uli++) {
        ul = uls[uli];
        if (ul.nodeName == "UL" && ul.className == "treeview") {
            processULELC(ul);
        }
    }
}

function processULELC(ul) {
    if (!ul.childNodes || ul.childNodes.length == 0) return;
    // Iterate LIs
    for (var itemi=0;itemi<ul.childNodes.length;itemi++) {
        var item = ul.childNodes[itemi];
        if (item.nodeName == "LI") {
            // Iterate things in this LI
            var a;
            var subul;
	    subul = "";
            for (var sitemi=0;sitemi<item.childNodes.length;sitemi++) {
                var sitem = item.childNodes[sitemi];
                switch (sitem.nodeName) {
                    case "A": a = sitem; break;
                    case "UL": subul = sitem; 
                               processULELC(subul);
                               break;
                }
            }
            if (subul) {
                associateELC(a,subul);
            } else {
                a.parentNode.className = "aq3bullet";
            }
        }
    }
}

function associateELC(a,ul) {
    if (a.parentNode.className.indexOf('aq3open') == -1)
      a.parentNode.className = 'aq3closed';
    a.onclick = function () {
        this.parentNode.className = (this.parentNode.className=='aq3open') ? "aq3closed" : "aq3open";
        return false;
    }
}

/*              Utility functions                    */

function addEvent(obj, evType, fn){
  /* adds an eventListener for browsers which support it
     Written by Scott Andrew: nice one, Scott */
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
  } else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
	return false;
  }
}


/* ______________________[ 10 | Lancement des scripts : méthode dite « Unobtrusive JavaScript » ]________________________ */

window.onload=function() {
	SmartHover();
	SmartSize();
	AddBookmark("Bookmark");
	OpenReactions("rea1","rea2","rea3");
	/*SmartFolder(1);
	SmartDL("listeDynamique",0,"FAQ",0,"Guides",1);
	SmartMap();
	findimg();
	externalLinks();*/
}


