// JavaScript Document

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
addLoadEvent(function(){fmenu("menu");});
addLoadEvent(function(){fmenu("listecatalogues");});
addLoadEvent(function(){pdfA();});
addLoadEvent(function(){popup();});

/*Pour fonctionner, cette fonction ncessite 
- Un menu, un div ou une liste dont l'id est l'argument de la fonction, contenant des balises "a" comportant un id ;
- Tous ou certains de ces menus peuvent avoir des sous menus, div ou id de la mme forme que le menu;
- les sous menus doivent avoir pour id l'id du a menu prcd de menu. Ex : id=presentation ; id=menupresentation;
*/
function fmenu(menu)
{
	document["over"+menu]=false;
	var tabarguments=new Array();
	for(var i=0;i<document.getElementById(menu).getElementsByTagName("a").length;i++)
	{
		if(document.getElementById(menu).getElementsByTagName("a")[i].id!="")
		{
			tabarguments.push(document.getElementById(menu).getElementsByTagName("a")[i].id);
		}
	}
	//alert(tabarguments);
	for(i=0;i<tabarguments.length;i++)
	{
		//alert(document.getElementById(tabarguments[i]).id);		
		document.getElementById(tabarguments[i]).onmouseover=function()
		{
			if(menu=="menu")rolloverMenub("over",this)

			//alert(this.id);
			if(document.getElementById("menu"+this.id))
			{
	
				for(var j=0;j<tabarguments.length;j++)
				{
					if(document.getElementById("menu"+tabarguments[j]))
						document.getElementById("menu"+tabarguments[j]).style.display="none";
				}
							
				var menuCourant="menu"+this.id;
				//alert(menuCourant);
				if(document.getElementById(menuCourant))document.getElementById(menuCourant).style.display="block";
				if(document["over"+menu]==true)
				{
					window.clearTimeout(document["interval"+menu]);
					//alert("interval"+menu);
					document["over"+menu]=false;
				}
			}

		}	
		document.getElementById(tabarguments[i]).onmouseout=function()
		{
			if(menu=="menu")rolloverMenub("out",this)
			if(document.getElementById("menu"+this.id))
			{
				document["interval"+menu]=window.setTimeout('masquemenu("menu'+this.id+'")', 800);
				//alert("interval"+menu);
				document["over"+menu]=true;
			}
		}
		if(document.getElementById("menu"+tabarguments[i]))gereMenu("menu"+tabarguments[i])
	}
}


function gereMenu(menu)
{
	var idParent=document.getElementById(menu).parentNode.parentNode.id;
	for(var i=0;i<document.getElementById(menu).getElementsByTagName("a").length;i++)
	{
		if(document.getElementById(menu).getElementsByTagName("a")[i])
		{
			document.getElementById(menu).getElementsByTagName("a")[i].onmouseover=function()
			{
				if(document["over"+idParent]==true)
				{
					//alert("interval"+document.getElementById(menu).parentNode.parentNode.id);
					window.clearTimeout(document["interval"+idParent]);
					document["over"+idParent]=false;
				}
			}
			document.getElementById(menu).getElementsByTagName("a")[i].onmouseout=function()
			{
				document["interval"+idParent]=window.setTimeout('masquemenu("'+menu+'")', 1000);
				document["over"+idParent]=true;
			}
		}
	}
}

function masquemenu(identifiant)
{
	if(document.getElementById(identifiant))document.getElementById(identifiant).style.display="none";
}

var img1=new Object;
img1.src="../../res/img/menub/menub2a.gif";
var img2=new Object;
img2.src="../../res/img/menub/menub2b.gif";

function rolloverMenub(etat,itemMenu)
{
	/*alert(etat+" ; "+itemMenu);*/
	if(etat=="over" && itemMenu.parentNode.id!="select")
	{
		itemMenu.style.backgroundImage='url(../../res/img/menub/menub2b.gif)';
		itemMenu.parentNode.style.backgroundImage='url(../../res/img/menub/menub2a.gif)';
	}
	if(etat=="out" && itemMenu.parentNode.id!="select")
	{
		itemMenu.style.backgroundImage='url(../../res/img/menub/menub1b.gif)';
		itemMenu.parentNode.style.backgroundImage='url(../../res/img/menub/menub1a.gif)';
	}
}
//------------------------------------------------------------------
function hasClass(obj,cName) {
        return new RegExp('\\b'+cName+'\\b').test(obj.className);
}
function pdfA()
{
	for(var i=0;i<document.getElementsByTagName("a").length;i++)
	{
		var lien=document.getElementsByTagName("a")[i];
		/*if(hasClass(lien.parentNode,"pdf"))
		{
			//alert("class pdf detected");
			lien.style.display="block";
			lien.style.lineHeight="18px";
			lien.style.background="url(http://www.filtrauto.com/site/res/img/lirelasuite.gif) top right no-repeat";
			lien.style.fontSize="11px";
			lien.style.fontStyle="italic";
			lien.style.fontWeight="bold";
			lien.style.color="white";
			lien.style.textAlign="center";
			lien.style.marginLeft="10px";
			lien.style.paddingRight="10px";
			lien.style.textDecoration="none";
			lien.style.whiteSpace="nowrap";
			
		}*/
	}
}
function popup()
{
	for(var i=0;i<document.getElementsByTagName("a").length;i++)
	{
		var lien=document.getElementsByTagName("a")[i];
		if(hasClass(lien,"popup"))
		{
			lien.onclick=function()
			{
				fen=window.open(this.href,"popup","menubar=no, status=no, width=1024, height=750, scrollbars=yes, resizable=yes");
				fen.focus;
				return false;
			}
			
		}
		if(hasClass(lien,"blank"))
		{
			lien.onclick=function()
			{
				fen=window.open(this.href);
				fen.focus;
				return false;
			}
			
		}
	}
}
	/*display: block;
	line-height: 18px;
	background:url(http://www.filtrauto.com/site/res/img/lirelasuite.gif) top right no-repeat ;
	font-size: 11px;
	font-style:italic;
	font-weight:bold;
	color: white;
	text-align: center;
	margin-left: 10px;
	padding-right: 10px;
	text-decoration: none;
	white-space: nowrap;*/