
///Permet d'ajouter autant de methodes que l'on veut au chargement de la page
function AddEventOnLoad(newFunction)
{
    var oldOnLoad = window.onload;

    if (typeof(oldOnLoad) != 'function')
    {
        window.onload = newFunction;
    }
    else
    {
        window.onload = function()
        {
            oldOnLoad();
            newFunction();
        }
    }
}


//var ShowMenuHeaderActive = function()
//{
//    var menu  = document.getElementById('header');
//    if (menu != null)
//    {
//        var listLI = menu.getElementsByTagName('li');
//        for (var i = 0; i < listLI.length; i ++)
//        {
//            var listA = listLI[i].getElementsByTagName('a');
//            var link;
//            if (listA.length > 0)
//            {
//                link = listA[0];
//                var url = document.location;
//                if (url.href == link.href)
//                {
//                    link.style.borderBottom = "5px solid";
//                }
//            }
//                
//            
//        }
//    }        
//}

//var ShowMenuLeftActive = function()
//{
//    var menu  = document.getElementById('menu');
//    if (menu != null)
//    {
//        var listLI = menu.getElementsByTagName('li');
//        for (var i = 0; i < listLI.length; i ++)
//        {
//            var listA = listLI[i].getElementsByTagName('a');
//            var link;
//            if (listA.length > 0)
//            {
//                link = listA[0];
//                var url = document.location;
//                if (url.href == link.href)
//                {
//                    link.style.backgroundColor = "#E8E6E3";
//                }
//            }
//                
//            
//        }
//    }    
//}

//change affichage bloc dans groupe - redcats dans le monde
function afficheBloc(id,lien) {
	//affichage bloc
	var d = document.getElementById(id);
	// récupération du début de l'id
	var idDivBloc = id.substring(0, id.length - 1);
		for (var i = 1; i<=4; i++) 
		{
			if (document.getElementById(idDivBloc+i)) 
			    document.getElementById(idDivBloc+i).style.display='none';
			
		}
	if (d) 
	    {d.style.display='block';}
	
	//affichage lien actif
	var d2 = document.getElementById(lien);
	// récupération du début de l'id
	var idLienBloc = lien.substring(0, id.length - 1);
		for (var i = 1; i<=4; i++) {
			if (document.getElementById(idLienBloc+i)) {document.getElementById(idLienBloc+i).className='';}
		}
	if (d2) {d2.className='actif';}	
}


//affiche div avec schema dasn redcats asie
//utilisation de la fonction pour la page historique
function afficheSchema(id) {
	var d = document.getElementById(id);
		for (var i = 1; i<=2; i++) {
			if (document.getElementById('div'+i)) {document.getElementById('div'+i).style.display='none';}
		}
	if (d) {d.style.display='block';}
}

//ferme div avec schema dasn redcats asie
function fermerSchema(id) {
	var d = document.getElementById(id);
		for (var i = 1; i<=2; i++) {
			document.getElementById('div'+i).style.display='none';
		}
}

//popup redcats dans le monde - pays
function affichagePopupPays(nomPage,nomFenetre)
{
	window.open (nomPage,nomFenetre, config='height=400, width=500, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no')
}

//popup equipe dirigente - fiche personne
function affichageFicheEquipe(nomPage,nomFenetre)
{
	window.open (nomPage,nomFenetre, config='height=450, width=600, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no')
}

//popup metiers - temoignage personne
function affichagePopupTemoi(nomPage,nomFenetre)
{
	window.open (nomPage,nomFenetre, config='height=600, width=700, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no')
}

//popup engagement
function affichagePopupEngagement(nomPage,nomFenetre)
{
	window.open (nomPage,nomFenetre, config='height=600, width=500, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no');
}

function ClosePopup(nomPage) {
        //Redirection 2 cas possible
        // Cas 1 : La fenetre principale qui a servi a l'ouverture de la fenetre a ete ferme
        // On rouvre la page du formulaire a partir de window.open

		if ( window.opener == null || window.opener.closed) {
			//On recupere la taille maximale possible d'affichage de fenetre
			if (document.getElementById || document.all) 
			{
				var lalargeur = screen.availWidth;
				var lahauteur = screen.availHeight;
			}
			else if (document.layers) 
			{
				if (window.outerHeight<screen.availHeight || window.outerWidth<screen.availWidth)
				{
					var lahauteur = screen.availHeight;
					var lalargeur = screen.availWidth;
				}
			}
			
			//On ferme la popUnder
			window.close();
		
			//On affecte les tailles maximales + on reaffiche l'ensemble des barres d'outils, menus... 
			var ledetail = "width="+lalargeur+", height="+lahauteur+", location=yes, menubar=yes,toolbar=yes,scrollbars=yes,status=yes,resizable=yes";
			//window.alert('ledetail =' + ledetail);
			window.open(nomPage,"",ledetail);		
		
		}
		else
		
//		Cas 2 : La fenetre principale qui a servi a l'ouverture de la fenetre est encore ouverte
//		On recharge la page principale avec une nouvelle adresse
		{
			opener.location=nomPage;
			window.close();
		}
}



/* Fonction pour images qui bougent dans marques */
rotateImg = 
{
	timer:1500,
	blockrotate:Object,
	activeIndex:0,
	init:function() 
	{
		var content = document.getElementById("content"); if (!content) return;
		var div = content.getElementsByTagName("div");
		for (var i=0; i<div.length; i++) 
			if (div[i].className.match(/\bbc_double_image_rotatif\b/)) break;
		if (i==div.length) return;
		var block = div[i];
		rotateImg.blockrotate = block;
		var span = block.getElementsByTagName("span");
		if (span.length<=1) return;
		for (var i=0; i<span.length; i++) 
		{
			var x = span[i];
			if (i>0) x.style.display = "none";
		}
		setTimeout("rotateImg.rotate()",rotateImg.timer);
	},
	rotate:function() 
	{
		span=rotateImg.blockrotate.getElementsByTagName("span");
		var i=rotateImg.activeIndex;
		span[i].style.display="none";
		i++;
		if (i>=span.length) i=0;
		span[i].style.display = "block";
		rotateImg.activeIndex=i;
 		setTimeout("rotateImg.rotate()",rotateImg.timer);
	}
}

search={
	searchTag:"span",
	alreadyInit:false,
	btnSubmit:null,
	btnReload:null,
	blockPays:null,
	blockUnivers:null,
	tempLabel:null,
	tempInput:null,
	resultList:null,
	init:function() {
		if (search.alreadyInit) return;
		var x;
		var srcblk = document.getElementById("BrandSearch"); if(!srcblk) return;
		var ul = srcblk.getElementsByTagName("ul"); 
		for (var i=0; i<ul.length;i++) 
			if (ul[i].className.indexOf("liste_marques")!=-1) search.liste_marques = ul[i];
		var inp = srcblk.getElementsByTagName("input");
		for (var i=0; i<inp.length;i++) {
			x=inp[i];
			if (x.type.toLowerCase()=="submit" && x.id.indexOf("Search")!=-1) search.btnSubmit = x;
			if (x.type.toLowerCase()=="reset") search.btnReload = x;
		}
		if (search.btnReload) { 
			search.btnReload.onclick = search.reset;
			addEvent(search.btnReload,"click",search.cancelClick);
		}
		var div = srcblk.getElementsByTagName(search.searchTag);
		for (var i=0; i<div.length;i++) {
			x=div[i];
			if (x.id.indexOf("pays")!=-1) search.blockPays = x;
			if (x.id.indexOf("univers")!=-1) search.blockUnivers = x;
		}
		if (search.blockPays) search.initLabel(search.blockPays);
		if (search.blockUnivers) search.initLabel(search.blockUnivers);
		search.alreadyInit = true;
	},

	clickInp:function() {
		this.blur();
		var inp=document.getElementById((this.getAttribute("for")) ? this.getAttribute("for") : this.getAttribute("htmlFor"));
		this.className = (this.className.indexOf("checked")!=-1) ? this.className.replace("checked","") : this.className+" checked"; 
		inp.checked = (this.className.indexOf('checked')!=-1)? "checked" : "";
	},

	initLabel:function(obj) {
		var lab = obj.getElementsByTagName("label");
		for (var i=0; i<lab.length; i++) {
			var x = lab[i];
			search.createCheckOpacity(x);
			var inp = document.getElementById((x.getAttribute("for")) ? x.getAttribute("for") : x.getAttribute("htmlFor") );
			if (inp) {
				x.onclick = search.clickInp;
				addEvent(x, "click", search.cancelClick);
				with (x.style) {
					width = (x.offsetWidth-intStyle(x,"padding-left")-intStyle(x,"padding-right"))+"px";
				}
				if (inp.checked) x.className="checked";
				var s = x.getElementsByTagName("span");
				if (s.length>0) {
					s=s[0];
					if ((s.textContent||s.innerText).length>18 || s.getElementsByTagName("br").length>0) s.className = "twoLines";
				}
			}
		}
	},

	createCheckOpacity:function(elt) {
		if (elt.opacityElt) return; 
		var div=document.createElement("div");
		div=elt.appendChild(div);
		div.className = "opac";
		with (div.style) {
			width=elt.offsetWidth+"px";
			height=elt.offsetHeight+"px";
		}
		elt.opacityElt = div;
		var div2 = elt.appendChild(div.cloneNode(true));
		div2.className="opacBrd";
		elt.borderElt = div2;
		var ua = navigator.userAgent;
		if (ua.indexOf("Opera/8")!=-1 && parseInt(ua.replace("Opera/",""))<9)  div.style.display = "none";
		var x =elt.borderElt;
		with (x.style) {
			width=(elt.offsetWidth-intStyle(x,"border-left-width")-intStyle(x,"border-right-width"))+"px";
			height=(elt.offsetHeight-intStyle(x,"border-top-width")-intStyle(x,"border-bottom-width"))+"px";
		}
		with(elt.opacityElt) {
			width=elt.offsetWidth+"px";
			height=elt.offsetHeight+"px";
		}
	},

	reset:function()
	{
		var ArrayElt = [search.blockUnivers,search.blockPays];
		for (var i=0; i<ArrayElt.length;i++) {
			var lab = ArrayElt[i].getElementsByTagName("label");
			for (var j=0; j<lab.length;j++) lab[j].className="";
			var inp = ArrayElt[i].getElementsByTagName("input");
			for (var j=0; j<inp.length;j++) {
				if (inp[j].type=="checkbox") inp[j].checked="";
			}
		}
		if (search.liste_marques) search.liste_marques.innerHTML = "";
	},

	cancelClick:function(e){
		if (window.event){
			window.event.cancelBubble = true;
			window.event.returnValue = false;
			return;
		}
		if (e){
			if (e.stopPropagation) {
				e.stopPropagation();
				e.preventDefault();
			}
		}
	}
}





/* Fonction dans la partie menu marque */
function goUrl(elm,target) {
if (elm[elm.selectedIndex].value.length > 0)
    var newWindow = window.open(elm[elm.selectedIndex].value,target).focus();
}

function checkbox(elementCB, elementLB)
{
	var checkbox = document.getElementById(elementCB);
	var labelCb = document.getElementById(elementLB);
	if(checkbox.checked == true)
	{
		checkbox.checked = false;
		//Retire le hover si présent
		if(labelCb.className.substr(labelCb.className.length- 6,labelCb.className.length) == " hover")
		    labelCb.className = labelCb.className.substring(0, labelCb.className.length - 6);
	}
	else
	{
		checkbox.checked = true;
		//Ajouté le hover si non présent
		if(labelCb.className.substr(labelCb.className.length- 6,labelCb.className.length) != " hover")
            labelCb.className += " hover";
	}
}


AddEventOnLoad(rotateImg.init);
AddEventOnLoad(search.init);