
loader = window;
isLoaded = false;
areCreated = false;
menuLoc = null;

function initVars() {
        if(areCreated) {
                for(i=1; i<topCount; i++) {
                        cur = eval("MenuUae"+i);
                        clearTimeout(cur.hideTimer);
                        cur.hideTimer=null;
                }
                clearTimeout(allTimer);
        }
        topCount = 1;
        areCreated = false;
        beingCreated = false;
        isOverMenu = false;
        currentMenu = null;
        allTimer = null;
}

initVars();

function IEunloaded() {
        initVars();
        isLoaded = false;
        setTimeout("keepTrack()",50)
}

function keepTrack() {
        if (menuLoc.document.readyState == "complete") {
                initVars();
                startIt();
        }
        else {
                setTimeout("keepTrack()",50);
        }
}

function startIt() {
        isLoaded = true;
        menuLoc = window;
        menuLoc.nav = nav = window;
        makeTop();
}

function makeTop(){
        beingCreated = true;
        while(eval("window.MenuContenu" + topCount)) {
                makeMenuIE(false,topCount);
                topCount++
        }
        status = "Done"
        areCreated = true;
        beingCreated = false;
}

function setMenuTree(isChild,parMenu,largeur) {
        this.menuWidth = largeur;
        this.menuFontColor = "#7F0F57";
        this.TitreFontColor = "#FFFFFF";
        this.menuFontOver = "#7F0F57";
        this.menuBGColor = "#C696B4";
        this.menuBGOver = "#FFFFFF";
        this.menuBorCol = "#7F0F57";
        this.treeParent = this;
        this.startChild = this;
        this.maxItems = (this.array.length)/4;
        this.hasParent = isChild;
    this.setup = menuSetup;
        this.itemCount = 0;
}

function makeMenuIE(isChild,menuCount,parMenu) {
        menu = makeElement("MenuUae" + menuCount);
        menu.array = eval("MenuContenu" + menuCount);
        if ((menuCount == 5 || menuCount == 6) || menuCount == 7) {
                menu.setMenuTree = setMenuTree;
                menu.setMenuTree(isChild,parMenu,130);
        }
        else {
                menu.setMenuTree = setMenuTree;
                menu.setMenuTree(isChild,parMenu,130);
        }

        menu.itemStr = "";
        while (menu.itemCount < menu.maxItems) {
                menu.itemCount++;
                status = "Consctruction du menu...";
                itemName = "item" + menuCount + "_" + menu.itemCount;
                arrayPointer = ((menu.itemCount-1)*4);
                dispText = menu.array[arrayPointer];
                hasMore = menu.array[arrayPointer + 2];
                titre = menu.array[arrayPointer + 4];
                htmStr = (hasMore) ? dispText : dispText;
                menu.itemStr += "<SPAN ID=" + itemName + " STYLE=\"width:130;font-size:8pt;z-index:51;\">&nbsp;&nbsp;" + htmStr + "</SPAN><BR>";


                if (hasMore) {
                        makeMenuIE(true,menuCount + "_" + menu.itemCount,menu);
                        menu = menu.parentMenu;
                }
        }

        menu.innerHTML = menu.itemStr;
        itemColl = menu.children.tags("SPAN");
        for (i=0; i<itemColl.length; i++) {
                it = itemColl(i);
                it.setup = itemSetup;
                it.setup(i+1,menu.array);
        }
        menu.lastItem = itemColl(itemColl.length-1);
        menu.setup(isChild,parMenu);
}

function makeElement(whichEl,whichWidth,whichParent,whichContainer) {
        elStr = "<DIV ID=" + whichEl + " STYLE='position:absolute;z-index:51;'></DIV>";
        menuLoc.document.body.insertAdjacentHTML("BeforeEnd",elStr);
        return eval(whichEl);
}

function itemSetup(whichItem,whichArray) {
        this.onmouseover = itemOver;
        this.onmouseout = itemOut;
        this.container = this.offsetParent;
        arrayPointer = (this.container.hasParent) ? (whichItem-1)*4 : ((whichItem-1)*4);
        this.dispText = whichArray[arrayPointer];
        this.Adresse = whichArray[arrayPointer + 1];
        this.hasMore = whichArray[arrayPointer + 2];
        this.cat = whichArray[arrayPointer + 3];
        this.titre = whichArray[arrayPointer + 4];
        if (this.hasMore) {
                this.child = eval("MenuUae" + this.id.substr(4));
                this.child.parentMenu = this.container;
                this.child.parentItem = this;
        }
        if (this.Adresse) {
                        this.onclick = linkIt;
                        this.style.cursor = "hand";
        }

        with (this.style) {
                padding = 2;
                if (this.Adresse) {
                    color = this.container.menuFontColor;
                } else {
                  color = this.container.TitreFontColor;
                }
                fontSize = "7 pt";
                fontWeight = "normal";
                fontStyle = "normal";
                fontFamily = "verdana";
                backgroundColor = this.container.menuBGColor;
        }
}

function menuSetup(hasParent,openCont,openItem) {
        this.onmouseover = menuOver;
        this.onmouseout = menuOut;
        this.showIt = showIt;
        this.hideTree = hideTree
        this.hideParents = hideParents;
        this.hideTop = hideTop;
        this.isOn = false;
        this.hideTimer = null;
        this.currentItem = null;
        this.hideSelf = hideSelf;
        this.hasParent = false;

        with (this.style) {
                width = this.menuWidth;
                borderWidth = 1;
                borderColor = this.menuBorCol;
                borderStyle = "solid";
        }
        this.lastItem.style.border="";
        this.fullHeight = this.scrollHeight;
        this.showIt(false);
        this.onselectstart = cancelSelect;
        this.moveTo = moveTo;
        this.moveTo(0,0);
}

function popUp(menuName,e,numlay,nomimg){
        if (!isLoaded) return;
        linkEl = event.srcElement;
        if (!beingCreated && !areCreated) startIt();
        linkEl.menuName = menuName;
        popMenu(e,numlay,nomimg);
}

function getRealLeft() {
        xPos = this.offsetLeft;
    tempEl = this.offsetParent;
        while (tempEl != null) {
        xPos += tempEl.offsetLeft;
                tempEl = tempEl.offsetParent;    }
    return xPos;
}

function getTrueX(numlay) {
        linkEl.getRealLeft = getRealLeft;
        if (numlay == "o_gestion" || numlay == "o_parametre"){
                trueX = (linkEl.getRealLeft() + 0);
        }
        else {
                trueX = (linkEl.getRealLeft() - 8);
        }
        return trueX;
}

function getRealTop() {
        yPos = this.offsetTop;
        tempEl = this.offsetParent;
    while (tempEl != null) {
                yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;    }
        return yPos;
}

function getTrueY(numlay) {
        linkEl.getRealTop = getRealTop;
        if (numlay == "o_gestion" || numlay == "o_parametre"){
                trueY = (linkEl.getRealTop() + 12);
        }
        else {
                trueY = (linkEl.getRealTop() + 13);
        }

        return trueY;
}

function popMenu(e,numlay,nomimg){
        if (!isLoaded || !areCreated) return true;
        eType = event.type;
        hideAll();
        linkEl = event.srcElement;
        currentMenu = eval(linkEl.menuName);
        currentMenu.hasParent = false;
        currentMenu.treeParent.startChild = currentMenu;
        linkEl.getRealTop = getRealTop;
        menuLocBod = menuLoc.document;
//        yPos = 30;
        yPos = getTrueY(nomimg)+4;
        xPos = getTrueX(nomimg)+3;
        currentMenu.moveTo(xPos,yPos);
        currentMenu.isOn = true;
        currentMenu.showIt(true);
        return false;
}

function menuOver(e) {
        this.isOn = true;
        isOverMenu = true;
        currentMenu = this;
        if (this.hideTimer) clearTimeout(this.hideTimer);
}

function menuOut() {
        theEvent = menuLoc.event;
        if (theEvent.srcElement.contains(theEvent.toElement)) return;
        this.isOn = false;
        isOverMenu = false;
        menuLoc.status = "";
        allTimer = setTimeout("currentMenu.hideTree()",10);
}

function itemOver(){
        theEvent = menuLoc.event;
        if (theEvent.srcElement.tagName == "IMG") return;
        if (this.Adresse) {
                this.style.color = this.container.menuFontOver;
                this.style.backgroundColor = this.container.menuBGOver;
                                }
                                else
                                {
                this.style.color = this.container.TitreFontColor;
                                }
        this.container.currentItem = this;
}

function itemOut() {
        theEvent = menuLoc.event;
           if (theEvent.srcElement.contains(theEvent.toElement)
     || (theEvent.fromElement.tagName=="IMG" && theEvent.toElement.contains(theEvent.fromElement)))
       return;
        this.style.backgroundColor = this.container.menuBGColor;
        if (this.Adresse) {
                this.style.color = this.container.menuFontColor;
                                }
                                else
                                {
                this.style.color = this.container.TitreFontColor;
                                }
}

function moveTo(xPos,yPos) {
        this.style.pixelLeft = xPos;
        this.style.pixelTop = yPos;
}

function showIt(on) {
        this.style.visibility = (on) ? "visible" : "hidden";
        this.currentItem = null;
}

function linkIt() {
                document.location=this.Adresse;
}

function popDown(menuName){
        if (!isLoaded || !areCreated) return;
        whichEl = eval(menuName);
        whichEl.isOn = false;
        whichEl.hideTop();
}

function hideAll() {
        for(i=1; i<topCount; i++) {
                temp = eval("MenuUae" + i + ".startChild");
                temp.isOn = false;
                temp.showIt(false);
        }
}

function hideTree() {
        allTimer = null;
        if (isOverMenu) return;
        this.hideParents();
}

function hideTop() {
        whichEl = this;
        (this.hideTimer = setTimeout("whichEl.hideSelf()",0));
}

function hideSelf() {
        this.hideTimer = null;
        if (!this.isOn && !isOverMenu) {
                this.showIt(false);
        }
}

function hideParents() {
        tempMenu = this;
        while (tempMenu.hasParent) {
                tempMenu.showIt(false);
                tempMenu.parentMenu.isOn = false;
                tempMenu = tempMenu.parentMenu;
        }
        tempMenu.hideTop();
}


function cancelSelect(){return false}

function reDo(){
        if (loader.innerWidth==origWidth && loader.innerHeight==origHeight) return;
        initVars();
        menuLoc.location.reload();
}