// #######################################################################################################
//
//      ADEIS_xMenu.js
//      ==============
//
//      Dernière modification le 23/01/2004.
//
//
// #######################################################################################################

// #######################################################################################################
// ##################### cssexpr.js  #####################################################################
// #######################################################################################################

function constExpression(x) {
	return x;
}

function simplifyCSSExpression() {
	try {
		var ss,sl, rs, rl;
		ss = document.styleSheets;
		sl = ss.length
	
		for (var i = 0; i < sl; i++) {
			simplifyCSSBlock(ss[i]);
		}
	}
	catch (exc) {
		alert("Got an error while processing css. The page should still work but might be a bit slower");
		throw exc;
	}
}

function simplifyCSSBlock(ss) {
	var rs, rl;
	
	for (var i = 0; i < ss.imports.length; i++)
		simplifyCSSBlock(ss.imports[i]);
	
	if (ss.cssText.indexOf("expression(constExpression(") == -1)
		return;

	rs = ss.rules;
	rl = rs.length;
	for (var j = 0; j < rl; j++)
		simplifyCSSRule(rs[j]);
	
}

function simplifyCSSRule(r) {
	var str = r.style.cssText;
	var str2 = str;
	var lastStr;
	do {
		lastStr = str2;
		str2 = simplifyCSSRuleHelper(lastStr);
	} while (str2 != lastStr)

	if (str2 != str)
		r.style.cssText = str2;
}

function simplifyCSSRuleHelper(str) {
	var i, i2;
	i = str.indexOf("expression(constExpression(");
	if (i == -1) return str;
	i2 = str.indexOf("))", i);
	var hd = str.substring(0, i);
	var tl = str.substring(i2 + 2);
	var exp = str.substring(i + 27, i2);
	var val = eval(exp)
	return hd + val + tl;
}

if (/msie/i.test(navigator.userAgent) && window.attachEvent != null) {
	window.attachEvent("onload", function () {
		simplifyCSSExpression();
	});
}

// #######################################################################################################
// ##################### Fin cssexpr.js  #################################################################
// #######################################################################################################

// #######################################################################################################
// ##################### xmenu.js  #######################################################################
// #######################################################################################################

// check browsers
var ua = navigator.userAgent;
var opera = /opera [56789]|opera\/[56789]/i.test(ua);
var ie = !opera && /MSIE/.test(ua);
var ie50 = ie && /MSIE 5\.[01234]/.test(ua);
var ie6 = ie && /MSIE [6789]/.test(ua);
var ieBox = ie && (document.compatMode == null || document.compatMode != "CSS1Compat");
var moz = !opera && /gecko/i.test(ua);
var nn6 = !opera && /netscape.*6\./i.test(ua);
// define the default values
webfxMenuDefaultWidth			= 200;

webfxMenuDefaultBorderLeft		= 1;
webfxMenuDefaultBorderRight		= 1;
webfxMenuDefaultBorderTop		= 1;
webfxMenuDefaultBorderBottom	= 1;
webfxMenuDefaultPaddingLeft		= 1;
webfxMenuDefaultPaddingRight	= 1;
webfxMenuDefaultPaddingTop		= 1;
webfxMenuDefaultPaddingBottom	= 1;

webfxMenuDefaultShadowLeft		= 0;
webfxMenuDefaultShadowRight		= ie && !ie50 && /win32/i.test(navigator.platform) ? 4 :0;
webfxMenuDefaultShadowTop		= 0;
webfxMenuDefaultShadowBottom	= ie && !ie50 && /win32/i.test(navigator.platform) ? 4 : 0;

webfxMenuItemDefaultHeight		= 18;
webfxMenuItemDefaultText		= "------";
webfxMenuItemDefaultHref		= "javascript:void(0)";

webfxMenuSeparatorDefaultHeight	= 6;

webfxMenuDefaultEmptyText		= "Aucun lien.";

webfxMenuDefaultUseAutoPosition	= nn6 ? false : true;

// other global constants
webfxMenuImagePath				= "";

webfxMenuUseHover				= opera ? true : false;
webfxMenuHideTime				= 500;
webfxMenuShowTime				= 200;

var webFXMenuHandler = {
	idCounter		:	0,
	idPrefix		:	"webfx-menu-object-",
	all				:	{},
    topMenus        :   [],
    nbTopMenus      :   0,
	getId			:	function () { return this.idPrefix + this.idCounter++; },
	overMenuItem	:	function (oItem) {
		if (this.showTimeout != null)
			window.clearTimeout(this.showTimeout);
		if (this.hideTimeout != null)
			window.clearTimeout(this.hideTimeout);
		var jsItem = this.all[oItem.id];
		if (webfxMenuShowTime <= 0)
			this._over(jsItem);
		else
			//this.showTimeout = window.setTimeout(function () { webFXMenuHandler._over(jsItem) ; }, webfxMenuShowTime);
			// I hate IE5.0 because the piece of shit crashes when using setTimeout with a function object
			this.showTimeout = window.setTimeout("webFXMenuHandler._over(webFXMenuHandler.all['" + jsItem.id + "'])", webfxMenuShowTime);
	},
	outMenuItem	:	function (oItem) {
		if (this.showTimeout != null)
			window.clearTimeout(this.showTimeout);
		if (this.hideTimeout != null)
			window.clearTimeout(this.hideTimeout);
		var jsItem = this.all[oItem.id];
		if (webfxMenuHideTime <= 0)
			this._out(jsItem);
		else
			//this.hideTimeout = window.setTimeout(function () { webFXMenuHandler._out(jsItem) ; }, webfxMenuHideTime);
			this.hideTimeout = window.setTimeout("webFXMenuHandler._out(webFXMenuHandler.all['" + jsItem.id + "'])", webfxMenuHideTime);
	},
	blurMenu		:	function (oMenuItem) {
		window.setTimeout("webFXMenuHandler.all[\"" + oMenuItem.id + "\"].subMenu.hide();", webfxMenuHideTime);
	},
	_over	:	function (jsItem) {
	    for (var i=0;i<this.topMenus.length; i++) {
		    if(jsItem.topParentId != this.topMenus[i].menu.id) {
			    this.topMenus[i].menu.hideAllSubs();
            }
	    }
		if (jsItem.subMenu) {
			jsItem.parentMenu.hideAllSubs();
			jsItem.subMenu.show();
		}
		else
			jsItem.parentMenu.hideAllSubs();
	},
	_out	:	function (jsItem) {
		// find top most menu
		var root = jsItem;
		var m;
		if (root instanceof WebFXMenuButton)
			m = root.subMenu;
		else {
			m = jsItem.parentMenu;
			while (m.parentMenu != null && !(m.parentMenu instanceof WebFXMenuBar))
				m = m.parentMenu;
		}
		if (m != null)
            // ----------- Début Gilbert -----------------
            //m.hide();
            if(m.parentMenu!=null) {
                m.hide();
            } else {
                m.hideAllSubs();
            }
            // ----------- Fin Gilbert -----------------
	},
	hideMenu	:	function (menu) {
		if (this.showTimeout != null)
			window.clearTimeout(this.showTimeout);
		if (this.hideTimeout != null)
			window.clearTimeout(this.hideTimeout);

		this.hideTimeout = window.setTimeout("webFXMenuHandler.all['" + menu.id + "'].hide()", webfxMenuHideTime);
	},
	showMenu	:	function (menu, src, dir) {
		if (this.showTimeout != null)
			window.clearTimeout(this.showTimeout);
		if (this.hideTimeout != null)
			window.clearTimeout(this.hideTimeout);
		if (arguments.length < 3)
			dir = "BG";

		menu.show(src, dir);
	}
};

function WebFXMenu(idMenu, style, titreMenu) {
	this._menuItems	= [];
	this._subMenus	= [];
	this.id			= idMenu ? idMenu : webFXMenuHandler.getId();
    this.numStyle   = style;
	this.top		= 0;
	this.left		= 0;
	this.shown		= false;
	this.parentMenu	= null;
	webFXMenuHandler.all[this.id] = this;
    this.menuSystem = null; // menuSystem auquel appartient ce menu ( sert pour zIndex )
    this.texteTitre = null;
    this.styleTitre = "";
                
    if (titreMenu) {
        // Titre sous la forme : Texte|Couleur du texte|Couleur de fond|Alignement du texte
        var index, tmp;        
        index = titreMenu.indexOf("|");
/*        
        if(index!=-1) {
            this.texteTitre = titreMenu.substring(0, index);
            tmp = titreMenu.substring(index+1, titreMenu.length);
            index = tmp.indexOf("|");
            if(index!=-1) {
                this.styleTitre = this.styleTitre + " color: " + tmp.substring(0, index) + ";";
                tmp = tmp.substring(index+1, tmp.length);
                index = tmp.indexOf("|");
                if(index!=-1) {
                    if(tmp.substring(0, index)!="none") {
                        this.styleTitre = this.styleTitre + " background-color: " + tmp.substring(0, index) + ";";                   
                    }
                    this.styleTitre = this.styleTitre + " text-align: " + tmp.substring(index+1, tmp.length) + ";";                    
                } else {
                    if(tmp!="none") {
                        this.styleTitre = this.styleTitre + " background-color: " + tmp + ";";
                    }
                }
            } else {
                this.styleTitre = this.styleTitre + " color: " + tmp + ";";
            }
        } else {
           this.texteTitre = titreMenu;
        }    
*/
        if(index!=-1) {
            this.texteTitre = titreMenu.substring(0, index);
        } else {
           this.texteTitre = titreMenu;
        }     
    }
}

WebFXMenu.prototype.width			= webfxMenuDefaultWidth;
WebFXMenu.prototype.emptyText		= webfxMenuDefaultEmptyText;
WebFXMenu.prototype.useAutoPosition	= webfxMenuDefaultUseAutoPosition;

WebFXMenu.prototype.borderLeft		= webfxMenuDefaultBorderLeft;
WebFXMenu.prototype.borderRight		= webfxMenuDefaultBorderRight;
WebFXMenu.prototype.borderTop		= webfxMenuDefaultBorderTop;
WebFXMenu.prototype.borderBottom	= webfxMenuDefaultBorderBottom;

WebFXMenu.prototype.paddingLeft		= webfxMenuDefaultPaddingLeft;
WebFXMenu.prototype.paddingRight	= webfxMenuDefaultPaddingRight;
WebFXMenu.prototype.paddingTop		= webfxMenuDefaultPaddingTop;
WebFXMenu.prototype.paddingBottom	= webfxMenuDefaultPaddingBottom;

WebFXMenu.prototype.shadowLeft		= webfxMenuDefaultShadowLeft;
WebFXMenu.prototype.shadowRight		= webfxMenuDefaultShadowRight;
WebFXMenu.prototype.shadowTop		= webfxMenuDefaultShadowTop;
WebFXMenu.prototype.shadowBottom	= webfxMenuDefaultShadowBottom;

WebFXMenu.prototype.add = function (menuItem) {
	this._menuItems[this._menuItems.length] = menuItem;
	if (menuItem.subMenu) {
		this._subMenus[this._subMenus.length] = menuItem.subMenu;
		menuItem.subMenu.parentMenu = this;
	}

	menuItem.parentMenu = this;
};

WebFXMenu.prototype.show = function (relObj, sDir) {
	if (this.useAutoPosition)
		this.position(relObj, sDir);

	var divElement = document.getElementById(this.id);
	divElement.style.left = opera ? this.left : this.left + "px";
	divElement.style.top = opera ? this.top : this.top + "px";
    if(this.menuSystem!=null) {
        divElement.style.zIndex = ++this.menuSystem.zindex;
    }
	divElement.style.visibility = "visible";
	this.shown = true;
	if (this.parentMenu)
		this.parentMenu.show();
};

WebFXMenu.prototype.hide = function () {
	this.hideAllSubs();
	var divElement = document.getElementById(this.id);
	divElement.style.visibility = "hidden";
	this.shown = false;
};

WebFXMenu.prototype.hideAllSubs = function () {
	for (var i = 0; i < this._subMenus.length; i++) {
		if (this._subMenus[i].shown)
			this._subMenus[i].hide();
	}
};
WebFXMenu.prototype.toString = function () {
	var top = this.top + this.borderTop + this.paddingTop;
	var str = "<div id='" + this.id + "' class='mx-"+this.numStyle+"' style='visibility:hidden; z-index:0;" +
	"width:" + (!ieBox  ?
		this.width - this.borderLeft - this.paddingLeft - this.borderRight - this.paddingRight  :
		this.width) + "px;" +
	(this.useAutoPosition ?
		"left:" + this.left + "px;" + "top:" + this.top + "px;" :
		"") +
	(ie50 ? "filter: none;" : "") +
	"'>";
	if (this.texteTitre) {
		str +=	"<span class='mx-"+this.numStyle+"-titre' style='"+this.styleTitre+"font: menu; "+
//	    "width:" + (!ieBox  ?
//      this.width - this.borderLeft - this.paddingLeft - this.borderRight - this.paddingRight  :
//		this.width) + "px;" +          
        "width: 100%;"+
        "'>" + this.texteTitre + "</span>";
	}
	if (this._menuItems.length == 0) {
		str +=	"<span class='mx-"+this.numStyle+"-empty' style='visibility:visible;'>" + this.emptyText + "</span>";
	}
	else {
		// loop through all menuItems
		for (var i = 0; i < this._menuItems.length; i++) {
			var mi = this._menuItems[i];
			str += mi;
			if (!this.useAutoPosition) {
				if (mi.subMenu && !mi.subMenu.useAutoPosition)
					mi.subMenu.top = top - mi.subMenu.borderTop - mi.subMenu.paddingTop;
				top += mi.height;
			}
		}

	}

	str += "</div>";

	for (var i = 0; i < this._subMenus.length; i++) {
		this._subMenus[i].left = this.left + this.width - this._subMenus[i].borderLeft;
		str += this._subMenus[i];
	}

	return str;
};
// WebFXMenu.prototype.position defined later
function WebFXMenuItem(topId, sText, sHref, sToolTip, oSubMenu, sImagePath) {
	this.text = sText || webfxMenuItemDefaultText;
	this.href = (sHref == null || sHref == "") ? webfxMenuItemDefaultHref : sHref;
	this.subMenu = oSubMenu;
	if (oSubMenu)
		oSubMenu.parentMenuItem = this;
    this.image = sImagePath;
	this.toolTip = sToolTip;
	this.id = webFXMenuHandler.getId();
    this.topParentId = topId;
	webFXMenuHandler.all[this.id] = this;
};
WebFXMenuItem.prototype.height = webfxMenuItemDefaultHeight;
WebFXMenuItem.prototype.toString = function () {
	return	"<a" +
			" id='" + this.id + "'" +
			" href=\"" + this.href + "\"" +
			(this.target ? " target=\"" + this.target + "\"" : "") +
			(this.toolTip ? " title=\"" + this.toolTip + "\"" : "") +
			" onmouseover='webFXMenuHandler.overMenuItem(this)'" +
			(webfxMenuUseHover ? " onmouseout='webFXMenuHandler.outMenuItem(this)'" : "") +
			(this.subMenu ? " unselectable='on' tabindex='-1'" : "") +
			">" +
			(this.subMenu ? "<img class='arrow' src=\"" + this.image + "\">" : "") +
			this.text +
			"</a>";
};


function WebFXMenuSeparator() {
	this.id = webFXMenuHandler.getId();
	webFXMenuHandler.all[this.id] = this;
};
WebFXMenuSeparator.prototype.height = webfxMenuSeparatorDefaultHeight;
WebFXMenuSeparator.prototype.toString = function () {
	return	"<div" +
			" id='" + this.id + "'" +
			(webfxMenuUseHover ?
			" onmouseover='webFXMenuHandler.overMenuItem(this)'" +
			" onmouseout='webFXMenuHandler.outMenuItem(this)'"
			:
			"") +
			"></div>"
};

function WebFXMenuBar(idMenu, titreMenu) {
	this._parentConstructor = WebFXMenu;
	this._parentConstructor(idMenu, titreMenu);
}
WebFXMenuBar.prototype = new WebFXMenu;
WebFXMenuBar.prototype.toString = function () {
    // ----------- Début Gilbert -----------------
	//var str = "<div id='" + this.id + "' class='webfx-menu-bar'>";
	var str = "<div id='" + this.id + "' class='mx-"+this.numStyle+"-bar' style='visibility:hidden;" +
	"width:" + (!ieBox  ?
		this.width - this.borderLeft - this.paddingLeft - this.borderRight - this.paddingRight  :
		this.width) + "px;" +
	(this.useAutoPosition ?
		"left:" + this.left + "px;" + "top:" + this.top + "px;" :
		"") +
	(ie50 ? "filter: none;" : "") +
	"'>";
    if (this.texteTitre) {
		str +=	"<span class='mx-"+this.numStyle+"-titre' style='"+this.styleTitre+"font: menu; "+
//	    "width:" + (!ieBox  ?
//      this.width - this.borderLeft - this.paddingLeft - this.borderRight - this.paddingRight  :
//		this.width) + "px;" +       
        "width: 100%;"+        
        "'>" + this.texteTitre + "</span>";
	}
    
    // ----------- Fin Gilbert -----------------   
    
	// loop through all menuButtons
	for (var i = 0; i < this._menuItems.length; i++)
		str += this._menuItems[i];

	str += "</div>";

	for (var i = 0; i < this._subMenus.length; i++)
		str += this._subMenus[i];

	return str;
};

function WebFXMenuButton(topId, sText, sHref, sToolTip, oSubMenu, sImagePath) {
	this._parentConstructor = WebFXMenuItem;
	this._parentConstructor(topId, sText, sHref, sToolTip, oSubMenu, sImagePath);
}
WebFXMenuButton.prototype = new WebFXMenuItem;
WebFXMenuButton.prototype.toString = function () {
	return	"<a" +
			" id='" + this.id + "'" +
			" href=\"" + this.href + "\"" +
			(this.target ? " target=\"" + this.target + "\"" : "") +
			(this.toolTip ? " title=\"" + this.toolTip + "\"" : "") +
			(webfxMenuUseHover ?
				(" onmouseover='webFXMenuHandler.overMenuItem(this)'" +
				" onmouseout='webFXMenuHandler.outMenuItem(this)'") :
				(
					" onfocus='webFXMenuHandler.overMenuItem(this)'" +
					(this.subMenu ?
						" onblur='webFXMenuHandler.blurMenu(this)'" :
						""
					)
				)) +
			">" +
			this.text +
			(this.subMenu ? " <img class='arrow' src=\"" + this.image + "\" align='absmiddle'>" : "") +
			"</a>";
};


/* Position functions */

function getInnerLeft(el) {
	if (el == null) return 0;
	if (ieBox && el == document.body || !ieBox && el == document.documentElement) return 0;
	return getLeft(el) + getBorderLeft(el);
}

function getLeft(el) {
	if (el == null) return 0;
	return el.offsetLeft + getInnerLeft(el.offsetParent);
}

function getInnerTop(el) {
	if (el == null) return 0;
	if (ieBox && el == document.body || !ieBox && el == document.documentElement) return 0;
	return getTop(el) + getBorderTop(el);
}

function getTop(el) {
	if (el == null) return 0;
	return el.offsetTop + getInnerTop(el.offsetParent);
}

function getBorderLeft(el) {
	return ie ?
		el.clientLeft :
		parseInt(window.getComputedStyle(el, null).getPropertyValue("border-left-width"));
}

function getBorderTop(el) {
	return ie ?
		el.clientTop :
		parseInt(window.getComputedStyle(el, null).getPropertyValue("border-top-width"));
}

function opera_getLeft(el) {
	if (el == null) return 0;
	return el.offsetLeft + opera_getLeft(el.offsetParent);
}

function opera_getTop(el) {
	if (el == null) return 0;
	return el.offsetTop + opera_getTop(el.offsetParent);
}

function getOuterRect(el) {
	return {
		left:	(opera ? opera_getLeft(el) : getLeft(el)),
		top:	(opera ? opera_getTop(el) : getTop(el)),
		width:	el.offsetWidth,
		height:	el.offsetHeight
	};
}

// mozilla bug! scrollbars not included in innerWidth/height
function getDocumentRect(el) {
	return {
		left:	0,
		top:	0,
		width:	(ie ?
					(ieBox ? document.body.clientWidth : document.documentElement.clientWidth) :
					window.innerWidth
				),
		height:	(ie ?
					(ieBox ? document.body.clientHeight : document.documentElement.clientHeight) :
					window.innerHeight
				)
	};
}

function getScrollPos(el) {
	return {
		left:	(ie ?
					(ieBox ? document.body.scrollLeft : document.documentElement.scrollLeft) :
					window.pageXOffset
				),
		top:	(ie ?
					(ieBox ? document.body.scrollTop : document.documentElement.scrollTop) :
					window.pageYOffset
				)
	};
}

/* end position functions */

WebFXMenu.prototype.position = function (relEl, sDir) {
	var dir = sDir;
	// find parent item rectangle, piRect
	var piRect;
	if (!relEl) {
		var pi = this.parentMenuItem;
		if (!this.parentMenuItem)
			return;

		relEl = document.getElementById(pi.id);
		if (dir == null)
			dir = pi instanceof WebFXMenuButton ? "BG" : "HD";

		piRect = getOuterRect(relEl);
	}
	else if (relEl.left != null && relEl.top != null && relEl.width != null && relEl.height != null) {	// got a rect
		piRect = relEl;
	}
	else
		piRect = getOuterRect(relEl);

	var menuEl = document.getElementById(this.id);
	var menuRect = getOuterRect(menuEl);
	var docRect = getDocumentRect();
	var scrollPos = getScrollPos();
	var pMenu = this.parentMenu;

	if (dir == "BG") {
		if (piRect.left + menuRect.width - scrollPos.left <= docRect.width)
			this.left = piRect.left;
		else if (docRect.width >= menuRect.width)
			this.left = docRect.width + scrollPos.left - menuRect.width;
		else
			this.left = scrollPos.left;

		if (piRect.top + piRect.height + menuRect.height <= docRect.height + scrollPos.top)
			this.top = piRect.top + piRect.height;
		else if (piRect.top - menuRect.height >= scrollPos.top)
			this.top = piRect.top - menuRect.height;
		else if (docRect.height >= menuRect.height)
			this.top = docRect.height + scrollPos.top - menuRect.height;
		else
			this.top = scrollPos.top;
	} else {
        if (dir == "HD") {
            if (piRect.top + menuRect.height - this.borderTop - this.paddingTop <= docRect.height + scrollPos.top)
                this.top = piRect.top - this.borderTop - this.paddingTop;
            else if (piRect.top + piRect.height - menuRect.height + this.borderTop + this.paddingTop >= 0)
                this.top = piRect.top + piRect.height - menuRect.height + this.borderBottom + this.paddingBottom + this.shadowBottom;
            else if (docRect.height >= menuRect.height)
                this.top = docRect.height + scrollPos.top - menuRect.height;
            else
                this.top = scrollPos.top;
    
            var pMenuPaddingLeft = pMenu ? pMenu.paddingLeft : 0;
            var pMenuBorderLeft = pMenu ? pMenu.borderLeft : 0;
            var pMenuPaddingRight = pMenu ? pMenu.paddingRight : 0;
            var pMenuBorderRight = pMenu ? pMenu.borderRight : 0;
    
            if (piRect.left + piRect.width + menuRect.width + pMenuPaddingRight +
                pMenuBorderRight - this.borderLeft + this.shadowRight <= docRect.width + scrollPos.left)
                this.left = piRect.left + piRect.width + pMenuPaddingRight + pMenuBorderRight - this.borderLeft;
            else if (piRect.left - menuRect.width - pMenuPaddingLeft - pMenuBorderLeft + this.borderRight + this.shadowRight >= 0)
                this.left = piRect.left - menuRect.width - pMenuPaddingLeft - pMenuBorderLeft + this.borderRight + this.shadowRight;
            else if (docRect.width >= menuRect.width)
                this.left = docRect.width  + scrollPos.left - menuRect.width;
            else
                this.left = scrollPos.left;
        } else {
            if (dir == "BD") {
                if (piRect.top + piRect.height + menuRect.height <= docRect.height + scrollPos.top)
                    this.top = piRect.top + piRect.height;
                else if (piRect.top - menuRect.height >= scrollPos.top)
                    this.top = piRect.top - menuRect.height;
                else if (docRect.height >= menuRect.height)
                    this.top = docRect.height + scrollPos.top - menuRect.height;
                else
                    this.top = scrollPos.top; 
                    
                var pMenuPaddingLeft = pMenu ? pMenu.paddingLeft : 0;
                var pMenuBorderLeft = pMenu ? pMenu.borderLeft : 0;
                var pMenuPaddingRight = pMenu ? pMenu.paddingRight : 0;
                var pMenuBorderRight = pMenu ? pMenu.borderRight : 0;
        
                if (piRect.left + piRect.width + menuRect.width + pMenuPaddingRight +
                    pMenuBorderRight - this.borderLeft + this.shadowRight <= docRect.width + scrollPos.left)
                    this.left = piRect.left + piRect.width + pMenuPaddingRight + pMenuBorderRight - this.borderLeft;
                else if (piRect.left - menuRect.width - pMenuPaddingLeft - pMenuBorderLeft + this.borderRight + this.shadowRight >= 0)
                    this.left = piRect.left - menuRect.width - pMenuPaddingLeft - pMenuBorderLeft + this.borderRight + this.shadowRight;
                else if (docRect.width >= menuRect.width)
                    this.left = docRect.width  + scrollPos.left - menuRect.width;
                else
                    this.left = scrollPos.left;                    
            } else {
                if (piRect.top + menuRect.height - this.borderTop - this.paddingTop <= docRect.height + scrollPos.top)
                    this.top = piRect.top - this.borderTop - this.paddingTop;
                else if (piRect.top + piRect.height - menuRect.height + this.borderTop + this.paddingTop >= 0)
                    this.top = piRect.top + piRect.height - menuRect.height + this.borderBottom + this.paddingBottom + this.shadowBottom;
                else if (docRect.height >= menuRect.height)
                    this.top = docRect.height + scrollPos.top - menuRect.height;
                else
                    this.top = scrollPos.top;
                if (piRect.left + menuRect.width - scrollPos.left <= docRect.width)
                    this.left = piRect.left;
                else if (docRect.width >= menuRect.width)
                    this.left = docRect.width + scrollPos.left - menuRect.width;
                else
                    this.left = scrollPos.left;                    
            }
        }
	}
};

// #######################################################################################################
// ##################### Fin xmenu.js  ###################################################################
// #######################################################################################################

// #######################################################################################################
// ##################### AetD  ###########################################################################
// #######################################################################################################

//document.write("<script src='xmlmenu.js'><\/script>");

function XMENU_Menu(idMenu, url, vueXml, imagePathH, imagePathV, numStyle, idPosition, ancrePosition, sens, width, left, top, decalageH, decalageV, posFixe, titreMenu) {

    this.created = false;
    this.shown = false;
    //this.left = 0;
    //this.top = 0;
    this.menu = null;
    this.id = idMenu;
    this.menuBar = ( sens == "H" ? true : false );
    this.style = numStyle;
    this.position = idPosition;
    this.ancre = ancrePosition;
    this.sens = sens;
    this.width = width;
    this.posLeft = left;
    this.posTop = top;
    this.decalH = decalageH;
    this.decalV = decalageV;
    this.aimant = posFixe;
    this.titre = titreMenu;
    this.left = 0;
    this.top = 0;

 //   if(this.menuBar && this.position!="" && this.width==null && (this.ancre=="BG" || this.ancre=="HG") ) {
   if(this.position!="" && this.width==null && (this.ancre=="BG" || this.ancre=="HG") ) {         
        // Barre de menu au dessus ou au dessous d'un élément, sans précision de largeur
        // ===> On force la largeur à la même largeur que l'élément
        var objPos, objRect;
        objPos = document.getElementById(this.position);
        if(objPos) {
            objRect = getOuterRect(objPos);
            this.width = objRect.width;
        }
    }
    if(this.width==null || this.width==0 || this.width==-1) {
        var el = getDocumentRect();    
        this.width = (this.menuBar || this.width==-1) ? el.width-this.decalH-20 : 200;
    }

//    alert("largeur="+this.width);
//    alert("position="+this.position);
//    alert("ancre="+this.ancre);
          
    if(this.menuBar) {
        webfxMenuHideTime = 100;
        webfxMenuShowTime = 10;
        webfxMenuUseHover = true; //false;
        WebFXMenuBar.prototype.useAutoPosition = true;
        WebFXMenuBar.prototype.width = this.width;
        //WebFXMenu.prototype.width = 100;
    } else {
        webfxMenuHideTime = 100;
        webfxMenuShowTime = 0;
        webfxMenuUseHover = true;
        WebFXMenu.prototype.useAutoPosition = true;
        WebFXMenu.prototype.width = this.width;
    }
      
    this.getMenu = function(id, style, menuNode, menuBar, topParentId, imagePathH, imagePathV, titre) {
        var menu = menuBar ? new WebFXMenuBar(id, style, titre) : new WebFXMenu(id, style, titre);
        var cs = menuNode.childNodes;
        var menuItem;
    
        if(topParentId==null) {
            topParentId = menu.id;
        }
        for(var i=0;i<cs.length;i++) {
            if(!cs[i].hasChildNodes) {
                if(menuBar) {
                    menuItem = new WebFXMenuButton(topParentId, unescape(cs[i].getAttribute("libelle")),
                                        unescape(cs[i].getAttribute("url")),
                                        unescape(cs[i].getAttribute("bulle")));
                } else {
                    menuItem = new WebFXMenuItem(topParentId, unescape(cs[i].getAttribute("libelle")),
                                        unescape(cs[i].getAttribute("url")),
                                        unescape(cs[i].getAttribute("bulle")));
                }
                if(unescape(cs[i].getAttribute("cible"))!="") {
                    menuItem.target = unescape(cs[i].getAttribute("cible"));
                }
            } else {
                if(menuBar) {
                    menuItem = new WebFXMenuButton(topParentId, unescape(cs[i].getAttribute("libelle")),
                                        unescape(cs[i].getAttribute("url")),
                                        unescape(cs[i].getAttribute("bulle")),
                                        this.getMenu(null, style, cs[i], false, topParentId, imagePathH, imagePathV, null),
                                        imagePathH);
                 } else {
                    menuItem = new WebFXMenuItem(topParentId, unescape(cs[i].getAttribute("libelle")),
                                        unescape(cs[i].getAttribute("url")),
                                        unescape(cs[i].getAttribute("bulle")),
                                        this.getMenu(null, style, cs[i], false, topParentId, imagePathH, imagePathV, null),
                                        imagePathV);
                }
            }
            
            menu.add(menuItem);
        }
        return(menu);
    }
    
    var menuXml = new xmlMenu(url, vueXml);
/*    if(menuXml.menuLoaded) {
        this.menu = this.getMenu(this.id, menuXml.menuRoot, this.menuBar, null, imagePath, this.titre);
        //this.menu.width= this.width;
        if(this.menu!=null) {
            this.created = true;
            document.write(this.menu);
        }
    }*/
    if(menuXml.menuLoaded) {
        this.menu = this.getMenu(this.id, this.style, menuXml.menuRoot, this.menuBar, null, imagePathH, imagePathV, this.titre);
        //this.menu.width= this.width;
        if(this.menu!=null) {
            this.created = true;
            document.write(this.menu);
        }
    } else {
        this.menu = this.menuBar ? new WebFXMenuBar(this.id, this.style, this.titre) : new WebFXMenu(this.id, this.style, this.titre);
        this.created = true;
        document.write(this.menu);
    }
}

function menuSystem() {
    this.menus = [];
    this.nbMenus = 0;
    this.zindex = 0;    // Variable globale à tous les menus
    
    this.addMenu = function(idMenu, urlVueXml, vueXml, imagePathH, imagePathV, style, position, sens, largeur, decalageH, decalageV, aimant, titre) {
        //webfxMenuImagePath = imagePath;
        var xmenu, id;
        var idPosition = "", ancrePosition="";
        var numStyle, sensMenu, width, left, top, decalH, decalV, posFixe, titreMenu;
        var index;
        
        id = (idMenu=="undefined" || idMenu==null) ? null : idMenu;
        numStyle = (style=="undefined" || style==null) ? "0" : style;
        width = (largeur=="undefined" || largeur==null || largeur==0) ? null : largeur;
        decalH = (decalageH=="undefined" || decalageH==null) ? 0 : decalageH;
        decalV = (decalageV=="undefined" || decalageV==null) ? 0 : decalageV;    
        posFixe = (aimant=="undefined" || aimant==null || aimant.toLowerCase()!="aimant") ? false : true;  
        titreMenu = (titre=="undefined" || titre==null || titre=="") ? null : titre;   
        switch(position) {
            case "Gauche" :
                sensMenu = "V";
                left = "G";
                top = "H";
                break;
            case "Droite" :
                sensMenu = "V";
                left = "D";
                top = "H";
                break;
            case "Milieu" :
                sensMenu = "V";
                left = "M";
                top = "H";            
                break;             
            case "Haut" :
                sensMenu = "H";   
                left = "G";
                top = "H";
                break;
            case "Bas" :
                sensMenu = "H";
                left = "G";
                top = "B";            
                break;
            default :
                sensMenu = sens;
                left = "G";
                top = "H";
                index = position.indexOf(":");
                if(index!=-1) {
                    idPosition = position.substring(0, index);
                    ancrePosition = position.substring(index+1, position.length);
                } else {
                    idPosition = position;
                    ancrePosition = "BG";
                }
                break;
        }
        xmenu = new XMENU_Menu(id, urlVueXml, vueXml, imagePathH, imagePathV, numStyle, idPosition, ancrePosition, sensMenu, width, left, top, decalH, decalV, posFixe, titreMenu);
        if(xmenu.created) {
            this.menus[this.nbMenus] = xmenu;
	        webFXMenuHandler.topMenus[this.nbMenus] = this.menus[this.nbMenus];
            this.menus[this.nbMenus].menu.menuSystem = this;
            this.nbMenus++;   
        }
    }
    
    this.showMenu = function(numMenu) {
        if(numMenu<this.nbMenus) {
            var menu = this.menus[numMenu];
            var objPos = null;
            var border = 5;
            var el, left, top;

            if(menu!=null) {
                if(menu.created) {
                    if(menu.shown && menu.aimant) {
                        var scroll = getScrollPos(); 
                        menu.menu.left = menu.left + scroll.left;
                        menu.menu.top = menu.top + scroll.top;
                        menu.menu.show();
                    } else {
                        if(menu.position!="") {
                            objPos = document.getElementById(menu.position);
                        }
                        if(objPos) {
                            menu.menu.show(objPos, menu.ancre);
                        } else {
                            el = getDocumentRect();
                            left = border;
                            top = border;
                            if(menu.posLeft=="G") {
                                left = border+menu.decalH;
                            } else {
                                if(menu.posLeft=="D") {
                                    left = el.width-menu.width-border-menu.decalH;
                                } else {
                                    if(menu.posLeft=="M") {
                                        left = parseInt((el.width-menu.width)/2)+menu.decalH;
                                    } else {
                                        left = border+menu.decalH;
                                    }
                                }
                            }
                            if(menu.posTop=="H") {
                                top = border+menu.decalV;
                            } else {
                                if(menu.posTop=="B") {
                                    top = el.height-getOuterRect(document.getElementById(menu.menu.id)).height-border-
                                            webfxMenuItemDefaultHeight-webfxMenuDefaultBorderTop-webfxMenuDefaultBorderBottom-
                                            menu.decalV;
                                } else {
                                    top = border+menu.decalV;
                                }
                            }
                            menu.menu.left = left;
                            menu.menu.top = top;
                            menu.menu.show();
                        }
                        //  Mémorisation des paramètres de positionnement initiaux
                        menu.left = menu.menu.left;
                        menu.top = menu.menu.top;
                        menu.shown = true;
                    }
                }
            }
        }
    }

    this.show = function() {
       	for(var i=0;i<this.nbMenus;i++) {
            this.showMenu(i);
    	} 
    }
}

// #######################################################################################################
// ##################### Fin AetD  #######################################################################
// #######################################################################################################
