/* variables de configuration */

document.writeln('<script type="text/javascript" src="//static.s-sfr.fr/resources/ist/loader.sfr.min.js"></script>');
document.writeln('<script type="text/javascript">sfrIstConfig.menuSelectedItem=0;</script>');


if (istDebugMode == undefined)
{
	var istDebugMode = false;
}

var varUniv = "univers"; // nom de la variable univers appelee en GET lors de l'appel a l'IST (ex : ist.js?univers=assistance)

var browser=navigator.appName;
var browser_floatversion=navigator.appVersion;
var browser_version=parseFloat(browser_floatversion);

/* IST */
var ist = [];
var cferAff = false;

if (!istDebugMode)
{
	if (document.URL.indexOf("www.sfr.fr") != "-1") {
		server = "//www.sfr.fr";
		akamai = "//s1.s-sfr.fr";
	}
	else if (document.URL.indexOf("cms.sfr.fr") != "-1") {
		server = "//cms.sfr.fr";
		akamai = "//cms.sfr.fr";
	}
	else if (document.URL.indexOf("www.sfr.sfrdev.fr") != "-1") {
		server = "//www.sfr.sfrdev.fr";
		akamai = "//s1.s-sfr.sfrdev.fr";
	}
	else if (document.URL.indexOf("cms.sfr.sfrdev.fr") != "-1") {
		server = "//cms.sfr.sfrdev.fr";
		akamai = "//cms.sfr.sfrdev.fr";
	}
	else if ((document.URL.indexOf("www-devsf") != "-1") || (document.URL.indexOf("localhost") != "-1")) {
		server = "";
		akamai = "";
	}
	else {
		server = "//www.sfr.fr";
		akamai = "//s1.s-sfr.fr";
	}
}else
{
	server = "//localhost:10007";
	akamai = "//localhost:10007";
}

univers = getUnivers(); // le nom de l'univers est stocke dans la variable

if (univers != "") {
	var _inc = "";
	_inc += "<link rel='stylesheet' type='text/css' href='"+akamai+"/css/ist.css' />";
	
	// ajout de la css par rapport a l'univers
	if (univers != "notransverse")
		_inc += "<link rel='stylesheet' type='text/css' href='"+akamai+"/css/"+univers+"/common.css' />";
	document.writeln(_inc);
}

if (univers == "notransverse")
	_stats_univers="transverse";
else
	_stats_univers=univers;

SfrIstUtils = function()
{
	this.hasClass = function(ele, cls)
	{
		return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
	}
	
	this.addClass = function(ele,cls) {
		if(ele)
		{
			if (!this.hasClass(ele,cls)) ele.className += " "+cls;
		}
	}
	

	this.removeClass = function(ele,cls) {
		if(ele)
		{
			if (this.hasClass(ele,cls)) {
				var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
				ele.className=ele.className.replace(reg,' ');
			}
		}
	}
	

	// retourne un tableau d'element ayant la classe cls
	// on peut tester avec plusieurs class, avec le separateur | ou &
	this.getElementsWithClass = function(context, cls) {

		var result = [];
		
		if (context)
		{
			var classesOR = cls.split("|");
			var classesAND = cls.split("&");
			var elements = context.getElementsByTagName("*");
			
			if (classesAND.length > 1)
			{
				for ( var i = 0, size = elements.length; i < size; i++ )
				{
					var nbLackClass = 0;
					
					for (var c = 0, max = classesAND.length; c < max; c++)
					{
						if (elements[i] != undefined && this.hasClass(elements[i], classesAND[c]))
							nbLackClass++; 
					}

					if (nbLackClass == classesAND.length)
					{
						result.push(elements[i]);
					}
				}
			}
			else
			{
				for ( var i = 0, size = elements.length; i < size; i++ )
				{						
					for (c = 0, max = classesOR.length; c < max; c++)
					{
						if (elements[i] != undefined && this.hasClass(elements[i], classesOR[c]))
						{
							result.push(elements[i]);
							break; // stops testing once at least one class has been found
						}
					}
				}
			}
		}

		return result;
	}
	
	this.getFirstIndexWithClass = function (elementsList, cls) {
		// retourne un entier correspondant à la position
		// du premier element ayant la classe cls
		
		var i=0;
		while(i < elementsList.length && !this.hasClass(elementsList[i], cls)) {
			i++;
		}
		
		return i;
	}
	

	this.addEvent = function(obj,type,fn) {

		if (obj.addEventListener) {
			obj.addEventListener(type,fn,false);
			return true;
		} else if (obj.attachEvent) {
			obj['e'+type+fn] = fn;
			obj[type+fn] = function() { obj['e'+type+fn]( window.event, obj );}
			var r = obj.attachEvent('on'+type, obj[type+fn]);
			return r;
		} else {
			obj['on'+type] = fn;
			return true;
		}

	}
	
	this.each = function(collection, callback)
	{
		// TODO: check for input type !
		for (var obj in collection)
			callback(collection[obj]);
	}

	this.getEventTarget = function(e, current)
	{
		if (!e)
			var e = window.event;
		
		return e.currentTarget || current;
	}


	this.getEventRelTarget = function(e)
	{
		if (!e)
			var e = window.event;
		
		return e.target || e.srcElement;
	}
	
	this.toggle = function(el)
	{
		if (el)
		{
			if (el.style.display == "none" || el.style.display == "")
				el.style.display = "block";
			else		
				el.style.display = "none";
		}
	}

	this.toggleClass = function(el, cls)
	{
		if (el)
		{
			if (this.hasClass(el, cls))
				this.removeClass(el, cls);
			else
				this.addClass(el, cls);
		}
	}

	this.setAttribute = function(el, attr, val)
	{
		el.removeAttribute(attr);
		var z = document.createAttribute(attr);
		z.value = val;
		el.setAttributeNode(z);
	}
}

istUtils = new SfrIstUtils();

// parametre : el -> Element DOM pour lequel on doit determiner le niveau d'arborescence
// determine a quel niveau d'arborescence appartient l'element
// retourne un tableau a 2 indice : le parent contenant tout le niveau (element DOM) et le niveau (entier)
//
//
// NOTE: retourne l'element selectionnable le plus proche de l'element selectionne
// seuls les niveaux n-2 et n-3 sont selectionnables
// tout element de n-4, n-5 retournera donc le parent n-3
//
function getMyLevel(el)
{
	if (istDebugMode)
		console.log('getMyLevel');
	var nbLevel = 5;
	var levelNotFound = true;
	var cursor = el;
	var level = 0;

	while (levelNotFound)
	{
		for (var i = 1; i <= nbLevel; i++)
		{
			if (istUtils.hasClass(cursor, "niv" + i))
			{
				levelNotFound = false;
				level = i;
			}
		}
		
		if (levelNotFound)
		{
			cursor = cursor.parentNode;
			if ((cursor.nodeName.toUpperCase() == "BODY") || cursor == undefined)
			{
				levelNotFound = false;
			}
		}
	}

	var result = new Array(cursor, level);

	return result;
}

/********************
 * BEGIN PATCH IST v2 
 ********************/

/*
 * OVERRIDE ist_aff() to display IST v2 header & footer
 */
function ist_aff(nav)
{

	if (nav == "chemindefer") {
		cfer();
	} else if (nav.indexOf("navg.jsp") > -1 || nav.indexOf("navtab.jsp") > -1) {
	
		document.write("<script type='text/javascript' charset='ISO-8859-1' src='"+server+"/"+nav+"'></script>");
		
	} else {
		if (nav.indexOf("header") > -1)
			document.writeln('<script type="text/javascript">$sfr.istHeaderHome();</script>');
		if (nav.indexOf("footer") > -1) {
			document.writeln('<script type="text/javascript">$sfr.istFooter();</script>');
			document.writeln('<style>#ctn_ft .footer.sfrDom li {display:block;}</style>');
		}
	}
	$sfr(".itemProfile.sso").show();
	$sfr('#sfrHeaderHome').css({"margin-bottom" : 0});
}
/********************
 * END PATCH IST v2 
 ********************/

function ist_action(url, noAff)
{
	var navT = url.split("/");
	var nomPage = navT[navT.length - 1];
	var nomPageT = nomPage.split(".");
	var nav = nomPageT[0];

	// affiche le fragment si noAff === undefined ou false
	// par defaut on affiche tout en cache et nav_xx() se charge d'afficher l'element profile...
	if (!noAff)
	{   
		document.write("<div id='ist_"+nav+"'>");
		document.write(ist[url]);
		document.write("</div>");
	}

	if (istDebugMode)
		console.log('ist_action=', url);

	// on execute l'action qui correspond au fragment qu'on a affiche
	if (url.indexOf("header") > -1)
		ist_navh();
	else if (url.indexOf("navg") > -1)
		ist_navg2();
	else if (url.indexOf("navtab") > -1)
		ist_navtab();
	else if (url.indexOf("quiz") > -1)
	{
		var sfrIstQuizScript = document.getElementById("quizScript");
		if (sfrIstQuizScript)
		{
			eval(sfrIstQuizScript.innerHTML);
			sfrQuizInit();
		}
	}
	
	$sfr(document).ready(function(){
			
			$sfr(".itemProfile.sso").show();
			$sfr('#sfrHeaderHome').css({"margin-bottom" : 0});
			
	});
	
}
 
// ajout des liens externes a l'arborescence
function updateMap(nom, mapExt)
{	
	// On concatene l'html qui va etre injecte dans la balise correspondante
	var html = "";

	for (var i = 0; i < mapExt.length; i++)
	{
		html += "<li><a href='" + mapExt[i].url + "'>> " + mapExt[i].name + "</a></li>";
	}

	document.write(html);
	ist_navg();
}

// recuperation de l'univers donne en parametres
function getUnivers()
{
	var src = document.getElementById("ist_js").src;
	if ((src.indexOf(varUniv) != -1) && (src.split(varUniv + "=")[1] != ""))
	{
		return src.split(varUniv + "=")[1];
	}
	else
		return "transverse";
}

/* returns the directory part of the specified url or the full url if there wasn't any directory part
   ex.: 'http://www.sfr.fr/vos-services/services-mobiles/index.jsp' would return '/vos-services/services-mobiles/'
   ex.2: 'http://www.sfr.fr/' will return 'http://www.sfr.fr'
   
*/
function getDirPart(url)
{
	var reg = /^(http:\/\/|https:\/\/|\/\/){1}([a-z\-]+\.[a-z\-]+\.[a-z\-]+)([a-zA-Z0-9\.\-\/\?\=]*)/;

	if (result = url.match(reg))
	{
		//  (for the sake of compatibility we return the full url if directory part is empty)
		if (result[3].length < 2)
			return url;
		else
			return result[3];
	}
	else
		return url;
}

/* returns the list of selected elements in the navigation found inside '#nav' element
   @return type: array of Elements of type <a/>
*/
function getSelectedMenus(nav)
{
	var divElt = document.getElementById(nav),
	selectedMenus = [],
	currentPage = (typeof(_hilight) === 'string') ? _hilight : document.URL;
	currentPage = getDirPart(currentPage);

	if (divElt)
	{
		var linksList = divElt.getElementsByTagName("a");
		
		for ( var i = 0, taille = linksList.length; i < taille; i++ )
		{
			if (getDirPart(linksList[i].href) == currentPage)
			{
				selectedMenus.push(linksList[i]);
			}
		}
	}

	return selectedMenus;
}

// lien plus + moteur de recherche
function ist_navh()
{
	var a = function()
	{
		var that = this;
		
		this.services = document.getElementById("hdnav_services");
		this.toggleIndicator = this.services.getElementsByTagName("small")[0];
		
		if (!this.services)
			return;

		this.sublist = document.getElementById("hdnav_sublist");

		if (!this.sublist)
			return;

		istUtils.setAttribute(this.services, "href", "javascript:;");

		istUtils.addEvent(document, "click", function(e)
		{
			var relTarg = istUtils.getEventRelTarget(e);
			
			if (relTarg != that.services && relTarg != that.toggleIndicator)
			{
				that.documentClick();
			}
		});

		istUtils.addEvent(this.services, "click", function(e)
		{
			that.servicesClick();
		});
	}

	a.prototype = 
	{
		servicesClick: function()
		{		
			this.servicesToggle();
		},
		
		documentClick: function()
		{
			if (this.sublist.style.display == "block")
			{
				this.servicesToggle();
			}
		},
		
		servicesToggle: function()
		{
			this.services.blur();
			istUtils.toggle(this.sublist);
			istUtils.toggleClass(this.services, "collapse");
			istUtils.toggleClass(this.sublist, "enabled");

			if (istUtils.hasClass(this.services, "collapse"))
				this.services.getElementsByTagName("small")[0].innerHTML = "&#9650;";
			else 
				this.services.getElementsByTagName("small")[0].innerHTML = "&#9660;";
		}
	}; // a.prototype
	
	// Gestion du switch tab pour les formulaires du header
	var b = function(c)
	{
		  	
		var conteneur = document.getElementById(c);
		if (conteneur)
		{
			this.tabsA = conteneur.getElementsByTagName("a");
		    this.tabsN = this.tabsA.length;

		    this.init();
		}
	};
		  
	b.prototype = 
	{
	    init:function()
		{	  
			var that = this;
		    for (t in this.tabsA)
		    {
				if (this.tabsA[t].nodeName == "A")
				{
					if (istUtils.hasClass(this.tabsA[t], "selected"))
					{
						var formSelected = this.tabsA[t].getAttribute('title');
						document.getElementById(formSelected).style.display = "block";
						document.getElementById(formSelected).q.focus();
					}
					
					istUtils.setAttribute(this.tabsA[t], "href", "javascript:;");
					
					istUtils.addEvent(this.tabsA[t], "click", function(e)
					{
						this.blur();
					    that.switchTab(this);
					    return false;
					});
				}
			}
		},
		    
		resetTab: function()
		{    	
			for (t in this.tabsA)
			{
				if (this.tabsA[t].nodeName == "A")
				{
					if (istUtils.hasClass(this.tabsA[t], "selected"))
							istUtils.removeClass(this.tabsA[t], "selected")

					var formSelected = this.tabsA[t].getAttribute('title');
					document.getElementById(formSelected).style.display = "none";
				}
			}
		},
		      
		switchTab: function(c)
		{
			this.duplicateFieldValue();
		    this.resetTab();
		    istUtils.addClass(c, "selected");
		    var formSelected = that.getAttribute('title');
		    document.getElementById(formSelected).style.display = "block";
			document.getElementById(formSelected).q.focus();
		},
		      
		// copie la saisie du champs de recherche "d" vers les autres champs de recherche
		duplicateFieldValue: function()
		{
		var TabNameToDuplicate = "";
		
		for (t in this.tabsA)
		{
			if (this.tabsA[t].nodeName == "A")
			{
				if (istUtils.hasClass(this.tabsA[t], "selected"))
				{
					TabNameToDuplicate = this.tabsA[t].getAttribute('title');
				}					    
			}
		}

		if (TabNameToDuplicate != "")
		{
			var tab = document.getElementById(TabNameToDuplicate);
			var valueToduplicate = istUtils.getElementsWithClass(tab, "fld_txt")[0].value;

			for (t in this.tabsA)
			{
				if (this.tabsA[t].nodeName == "A")
				{
					var tabName = this.tabsA[t].getAttribute('title');
					var tab = document.getElementById(tabName);
					var valueToduplicate = istUtils.getElementsWithClass(tab, "fld_txt")[0].value = valueToduplicate;
				}
			}
		}
	}	// b.prototype = ...	      
};	// function ist_navh()
		  
		  new a();
		  new b("searchTabs");
}

function ist_navg2()
{
	var aCurrent = getSelectedMenus("ist_navtab");
	var navG = document.getElementById("ist_navg");

	var ul = document.createElement('ul');

	var title = document.createElement('div');
}

// ouverture de l'onglet courant dans navg
function ist_navg()
{
	var aCurrent = getSelectedMenus("ist_navg");
	var navG = document.getElementById("ist_navg");

	// open highlighted menu, if any
	for (var i in aCurrent)
	{
		istUtils.addClass(aCurrent[i].parentNode, "open");
		istUtils.addClass(aCurrent[i].parentNode, "current");
		istUtils.addClass(aCurrent[i].parentNode.parentNode.parentNode, "open");
	}

	// if the userProfile is defined, first show the corresonding elements
	if (typeof(userProfilePsw) != "undefined")
	{
		var listItemOfProfil = istUtils.getElementsWithClass(navG, userProfilePsw);

		for (var p in listItemOfProfil)
		{
			if (listItemOfProfil[p].nodeName == "LI")
			{
				// listItemOfProfil[p].style.display = "inline";
				listItemOfProfil[p].style.display = "block";
			}
		}
	}
	
	// then show elements that should always appear
	var listItemAlwaysShowed = istUtils.getElementsWithClass(navG, "always");

	for (var a in listItemAlwaysShowed)
	{
		if (listItemAlwaysShowed[a].nodeName == "LI")
		{
			// listItemAlwaysShowed[a].style.display = "inline";
			listItemAlwaysShowed[a].style.display = "block";
		}
	}
}

// ouverture du/des onglet(s) courant(s) dans navtab
function ist_navtab()
{
	document.write("<link rel='stylesheet' type='text/css' href='" + akamai + "/css/ist_navtab.css' />");
	
	var mainContainer = document.getElementById("ist_navtab");
	
	// on recupere le/les elements selectionnes
	var selectedItems = getSelectedMenus('ist_navtab');
	if (istDebugMode)
		console.log('navtab', selectedItems);

	if (selectedItems.length > 0)
	{
		// pour chaque element selectionne, on recupere le niveau
		for (var n = 0, max = selectedItems.length; n < max; n++)
		{
			// get item level information (element + levelNum)
			var levelInfos = getMyLevel(selectedItems[n]),
			levelNum = (levelInfos) ? levelInfos[1] : null,
			itemContainer = (levelInfos) ? levelInfos[0] : null;
			if (istDebugMode)
				console.log(levelInfos);

			if (levelNum == 2)  // le hilight est dans une section n-2
			{
				if (istDebugMode)
					console.log('** levelNum == 2 **');
				
				istUtils.addClass(selectedItems[n].parentNode, "open");
				istUtils.addClass(selectedItems[n].parentNode, "current");
				istUtils.addClass(selectedItems[n], "selected");
			
				// on hilight le n-3 correspondant
				var itemContainerLi = itemContainer.getElementsByTagName("li");
				var position = istUtils.getFirstIndexWithClass(itemContainerLi, "open");
				var tab = istUtils.getElementsWithClass(mainContainer, "niv3");		

				if (position < tab.length)
				{
					istUtils.addClass(tab[position], "open");
				}
			}
			else  // n-3 ou n-4
			{
				if (istDebugMode)
					console.log('** levelNum == 3 **');
				
				// first open the n-3 menu
				if (levelNum == 3) // == 3
					istUtils.addClass(itemContainer, "open");
				else if (levelNum == 5)
					istUtils.addClass(itemContainer.parentNode.parentNode.parentNode.parentNode, "open");

				// then get the first (n-3) opened menu
				if (levelNum == 5)
					var itemContainerUl = itemContainer.parentNode.parentNode.parentNode.parentNode.parentNode.childNodes;
				else
					var itemContainerUl = itemContainer.parentNode.childNodes;

				// store the index (in the DOM) of this menu
				var position = istUtils.getFirstIndexWithClass(itemContainerUl, "open");
				
				if (istDebugMode)
					console.log('posUl', itemContainerUl, position);
				
				// get the coresponding n-2 menu item
				var selectedLi = istUtils.getElementsWithClass(mainContainer, "niv2")[0].childNodes[position];
	
				// open the menu and selects its links
				istUtils.addClass(selectedLi, "open");
				istUtils.addClass(selectedLi, "current");
				istUtils.addClass(selectedLi.getElementsByTagName("a")[0], "selected");
			}
			
			/* patch IST v2 */
	
	$sfr(document).ready(function(){
			
			$sfr(".itemProfile.sso").show();
			$sfr('#sfrHeaderHome').css({"margin-bottom" : 0});
			
	});
	
			
		}

		/* hover */	
		// ajout des evts pour le niv3 (ouverture des menus deroulants niv4)
		var AllNiv3 = istUtils.getElementsWithClass(mainContainer, "niv3");

		// show all level 4 menus when hover a level 3 menu (we do that for any level 3 menus, including the 95% which will be hidden because they don't
		// follow the profile...
		for (n in AllNiv3)
		{
			var AllNiv3Li = AllNiv3[n].childNodes;
			for (l in AllNiv3Li)
			{
				if (AllNiv3Li[l].nodeName == "LI")
				{
					istUtils.addEvent(AllNiv3Li[l], "mouseover", navTab_HandleMenuOver);
					istUtils.addEvent(AllNiv3Li[l], "mouseout", navTab_HandleMenuOut);
				}
			}
		}
	}	// / selectedItems.length
	
	// now that we have "opened" all selected menus, we simply show (ie: set display to inline) using the selected profile
	// affichage des items correspondant au profil
	if (typeof(userProfilePsw) != "undefined")
	{
		var listItemOfProfil = istUtils.getElementsWithClass(mainContainer, userProfilePsw);

		if (listItemOfProfil.length > 0)
			istUtils.each(listItemOfProfil, function(item) {
				if (item.nodeName == "LI")
					item.style.display = "inline";
			});
		else
		{
			if (userProfilePsw != "prospect" && userProfilePsw != "" )
			{
				var listItemOfProfilSSO = istUtils.getElementsWithClass(mainContainer, "sso");
				
				istUtils.each(listItemOfProfilSSO, function(item) {
					if (item.nodeName == "LI")
						item.style.display = "inline";
				});
			}
		}
	}
	
	var listItemAlwaysShowed = istUtils.getElementsWithClass(mainContainer, "always")
	
	for (var a in listItemAlwaysShowed)
	{
		if (listItemAlwaysShowed[a].nodeName == "LI")
			listItemAlwaysShowed[a].style.display = "inline";
	}
	
	var listItemNiv3Opened = istUtils.getElementsWithClass(mainContainer, "niv3&open");
	
	// add a 'first' class to the first n - 3 element
	if (listItemNiv3Opened.length > 0)
	{
		var listItemNiv3OpenedLi = listItemNiv3Opened[0].childNodes;
		
		for (var i in listItemNiv3OpenedLi)
		{
			if ((listItemNiv3OpenedLi[i].nodeName == "LI") && (listItemNiv3OpenedLi[i].style.display == "inline"))
			{
				istUtils.addClass(listItemNiv3OpenedLi[i], "first");
				break;
			}
		}
	}	
}	// /ist_navtab()

function navTab_HandleMenuOver(e, current)
{
	if (!e)
		var e = window.event;
	
	e.cancelBubble = true;
	
	if (e.stopPropagation)
		e.stopPropagation();

	var elMouseOvered = istUtils.getEventTarget(e, current);
	
	if (elMouseOvered.nodeName == "LI")
	{
		var menuDeroulants = istUtils.getElementsWithClass(elMouseOvered, "menu-deroulant");
		
		if (menuDeroulants.length > 0)
		{
			var menuDeroulant = menuDeroulants[0];
	
			if (menuDeroulant && menuDeroulant.getElementsByTagName("li").length > 0)
			{
				var elLink = istUtils.getElementsWithClass(elMouseOvered, "inlineSublist-haut-normal")[0];
				
				istUtils.addClass(elLink, "inlineSublist-haut-hover");
				istUtils.removeClass(elLink, "inlineSublist-haut-normal");
				elMouseOvered.style.zIndex = "101";
	
				menuDeroulant.style.display = "block";
				
				//if((browser == "Microsoft Internet Explorer") && (browser_version < 7))
				//{
					var largeurItem = elMouseOvered.offsetWidth;

					if (menuDeroulant.offsetWidth < largeurItem)
						menuDeroulant.style.width = largeurItem - 12;
			//	}
			}
		}
	}
}

function navTab_HandleMenuOut(e,current)
{
	if (!e)
		var e = window.event;
	
	e.cancelBubble = true;
	
	if (e.stopPropagation)
		e.stopPropagation();

	var elMouseOuted = istUtils.getEventTarget(e, current);
	
	if (elMouseOuted.nodeName == "LI" && istUtils.hasClass(elMouseOuted.parentNode, "niv3"))
	{
		var menuDeroulants = istUtils.getElementsWithClass(elMouseOuted, "menu-deroulant");
		
		if (menuDeroulants.length > 0)
		{
			var menuDeroulant = menuDeroulants[0];
			
			if (menuDeroulant && menuDeroulant.getElementsByTagName("li").length > 0)
			{
				var elLink = istUtils.getElementsWithClass(elMouseOuted, "inlineSublist-haut-hover")[0];
				istUtils.addClass(elLink, "inlineSublist-haut-normal");
				istUtils.removeClass(elLink, "inlineSublist-haut-hover");
				
				menuDeroulant.style.display="none";
			}
		}
	}
}

function cfer()
{
	cferAff = true;
	if (univers != "transverse" && univers != "notransverse")
		document.write("<script type='text/javascript' charset='UTF-8' src='"+server+"/ist/"+univers+"/arboJSON.js'></script>"); 
}

function cferAffF()
{
	if (!cferAff)
		return;
	
	// affichage du chemin de fer

	// On recherche dans l'arbo l'endroit ou on se trouve
	var i = 0;
	var found = false;
	var currentPage = (typeof(_hilight) === 'string') ? _hilight : document.URL;
	currentPage = getDirPart(currentPage);
	
	if (istDebugMode)
		console.log('currentPage', currentPage);

	while (i < arboJSON.length && !found)
	{
		if (getDirPart(arboJSON[i].URL) == getDirPart(currentPage))
		{
			if (istDebugMode)
				console.log('trouve', getDirPart(arboJSON[i]));
			found = true;
			break;
		}
		else
			i++;
	}
	
	if (found)
	{ // on a trouve, on a va chercher ses parents
		document.write("<div class=\"content\"><ul class=\"cnt_bdct\">");
	
		var current = arboJSON[i];
		if (typeof(_cfer_name) == "undefined")
		{
			var html = "<li class=\"currentPage\">> " + arboJSON[i].LABEL + "</li>";
		}
		else
		{
			var html = "<li class=\"currentPage\">> " + _cfer_name + "</li>";
		}
		
		var currentArbo = current;
		
		do
		{
			var parent_id = currentArbo.PARENT_ID;
			var parent = getArboParent(arboJSON, parent_id);
			
			if (parent != -1)
			{
				html = "<li class=\"hidden\">> <a href=\"" + parent.URL + "\">" + parent.LABEL + " </a></li>" + html;
				currentArbo = parent;
			}
		}
		while (parent != -1);
		
		html = "<li class=\"welcome\"><a href=\"/do/Home\">Accueil</a></li>" + html;
		document.write(html + "</ul></div>");
	}
}

function getArboParent(arboJSON, parent_id)
{
	// On recherche dans l'arbo l'endroit ou on se trouve
	var i = 0;
	var found = false;
	while (i < arboJSON.length && !found)
	{
		if (arboJSON[i].IST_ITEM_ID == parent_id)
			found = true;
		else
			i++;
	}
	
	if (found) // on a trouve, on a va chercher ses parents
		return arboJSON[i];
	else
		return -1; // si non trouve
}

/* Bandeaux publicitaires */
function SFR_AdBanner(tagId, size, params)
{
	/*
	tagId = Identifiant de tag
	size = Dimensions [megaban|square|halfsquare|sky]
	params = Parametres optionnels : notation cle=valeur, separateur ';' (Ex: 'kvtype=adsl;kvage=30plus')
	*/
	var adserver = '';
	var network = '516';
	var sizes = new Array;
		sizes['sky'] = 168;
		sizes['square'] = 170;
		sizes['megaban'] = 225;
		sizes['halfsquare'] = 457;
		sizes['1pixel'] = 16;

	( params ) ? params += ';' : params = '';
	( window.location.protocol == 'https:' ) ? adserver = 'https://adssl-dc2.adtech.de' : adserver = 'http://adserver.aol.fr';
	document.write('<scr'+'ipt language="javascript1.1" src="' + adserver + '/addyn|3.0|' + network + '|' + tagId + '|0|' + sizes[size] + '|ADTECH;loc=100;target=_blank;sub1=[subst];key=key1+key2+key3+key4;' + params + 'grp=[group];misc='+new Date().getTime()+'"></scri'+'pt>');
}

function changeTextToOther()
{
	return false;
}

// TODO: highlight selected element
var istAPI = (function() 
{
	/**** Private methods ****/

	/**** Public interface ****/
	return {

		/****************************
		 *	displays the left Navigation to the destination node
		 *
		 *  @params:
		 *
		 *  destinationElt: node where to insert the LeftNavigation
		 *
		 * NOTE: the use of left navigation requires a level5 (niv5) menu and an _hilight set to a level 5 item
		 *
		 */
		getLeftNavigation: function(destinationElt)
		{
			var container = null,
				selectedMenu = null;

			if (typeof destinationElt === 'string')
			{
				container = document.getElementById(destinationElt);
				if (istDebugMode)			
					console.log(container);
			}
			else	// assume we receive an element
				container = destinationElt;

			// get Elements selected (we assume only n-5 level can be highlighted...
			// we also assume navtab contains every elements, *including* n-5 so we
			// do have to make an extra request for navg
			var selectedElements = getSelectedMenus("ctn_tab");

			// let's see if we have a n-5 hilighted menu
			// 
			// NOTE: since the _hilight may be found in several menus, we loop
			// through all menus and break when we find one
			//
			if (selectedElements.length)
			{
				for (var i = 0, len = selectedElements.length; i < len; i++)
				{
					var levelInfos = getMyLevel(selectedElements[i]);
					if (levelInfos[1] == 5)
					{
						selectedMenu = selectedElements[i];
						break;
					}
				}
				
				// _hilight *must* be set to n-5 level for left navigation to be displayed
				if (selectedMenu == null)	// levelInfos[1] !== 5
				{
					throw("can't display leftNav: not n-5 !!!");
					return;
				}
			}
			else	// don't do anything if no menu could be found
			{
				throw("can't find any selected element: check that _hilight is set to an element of n-5 level");
				return;
			}

			var ulElt = document.createElement('ul');
			var titleElt = document.createElement('div');
			var title = selectedMenu.parentNode.parentNode.parentNode.firstChild;	// aCurrent[0]
			titleElt.setAttribute('id', 'ctn_ttl');

			// get sectionName
			var h2 = document.createElement('h2');
			h2.appendChild(title.cloneNode(true));
			titleElt.appendChild(h2);
			container.appendChild(titleElt);

			var children = selectedMenu.parentNode.parentNode.childNodes;	// aCurrent[0]

			// TODO: selectedMenu wrapping:
			// 1: get content
			// 2: create strong with this content
			// 3: add strong to the children

			for (var i = 0; i < children.length; i++)
			{
				var li = children[i].cloneNode(true);
				ulElt.appendChild(li);
			}

			container.appendChild(ulElt);
		}
	};	// API object
})();
