// $Id: commun.js,v 1.9 2007/04/20 16:13:59 christian Exp $

var isIE7 = (window.ActiveXObject && window.XMLHttpRequest);
var isIE5 = (window.ActiveXObject && document.getElementById);
var isIE5Mac = (window.ActiveXObject && document.getElementById && !window.showModelessDialog);
var isSafari = (navigator.userAgent.toLowerCase().indexOf('safari') != -1);
var isMac = (navigator.userAgent.toLowerCase().indexOf('mac') != -1);
var isOldGecko =  (	!document.readyState &&
			!window.opera &&
			!window.find &&
			window.home &&
			document.getElementsByTagName &&
			navigator.product &&
			(navigator.product == 'Gecko')	
);
var commun_old_onload = null;
if (typeof window.onload == "function")
{
	commun_old_onload = window.onload;
}
window.onload = function()
{
	if (commun_old_onload)
	{
		commun_old_onload();
		commun_old_onload = null;
	}
	window.isloaded = true;
	if (isIE5 || isOldGecko) deplaceListes();
	if (isIE7) fixIE7();
}

function fixIE7()
{
	var ul = document.getElementById('menu-principal');
	for (var i = 0, li; li = ul.getElementsByTagName('LI')[i]; i++)
	{
		with (li.style)
		{
			switch (i)
			{
				case 0: width = '84px'; break;
				case 1: width = '93px'; break;
				case 2: width = '125px'; break;
				case 3: width = '44px'; break;
				case 4: width = '62px'; break;
			}
		}/*
		for (var j = 0, a; a = li.getElementsByTagName('A')[j]; j++)
		{
			with (a.style)
			{
			}
		}*/
	}
}

function fixIE5Mac(status)
{
	var divs = new Array('nav-ariane','intitule','contenu');
	for (var i = 0; i < divs.length; i++)
	{
		if (document.getElementById(divs[i]))
		{
			document.getElementById(divs[i]).style.visibility = status;
		}
	}
}

function deplaceListes()
{
	var rootUL = document.getElementById('menu-principal');
	var cible = document.getElementById('metacontenu');
	if (!rootUL || !cible) return;
	var i = 0;
	function getUL()
	{
		if (	rootUL.getElementsByTagName('UL') && 
			rootUL.getElementsByTagName('UL').length && 
			rootUL.getElementsByTagName('UL').length > 0
		)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	while (getUL() == true)
	{
		ul = rootUL.getElementsByTagName('UL')[0];
		ul.onmouseover = function()
		{
			ref = document.getElementById(this.id.replace(/-ie/,'-ie-a'));
			ref.getElementsByTagName('A')[0].style.backgroundColor = 'white';
			ref.getElementsByTagName('A')[0].style.color = 'black';
			this.style.display = 'block';
			if (isIE5Mac && document.getElementById('col-right')) { fixIE5Mac('hidden'); }
		}
		ul.onmouseout = function()
		{
			ref = document.getElementById(this.id.replace(/-ie/,'-ie-a'));
			ref.getElementsByTagName('A')[0].style.backgroundColor = '';
			ref.getElementsByTagName('A')[0].style.color = '';
			this.style.display = 'none';
			if (isIE5Mac && document.getElementById('col-right')) { fixIE5Mac('visible'); }
		}
		ul.className = 'menu-ie';
		//alert(ul.parentNode.tagName);
		ul.parentNode.id = ('menu-ie-a' + ++i);
		ul.id = ('menu-ie' + i);
		ul.style.display = 'none';
		cible.insertBefore(ul, cible.firstChild);
	}
}

function rcj_menuprincipal_cache(ref)
{
	if ((isOldGecko || isIE5) && window.isloaded)
	{
		ref.getElementsByTagName('A')[0].style.backgroundColor = '';
		ref.getElementsByTagName('A')[0].style.color = '';
		var ul = document.getElementById(ref.id.replace(/-a/,''));
		ul.style.display = 'none';
		if (isIE5Mac && document.getElementById('col-right')) { fixIE5Mac('visible'); }
	}
}
function rcj_menuprincipal_montre(ref)
{
	if (isMac && !isIE5)
	{
		ref.getElementsByTagName('UL')[0].style.width = '289px';
	}
	if ((isOldGecko || isIE5) && window.isloaded) 
	{
		ref.getElementsByTagName('A')[0].style.backgroundColor = 'white';
		ref.getElementsByTagName('A')[0].style.color = 'black';
		var ul = document.getElementById(ref.id.replace(/-a/,''));
		ul.style.display = 'block';
		if (isIE5Mac && document.getElementById('col-right')) { fixIE5Mac('hidden'); }
	}
}

