// Do *NOT* depend on this menu code, it *will* be rewritten in later versions
// of Plone. This is a quick fix that will be replaced with something more
// elegant later.

/* <!-- compression status: 1 --> (this is for http compression) */

// Code to determine the navigateur and version.

function Navigateur() {
    var ua, s, i;
    
    this.isIE = false; // Internet Explorer
    this.isNS = false; // Netscape
    this.version = null;
    
    ua = navigator.userAgent;
    
    s = "MSIE";
    if ((i = ua.indexOf(s)) >= 0) {
        this.isIE = true;
        this.version = parseFloat(ua.substr(i + s.length));
        return;
    }  
    s = "Netscape6/";
    if ((i = ua.indexOf(s)) >= 0) {
        this.isNS = true;
        this.version = parseFloat(ua.substr(i + s.length));
        return;
    }
    
    // Treat any other "Gecko" navigateur as NS 6.1.
    
    s = "Gecko";
    if ((i = ua.indexOf(s)) >= 0) {
        this.isNS = true;
        this.version = 6.1;
        return;
    }
}
var navigateur = new Navigateur();

// Code for handling the menu bar and active button.
var boutonactif = null;

// Capture mouse clicks on the page so any active button can be
// deactivated.

if (navigateur.isIE){
    document.onmousedown = ecranMousedown;
}else{
    document.addEventListener("mousedown", ecranMousedown, true);
}

function ecranMousedown(event) {
    
    var el;
    
    // If there is no active button, exit.
    
    if (boutonactif == null){
        return;
        }
    
    // Find the element that was clicked on.
    
    if (navigateur.isIE){
        el = window.event.srcElement;
    }else{
        el = (event.target.tagName ? event.target : event.target.parentNode);
    }
    // If the active button was clicked on, exit.
    
    if (el == boutonactif){
        return
        };
    
    // If the element is not part of a menu, reset and clear the active
    // button.
    
    if (getContenantAvec(el, "UL", "olssrvMenu") == null) {
        olssrvresetButton(boutonactif);
        boutonactif = null;
    }
}

function olssrvClick(event, menuId) {
    
    var button;
    
    // Get the target button element.
    
    if (navigateur.isIE){
        button = window.event.srcElement;
    }else{
        if (event)
          button = event.currentTarget;
        else
          return false;
    }
    // Blur focus from the link to remove that annoying outline.
    
    button.blur();
    
    // Associate the named menu to this button if not already done.
    // Additionally, initialize menu display.
    
    if (button.menu == null) {
        button.menu = document.getElementById(menuId);
        if (button.menu.isInitialized == null) {
            olssrvmenuInit(button.menu);
        }
    }
    
    // Reset the currently active button, if any.
    
    if (boutonactif != null){
        olssrvresetButton(boutonactif);
        }
    // Activate this button, unless it was the currently active one.
    
    if (button != boutonactif) {
        olssrvdepressButton(button);
        boutonactif = button;
    }else{
        boutonactif = null;
    }
    return false;
}

function olssrvover(event, menuId) {

    var button;
    
    // Find the target button element.
    
    if (navigateur.isIE){
        button = window.event.srcElement;
    }else{
        button = event.currentTarget;
    }
    // If any other button menu is active, make this one active instead.
    
    if (boutonactif != null && boutonactif != button){
        olssrvClick(event, menuId);
        }
}

function olssrvdepressButton(button) {

    var x, y;
    
    // Update the button's style class to make it look like it's
    // depressed.
    
    button.className += " menuButtonActive";
    
    // Make the associated drop down menu visible
    
    vis = button.menu.style.visibility;
    button.menu.style.visibility = (vis == "hidden" || vis == '') ? "visible" : "hidden";
}

function olssrvresetButton(button) {

    // Restore the button's style class.
    
    olssrvremoveClassName(button, "menuButtonActive");
    
    // Hide the button's menu, first closing any sub menus.
    
    if (button.menu != null) {
        olssrvcloseSubMenu(button.menu);
        button.menu.style.visibility = "hidden";
    }
}

// Code to handle the menus and sub menus.

function menuolssrvover(event) {
    
    var menu;
    
    // Find the target menu element.
    
    if (navigateur.isIE){
        menu = getContenantAvec(window.event.srcElement, "UL", "olssrvMenu");
    }else{
        menu = event.currentTarget;
    }
    
    // Close any active sub menu.
    
    if (menu.activeItem != null){
        olssrvcloseSubMenu(menu);
        }
}


function olssrvcloseSubMenu(menu) {
    
    if (menu == null || menu.activeItem == null)
    return;
    
    // Recursively close any sub menus.
    
    if (menu.activeItem.subMenu != null) {
    olssrvcloseSubMenu(menu.activeItem.subMenu);
    menu.activeItem.subMenu.style.visibility = "hidden";
    menu.activeItem.subMenu = null;
    }
    olssrvremoveClassName(menu.activeItem, "menuItemHighlight");
    menu.activeItem = null;
}

// Code to initialize menus.

function olssrvmenuInit(menu) {
    
    var itemList, spanList;
    var textEl, arrowEl;
    var itemWidth;
    var w, dw;
    var i, j;
    
    // For IE, replace arrow characters.
    
    if (navigateur.isIE) {
        menu.style.lineHeight = "2.5ex";
        spanList = menu.getElementsByTagName("SPAN");
        for (i = 0; i < spanList.length; i++)
        if (olssrvhasClassName(spanList[i], "menuItemArrow")) {
        spanList[i].style.fontFamily = "Webdings";
        spanList[i].firstChild.nodeValue = "4";
    }
}

// Find the width of a menu item.

itemList = menu.getElementsByTagName("A");
if (itemList.length > 0){
    itemWidth = itemList[0].offsetWidth;
}else{
    return;
}
// For items with arrows, add padding to item text to make the
// arrows flush right.

for (i = 0; i < itemList.length; i++) {
    spanList = itemList[i].getElementsByTagName("A");
    textEl = null;
    arrowEl = null;
    for (j = 0; j < spanList.length; j++) {
    if (olssrvhasClassName(spanList[j], "menuItemText")){
        textEl = spanList[j];
        }
    if (olssrvhasClassName(spanList[j], "menuItemArrow")){
        arrowEl = spanList[j];
        }
    }
    if (textEl != null && arrowEl != null){
    textEl.style.paddingRight = (itemWidth - (textEl.offsetWidth + arrowEl.offsetWidth)) + "px";
    }
}

// Fix IE hover problem by setting an explicit width on first item of
// the menu.

if (navigateur.isIE) {
    w = itemList[0].offsetWidth;
    itemList[0].style.width = w + "px";
    dw = itemList[0].offsetWidth - w;
    w -= dw;
    itemList[0].style.width = w + "px";
}

// Mark menu as initialized.

menu.isInitialized = true;
}

// General utility functions.

    function getContenantAvec(node, tagName, className) {
    
    // Starting with the given node, find the nearest containing element
    // with the specified tag name and style class.
    
    while (node != null) {
     if (node.tagName != null && node.tagName == tagName && olssrvhasClassName(node, className)){return node;}
     node = node.parentNode;
     }
    return node;
}

    function olssrvhasClassName(el, name) {
    
    var i, list;
    
    // Return true if the given element currently has the given class
    // name.
    if (el.className == null){
        return false;
        }
    list = el.className.split(" ");
    for (i = 0; i < list.length; i++)
    if (list[i] == name){
        return true;
        }
    return false;
}

function olssrvremoveClassName(el, name) {
    
    var i, curList, newList;
    
    if (el.className == null){
        return;
        }
    // Remove the given class name from the element's className property.
    
    newList = new Array();
    curList = el.className.split(" ");
    for (i = 0; i < curList.length; i++){
        if (curList[i] != name){
            newList.push(curList[i]);
            el.className = newList.join(" ");
        }
    }
}


// Fenetrage pour reroutage vers l'application bbs
// ----------------------------------------------- 
var bbswin = "";

function gobbs_save(url) {
if (document.all && bbswin) {bbswin.close(); bbswin="";}
if (!bbswin || !bbswin.location || bbswin.closed) {
 bbswin=window.open("", "BBS", "toolbar,menubar,resizable,scrollbars,status,width=850,height=550,screenX=10,screenY=10");
 bbswin.moveTo(10,10);
 }
bbswin.location.href=url;
bbswin.focus();
}

function gobbs_old(url) {
 nw = window.open(url,"_BLANK","left=10,width=850,height=550,toolbar=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,location=yes");
 nw.focus();
}

function gobbs(u) {
 e = u.split('|');
 if (e[0] == 'local') {
  url = '/ols/projects/' + e[1];
  window.location.href=url;
  } else {
  url = 'http://bbs.bull.net/php/CallManager/projet.php?projname=' + e[1] + '&page=' + e[0];
  goBbs(url);
  }
}

