/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \
|		
|		Copyright (c) 2007
|		Design + HTML/CSS/DOM JavaScript : Smart Agence
|		http://www.smartagence.com/
|		
\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

if(!siteMapManager) {
	var siteMapManager;
}

/* ______________________[ 00 | Rollover image-maps ]________________________ */

function highlightRegion(sImgID,sNewSrc){
		document.getElementById(sImgID).src = sNewSrc;
};


/* ______________________[ 01 | Interactivit&eacute; 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)) {
		var navRoot=document.getElementById(who);
		var aLI = navRoot.getElementsByTagName("LI");
		for (i=0;i<aLI.length;i++) {
			if (aLI[i].nodeName=="LI") {
				aLI[i].onmouseover = function() {this.className += " over";};
				aLI[i].onmouseout = function() {this.className=this.className.replace(" over", "");};
			}
		}
	}
	
	if(!(navigator.userAgent.indexOf('Gecko') != -1)) {
		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<navItm.length;i++) {
		navLnk[i].onfocus = function() {
			if (this.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):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 | 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);
};

function select_redirect(bitRedirect,oSelect) {
	var adresse = oSelect.options[oSelect.selectedIndex].value;
	if ((bitRedirect == 1) && (adresse !=''))
		window.open(adresse,'directory','width=500px,height=550px,scrollbars=yes');
}

function select_redirect2(bitRedirect,oSelect) {
	var adresse = oSelect.options[oSelect.selectedIndex].value;
	if ((bitRedirect == 1) && (adresse !='')) {
		var oCegeFrame = document.getElementById('cegeframe');
		oCegeFrame.src=adresse;
		with(oCegeFrame) {
			style.display = "block";
		}
	}
}

/* ______________________[ 05 | Ajout de la page courante aux favoris ]________________________ */

/* Mettre la page courante en favoris � MSIE and Firefox */
function myBookmark() {
	if (document.getElementById&&document.getElementById("favoris")) {
		var el=document.getElementById("favoris");
		var operaStr="&lsaquo; Ctrl + T &rsaquo; 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;
		}
	}
};

/* ______________________[ 06 | <select/> au clavier ]________________________ */

/* Thanks goes to Cameron Adams from http://www.themaninblue.com/ */

function initSelect(whichSelect) {
	if (document.getElementById&&document.getElementById(whichSelect)) {
		var theSelect=document.getElementById(whichSelect);
		theSelect.changed=false;
		theSelect.onfocus=selectFocussed;
		theSelect.onchange=selectChanged;
		theSelect.onkeydown=selectKeyed;
		theSelect.onclick=selectClicked;
		return true;
	}
};

function selectChanged(theElement) {
	var theSelect;
	if (theElement&&theElement.value) {
		theSelect=theElement;
	} else {
		theSelect=this;
	}
	if (!theSelect.changed) {
		return false;
	}
	if (theSelect.value&&theSelect.value!="0") window.location=theSelect.value;
	return true;
};

function selectClicked() {
	this.changed=true;
};

function selectFocussed() {
	this.initValue=this.value;
	return true;
};

function selectKeyed(e){
	var theEvent;
	var keyCodeTab="9";
	var keyCodeEnter="13";
	var keyCodeEsc="27";
	if (e) {
		theEvent=e;
	} else {
		theEvent=event;
	}
	if ((theEvent.keyCode==keyCodeEnter||theEvent.keyCode==keyCodeTab)&&this.value!=this.initValue) {
		this.changed=true;
		selectChanged(this);
	} else if (theEvent.keyCode==keyCodeEsc) {
		this.value=this.initValue;
	} else {
		this.changed=false;
	}
	return true;
};

/* ______________________[ 07 | faux select ]________________________ */

function SmartPos() {
	navBase=document.getElementById("otherSites").getElementsByTagName("UL");
	for (i=0; i<navBase.length; i++){
	  if (navBase[i].parentNode.className=='simuSelect') {
     var pos=navBase[i].offsetHeight+18;
     navBase[i].style.margin="-"+pos+"px 0 0 9px";
    }
  }	
}

function CreateSelect () {
  if (document.getElementById&&document.getElementById('otherSites')){
    //alert('oui');
		var cible=document.getElementById('otherSites');
		var t="<p class='plabel'>Other Cegelec group's web sites</p><div class='simuSelect' id='SimuPays'><p><strong>Select a country</strong></p><ul><li><a target='_blank' href='http://www.cegelec.at'>Austria</a></li><li><a target='_blank' href='http://www.comsip.com.bh'>Bahrain</a></li><li><a target='_blank' href='http://www.cegelec.com.br'>Brazil</a></li><li><a target='_blank' href='http://www.cameroon.cegelec'>Cameroon</a></li><li><a target='_blank' href='http://www.cegelec.com.cn'>China</a></li><li><a target='_blank' href='http://www.cegelec.cz'>Czech Republic</a></li><li><a target='_blank' href='http://www.cegelec.lu'>G D of Luxembourg</a></li><li><a target='_blank' href='http://www.cegelec.de'>Germany</a></li><li><a target='_blank' href='http://www.maroc.cegelec.com'>Morocco</a></li><li><a target='_blank' href='http://www.cegelec.pl'>Poland</a></li><li><a target='_blank' href='http://www.cegelec.pt'>Portugal</a></li><li><a target='_blank' href='http://www.cegelec.es'>Spain</a></li><li><a target='_blank' href='http://www.cegelec.ch'>Switzerland</a></li><li><a target='_blank' href='http://www.cegelec.nl'>The Netherlands</a></li></ul></div><p class='pchoix'>OR</p><div class='simuSelect' id='SimuAct'><p><strong>Select an activity</strong></p><ul><li><a target='_blank' href='http://www.defense.cegelec.com'>Defence</a></li><li><a target='_blank' href='http://www.maintenance-globale.cegelec.com/Cegelec_ang/index.htm'>Global Maintenance</a></li><li><a target='_blank' href='http://www.ndt.cegelec.com'>Non destructive testing</a></li><li><a target='_blank' href='http://www.oilandgas.cegelec.com'>Oil & Gas</a></li><li><a target='_blank' href='http://www.evolynx.eu'>Security</a></li><li><a target='_blank' href='http://www.space.cegelec.de'>Space</a></li><li><a target='_blank' href='http://www.transport.cegelec.com'>Transport</a></li></ul></div>"+cible.innerHTML;
		cible.innerHTML=t;
	}
};

function SmartSelect(who) {
	var args = SmartSelect.arguments;
	for (n=0;n<args.length;n++) {
		if (document.getElementById(args[n])) {
			mySelect=document.getElementById(args[n]);
			myList=mySelect.getElementsByTagName("UL")[0];
			myInput=mySelect.getElementsByTagName("P")[0];
			ProcessSelect(mySelect, myList, myInput);
		}
	}  
};

function ProcessSelect (Sel, list, inp) {
	list.className="cache";  
	inp.onclick = function() {
		affichSelect (Sel, list, inp);
	};	
	inp.onmouseout = null;

	list.onmouseover = function() { this.parentNode.firstChild.nodeType==1?this.className="overIE":this.className="over";};
	list.onmouseout = function() { this.className = "cache"; }; 
};

function affichSelect (Sel, list, inp) {
	if (list.className=="cache"){
		list.parentNode.firstChild.nodeType==1?list.className="overIE":list.className="over";
	}
	else {
		list.className="cache";
	}
}


/* ______________________[ 08 | Bouton generique - (c) remy@smartpixel / Smart Agence, 2007]________________________ */

function AddToolButton(sContainerID, oParams){
	var DOM = document.createElement && document.getElementById && document.getElementById(sContainerID);
	if(DOM){
		var cible=document.getElementById(sContainerID).getElementsByTagName('UL');
		
		if(cible){
			var oLi = document.createElement("LI");
			var oLink = document.createElement("A");
			var oImg = document.createElement("IMG");
			
			with(oLink){
				id = oParams.linkId;
				title = oParams.imgAlt;
				href = oParams.linkHREF ? oParams.linkHREF : "javascript:;";
				onclick = oParams.onclick ? oParams.onclick : "";
			};
			
			with(oImg){
				src = oParams.imgSrc;
				alt = oParams.imgAlt;
			};
			
			oLink.appendChild(oImg);
			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);
			}
		}	// end if cible
	}	// end if DOM
};	// end AddToolButton()

/* ______________________[ 09 | Interactivité carte du département ]________________________ */

function SmartCarte(cible) {
	if (document.getElementById&&document.getElementById(cible)) {
		var root=document.getElementById(cible).getElementsByTagName("AREA");
		for (a=0;a<root.length;a++) {
			if (root[a].nodeName=="AREA") {
				root[a].onmouseover=function() {
					var divid="d"+this.id.substring(1,this.id.length);
					SmartShowHide(divid);
				}
				root[a].onmouseout=function() {
					var divid="d"+this.id.substring(1,this.id.length);
					SmartShowHide(divid);
				}
			}
		}
	}
}

function SmartShowHide(who) {
	var div=document.getElementById(who);
	div.className=div.className==""?"over":"";
}

/* ______________________[ 10 | Lancement des scripts ]________________________ */

window.onload=function() {
  CreateSelect();
  SmartPos();
	SmartHover("NavigationPrincipale");
	SmartSelect("SimuPays", "SimuAct");
	AddToolButton("TxtTools",{linkId:"print",linkHREF:"javascript:DirectPrint();",imgSrc:"/fileadmin/templates/img/ico_print.gif",imgAlt:"Print current page",insertBefore:"Send"});
	AddToolButton("TxtTools",{linkId:"Tmoins",imgSrc:"/fileadmin/templates/img/ico_tmoins.gif",imgAlt:"Decrease texte size",insertBefore:"print"});
	AddToolButton("TxtTools",{linkId:"Tplus",imgSrc:"/fileadmin/templates/img/ico_tplus.gif",imgAlt:"Increase texte size",insertBefore:"Tmoins"});
	AddToolButton("TxtTools",{linkId:"favoris",linkHREF:"javascript:myBookmark();",imgSrc:"/fileadmin/templates/img/ico_favori.gif",imgAlt:"Bookmark current page"}); 
	SmartSize("ColB","ColC","ColD","ColMenu","ColContenu","ColContextuelle");
	if(siteMapManager) {
		siteMapManager.initialize("plansite",true).makeTreesC();
	}
	if(document.getElementById("selectCountry")) {
		var oSelectCountry = document.getElementById("selectCountry");
		oSelectCountry.onchange = function() {
			select_redirect2(1,this);
		};
	}
	if(document.getElementById("selectDivision")) {
		var oSelectDivision = document.getElementById("selectDivision");
		oSelectDivision.onchange = function() {
			select_redirect2(1,this);
		};
	}
	SmartCarte("Map");
};
