/*
* javascript multilevel menu developed by Matteo Bicocchi
* (c) 2002-2007 Open Lab srl, Matteo Bicocchi
* version 3.1
* free to use - please don't cut this lines
* tested on: Explorer, Mozilla, Netscape and Opera for PC
* Mozilla, Netscape and Safari for Mac Os X
*/
// inizializing variables
//
var theId;
var ContentLine;
var contentMenu;
var theLayer;
var trueX;
var trueY;
var windowHeight;
var winWidth,winHeight;
var zMax;
var menuDiv;
var actualMenu="";
var submenuOnLeft=false;
var submenuOnTop=false;
var activeOnClick=false;
var menuWidth=120;
var menuZIndex=2000;
var contentLineAlign="left";
var separatorHeight=0; // separator height
var lineHeight = 0;
//var distanceY=0; // menu top adjust
//var distanceX=0; // menu left adjust
var subMenuMarginLeft=0; // subMenu left adjust
var subMenuMarginTop=0; // subMenu top adjust
var imagesUrl="/commons/skin/blue/images/";
var actualId="";
var isTxt;
var arrowImg= "menuArrow.gif";
var documentLoaded=true;
var actualNode="";
var associationId="";
//-----------------link the right css class to the normal and the over state for the menubar---
barMenuOverClass="menuBarOver";
barMenuClass="menuBar";
//-----------------define if you have to click for the first open-------------------------
var menuOnClick=true;
var show= (menuOnClick)? false : true;
//-----------------if you attach the menu to a textual link define the normal and the over style---
var rollOverOnBar=true;
var whichMenuBar="";
//-----------------define if you have images or webdings in menu lines-------------------
var hasImg=true;
function createImg(imgDef){
var hasTxtImg=(imgDef && imgDef.indexOf(".")<1 );
if (hasImg ){
imgString="
";
if (!imgDef || imgDef.length==0 || (hasTxtImg && !isExplorer && isWin)){
imgString=imgString+" ";
}else{
if (hasTxtImg){
imgString=imgString+""+imgDef+"";
} else {
//imgString=imgString+" ";
imgString=imgString+" ";
}
}
imgString=imgString+" | ";
}else{
imgString="";
}
}
//-----------------recursive search for element----------------------------------
function findDiv(theEl){
while (!theEl.name) {
theEl=isNetscape ? theEl.parentNode: theEl.parentElement;
}
return theEl.id;
}
//-----------------create elements-------------------------------------------
function createMenuDiv (theId, where){
var menuDiv = createEl("DIV");
menuDiv.style.position = "absolute";
menuDiv.style.display = "none";
menuDiv.id = theId;
menuDiv.name = theId;
menuDiv.style.width= menuWidth;
menuDiv.style.zindex = menuZIndex;
document.body.appendChild(menuDiv);
actualMenu = menuDiv.id;
}
function createSubMenuDiv (subMenuId, relativeTo){
subMenuDiv = createEl("DIV");
subMenuDiv.style.position = "absolute";
subMenuDiv.id = subMenuId;
subMenuDiv.name = subMenuId;
subMenuDiv.style.width= menuWidth;
subMenuDiv.style.zindex = zMax;
//subMenuDiv.style.left= parseFloat(obj(relativeTo).offsetWidth+subMenuMarginLeft)+"px";
//subMenuDiv.style.marginTop= -(parseFloat(obj(relativeTo).offsetHeight+subMenuMarginTop))+"px";
obj(relativeTo).appendChild(subMenuDiv);
targetWidth= obj(relativeTo).offsetWidth;
windowWidth = getWindowDimensionW();
windowHeight = getWindowDimensionH();
/*
if (getAbsoluteLeft(subMenuDiv)>=(windowWidth-targetWidth) ){ // || submenuOnLeft
subMenuDiv.style.left= parseFloat(-obj(relativeTo).offsetWidth-subMenuMarginLeft)+"px";
submenuOnLeft=true;
}
if (submenuOnTop){
subMenuDiv.style.marginTop= -(parseFloat(-obj(subMenuId).offsetHeight+obj(relativeTo).offsetHeight))+"px";
submenuOnTop=true;
}
*/
theEl= obj(relativeTo);
theMenuToHide= obj(findDiv(theEl)).menuToHide;
if (theMenuToHide){
removeMenu(theMenuToHide);
}
obj(findDiv(theEl)).menuToHide=subMenuId;
}
// create the label of the menu
function createContentLineTitle (desc){
contentLine = "";
return contentLine;
}
// create the submenu line
function createSubmenuLine (desc, submenu,imgDef){
createImg(imgDef);
ContentLine="";
return ContentLine;
}
// create the menu line
function createContentLine (desc, lineUrl, target, contentTitle, script,imgDef, enabled){
createImg(imgDef);
if (!target) target="document";
if (target=="_parent") target="document.parent";
if (target=="_self") target="document.self";
if(!script){
if (contentTitle) contentTitle="title='"+contentTitle+"'"; else contentTitle=""
ContentLine="";
}else{
ContentLine="";
}
if((lineUrl=='#' && (script==null || script=='')))
ContentLine="";
if(enabled=="false")
ContentLine="";
return ContentLine;
}
// create the menu line disabled
function createContentLineDisabled (desc,imgDef){
createImg(imgDef);
ContentLine="";
return ContentLine;
}
// create the separator line
function createSeparator (){
ContentLine="";
return ContentLine;
}
// create the menu
function createContent (wich, theId){
var iframeHeight=0;
var h=0;
contentMenu="";
//if is explorer and Windows generate an iframe under the menu to prevent a bug in Explorer that put a form popup element over everything
// 30-11-05 tolto z-index:1; da style di iframe
contentMenu+=(isExplorer && isWin ? "":"");
//contentMenu+= "";
//
contentMenu+="
\n";
contentMenu+="";
contentMenu+="
\n";
contentMenu+="
\n";
return contentMenu;
}
// change the content of the menu according with the call in the page
function changeContent (theMenu, theId){
var menuContent= createContent (theMenu, theId);
/*
if(isExplorer){
theLayer = document.all[theId];
theLayer.innerHTML=menuContent;
}
if(isNetscape){
*/
theLayer = obj(theId);
theLayer.innerHTML =menuContent;
/* } */
//scriptDebugger(menuContent);
}
function showMenu(theMenu, where, theId, isTxt){
if(documentLoaded || !isExplorer){
if (actualId != "") {
hideMenu();
}
if (whichMenuBar!="" && rollOverOnBar && menuBarType ) obj(whichMenuBar).className=barMenuClass;
whichMenuBar=where;
menuBarType= isTxt;
if (whichMenuBar!="" && rollOverOnBar && menuBarType) obj(whichMenuBar).className=barMenuOverClass;
var el = obj(theId);
if (!el && show==true){
createMenuDiv (theId);
actualId=theId;
theMenuEl = obj(theId);
theMenuEl.style.display="";
positionIt(where, theId);
changeContent (theMenu, theId);
//----dimentioning iframe for Explorer bug collisioning with combo form element
tableMenuEl= obj('table'+theId);
containerMenuEl= obj('container'+theId);
topMenuEl= obj(where);
if(isExplorer){
containerMenuEl.style.width=tableMenuEl.offsetWidth;
containerMenuEl.style.height=tableMenuEl.offsetHeight;
}
//----END dimentioning iframe
// if the menu is out of the window then reposition it
targetWidth= tableMenuEl.offsetWidth;
targetHeight =tableMenuEl.offsetHeight;
windowHeight=getWindowDimensionH()
windowWidth = getWindowDimensionW();
if (getAbsoluteLeft(theMenuEl)>=(windowWidth-targetWidth)){
theMenuEl.style.left=(getAbsoluteLeft(theMenuEl)-(targetWidth)+topMenuEl.offsetWidth)+"px";
submenuOnLeft=true;
}
barHeight=(isExplorer)?45:20;
if (getAbsoluteTop(theMenuEl)+targetHeight>=(windowHeight-barHeight)){
theMenuEl.style.marginTop=-((getAbsoluteTop(theMenuEl)-((windowHeight-barHeight)-targetHeight)))+"px";
}
theMenuEl.style.zIndex=zMax++;
}
}
}
function showSubMenu(theMenu, theId, relativeTo) {
if (!obj(theId)) {
createSubMenuDiv (theId, relativeTo);
theSubMenuEl = obj(theId);
changeContent (theMenu, theId);
theSubMenuEl.style.zIndex=10+zMax;
zMax=zMax++;
theSubMenuEl.style.left= parseFloat(obj(relativeTo).offsetWidth+subMenuMarginLeft)+"px";
//theSubMenuEl.style.marginTop= -(parseFloat(obj(relativeTo).offsetHeight+subMenuMarginTop))+"px";
theSubMenuEl.style.top=theSubMenuEl.offsetTop-(parseFloat(obj(relativeTo).offsetHeight+subMenuMarginTop))+"px";
/*
if (isSafari){
theSubMenuEl.style.top= theSubMenuEl.offsetTop+(parseFloat(obj(relativeTo).offsetHeight))+"px";
}
*/
//----dimentioning iframe for Explorer bug collisioning with combo form element
if(isExplorer){
tableMenuEl= obj('table'+theId);
containerMenuEl= obj('container'+theId);
containerMenuEl.style.width=tableMenuEl.offsetWidth;
containerMenuEl.style.height=tableMenuEl.offsetHeight;
}
//----END dimentioning iframe
// if the subMenu is out of the window then reposition it
tableMenuEl= obj('table'+theId);
targetWidth= tableMenuEl.offsetWidth;
targetHeight =tableMenuEl.offsetHeight;
windowHeight=getWindowDimensionH()
windowWidth = getWindowDimensionW();
//modified 31.3.06
var inside=50;
if (getAbsoluteLeft(theSubMenuEl)>=(windowWidth-targetWidth)){
theSubMenuEl.style.marginLeft=-((obj(relativeTo).offsetWidth+targetWidth)+(subMenuMarginLeft*2)-inside);
theSubMenuEl.style.width=tableMenuEl.offsetWidth;
theSubMenuEl.style.height=tableMenuEl.offsetHeight;
theSubMenuEl.style.borderTop="1px solid #cccccc";
theSubMenuEl.style.borderLeft="1px solid #cccccc";
}
//end modified
barHeight=(isExplorer)?45:35;
if (getAbsoluteTop(theSubMenuEl)+targetHeight>=(windowHeight-barHeight)){
theSubMenuEl.style.marginTop=-((getAbsoluteTop(theSubMenuEl)-((windowHeight-barHeight)-targetHeight)))+"px";
}
}
}
var platActualObjID;
// contextualMenu
var contextualPageId;
function showContextualMenu(theMenu,theNodeId, uniqueID, docPageId,thePageId){
platActualObjID = theNodeId.substring(uniqueID.length, theNodeId.length);
show=true;
if (actualId && actualId != "") {
hideMenu();
}
if ( thePageId ) contextualPageId= thePageId;
theMenuId=theNodeId+"_contextual";
actualNode=theNodeId;
if(docPageId) associationId=docPageId;
var el = obj(theMenuId);
if (!el && show==true){
createMenuDiv (theMenuId);
actualId=theMenuId;
theMenuEl = obj(theMenuId);
theMenuEl.style.top=mouseY+"px";
theMenuEl.style.left=mouseX+"px";
theMenuEl.style.display="";
changeContent (theMenu, theMenuId);
//----dimentioning iframe for Explorer bug collisioning with combo form element
tableMenuEl= obj('table'+theMenuId);
containerMenuEl= obj('container'+theMenuId);
if(isExplorer){
containerMenuEl.style.width=tableMenuEl.offsetWidth;
containerMenuEl.style.height=tableMenuEl.offsetHeight;
}
//----END dimentioning iframe
// if the menu is out of the window then reposition it
targetWidth= tableMenuEl.offsetWidth;
targetHeight =tableMenuEl.offsetHeight;
windowHeight=getWindowDimensionH()
windowWidth = getWindowDimensionW();
var pageScrollLeft=isExplorer? document.body.scrollLeft:window.pageXOffset;
var pageScrollTop=isExplorer? document.body.scrollTop:window.pageYOffset;
if (getAbsoluteLeft(theMenuEl)>=(windowWidth-targetWidth)){
theMenuEl.style.left=(getAbsoluteLeft(theMenuEl)-(targetWidth)+pageScrollLeft)+"px";
}
barHeight=(isExplorer)?45:20;
if (getAbsoluteTop(theMenuEl)+targetHeight>=(windowHeight-barHeight)+pageScrollTop){
theMenuEl.style.marginTop=-((getAbsoluteTop(theMenuEl)-((windowHeight-barHeight+pageScrollTop)-targetHeight)))+"px";
}
theMenuEl.style.zIndex=zMax++;
}
}
// hide the menu & subMenu
function hideMenu(){
if (whichMenuBar!="" && rollOverOnBar && menuBarType) obj(whichMenuBar).className=barMenuClass;
actualMenu="";
actualSubMenu = "";
whichMenuBar="";
theMenuEl = obj(actualId);
if (theMenuEl){
removeMenu(actualId);
actualId="";
}
}
function hideSubMenu(theId){
theMenuEl = obj(theId);
theMenuToHide= obj(findDiv(theId)).menuToHide;
theMenuEl= obj(theMenuToHide);
if (theMenuEl){
removeMenu(theMenuToHide);
obj(findDiv(theId)).menuToHide=null;
}
}
function removeMenu (theId){
theMenu= obj(theId);
lineToRestore=obj(theId+"_sml");
if(theMenu) theMenu.parentNode.removeChild(theMenu);
if (lineToRestore) lineToRestore.className='subMenu';
}
function showOnClick(){
show=(menuOnClick)?true:show;
}
// END hide the menu & subMenu
document.onclick = function () {
if (menuOnClick) setTimeout('if(actualMenu==\'\') show=false;',250);
}
document.onmousedown = hideMenu;
//document.onblur = hideMenu;
//terrible hack
var setStart=true;
start = function (){
setTimeout('documentLoaded=true',1000);
}
//centralized on platform.js
//window.onload = start;