/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \
|		
|		Copyright (c) 2007 Forum de la Performance
|		Design + HTML/CSS/DOM JavaScript : 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/ */

function SmartHover(who) {
	if (document.all&&document.getElementById&&document.getElementsByTagName&&document.getElementById(who)) {
		navRoot=document.getElementById(who);
		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", "");};
			}
		}
	}
	SmartFocus(who);
};

function SmartFocus(who) {
	var navLnk=document.getElementById(who).getElementsByTagName("A");
	var navItm=document.getElementById(who).getElementsByTagName("LI");
	for (var n=0;n<navItm.length;n++) {
		if (navItm[n].className!="on") navItm[n].className="y";
	}
	for (var i=0;i<navLnk.length;i++) {
		navLnk[i].onfocus=function() {
			if (who == this.parentNode.parentNode.id) {
				this.parentNode.className+=" over";
			}
			else {	// on est sur un lien de sous-(sous-...)liste : remonter jusqu'au <ul> de niveau 2
				this.parentNode.parentNode.parentNode.parentNode.parentNode.className+=" over";
			};
		}
		navLnk[i].onblur=function() {
			if (who == this.parentNode.parentNode.id) {
				this.parentNode.className=this.parentNode.className.replace(" over", "");
			}
			else {	// on est sur un lien de sous-(sous-...)liste : remonter jusqu'au <ul> de niveau 2
				this.parentNode.parentNode.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.parentNode.parentNode.className.replace(" over", "");
			}
		};
	}
};


/* ______________________[ 02 | Gestion de la taille du texte d’un article ]________________________ */

function SmartSize() {
	var args=SmartSize.arguments;
	if (document.getElementById && document.getElementById("Tplus") && document.getElementById("Tmoins")) {
		var cibleplus=document.getElementById("Tplus");
		var ciblemoins=document.getElementById("Tmoins");
		cibleplus.onclick=function() {
			for (n=0;n<args.length;n++) {
				if (document.getElementById(args[n])) {
					var cibletxt=document.getElementById(args[n]);
					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);
					cibletxt.style.fontSize=(sizestr+1)+"px";
				}
			}
		};
		ciblemoins.onclick=function() {
			for (n=0;n<args.length;n++) {
				if (document.getElementById(args[n])) {
					var cibletxt=document.getElementById(args[n]);
					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);
					cibletxt.style.fontSize=(sizestr-1)+"px";
				}
			}
		};
	}
};


/* ______________________[ 03 | Miscellaneous ]________________________ */

function OpenPopup(url,nom,option) {
	window.open(url,nom,option);
};

function SmartRescueForm() {
	var args=SmartRescueForm.arguments;
	for (n=0;n<args.length;n++) {
		var cibleSelectName=args[n];
		if (document.getElementById&&document.getElementById(cibleSelectName)) {
			var cibleSelect=document.getElementById(cibleSelectName);
			cibleSelect.className="show";
		}
	}
};


/* ______________________[ 04 | Gestion de l’ouverture/fermeture d’un <h2> » ]________________________ */

function SmartPlan(cible) {
	if (document.getElementById&&document.getElementById(cible)) {
		var root=document.getElementById(cible).getElementsByTagName("H2");
		for (a=0;a<root.length;a++) {
			if (root[a].nodeName=="H2") {
				SmartOpenClose(root[a]);
			}
		}
	}
};

function SmartOpenClose(who) {
	var args=SmartOpenClose.arguments;
	if (who.nextSibling&&who.nextSibling.className=="treeview") {
		var Sister=who.nextSibling;
		Sister.style.display="block";
		who.className="on";
	} 
	if (!document.all&&who.nextSibling.nextSibling&&who.nextSibling.nextSibling.className=="treeview") {
		var Sister=who.nextSibling.nextSibling;
		Sister.style.display="block";
		who.className="on";
	}
	who.onclick=function() {
		if (Sister) {
			Sister.style.display=Sister.style.display=="none"?"block":"none";
			who.className=who.className=="off"?"on":"off";
		}
	};
};


/* ______________________[ 05 | Gestion de l'icône Impression de la Page ]________________________ */

function DirectPrint() {
	if (window.print) self.print();
};

function PushPrint(sContainerID) {
	if (document.getElementById&&document.getElementById(sContainerID)) {
		var cible=document.getElementById(sContainerID).getElementsByTagName('UL');
		if(document.createElement && document.getElementById) {
			var oNext = document.getElementById("toFriend").parentNode;
			var oLi = document.createElement("LI");
			var oLink = document.createElement("A");
			var oImg = document.createElement("IMG");
			
			with(oLink){
				id = "print";
				title = "Imprimer cette page";
				href = "javascript;";
			};
			
			with(oImg){
				src = "img/toolbox/print.gif";
				alt = "Imprimer cette page";
			};
			
			oLink.appendChild(oImg);
			oLi.appendChild(oLink);
			cible[0].insertBefore(oLi,oNext);
		}
		else {
			var t='<li><a id="print" title="Imprimer cette page" href="javascript:;" onclick="DirectPrint();return false;"><img src="img/toolbox/print.gif" alt="Imprimer cette page" /></a></li>';
			cible[0].innerHTML+=t;
		}
	}
};


/* ______________________[ 06 | Ajout de la page courante aux favoris de Microsoft Internet Explorer ]________________________ */

/* Mettre la page courante en favoris — MSIE and Firefox */
function myBookmark() {
	if (document.getElementById&&document.getElementById("Favoris")) {
		var el=document.getElementById("Favoris");
		var operaStr="« Ctrl + T » pour ajouter aux favoris.";
		if (document.all&&navigator.userAgent.indexOf("Opera")==-1) {
			window.external.AddFavorite(document.location,document.title);
		}
		else if (window.sidebar) {
			window.sidebar.addPanel(document.title,document.location.href,"");
		}
		else if (navigator.userAgent.indexOf("Opera")!=-1) {
			el.title=operaStr;
			window.status=operaStr;
		}
	}
};


/* ______________________[ 07 | Bouton generique ]________________________ */

function AddToolButton(sContainerID,oParams){
	if (document.createElement&&document.getElementById&&document.getElementById(sContainerID)){
		var cible=document.getElementById(sContainerID).getElementsByTagName('UL');
		var oLi=document.createElement("LI");
		var oLink=document.createElement("A");
		var oInnerElement;
		var oText;	
		with(oLink) {
			id=oParams.linkId;
			title=oParams.imgAlt;
			href=oParams.linkHREF?oParams.linkHREF:"javascript:;";
			onclick=oParams.onclick?oParams.onclick:"";
		};
		if (oParams.innerElement){
			oText = document.createTextNode(oParams.innerElement.text);
			oInnerElement = document.createElement(oParams.innerElement.name.toUpperCase());
			oInnerElement.className = oParams.innerElement.cssClass;
			oInnerElement.appendChild(oText);		
			oLink.appendChild(oInnerElement);
		}
		oLi.appendChild(oLink);
		// insertion... avant un element existant
		if (oParams.insertBefore) {
			var oNext=document.getElementById(oParams.insertBefore).parentNode;
			cible[0].insertBefore(oLi,oNext);
		} else {
			// ou en fin de liste
			cible[0].appendChild(oLi);
		}
	}
};


/* ______________________[ 08 | Completion champs formulaire ]________________________ */

function ChampComplete (eleDefaultVal, ele) {
	ele.onfocus = ele.onclick= function() {
		if(this.value == eleDefaultVal){
			this.value = "";
		}
		else {
			if(this.value=="") {
				this.value = eleDefaultVal;
			}
		}
	};
	
	ele.onblur = function() {
		if(this.value=="") {
			this.value=eleDefaultVal;
		}
	};
};

function AutoChamps(chpsId, chpsValue) {
	for (var i=0;i<chpsId.length;i++){
		listChps=document.getElementById(chpsId[i]);
		if (listChps && listChps.value=="") {
			listChps.value=chpsValue[i];
			ChampComplete(chpsValue[i], listChps);
		}
	}
};


/* ______________________[ 09 | Lancement des scripts ]________________________ */

window.onload=function() {
	SmartHover("NavigationPrincipale");
	AddToolButton("BoiteOutils",{"linkId":"imprimer","linkHREF":"javascript:DirectPrint();","innerElement":{"name":"span","cssClass":"horschamp","text":"Imprimer cette page"},"imgAlt":"Imprimer cette page"});
	AddToolButton("BoiteOutils",{"linkId":"Favoris","linkHREF":"javascript:myBookmark();","innerElement":{"name":"span","cssClass":"horschamp","text":"Ajouter cette page aux favoris"},"imgAlt":"Ajouter aux favoris","insertBefore":"unAmi"});
	AddToolButton("BoiteOutils",{"linkId":"Tmoins","innerElement":{"name":"span","cssClass":"horschamp","text":"Réduire le corps du texte"},"imgAlt":"Réduire le corps du texte","insertBefore":"Favoris"});
	AddToolButton("BoiteOutils",{"linkId":"Tplus","innerElement":{"name":"span","cssClass":"horschamp","text":"Augmenter le corps du texte"},"imgAlt":"Augmenter le corps du texte","insertBefore":"Tmoins"});
	SmartSize("ColMenu","ColContenu","ColContextuelle");
	AutoChamps(Array("email_inscr", "mot_cle"), Array("Adresse courriel", "Rechercher"));
};