/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \
|		
|		Copyright (c) 2007 Autoroutes.fr
|		Design + HTML/CSS/DOM JavaScript : Smart Agence
|		http://www.smartagence.com/
|		
\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */



function $id(sID) {
	return document.getElementById(sID);
};

/* ______________________[ 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 (this.parentNode.parentNode.id==who) {
				this.parentNode.className+=" over";
			} else {
				this.parentNode.parentNode.parentNode.className+=" over";
			}
		}
		navLnk[i].onblur=function() {
			if (this.parentNode.parentNode.id==who) {
				this.parentNode.className=this.parentNode.className.replace(" over", "");
			} else {
				this.parentNode.parentNode.parentNode.className=this.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):11;
					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):11;
					cibletxt.style.fontSize=sizestr-1+"px";
				}
			}
		}
	}
}


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

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


/* ______________________[ 04 | Miscellaneous ]________________________ */

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


/* ______________________[ 05 | Ouverture de fenêtre compatible XHTML 1.0 Strict ]________________________ */

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors=document.getElementsByTagName("a");
	for (var i=0;i<anchors.length;i++) {
		var anchor=anchors[i];
		if (anchor.getAttribute("href")&&anchor.getAttribute("rel")=="external") anchor.target="_blank";
	}
}


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

function SmartPlan() {
	var args=SmartPlan.arguments;
	if (document.getElementById&&document.getElementById(args[0])) {
		var root=document.getElementById(args[0]).getElementsByTagName("H2");
		for (a=0;a<root.length;a++) {
		if (root[a].nodeName=="H2") {
				SmartOpenClose(root[a]);
			}
		}
	}	
}		


function SmartOpenClose(who) {
	if (who.nextSibling.nextSibling&&who.nextSibling.nextSibling.className=="treeview") {
		var Sister=who.nextSibling.nextSibling;
		Sister.style.display="block";
		who.className="on";
	} else if (who.nextSibling&&who.nextSibling.className=="treeview") {
		var Sister=who.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";
		}
	}	
}		

function SmartPlanDL(arg) {
	if (document.getElementById&&document.getElementById(arg)) {
		var root=document.getElementById(arg).getElementsByTagName("DT");
		for (a=0;a<root.length;a++) {
		if (root[a].nodeName=="DT") {
				SmartOpenCloseDL(root[a]);
			}
		}
	}	
}		


function SmartOpenCloseDL(who2) {
	if (who2.nextSibling.nextSibling&&who2.nextSibling.nextSibling.nodeName=="DD") {
		var Sister=who2.nextSibling.nextSibling;
		Sister.style.display="none";
		who2.className="off";
	} else if (who2.nextSibling&&who2.nextSibling.nodeName=="DD") {
		var Sister=who2.nextSibling;
		Sister.style.display="none";
		who2.className="off";
	}
	who2.onclick=function() {
		if (Sister) {
			Sister.style.display=Sister.style.display=="none"?"block":"none";
			who2.className=who2.className=="off"?"on":"off";
		}
	}	
}	

/* ______________________[ 07 | Gestion des boites avec onglets ]________________________ */

function SmartList(listClass) {
	for (var i=0; i<document.getElementsByTagName("*").length; i++) {
		if (document.getElementsByTagName("*").item(i).className==listClass) {
			var node = document.getElementsByTagName("*").item(i).firstChild;
			var nbOfChilds = document.getElementsByTagName("*").item(i).childNodes;
			var j=1;
			while (node.nodeName!="LI" || j <= nbOfChilds){
				node = node.nextSibling;
				j++;
			}
			if (node.nodeName=="LI"){
				if(node.className=="on")
					node.className=node.className.replace("", " firstOn ");
				else
					node.className=node.className.replace("", " first ");
			}
		}
	}
}

/* ______________________[ 08 | Typo3 : Suppression du focus ]________________________ */
function blurLink(theObject){
	theObject.blur();
}

/* ______________________[ 09 | 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:"";
			}
		}
	}
}

/* ______________________[ 10| Gestion d'une zone info sur une map ]________________________ */

function SmartMapBoxes(idsLinks, idsTargets) {
	var link;
	var target;
	var tmpTarget;
	var indexTarget;
	for (var i=0;i<idsLinks.length;i++){
		link=document.getElementById(idsLinks[i]);
		if (link) {
			link.onclick=function() {
				//Cache l'ensemble des boites d'information
				for (var j=0;j<idsTargets.length;j++) {
					tmpTarget=document.getElementById(idsTargets[j]);
					if (idsLinks[j]==this.id)
						indexTarget=j;
					if (tmpTarget){
						if (tmpTarget.className=="visible") {
							tmpTarget.className=tmpTarget.className.replace("visible","hidden");
						}
					}
				}
				//Affiche de la boite séléctionnée
				target=document.getElementById(idsTargets[indexTarget]);
				target.className=target.className.replace("hidden","visible");
			}
			link.onfocus=function() {this.blur();}
		}
	}
}

/* ______________________[ 11| Fonction d'éxécution de SWF ]________________________ */

function RunFlash (urlFlash, widthF, heightF, titleF) {
    document.write ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+widthF+'" height="'+heightF+'">\n');
		document.write('<param name="movie" value="'+urlFlash+'" />\n');
		document.write('<param name="quality" value="high" />\n');
		document.write('<param name="wmode" value="transparent" />\n');
		document.write('<embed src="'+urlFlash+'" width="'+widthF+'" height="'+heightF+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>\n');
		document.write('</object>\n');
}


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

window.onload=function() {
	SmartList('onglets_bleu')
	if(document.getElementById("up")) eventLoader();
	if(document.getElementById("NavigationPrincipale")) SmartHover("NavigationPrincipale");
	SmartSize("ColA","ColB","ColC","ColD","ColMenu","ColContenu","ColContextuel");
	SmartPlan("plansite");
	SmartPlanDL("Newsletter");
	externalLinks();
	externalLinks();
	externalLinks();
	AddBookmark("Favoris");
	SmartMapBoxes(Array("ParkingValenciennes", "ParkingVemars", "ParkingLangres", "ParkingCommunay", "ParkingBeziers", "ParkingBosrobert", "ParkingChaumont", "ParkingLisledabeau", "ParkingParisSudEst", "AireStavold", "AireMorainvillers", "AireRouen", "AireStarnoult", "AireBrou", "AireLemans", "AireGravelle", "AireSaran", "AireOrleans", "AirePeageMonaie", "AireMonaie", "AireAncenis", "AirePoitou", "AireJura", "AireMacon", "AireNangy", "AireGranier", "AireVolcan", "AireAquitaine", "AireLancon", "AireCambarette", "AireNarbonne", "Aire01",  "Aire02",  "Aire03",  "Aire04",  "Aire05",  "Aire06",  "Aire07",  "Aire08",  "Aire09",  "Aire10",  "Aire11",  "Aire12",  "Aire13",  "Aire14",  "Aire15",  "Aire16",  "Aire17",  "Aire18",  "Aire19",  "Aire20",  "Aire21",  "Aire22",  "Aire23",  "Aire24",  "Aire25",  "Aire26",  "Aire27",  "Aire28",  "Aire29",  "Aire30",  "Aire31",  "Aire32",  "Aire33",  "Aire34",  "Aire35",  "Aire36",  "Aire37",  "Aire38",  "Aire39",  "Aire40",  "Aire41",  "Aire42",  "Aire43",  "Aire44",  "Aire45",  "Aire46",  "Aire47",  "Aire48",  "Aire49",  "Aire50",  "Aire51",  "Aire52",  "Aire53"), Array("InfoValenciennes", "InfoVemars", "InfoLangres", "InfoCommunay", "InfoBeziers", "InfoBosrobert", "InfoChaumont", "InfoLisledabeau", "InfoParisSudEst", "InfoStavold", "InfoMorainvilliers", "InfoRouen", "InfoStarnoult", "InfoBrou", "InfoLemans", "InfoGravelle", "InfoSaran", "InfoOrleans", "InfoPeageMonaie", "InfoMonaie", "InfoAncenis", "InfoPoitou", "InfoJura", "InfoMacon", "InfoNangy", "InfoGranier",  "InfoVolcan", "InfoAquitaine", "InfoLancon", "InfoCambarette", "InfoNarbonne", "Info01",  "Info02",  "Info03",  "Info04",  "Info05",  "Info06",  "Info07",  "Info08",  "Info09",  "Info10",  "Info11",  "Info12",  "Info13",  "Info14",  "Info15",  "Info16",  "Info17",  "Info18",  "Info19",  "Info20",  "Info21",  "Info22",  "Info23",  "Info24",  "Info25",  "Info26",  "Info27",  "Info28",  "Info29",  "Info30",  "Info31",  "Info32",  "Info33",  "Info34",  "Info35",  "Info36",  "Info37",  "Info38",  "Info39",  "Info40",  "Info41",  "Info42",  "Info43",  "Info44",  "Info45",  "Info46",  "Info47",  "Info48",  "Info49",  "Info50",  "Info51",  "Info52",  "Info53"));

	if($id("soc")) {
		$id("soc").onchange = function() {
			if(this.selectedIndex > 0 && this.options[this.selectedIndex].value != "") {
				urlStr=this.options[this.selectedIndex].value;
				oNewWindow = window.open(urlStr,"ASFA_Societe");
				xt_med('C','0',urlStr.substring(7, urlStr.length),'S');
				//alert (urlStr.substring(7, urlStr.length));
			}
		};
	}
}



/* ______________________[ 11 | 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;
	 }
}


/* tout afficher / tout masquer */

function affichage(element) 
	{
		var uls = document.getElementsByTagName('ul');
		var lis = document.getElementsByTagName('li');
		var hs = document.getElementsByTagName('h2')
		
		if (element=='all')
		{
			for(var i = 0; i < uls.length; ++i) 
			{
				if (uls[i].className=='treeview') {
					uls[i].style.display=uls[i].style.display=="none"?"block":"block";
					
				}
			
			}
			
			for(var i = 0; i < hs.length; ++i) 
			{
				if ((hs[i].nextSibling&&hs[i].nextSibling.className=="treeview") || (hs[i].nextSibling.nextSibling&&hs[i].nextSibling.nextSibling.className=="treeview"))
				hs[i].className="on"
			}
		
			for(var i = 0; i < lis.length; ++i) 
			{
				if (uls.className=='treeview' || lis[i].parentNode.className=='treeview')
				{
				lis[i].className = (lis[i].className=='aq3bullet') ? "aq3bullet" : "aq3open";
				}
			}
		}
		
		else
		{
			for(var i = 0; i < uls.length; ++i) 
			{
				if (uls[i].className=='treeview')
				{
					uls[i].style.display=uls[i].style.display=="block"?"none":"none";
					
				}
			}
			
			for(var i = 0; i < hs.length; ++i) 
			{
				if ((hs[i].nextSibling&&hs[i].nextSibling.className=="treeview") || (hs[i].nextSibling.nextSibling&&hs[i].nextSibling.nextSibling.className=="treeview"))
				hs[i].className="off"
			}
		
			for(var i = 0; i < lis.length; ++i) 
			{
				if (uls.className=='treeview' || lis[i].parentNode.className=='treeview')
				{
				lis[i].className = (lis[i].className=='aq3bullet') ? "aq3bullet" : "aq3open";
				}
			}
		}
	} 


	
/*              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;
  }
}


