var currentMenu				= "";
var currentMouseOverMenu	= "";

var iPage_Total_Width		= 780;

var aSousMenuAbsolutesName	= Array( );
var oSousMenuTimer		= null;


function showMenu( p_name )
{
	var oDivMenu = document.getElementById( "Menu" + p_name );
	if ( !oDivMenu ) return;
	

	DOM_showNode( document.getElementById( "Menu"+p_name+"Barre_Container" ) );
	DOM_showNode( document.getElementById( "Menu"+p_name+"Title_Container" ) );
	DOM_showNode( document.getElementById( "Menu"+p_name+"Barre_Container" ) );
	DOM_hideNode( document.getElementById( "Menu"+p_name+"Top" ) );
	DOM_hideNode( document.getElementById( "Menu"+p_name+"Barre2_Container" ) );
	DOM_hideNode( document.getElementById( "Menu"+p_name+"Title2_Container" ) );

	oDivMenu.style.visibility = "hidden";
	DOM_showNode( oDivMenu );
	var HeightMaxTheMenu = DOM_getNodeHeight( oDivMenu );
	DOM_hideNode( oDivMenu );
	oDivMenu.style.visibility = "visible";
	
	if ( currentMenu && currentMenu != p_name )
	{	
		_hideMenu( currentMenu );
	}

	if ( oSousMenuTimer && currentMenu == p_name ) 
	{
		clearTimeout( oSousMenuTimer );
		oSousMenuTimer = null;
	}
	
	var x = DOM_getNodePosX( document.getElementById( "Menu" + p_name + "Calleur" ) ) - 1;
	var y = DOM_getNodePosY( document.getElementById( "Menu" + p_name + "Calleur" ) );
	var w = DOM_getNodeWidth( document.getElementById( "Menu" + p_name + "MaxWidth" ) ) + 2;
	
	// On peut l'etendre vers le bas ? ou sinon vers le haut ?
	
	var iScrollTop = 0;
	if (document.documentElement && document.documentElement.scrollTop)				iScrollTop = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop)								iScrollTop = document.body.scrollTop;

	var iClientHeight = 0;
	if (document.documentElement && document.documentElement.clientHeight)			iClientHeight = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight)							iClientHeight = document.body.clientHeight;

	var sNameBarre = "Barre" 
	
	// On l'affiche vers le haut car il depasse !!!
	if ( HeightMaxTheMenu > 30 && y + HeightMaxTheMenu > iScrollTop + iClientHeight )
	{
		
		DOM_hideNode( document.getElementById( "Menu"+p_name+"Barre_Container" ) );
		DOM_hideNode( document.getElementById( "Menu"+p_name+"Title_Container" ) );
		DOM_hideNode( document.getElementById( "Menu"+p_name+"Bottom" ) );
		DOM_showNode( document.getElementById( "Menu"+p_name+"Barre2_Container" ) );
		DOM_showNode( document.getElementById( "Menu"+p_name+"Title2_Container" ) );
		DOM_showNode( document.getElementById( "Menu"+p_name+"Top" ) );
		
		document.getElementById( "Menu"+p_name).className = "HomePopupMenu2_Inverse";
		
		sNameBarre = "Barre2"
		
		y -= HeightMaxTheMenu;
		y += 18; // Pour caller le nom du menu du layer sur le nom du menu sur la home
	}
	// Sinon affichage normal vers le bas
	else
	{
		document.getElementById( "Menu"+p_name).className = "HomePopupMenu2";
	}
	
	oDivMenu.style.left = x + "px";
	oDivMenu.style.top = y + "px";
	document.getElementById( "Menu" + p_name + sNameBarre ).style.width = w + "px"
	
	DOM_showNode( oDivMenu );
	document.getElementById( "MenuLink" + p_name ).style.visibility = "hidden";
	document.getElementById( "Menu" + p_name + "MaxWidth" ).style.visibility = "hidden";
	
	currentMenu = p_name;
}


function hideMenu( p_name )
{
	if ( !document.getElementById( "Menu" + p_name ) ) return;
	
	if ( oSousMenuTimer && currentMenu != p_name )
	{
		_hideMenu( currentMenu );
		
	}
	if ( oSousMenuTimer )
	{
		clearTimeout( oSousMenuTimer );
		oSousMenuTimer = null;
	}
	oSousMenuTimer = setTimeout( "_hideMenu( '" + p_name + "' )", 50 );
}


function _hideMenu( p_name )
{
	if ( !document.getElementById( "Menu" + p_name ) ) return;

	if ( currentMouseOverMenu != p_name )
	{
		DOM_hideNode( document.getElementById( "Menu" + p_name ) );
		document.getElementById( "MenuLink" + p_name ).style.visibility = "visible";
		document.getElementById( "Menu" + p_name + "MaxWidth" ).style.visibility = "visible";
	}
	if ( oSousMenuTimer )
	{
		clearTimeout( oSousMenuTimer );
		oSousMenuTimer = null;
	}
	oSousMenuTimer = null;
}

function setMouseOverMenu( p_name )
{
	currentMouseOverMenu = p_name;
}


function getSousMenuIdByName( p_name )
{
	var i = 0;
	
	for ( i = 0 ; i < aSousMenuAbsolutesName.length ; i++ )
	{
		if ( aSousMenuAbsolutesName[ i ] == p_name )	return i;
	}
	return -1;
}


var currentOpenedMenu = "";

function openMenu( p_sName )
{
//	if ( currentOpenedMenu != "" )
//		closeMenu( currentOpenedMenu );
	if ( ! document.getElementById( "Menu" + p_sName + "Content" ) ) return;

	if( currentOpenedMenu == p_sName || document.getElementById( "Menu" + p_sName + "Content" ).style.display == "block" ) 
	{
		closeMenu( p_sName )
		return;
	}

	DOM_showNode( document.getElementById( "Menu" + p_sName + "Content" ) );
	
	// We must force height for Mozilla 
	if ( !ie4 )
	{
		document.getElementById( "Menu" + p_sName ).style.height = ( 72 + DOM_getNodeHeight( document.getElementById( "Menu" + p_sName + "Content" ) ) ) + "px";
	}
	
	currentOpenedMenu = p_sName;
}

function closeMenu( p_sName )
{
	// We must force height for Mozilla 
	if ( !ie4 )
	{
		document.getElementById( "Menu" + p_sName ).style.height = "72px";
	}

	DOM_hideNode( document.getElementById( "Menu" + p_sName + "Content" ) );
	currentOpenedMenu = "";
}
















/************************************
*
*
*		FOR TOOLBAR
*
*
**************************************/

var currentToolBoxMenu			= "";
var currentMouseOverToolBoxMenu	= "";
var oSousMenuToolBoxTimer		= null;


function showToolBoxMenu( p_name )
{
	// Etait-on sur la home pendant le clignotement de la toolbar ?
	if ( typeof oAnimToolbarTimer != "undefined" && oAnimToolbarTimer != null )
	{
		clearTimeout( oAnimToolbarTimer );
		oAnimToolbarTimer = null;

		DOM_hideNode( document.getElementById( "ToolBoxMenuJustTitle" ) );
		
		// On desactive l'Icon en cours de clignotement, s'il y en a une
		if ( oAnimCurrentIcon && oAnimCurrentIcon.src.indexOf( "_roll" ) >= 0 )	oAnimCurrentIcon.src = oAnimCurrentIcon.src.replace( "_roll.gif", ".gif" );
	}

	if ( document.getElementById( "ToolbarIcon"+p_name ).src.indexOf( "_roll" ) < 0 )
		document.getElementById( "ToolbarIcon"+p_name ).src = document.getElementById( "ToolbarIcon"+p_name ).src.replace( ".gif", "_roll.gif" );
		
	if ( currentToolBoxMenu && currentToolBoxMenu != p_name )
	{	
		_hideToolBoxMenu( currentToolBoxMenu );
	}

//	if ( !document.getElementById( "ToolBoxMenu" + p_name ) ) return;
	
	if ( oSousMenuToolBoxTimer && currentToolBoxMenu == p_name ) 
	{
		clearTimeout( oSousMenuToolBoxTimer );
		oSousMenuToolBoxTimer = null;
	}
	
//	document.getElementById( "ToolBoxMenu" + p_name ).style.left = DOM_getNodePosX( document.getElementById( "ToolBoxMenu" + p_name + "Calleur" ) ) + "px";
	DOM_showNode( document.getElementById( "ToolBoxMenu" + p_name ) );
	currentToolBoxMenu = p_name;
//	currentMouseOverMenu = p_name;
}


function hideToolBoxMenu( p_name )
{
	if ( oSousMenuToolBoxTimer && currentToolBoxMenu != p_name )
	{
		_hideToolBoxMenu( currentToolBoxMenu );
	}
	if ( oSousMenuToolBoxTimer )
	{
		clearTimeout( oSousMenuToolBoxTimer );
		oSousMenuToolBoxTimer = null;
	}
	oSousMenuToolBoxTimer = setTimeout( "_hideToolBoxMenu( '" + p_name + "' )", 500 );
}


function _hideToolBoxMenu( p_name )
{
	if ( document.getElementById( "ToolbarIcon"+p_name ).src.indexOf( "_roll" ) > 0 )
		document.getElementById( "ToolbarIcon"+p_name ).src = document.getElementById( "ToolbarIcon"+p_name ).src.replace( "_roll.gif", ".gif" );
			
//	if ( !document.getElementById( "ToolBoxMenu" + p_name ) ) return;

	if ( currentMouseOverToolBoxMenu != p_name )
	{
		DOM_hideNode( document.getElementById( "ToolBoxMenu" + p_name ) );
	}
	if ( oSousMenuToolBoxTimer )
	{
		clearTimeout( oSousMenuToolBoxTimer );
		oSousMenuToolBoxTimer = null;
	}
	oSousMenuToolBoxTimer = null;
}


function setMouseOverToolBoxMenu( p_name )
{
	if ( oSousMenuToolBoxTimer ) 
	{
		clearTimeout( oSousMenuToolBoxTimer )
		oSousMenuToolBoxTimer = null;
	}
	currentMouseOverToolBoxMenu = p_name;
}


var OldActionMissionId = 0;
function showActionMission( p_id )
{
	if ( OldActionMissionId != 0 )
	{
		document.getElementById( "ActeurLink" + OldActionMissionId ).className = "LinkActeur";
		DOM_hideNode( document.getElementById( "MissionActeur" + OldActionMissionId ) );
		OldActionMissionId = 0;
	}
	if ( p_id == 0 ) return;
	
	document.getElementById( "ActeurLink" + p_id ).className = "LinkActeurOn";
	DOM_showNode( document.getElementById( "MissionActeur" + p_id ) );
	OldActionMissionId = p_id;
}

var OldEtapeActeursId = 0;
function showEtapeActeurs( p_id )
{
	if ( OldEtapeActeursId != 0 )
	{
		DOM_hideNode( document.getElementById( "EtapeActeursAndMissions" + OldEtapeActeursId ) );
		OldEtapeActeursId = 0;
	}
	// Reset mission
	showActionMission( 0 );
	
	if ( p_id == 0 ) return;
	if ( !document.getElementById( "EtapeActeursAndMissions" + p_id ) ) return;
	
	DOM_showNode( document.getElementById( "EtapeActeursAndMissions" + p_id ) );
	OldEtapeActeursId = p_id;
}

function Home_updateTableSize( oTable )
{
	var iNumColumns = 0;
	var oTds = oTable.getElementsByTagName( "TD" )
	var aTdsToRemove = new Array( );
	var aTdsAddEspaceBefore = new Array( );
	for ( var i = 0 ; i < oTds.length ; i++ )
	{
		if ( oTds[ i ].nodeName.toUpperCase( ) == "TD" && oTds[ i ].getAttribute( "nocontent" ) == null  )
		{
			iNumColumns++;
		}
		// Doit on remover ?
		if ( ( i == 0 && oTds[ i ].getAttribute( "nocontent" ) != null ) || 
			 ( i == oTds.length-1 && oTds[ i ].getAttribute( "nocontent" ) != null ) ||
			 ( i > 0 && oTds[ i ].getAttribute( "nocontent" ) != null && oTds[ i-1 ].getAttribute( "nocontent" ) != null ) )
		{
			aTdsToRemove[ aTdsToRemove.length ] = oTds[ i ];
		}
		// Doit on rajouter un espace avant ?
		if ( i > 0 && oTds[ i ].getAttribute( "nocontent" ) == null && oTds[ i-1 ].getAttribute( "nocontent" ) == null )
		{
			aTdsAddEspaceBefore[ aTdsAddEspaceBefore.length ] = oTds[ i ];
		}
		
	}
	for ( var i = 0 ; i < aTdsToRemove.length ; i++ )
	{
		var oParent = aTdsToRemove[ i ].parentNode;
		oParent.removeChild( aTdsToRemove[ i ] );
	}
	for ( var i = 0 ; i < aTdsAddEspaceBefore.length ; i++ )
	{
		var oTdEspace = document.createElement( "TD" );
		oTdEspace.setAttribute( "style", "background-color:#baabb7;" )
		oTdEspace.setAttribute( "nocontent", "true" )
		oTdEspace.innerHTML = "&#160;";
		oTdEspace.style.width = "5px";
		var oParent = aTdsAddEspaceBefore[ i ].parentNode;
		oParent.insertBefore( oTdEspace, aTdsAddEspaceBefore[ i ] );
	}
	
	// No Columns ? Cassos
	if ( iNumColumns == 0 ) return;
	
	var iPercent = Math.round( 100 / iNumColumns );
	for ( var i = 0 ; i< oTds.length ; i++ )
	{
		if ( oTds[ i ].nodeName.toUpperCase( ) == "TD" && oTds[ i ].getAttribute( "nocontent" ) == null  )
			oTds[ i ].style.width = iPercent+"%";
	}
}

function hideOrShowArticle( p_id )
{
	var oImg = document.getElementById( "imgLireArticle" + p_id );
	var oDiv = document.getElementById( "Object_CONTENU_" + p_id + "_Details" );
	// On l'hide
	if ( oImg.src.indexOf( "_on.gif" ) >= 0 )
	{
		oImg.src = oImg.src.replace( "_on", "" );
		DOM_hideNode( oDiv );
	}
	// On le show
	else
	{
		oImg.src = oImg.src.replace( ".gif", "_on.gif" );
		DOM_showNode( oDiv );
	}
	
}


/* ****************

	POUR LES POPUPS INTERLOCUTEURS
	
**************** */

function getPageScroll(){

	var yScroll;

	if ( self.pageYOffset ) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	// Bidouille pour forcer la position à l'écran
	pageWidth = 980;
	windowWidth = 980;
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

var isDialogBoxOpened = false;
var oDialogBoxOpened = null;

function showDialogBox( p_sDivName )
{
	oDialogBoxOpened = document.getElementById( p_sDivName );
	isDialogBoxOpened = true;
	initOverlay( );
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	document.getElementById( p_sDivName ).style.display = "block";
	var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - document.getElementById( p_sDivName ).offsetHeight) / 2);
	if ( lightboxTop < 5 ) lightboxTop = 5;
	var lightboxLeft = ((arrayPageSize[0] - 20 - document.getElementById( p_sDivName ).offsetWidth) / 2);	
	document.getElementById( p_sDivName ).style.left = lightboxLeft+"px";
	document.getElementById( p_sDivName ).style.top = lightboxTop+"px";
}


function hideDialogBox( p_sName )
{
	isDialogBoxOpened = false;
	if ( !oDialogBoxOpened )	oDialogBoxOpened = document.getElementById( p_sName );
	if ( !oDialogBoxOpened ) return;
	oDialogBoxOpened.style.display = "none";
	document.getElementById( "overlay" ).style.display = "none";
	oDialogBoxOpened = null;
}

function initOverlay( )
{
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	// preload and create loader image
	var objOverlay = document.getElementById( "overlay" );
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';	
}

window.onresize = function( )
{
	if ( isDialogBoxOpened ) initOverlay( );
}

//initOverlay( );
//showLogit( );

/* ****************

	/FIN - POUR LES POPUPS INTERLOCUTEURS
	
**************** */



function LoadApplicationHTML( p_sHTML )
{
	document.getElementById( "DivLoadApplicationStructuree" ).innerHTML = p_sHTML;
	var aScripts = document.getElementById( "DivLoadApplicationStructuree" ).getElementsByTagName( "script" );
	
	
	var sCriptJS = "";
	for ( var i = 0 ; i < aScripts.length ; i++ )
	{
		if( aScripts[ i ].innerHTML != "" )
		{
			sCriptJS +=  aScripts[ i ].innerHTML;
		}
		else if( DOM_outerText( aScripts[ i ] ) != "" )
		{
			sCriptJS +=  DOM_outerText( aScripts[ i ] ) ;
		}
	}
	
	parent.eval( "" + internalReplace( sCriptJS, "\t", "\r" ) + "" );
	
	/*
	document.getElementById( "DivLoadApplicationStructureeJS" ).innerHTML = internalReplace( sCriptJS, "\t", "\r" );
	alert( document.getElementById( "DivLoadApplicationStructureeJS" ).innerHTML  );
	UpdateResultats(  );
	*/
	return;
}


function CloseLoading()
{
	if( parent )
	{
		if( parent.HideLoading )
			parent.HideLoading();
	}	
}


