
window.onload = function () {
	genererMenuActif();
	genererLienLangue();
	genererRolloversCol1();
	classerDonnees("datalistClassee");
	genererLiensExternes();
}


function genererMenuActif() {
	if ( document.getElementById ) {
		sURI = window.location.href;
		
		aIdentifiants = new Array();
		
		if ( sURI.indexOf("/nouvelles") != -1 )
			aIdentifiants = ["mnNouvelles", "mnpNouvelles"];
		else if ( sURI.indexOf("/nouvelle_analyse") != -1 )
			aIdentifiants = ["mnNouvelles", "smnNouvelles", "smnAnalyses"];
		else if ( sURI.indexOf("/liens") != -1 )
			aIdentifiants = ["mnLiens", "mnpLiens"];
		else if ( sURI.indexOf("/lachambre") != -1 )
			aIdentifiants = ["mnChambre", "mnpChambre"];
		else if ( sURI.indexOf("/emplois") != -1 )
			aIdentifiants = ["mnEmplois", "mnpEmplois"];
		else if ( sURI.indexOf("/plan") != -1 )
			aIdentifiants = ["btnPlan", "mnpPlan"];
		else if ( sURI.indexOf("/contact") != -1 )
			aIdentifiants = ["mnJoindre", "mnpContact"];
		else
			aIdentifiants = ["mnAccueil", "mnpAccueil"];
		
		for ( compteur = 0; compteur < aIdentifiants.length; compteur++ ) {
			if ( oMenu = document.getElementById(aIdentifiants[compteur]) )
				oMenu.className = "actif";
		}
	}
}




/* - - - - - - - - - - - - - - - - - - - - - - - - */
/* Ouvre les liens externes et les fichuiers PDF   */
/* dans une nouvelle fenetre                       */
/* - - - - - - - - - - - - - - - - - - - - - - - - */
function genererLiensExternes() {
	var sRacine = window.location.href;
	var sLangue = document.body.className;
	
	if ( sRacine.indexOf("/" + sLangue + "/") != -1 )
		sRacine = sRacine.substring( 0, sRacine.lastIndexOf("/" + sLangue + "/") + 1 );
	else
		sRacine = sRacine.substring( 0, sRacine.lastIndexOf("/") + 1 );
	
	var aAncres = document.getElementsByTagName("a");
	for ( var compteur = 0; compteur < aAncres.length; compteur++ ) {
		var eAncre = aAncres[compteur];
		if ( (!eAncre.onclick) && (eAncre.href.indexOf("mailto:") != 0) ) {
			if ( (eAncre.href.indexOf(sRacine) == -1) || eAncre.href.substring(eAncre.href.length - 4).indexOf(".pdf") != -1 )
				eAncre.onclick = function () { window.open(this.href); return false; };
		}
	}
}


function ouvriragent (eAncre) {

	var largeur = 570;
	var	hauteur = 470;
	var	posX = Math.ceil( ( screen.availWidth / 2 ) - ( largeur / 2 ) );
	var	posY = Math.ceil( ( screen.availHeight / 2 ) - ( hauteur / 2 ) );
				
	var	uneFenetre = window.open(eAncre.href, "Trouver", "left=" + posX + ",top=" + posY + ",width=" + largeur + ",height=" + hauteur + ",menubar=no,location=no,toolbar=no,resizable=yes,scrollbars=no");
	uneFenetre.focus();
}

/* - - - - - - - - - - - - - - - - - - - - - - - - */
/* Ouvre la fonction financiere dans une nouvelle  */
/* fenetre                                         */
/* - - - - - - - - - - - - - - - - - - - - - - - - */
function ouvrirFonctionFinaciere( eAncre) {
	
	var iLargeur = 800;
	var iHauteur = 670;
	var iPosX = Math.round( ( screen.availWidth / 2 ) - ( iLargeur / 2 ) );
	var iPosY = Math.round( ( screen.availHeight / 2 ) - ( iHauteur / 2 ) );
	
	var oFenetre = window.open( eAncre.href, "FonctionsFinancieres", "left=" + iPosX + ",top=" + iPosY + ",width=" + iLargeur + ",height=" + iHauteur + ",menubar=no,locationbar=no,statusbar=no,scrollbars=yes" );
	oFenetre.focus();
}

function genererLienLangue () {
	if ( document.getElementById ) {
		if ( oBt = document.getElementById("btnLangue") ) {
			sURI = window.location.href;
			if ( (sURI.indexOf("/fr/") != -1) || (sURI.indexOf("/fr/") != -1) ) {
				// De francais a anglais
				oBt.href = sURI.replace("/fr/", "/en/");
				
				if ( oBt2 = document.getElementById("btnLangue2") )
					oBt2.href = sURI.replace("/fr/", "/en/");
			} else if ( (sURI.indexOf("/en/") != -1) || (sURI.indexOf("/en/") != -1) ) {
				// De anglais a francais
				oBt.href = sURI.replace("/en/", "/fr/");
				
				if ( oBt2 = document.getElementById("btnLangue2") )
					oBt2.href = sURI.replace("/en/", "/fr/");
			}
		}
	}
}




function classerDonnees( sClasse ) {
	var aTypes = new Array("table", "dl");
	
	for ( var compteurTypes = 0; compteurTypes < aTypes.length; compteurTypes++) {
		var aElements = document.getElementsByTagName(aTypes[compteurTypes]);
		
		for ( var compteurElements = 0; compteurElements < aElements.length; compteurElements++ ) {
			var eElement = 	aElements[compteurElements];
			
			if ( eElement.className.indexOf(sClasse) != -1 ) {
				
				switch ( eElement.nodeName.toLowerCase() ) {
					// DL
					case "dl":
						for ( var compteurRangees = 0; compteurRangees < eElement.getElementsByTagName("dt").length; compteurRangees++ ) {
							var eDT = eElement.getElementsByTagName("dt")[compteurRangees];
							var eDD = eElement.getElementsByTagName("dd")[compteurRangees];
							
							if ( compteurRangees % 2 == 0 ) {
								eDT.className = "impair";
								eDD.className = "impair";
							} else {
								eDT.className = "pair";
								eDD.className = "pair";
							}
						}
						break;
						
					// TABLES
					case "table":
						var eDatalist = eElement.getElementsByTagName("tbody")[0].getElementsByTagName("tr");
						
						for ( var compteurRangees = 0; compteurRangees < eDatalist.length; compteurRangees++ ) {
							var eTR = eDatalist[compteurRangees];
							
							if ( compteurRangees % 2 == 0 ) {
								eTR.className = "impair";
							} else {
								eTR.className = "pair";
							}
						}
						break;
					
					// Par defaut
					default:
						break;
				}
			}
		}
	}
}


/* Ajoute les actions de survol aux boutons de la colonne 1 */
function genererRolloversCol1() {
	/* Bouton lancer */
	if ( oBouton = document.getElementById("btnLancer") ) {
		oBouton.onmouseover = function () { boutonSurvol(this, true); }
		oBouton.onfocus = function () { boutonSurvol(this, true); }
		oBouton.onmouseout = function () { boutonSurvol(this, false); }
		oBouton.onblur = function () { boutonSurvol(this, false); }
	}
	
	/* Bouton acceder */
	if ( oBouton = document.getElementById("btnAcceder") ) {
		oBouton.onmouseover = function () { boutonSurvol(this, true); }
		oBouton.onfocus = function () { boutonSurvol(this, true); }
		oBouton.onmouseout = function () { boutonSurvol(this, false); }
		oBouton.onblur = function () { boutonSurvol(this, false); }
	}
}




function boutonSurvol( oElement, sEtat ) {
	if ( sEtat ) {
		if ( oElement.src.indexOf("_over") == -1 )
			oElement.src = oElement.src.substring(0,oElement.src.lastIndexOf(".")) + "_over" + oElement.src.substring(oElement.src.lastIndexOf("."));
	} else {
		if ( oElement.src.indexOf("_over") != -1 )
			oElement.src = oElement.src.replace(/_over/gi, "");	
	}
}












