// JAG - Variables Declaration...
NS4 = (document.layers);
NS6 =  ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) == 5))
IE4 = (document.all);
ver4 = (NS4 || IE4);
MAC45 = (navigator.appVersion.indexOf("MSIE 4.5") != -1)
isMac = (navigator.appVersion.indexOf("Mac") != -1);

// routing 'constants'...
imgPrefixLang           = "_f";
menuCloser              = null;
currentChildpopup       = "";
currentParentpopupX      = "";
currentImageMenuParent  = "";
maxlevels               = 16;
currentParentText       = 0;
menuLevels              = new Array("","","","","","","","","","","","","","","","");
parentText              = new Array("","","","","","","","","","","","","","","","");
menuIsActive = false;
loaded = false;
xTimes=1;
var US                  = 1;
var ES                  = 2;
var CA                  = 3;
var CAEN                = 1;
var CAFR                = 3;
var OT                  = 1;
var us                  = 1;
var es                  = 2;
var ca                  = 3;
var caen                = 1;
var cafr                = 3;
var ot                  = 1;
// Next variables are used for Flash version pages mapping
var N                   = 'N';
var Y                   = 'Y';
var n                   = 'N';
var y                   = 'Y';
var userFlashChoice     = 0;
var flashVersion        = null;
var realLangue          = 'CA';
var pageId              = "0";
var lang                = "US";
var IMG_ON              = "on";
var IMG_OFF             = "off";
// Default values...
var mainPagePath        = "/web/jsp/";
var imgLangPreSufix     = "images/";
var imgLangPostSufixOn  = "_1_f";
var imgLangPostSufixOff = "_0_f";
var tempChild = null;
var tempParent = null;
// JAG - End variables declaration...
function reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
function menuLoadImage() {
//	MM_preloadImages("");
}
function MM_preloadImages() { //v3.0
    var d=document;
    if(d.images){
        if(!d.MM_p)
            d.MM_p=new Array();
            var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
            for(i=0; i<a.length; i++)
                if (a[i].indexOf("#")!=0){
                    d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
                }
    }
}
function popupJSP(popJSP) {
}
function setJSPVars(langJS,strFlashV,strPageId,usrFlash,xactiveMenuLayer,xactiveItem,xactiveParent,ImgOn,mainJspId) {
        pageId          = strPageId;
        flashVersion    = strFlashV;
        userFlashChoice = usrFlash;
	activeMenuLayer	= xactiveMenuLayer;
	activeItem      = xactiveItem;
	activepopup 	= xactiveMenuLayer;
	activeParent 	= xactiveParent;
        mainPagePath    = mainJspId;

	switch (langJS)
	{
		case 1:
			imgLangPostSufixOn  = "_1_e";
			imgLangPostSufixOff = "_0_e";
                        imgPrefixLang       = "_e";
                        realLangue          = "US";
			break;
		case 2:
			imgLangPostSufixOn  = "_1_s";
			imgLangPostSufixOff = "_0_s";
                        imgPrefixLang       = "_s";
                        realLangue          = "ES";
			break;
		case 3:
			imgLangPostSufixOn  = "_1_f";
			imgLangPostSufixOff = "_0_f";
                        imgPrefixLang       = "_f";
                        realLangue          = "CA";
			break;
	}
        lang =realLangue;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function tocItem(name,nMenuParent,strMenuLayer,popupMenu,fileExtension,imgRealName,noAddPrefix,keepHighLight) {
  this.name = name;
  this.isImageItem = (imgRealName != null);
  this.keepHighLight = keepHighLight;
  this.menuParent = nMenuParent;
  this.parentLayer = strMenuLayer;
  this.popupChild = popupMenu;
  this.visible = false;
  if (this.isImageItem) {
    if ((noAddPrefix == null) || (!noAddPrefix)) {
      this.on = imgLangPreSufix + imgRealName + imgLangPostSufixOn + fileExtension;
      this.off = imgLangPreSufix + imgRealName + imgLangPostSufixOff + fileExtension;
    }
    else {
      this.on = imgLangPreSufix + imgRealName + "_1" + fileExtension;
      this.off = imgLangPreSufix + imgRealName + "_0" + fileExtension;
    }
  }
}
function toc_new(name,nMenuParent,strMenuLayer,popupMenu,fileExtension,imgRealName,noAddPrefix,keepHighLight) {
  if ((fileExtension != null) && (fileExtension != "") && (fileExtension != "null")) {
    if (fileExtension.indexOf(".") == -1) {
      fileExtension = "." + fileExtension;
    }
  }
  tocItem[name] = new tocItem(name,nMenuParent,strMenuLayer,popupMenu,fileExtension,imgRealName,noAddPrefix,keepHighLight);
}
function swapImgDirect(imgContainer,imgName,parentLayer) {
    if (document.images) {
        if (imgName != null) {
             if ((parentLayer == null) || (IE4) || (NS6)) {
                document[imgContainer].src = imgName;
            }
            else {
                image= eval("document.layers."+parentLayer+".document.images['"+imgContainer+"']");
                image.src = imgName;
            }
        }
    }
}
function changeLang(strNextLang) {
  toHREF = top.location.href;
  if ((toHREF.indexOf("edrMain") > -1) && (toHREF.indexOf("Params=") == -1)) {
    toHREF = "edrMain.jsp?Params=" + flashVersion + "." + strNextLang + "." + pageId + "." + userFlashChoice;
  }
  else {
    var frFrom 	= new Array(/\.CA\./, /\/fr\//,/_fr_/);
    var frTo      = new Array("\.CA\.", "/fr/","_fr_");

    var enFrom 	= new Array(/\.US\./, /\/en\//,/_en_/);
    var enTo      = new Array("\.US\.", "/en/","_en_");

    var esFrom 	= new Array(/\.ES\./, /\/es\//,/_es_/);
    var esTo      = new Array("\.ES\.", "/es/","_es_");

    var from      = ((realLangue=="CA")?frFrom:((realLangue=="US")?enFrom:esFrom));
    var to        = ((strNextLang=="CA")?frTo:((strNextLang=="US")?enTo:esTo));

    for (var i = 0; i < from.length; i++) {
      toHREF = toHREF.replace(from[i], to[i]);
    }
  }
  top.location.href = toHREF;
}
function rout2Page(fixURL,bNewWindow, strPageId) {
    if (pageId == null || strPageId == null) {
        pageId = "0";
    }
    if (flashVersion == null) {
        flashVersion = "Y";
    }
    if (userFlashChoice == null) {
        userFlashChoice = "0";
    }
    if ((bNewWindow == null) || (!bNewWindow)) {
        top.location.href = fixURL + "?Params=" + flashVersion + "." + realLangue + "." + pageId + "." + userFlashChoice;
    }
    else {
        document.open(  fixURL + "?Params=" + flashVersion + "." + realLangue + "." + pageId + "." + userFlashChoice,
                        "","toolbar=yes,menubar=yes,scrollbars=yes,location=yes,status=yes,width=750,height=500,resizable=yes,top=0,left=0");
    }
}
function getNewURL(strPageId,bNewWindow,strLangParam,xParameters) {
    strNewPageId  = strPageId;
    strLangToUse  = realLangue;
    strInk        = "";
    strXParameter = "";
    nPos = strPageId.indexOf("INK");

    if (nPos > -1) {
        strNewPageId = strPageId.substring(0,nPos);
        strInk = "#" + strPageId.substring(nPos + 3);
    }
    if (flashVersion == null) {
        flashVersion = "Y";
    }
    if (userFlashChoice == null) {
        userFlashChoice = "0";
    }
    if (strLangParam != null) {
        strLangToUse = strLangParam;
    }
    if ((xParameters != null) && (xParameters != "") && (xParameters != "null")) {
      strXParameter = xParameters;
    }
    else {
      if (strPageId.indexOf("61") > -1) {
        strXParameter = "&categ=" + docCateg + "&level=2";
      }
    }
    if ((bNewWindow == null) || (!bNewWindow)) {
        top.location.href = mainPagePath + flashVersion + "." + strLangToUse + "." + strNewPageId + "." + userFlashChoice + strInk + strXParameter;
    }
    else {
        document.open(  mainPagePath + flashVersion + "." + strLangToUse + "." + strNewPageId + "." + userFlashChoice + strInk + strXParameter,
                        "","toolbar=yes,menubar=yes,scrollbars=yes,location=yes,status=yes,width=750,height=500,resizable=yes,top=0,left=0");
    }
}
function forwardTo(strFixUrl,strPageId,bNewWindow) {
    strNewPageId = strPageId;
    strInk = "";
    nPos = strPageId.indexOf("INK");
    if (nPos > -1) {
        strNewPageId = strPageId.substring(0,nPos);
        strInk = "#" + strPageId.substring(nPos + 3);
    }
    if (flashVersion == null) {
        flashVersion = "Y";
    }
    if (userFlashChoice == null) {
        userFlashChoice = "0";
    }
    if ((bNewWindow == null) || (!bNewWindow)) {
        top.location.href = strFixUrl + mainPagePath + flashVersion + "." + realLangue + "." + strNewPageId + "." + userFlashChoice + strInk;
    }
    else {
        window.open(  strFixUrl + mainPagePath + flashVersion + "." + realLangue + "." + strNewPageId + "." + userFlashChoice + strInk,
                        "","toolbar=yes,menubar=yes,scrollbars=yes,location=yes,status=yes,width=750,height=500,resizable=yes,top=0,left=0");
    }
}
function initValues() {
  if (NS4) {
    document.captureEvents(Event.MOUSEUP);
  }
  document.onmouseup = mouseUp;
}
function mouseUp(e) {
  closeCurrents(null,true);
  return true;
}
function dummy() {
  return;
}
// NEW FUNCTIONS SECTION
function checkMenuMO(strMenu) {
  menuIsActive = true;
  if ((tocItem[strMenu].isImageItem) && (!tocItem[strMenu].keepHighLight)) {
    switchImage(strMenu,IMG_ON);
    if ((tocItem[strMenu].popupChild != null) &&
        (tocItem[strMenu].popupChild != "null") &&
        (tocItem[strMenu].popupChild != "none")) {
      if (strMenu != currentImageMenuParent) {
        closeCurrents(null,true);
      }
      currentImageMenuParent = strMenu;
      if (!tocItem[strMenu].visible) {
        closeCurrents(null,true);
        openPopup(tocItem[strMenu].popupChild);
        tocItem[strMenu].visible = true;
        registerMenus(strMenu,tocItem[strMenu].popupChild,true,false,false);
      }
    }
    else {
      closeCurrents(null,true);
    }
  }
}
function checkMenuMOUT(strMenu) {
  clearTimeout(menuCloser);
  menuIsActive = false;
  if (tocItem[strMenu].visible) {
    menuCloser = setTimeout("checkmenu('"+ strMenu +"')",200);
  }
  else {
    switchImage(strMenu,IMG_OFF);
  }

}
function openPopup(strMenu,itemId,hLiteColor,childPopup,isFloat,menuParent) {	
  if ((strMenu=="N1X2")&&(hasRightVersion)) { // si le no de menu est N1X2, on desactive le flash (hardcod&eacute;), si le flash est présent
  	desactiveFlash();
  }   
 // alert("de"+strMenu);
  if (isParentText(strMenu) && currentChildpopup != childPopup) {
    closeCurrents(null,false);
  }
  menuIsActive = true;
  openClosePopup(strMenu,true);
  if ((childPopup != null) && (childPopup != "null") && (childPopup != "none")) {
    if ((childPopup != currentParentpopupX) && (strMenu != currentParentpopupX) && (currentChildpopup != strMenu)) {
      closeXPopup(currentParentpopupX);
    }
    openClosePopup(strMenu,true);
    openPopup(childPopup,null,null,null,null,strMenu);
    currentChildpopup = childPopup;
    currentParentpopupX = strMenu;
  }
  else {
    if ((strMenu != currentChildpopup) && (menuParent != currentChildpopup)) {
      closeXPopup(currentChildpopup);
      currentChildpopup = "";
    }
  }
  registerMenus(strMenu,childPopup,false,false,false);
}
function closeXPopup(strMenu) {
  openClosePopup(strMenu,false);
}
function openClosePopup(strMenu,bOnOff) {
  if ((strMenu == null) || (strMenu == 'none') || (strMenu == "null") || (strMenu == "") || (isParentText(strMenu))) {
    return;
  }

  if (bOnOff) {
    clearTimeout(menuCloser);
    menuCloser = null;
  }
  if (NS6) {
    menu=document.getElementById(strMenu);
  }
  else {
    menu = (NS4) ? eval("document.layers."+strMenu) : eval(strMenu);
  }
  if ((menu != null) && (menu != 'none')) {
    if (NS4) menu.visibility = (bOnOff) ? "show" : "hide";
    else menu.style.visibility = (bOnOff) ? "visible" : "hidden";
    if ((strMenu=="N1X2")&&(!(bOnOff))&&(hasRightVersion)) { // si le no de menu est N1X2, on active le flash (hardcod&eacute;)
		activeFlash();
    } 
  }
 
}

function switchImage(imgName,imgState) {
  if ((imgName == null) || (imgName == "") || (imgName == 'null') || (imgName == "none")) {
    return;
  }
  if (document.images) {
    if ((tocItem[imgName].parentLayer == null) || (IE4) || (NS6)) {
      document[imgName].src = eval("tocItem[imgName]."+imgState);
    }
    else {
      image= eval("document.layers."+tocItem[imgName].parentLayer+".document.images['"+imgName+"']");
      eval("image.src = tocItem[imgName]."+imgState);
    }
  }
}
function checkmenu(strMenu) {
  if (menuIsActive) {
    return;
  }
  menuCloser = null;
  closeCurrents(strMenu,false);
}
function closePopup(strMenu,itemId,bgColor,childPopup,isFloat) {

//alert("closePopup strMenu,itemId,childPopup,isFloat" + " " +  strMenu + " " +  itemId + " " +  childPopup + " " +  isFloat );

  menuIsActive = false;
  if (menuCloser == null) {
    menuCloser = setTimeout("checkmenu('" + strMenu + "')",200);
  }
}
function closeCurrents(strMenu,bIsImage) {
  menuLevel = 0;
  if ((strMenu != null) && (menuIsActive)) {
    menuLevel = findMenuLevel(new String(strMenu));
    if (menuLevel == -1) {
      return;
    }
  }
  for(x=(maxlevels -1);x>=menuLevel;--x) {
    if (menuLevels[x] != "") {
      closeMenu(x);
    }
  }
}
function registerMenus(parentMenu,childMenu,bParentImage,bChildImage,bFloatParent) {
  parentMenu = ((parentMenu == null) || (parentMenu == "null") || (parentMenu == "none")) ? "" : parentMenu;
  childMenu = ((childMenu == null) || (childMenu == "null") || (childMenu == "none")) ? "" : childMenu;
  nextLevelPosition = -1;
  canRegisterParent = (findMenuLevel(parentMenu) == -1);
  canRegisterChild = (findMenuLevel(childMenu) == -1);
  if (canRegisterParent || canRegisterChild) {
    for(x=0;x<maxlevels;x++) {
      if (menuLevels[x] == "") {
        nextLevelPosition = x;
        break;
      }
    }
    if (nextLevelPosition > -1) {
      if ((canRegisterParent) && (parentMenu != "")) {
        menuLevels[nextLevelPosition] = ((bParentImage) ? "1" : "0") + ";0;" + parentMenu;
        if ((childMenu != null) && (nextLevelPosition < 15) && (childMenu != "")) {
          menuLevels[nextLevelPosition + 1] = ((bChildImage) ? "1" : "0") + ";1;" + childMenu;
        }
      }
      if ((!canRegisterParent) && (canRegisterChild) && (childMenu != "")) {
        menuLevels[nextLevelPosition] = "0;1;" + childMenu;
      }
    }
  }
  for (x=0;x<maxlevels;x++) {
    if (menuLevels[x] != "") {
//      alert(menuLevels[x]);
    }
  }
}
function findMenuLevel(strMenu) {
  for(x=0;x<maxlevels;x++) {
    tmp = menuLevels[x];
//    if (tmp != "") alert(tmp.substring(4));
    if ((tmp != "") && (tmp.substring(4) == strMenu)) {
      return x;
      break;
    }
  }
  return -1;
}
function closeMenu(nMenu) {
  strMenu = menuLevels[nMenu];
  isImage = (strMenu.substring(0,1) == "1") ? true : false;
  isLayer = (strMenu.substring(2,3) == "1") ? true : false;
  strMenu = strMenu.substring(4);
  if (isImage) {
    switchImage(strMenu,IMG_OFF);
    tocItem[strMenu].visible = false;
  }
  else {
    closeXPopup(strMenu);
  }
  menuLevels[nMenu] = "";
}
function menutimeout() {
}
function isParentText(strMenu) {
  for(x=0;x<maxlevels;x++) {
    if (parentText[x] == strMenu) {
      return true;
    }
  }
  return false;
}
function registerParentText(strMenu) {
  if (currentParentText < (maxlevels -1)) {
    currentParentText++;
    parentText[currentParentText] = strMenu;
  }
}
function currentsAreNotActive(strMenu,childPopup,menuParent) {
/*  alert("strMenu ===" + strMenu);
  alert("childPopup ===" + childPopup);
  alert("menuParent ===" + menuParent);
  alert("currentChildpopup ===" + currentChildpopup);
  alert("currentParentpopupX ===" + currentParentpopupX);*/
  bReturn = ((menuParent == null) || (menuParent == "undefined"));
 // alert(menuParent + " = " + bReturn);
  return bReturn;
/*
    currentChildpopup = childPopup;
    currentParentpopupX = strMenu;
*/
}
// fonction hardcodee!!!!!!
function desactiveFlash() {	
	if (document.getElementById) {		
		document.getElementById("banniereFlashObj").style.visibility="hidden";	
	} else if (document.layers) {	
		document.layers("banniereFlashDiv").visibility="hidden";
		document.banniereFlashObj.StopPlay();
	} else if (document.all) {		
		document.all["banniereFlashObj"].style.visibility="hidden";	
		document.all["banniereFlashObj"].StopPlay();			
	}  


}

function activeFlash() {
	if (document.getElementById) {
		document.getElementById("banniereFlashObj").style.visibility="visible";
	} else if (document.layers) {
		document.layers("banniereFlashDiv").visibility="visible";	
	} else if (document.all) {
		document.all["banniereFlashObj"].style.visibility="visible";	
	}  
}

