home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / themes / nuvola / JSCookMenu.js < prev    next >
Text File  |  2004-03-08  |  21KB  |  824 lines

  1. /*
  2.     JSCookMenu v1.23.  (c) Copyright 2002 by Heng Yuan
  3.  
  4.     Permission is hereby granted, free of charge, to any person obtaining a
  5.     copy of this software and associated documentation files (the "Software"),
  6.     to deal in the Software without restriction, including without limitation
  7.     the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8.     and/or sell copies of the Software, and to permit persons to whom the
  9.     Software is furnished to do so, subject to the following conditions:
  10.  
  11.     The above copyright notice and this permission notice shall be included
  12.     in all copies or substantial portions of the Software.
  13.  
  14.     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15.     OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16.     ITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17.     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18.     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19.     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20.     DEALINGS IN THE SOFTWARE.
  21. */
  22.  
  23. // Globals
  24. var _cmIDCount = 0;
  25. var _cmIDName = 'cmSubMenuID';        // for creating submenu id
  26.  
  27. var _cmTimeOut = null;            // how long the menu would stay
  28. var _cmCurrentItem = null;        // the current menu item being selected;
  29.  
  30. var _cmNoAction = new Object ();    // indicate that the item cannot be hovered.
  31. var _cmSplit = new Object ();        // indicate that the item is a menu split
  32.  
  33. var _cmItemList = new Array ();        // a simple list of items
  34.  
  35. // default node properties
  36. var _cmNodeProperties =
  37. {
  38.       // main menu display attributes
  39.       //
  40.       // Note.  When the menu bar is horizontal,
  41.       // mainFolderLeft and mainFolderRight are
  42.       // put in <span></span>.  When the menu
  43.       // bar is vertical, they would be put in
  44.       // a separate TD cell.
  45.  
  46.       // HTML code to the left of the folder item
  47.       mainFolderLeft: '',
  48.       // HTML code to the right of the folder item
  49.       mainFolderRight: '',
  50.     // HTML code to the left of the regular item
  51.     mainItemLeft: '',
  52.     // HTML code to the right of the regular item
  53.     mainItemRight: '',
  54.  
  55.     // sub menu display attributes
  56.  
  57.     // HTML code to the left of the folder item
  58.     folderLeft: '',
  59.     // HTML code to the right of the folder item
  60.     folderRight: '',
  61.     // HTML code to the left of the regular item
  62.     itemLeft: '',
  63.     // HTML code to the right of the regular item
  64.     itemRight: '',
  65.     // cell spacing for main menu
  66.     mainSpacing: 0,
  67.     // cell spacing for sub menus
  68.     subSpacing: 0,
  69.     // auto dispear time for submenus in milli-seconds
  70.     delay: 500
  71. };
  72.  
  73. //////////////////////////////////////////////////////////////////////
  74. //
  75. // Drawing Functions and Utility Functions
  76. //
  77. //////////////////////////////////////////////////////////////////////
  78.  
  79. //
  80. // produce a new unique id
  81. //
  82. function cmNewID ()
  83. {
  84.     return _cmIDName + (++_cmIDCount);
  85. }
  86.  
  87. //
  88. // return the property string for the menu item
  89. //
  90. function cmActionItem (item, prefix, isMain, idSub, orient, nodeProperties)
  91. {
  92.     // var index = _cmItemList.push (item) - 1;
  93.     _cmItemList[_cmItemList.length] = item;
  94.     var index = _cmItemList.length - 1;
  95.     idSub = (!idSub) ? 'null' : ('\'' + idSub + '\'');
  96.     orient = '\'' + orient + '\'';
  97.     prefix = '\'' + prefix + '\'';
  98.     return ' onmouseover="cmItemMouseOver (this,' + prefix + ',' + isMain + ',' + idSub + ',' + orient + ',' + index + ')" onmouseout="cmItemMouseOut (this,' + nodeProperties.delay + ')" onmousedown="cmItemMouseDown (this,' + index + ')" onmouseup="cmItemMouseUp (this,' + index + ')"';
  99. }
  100.  
  101. function cmNoActionItem (item, prefix)
  102. {
  103.     return item[1];
  104. }
  105.  
  106. function cmSplitItem (prefix, isMain, vertical)
  107. {
  108.     var classStr = 'cm' + prefix;
  109.     if (isMain)
  110.     {
  111.         classStr += 'Main';
  112.         if (vertical)
  113.             classStr += 'HSplit';
  114.         else
  115.             classStr += 'VSplit';
  116.     }
  117.     else
  118.         classStr += 'HSplit';
  119.     var item = eval (classStr);
  120.     return cmNoActionItem (item, prefix);
  121. }
  122.  
  123. //
  124. // draw the sub menu recursively
  125. //
  126. function cmDrawSubMenu (subMenu, prefix, id, orient, nodeProperties)
  127. {
  128.     var str = '<div class="' + prefix + 'SubMenu" id="' + id + '"><table summary="sub menu" cellspacing="' + nodeProperties.subSpacing + '" class="' + prefix + 'SubMenuTable">';
  129.     var strSub = '';
  130.  
  131.     var item;
  132.     var idSub;
  133.     var hasChild;
  134.  
  135.     var i;
  136.  
  137.     var classStr;
  138.  
  139.     for (i = 5; i < subMenu.length; ++i)
  140.     {
  141.         item = subMenu[i];
  142.         if (!item)
  143.             continue;
  144.  
  145.         hasChild = (item.length > 5);
  146.         idSub = hasChild ? cmNewID () : null;
  147.  
  148.         str += '<tr class="' + prefix + 'MenuItem"' + cmActionItem (item, prefix, 0, idSub, orient, nodeProperties) + '>';
  149.  
  150.         if (item == _cmSplit)
  151.         {
  152.             str += cmSplitItem (prefix, 0, true);
  153.             str += '</tr>';
  154.             continue;
  155.         }
  156.  
  157.         if (item[0] == _cmNoAction)
  158.         {
  159.             str += cmNoActionItem (item, prefix);
  160.             str += '</tr>';
  161.             continue;
  162.         }
  163.  
  164.         classStr = prefix + 'Menu';
  165.         classStr += hasChild ? 'Folder' : 'Item';
  166.  
  167.         str += '<td class="' + classStr + 'Left">';
  168.  
  169.         if (item[0] != null && item[0] != _cmNoAction)
  170.             str += item[0];
  171.         else
  172.             str += hasChild ? nodeProperties.folderLeft : nodeProperties.itemLeft;
  173.  
  174.         str += '<td class="' + classStr + 'Text">' + item[1];
  175.  
  176.         str += '<td class="' + classStr + 'Right">';
  177.  
  178.         if (hasChild)
  179.         {
  180.             str += nodeProperties.folderRight;
  181.             strSub += cmDrawSubMenu (item, prefix, idSub, orient, nodeProperties);
  182.         }
  183.         else
  184.             str += nodeProperties.itemRight;
  185.         str += '</td></tr>';
  186.     }
  187.  
  188.     str += '</table></div>' + strSub;
  189.     return str;
  190. }
  191.  
  192. //
  193. // The function that builds the menu inside the specified element id.
  194. //
  195. // @param    id    id of the element
  196. //        orient    orientation of the menu in [hv][ab][lr] format
  197. //        menu    the menu object to be drawn
  198. //        nodeProperties    properties for each menu node
  199. //
  200. function cmDraw (id, menu, orient, nodeProperties, prefix)
  201. {
  202.     var obj = cmGetObject (id);
  203.  
  204.     if (!nodeProperties)
  205.         nodeProperties = _cmNodeProperties;
  206.     if (!prefix)
  207.         prefix = '';
  208.  
  209.     var str = '<table summary="main menu" class="' + prefix + 'Menu" cellspacing="' + nodeProperties.mainSpacing + '">';
  210.     var strSub = '';
  211.  
  212.     if (!orient)
  213.         orient = 'hbr';
  214.  
  215.     var orientStr = String (orient);
  216.     var orientSub;
  217.     var vertical;
  218.  
  219.     // draw the main menu items
  220.     if (orientStr.charAt (0) == 'h')
  221.     {
  222.         // horizontal menu
  223.         orientSub = 'v' + orientStr.substr (1, 2);
  224.         str += '<tr>';
  225.         vertical = false;
  226.     }
  227.     else
  228.     {
  229.         // vertical menu
  230.         orientSub = 'v' + orientStr.substr (1, 2);
  231.         vertical = true;
  232.     }
  233.  
  234.     var i;
  235.     var item;
  236.     var idSub;
  237.     var hasChild;
  238.  
  239.     var classStr;
  240.  
  241.     for (i = 0; i < menu.length; ++i)
  242.     {
  243.         item = menu[i];
  244.  
  245.         if (!item)
  246.             continue;
  247.  
  248.         str += vertical ? '<tr' : '<td';
  249.         str += ' class="' + prefix + 'MainItem"';
  250.  
  251.         hasChild = (item.length > 5);
  252.         idSub = hasChild ? cmNewID () : null;
  253.  
  254.         str += cmActionItem (item, prefix, 1, idSub, orient, nodeProperties) + '>';
  255.  
  256.         if (item == _cmSplit)
  257.         {
  258.             str += cmSplitItem (prefix, 1, vertical);
  259.             str += vertical? '</tr>' : '</td>';
  260.             continue;
  261.         }
  262.  
  263.         if (item[0] == _cmNoAction)
  264.         {
  265.             str += cmNoActionItem (item, prefix);
  266.             str += vertical? '</tr>' : '</td>';
  267.             continue;
  268.         }
  269.  
  270.         classStr = prefix + 'Main' + (hasChild ? 'Folder' : 'Item');
  271.  
  272.         str += vertical ? '<td' : '<span';
  273.         str += ' class="' + classStr + 'Left">';
  274.  
  275.         str += (item[0] == null) ? (hasChild ? nodeProperties.mainFolderLeft : nodeProperties.mainItemLeft)
  276.                      : item[0];
  277.         str += vertical ? '</td>' : '</span>';
  278.  
  279.         str += vertical ? '<td' : '<span';
  280.         str += ' class="' + classStr + 'Text">';
  281.         str += item[1];
  282.  
  283.         str += vertical ? '</td>' : '</span>';
  284.  
  285.         str += vertical ? '<td' : '<span';
  286.         str += ' class="' + classStr + 'Right">';
  287.  
  288.         str += hasChild ? nodeProperties.mainFolderRight : nodeProperties.mainItemRight;
  289.  
  290.         str += vertical ? '</td>' : '</span>';
  291.  
  292.         str += vertical ? '</tr>' : '</td>';
  293.  
  294.         if (hasChild)
  295.             strSub += cmDrawSubMenu (item, prefix, idSub, orientSub, nodeProperties);
  296.     }
  297.     if (!vertical)
  298.         str += '</tr>';
  299.     str += '</table>' + strSub;
  300.     obj.innerHTML = str;
  301.     //document.write ("<xmp>" + str + "</xmp>");
  302. }
  303.  
  304. //////////////////////////////////////////////////////////////////////
  305. //
  306. // Mouse Event Handling Functions
  307. //
  308. //////////////////////////////////////////////////////////////////////
  309.  
  310. //
  311. // action should be taken for mouse moving in to the menu item
  312. //
  313. function cmItemMouseOver (obj, prefix, isMain, idSub, orient, index)
  314. {
  315.     clearTimeout (_cmTimeOut);
  316.  
  317.     if (!obj.cmPrefix)
  318.     {
  319.         obj.cmPrefix = prefix;
  320.         obj.cmIsMain = isMain;
  321.     }
  322.  
  323.     var thisMenu = cmGetThisMenu (obj, prefix);
  324.  
  325.     // insert obj into cmItems if cmItems doesn't have obj
  326.     if (!thisMenu.cmItems)
  327.         thisMenu.cmItems = new Array ();
  328.     var i;
  329.     for (i = 0; i < thisMenu.cmItems.length; ++i)
  330.     {
  331.         if (thisMenu.cmItems[i] == obj)
  332.             break;
  333.     }
  334.     if (i == thisMenu.cmItems.length)
  335.     {
  336.         //thisMenu.cmItems.push (obj);
  337.         thisMenu.cmItems[i] = obj;
  338.     }
  339.  
  340.     // hide the previous submenu that is not this branch
  341.     if (_cmCurrentItem)
  342.     {
  343.         // occationally, we get this case when user
  344.         // move the mouse slowly to the border
  345.         if (_cmCurrentItem == thisMenu)
  346.             return;
  347.  
  348.         var thatPrefix = _cmCurrentItem.cmPrefix;
  349.         var thatMenu = cmGetThisMenu (_cmCurrentItem, thatPrefix);
  350.         if (thatMenu != thisMenu.cmParentMenu)
  351.         {
  352.             if (_cmCurrentItem.cmIsMain)
  353.                 _cmCurrentItem.className = thatPrefix + 'MainItem';
  354.             else
  355.                 _cmCurrentItem.className = thatPrefix + 'MenuItem';
  356.             if (thatMenu.id != idSub)
  357.                 cmHideMenu (thatMenu, thisMenu, thatPrefix);
  358.         }
  359.     }
  360.  
  361.     // okay, set the current menu to this obj
  362.     _cmCurrentItem = obj;
  363.  
  364.     // just in case, reset all items in this menu to MenuItem
  365.     cmResetMenu (thisMenu, prefix);
  366.  
  367.     var item = _cmItemList[index];
  368.     var isDefaultItem = cmIsDefaultItem (item);
  369.  
  370.     if (isDefaultItem)
  371.     {
  372.         if (isMain)
  373.             obj.className = prefix + 'MainItemHover';
  374.         else
  375.             obj.className = prefix + 'MenuItemHover';
  376.     }
  377.  
  378.     if (idSub)
  379.     {
  380.         var subMenu = cmGetObject (idSub);
  381.         cmShowSubMenu (obj, prefix, subMenu, orient);
  382.     }
  383.  
  384.     var descript = '';
  385.     if (item.length > 4)
  386.         descript = (item[4] != null) ? item[4] : (item[2] ? item[2] : descript);
  387.     else if (item.length > 2)
  388.         descript = (item[2] ? item[2] : descript);
  389.  
  390.     window.defaultStatus = descript;
  391. }
  392.  
  393. //
  394. // action should be taken for mouse moving out of the menu item
  395. //
  396. function cmItemMouseOut (obj, delayTime)
  397. {
  398.     if (!delayTime)
  399.         delayTime = _cmNodeProperties.delay;
  400.     _cmTimeOut = window.setTimeout ('cmHideMenuTime ()', delayTime);
  401.     window.defaultStatus = '';
  402. }
  403.  
  404. //
  405. // action should be taken for mouse button down at a menu item
  406. //
  407. function cmItemMouseDown (obj, index)
  408. {
  409.     if (cmIsDefaultItem (_cmItemList[index]))
  410.     {
  411.         if (obj.cmIsMain)
  412.             obj.className = obj.cmPrefix + 'MainItemActive';
  413.         else
  414.             obj.className = obj.cmPrefix + 'MenuItemActive';
  415.     }
  416. }
  417.  
  418. //
  419. // action should be taken for mouse button up at a menu item
  420. //
  421. function cmItemMouseUp (obj, index)
  422. {
  423.     var item = _cmItemList[index];
  424.  
  425.     var link = null, target = '_self';
  426.  
  427.     if (item.length > 2)
  428.         link = item[2];
  429.     if (item.length > 3)
  430.         target = item[3] ? item[3] : target;
  431.  
  432.     if (link != null)
  433.     {
  434.         window.open (link, target);
  435.     }
  436.  
  437.     var prefix = obj.cmPrefix;
  438.     var thisMenu = cmGetThisMenu (obj, prefix);
  439.  
  440.     var hasChild = (item.length > 5);
  441.     if (!hasChild)
  442.     {
  443.         if (cmIsDefaultItem (item))
  444.         {
  445.             if (obj.cmIsMain)
  446.                 obj.className = prefix + 'MainItem';
  447.             else
  448.                 obj.className = prefix + 'MenuItem';
  449.         }
  450.         cmHideMenu (thisMenu, null, prefix);
  451.     }
  452.     else
  453.     {
  454.         if (cmIsDefaultItem (item))
  455.         {
  456.             if (obj.cmIsMain)
  457.                 obj.className = prefix + 'MainItemHover';
  458.             else
  459.                 obj.className = prefix + 'MenuItemHover';
  460.         }
  461.     }
  462. }
  463.  
  464. //////////////////////////////////////////////////////////////////////
  465. //
  466. // Mouse Event Support Utility Functions
  467. //
  468. //////////////////////////////////////////////////////////////////////
  469.  
  470. //
  471. // move submenu to the appropriate location
  472. //
  473. // @param    obj    the menu item that opens up the subMenu
  474. //        subMenu    the sub menu to be shown
  475. //        orient    the orientation of the subMenu
  476. //
  477. function cmMoveSubMenu (obj, subMenu, orient)
  478. {
  479.     var mode = String (orient);
  480.     var p = subMenu.offsetParent;
  481.     if (mode.charAt (0) == 'h')
  482.     {
  483.         if (mode.charAt (1) == 'b')
  484.             subMenu.style.top = (cmGetYAt (obj, p) + obj.offsetHeight) + 'px';
  485.         else
  486.             subMenu.style.top = (cmGetYAt (obj, p) - subMenu.offsetHeight) + 'px';
  487.         if (mode.charAt (2) == 'r')
  488.             subMenu.style.left = (cmGetXAt (obj, p)) + 'px';
  489.         else
  490.             subMenu.style.left = (cmGetXAt (obj, p) + obj.offsetWidth - subMenu.offsetWidth) + 'px';
  491.     }
  492.     else
  493.     {
  494.         if (mode.charAt (2) == 'r')
  495.             subMenu.style.left = (cmGetXAt (obj, p) + obj.offsetWidth) + 'px';
  496.         else
  497.             subMenu.style.left = (cmGetXAt (obj, p) - subMenu.offsetWidth) + 'px';
  498.         if (mode.charAt (1) == 'b')
  499.             subMenu.style.top = (cmGetYAt (obj, p)) + 'px';
  500.         else
  501.             subMenu.style.top = (cmGetYAt (obj, p) + obj.offsetHeight - subMenu.offsetHeight) + 'px';
  502.         //alert (subMenu.style.top + ', ' + cmGetY (obj) + ', ' + obj.offsetHeight);
  503.     }
  504. }
  505.  
  506. //
  507. // show the subMenu w/ specified orientation
  508. // also move it to the correct coordinates
  509. //
  510. // @param    obj    the menu item that opens up the subMenu
  511. //        subMenu    the sub menu to be shown
  512. //        orient    the orientation of the subMenu
  513. //
  514. function cmShowSubMenu (obj, prefix, subMenu, orient)
  515. {
  516.     if (!subMenu.cmParentMenu)
  517.     {
  518.         // establish the tree w/ back edge
  519.         var thisMenu = cmGetThisMenu (obj, prefix);
  520.         subMenu.cmParentMenu = thisMenu;
  521.         if (!thisMenu.cmSubMenu)
  522.             thisMenu.cmSubMenu = new Array ();
  523.         //thisMenu.cmSubMenu.push (subMenu);
  524.         thisMenu.cmSubMenu[thisMenu.cmSubMenu.length] = subMenu;
  525.     }
  526.  
  527.     // position the sub menu
  528.     cmMoveSubMenu (obj, subMenu, orient);
  529.     subMenu.style.visibility = 'visible';
  530.  
  531.     //
  532.     // On IE, controls such as SELECT, OBJECT, IFRAME (before 5.5)
  533.     // are window based controls.  So, if sub menu and these controls
  534.     // overlap, sub menu would be hid behind them.  Thus, one needs to
  535.     // turn the visibility of these controls off when the
  536.     // sub menu is showing, and turn their visibility back on
  537.     //
  538.     if (document.all)    // it is IE
  539.     {
  540.         subMenu.cmOverlap = new Array ();
  541.  
  542.         cmHideControl ("SELECT", subMenu);
  543.         cmHideControl ("OBJECT", subMenu);
  544.         cmHideControl ("IFRAME", subMenu);
  545.     }
  546. }
  547.  
  548. //
  549. // reset all the menu items to class MenuItem in thisMenu
  550. //
  551. function cmResetMenu (thisMenu, prefix)
  552. {
  553.     if (thisMenu.cmItems)
  554.     {
  555.         var i;
  556.         var str;
  557.         var items = thisMenu.cmItems;
  558.         for (i = 0; i < items.length; ++i)
  559.         {
  560.             if (items[i].cmIsMain)
  561.                 str = prefix + 'MainItem';
  562.             else
  563.                 str = prefix + 'MenuItem';
  564.             if (items[i].className != str)
  565.                 items[i].className = str;
  566.         }
  567.     }
  568. }
  569.  
  570. //
  571. // called by the timer to hide the menu
  572. //
  573. function cmHideMenuTime ()
  574. {
  575.     if (_cmCurrentItem)
  576.     {
  577.         var prefix = _cmCurrentItem.cmPrefix;
  578.         cmHideMenu (cmGetThisMenu (_cmCurrentItem, prefix), null, prefix);
  579.     }
  580. }
  581.  
  582. //
  583. // hide thisMenu, children of thisMenu, as well as the ancestor
  584. // of thisMenu until currentMenu is encountered.  currentMenu
  585. // will not be hidden
  586. //
  587. function cmHideMenu (thisMenu, currentMenu, prefix)
  588. {
  589.     var str = prefix + 'SubMenu';
  590.  
  591.     // hide the down stream menus
  592.     if (thisMenu.cmSubMenu)
  593.     {
  594.         var i;
  595.         for (i = 0; i < thisMenu.cmSubMenu.length; ++i)
  596.         {
  597.             cmHideSubMenu (thisMenu.cmSubMenu[i], prefix);
  598.         }
  599.     }
  600.  
  601.     // hide the upstream menus
  602.     while (thisMenu && thisMenu != currentMenu)
  603.     {
  604.         cmResetMenu (thisMenu, prefix);
  605.         if (thisMenu.className == str)
  606.         {
  607.             thisMenu.style.visibility = 'hidden';
  608.             cmShowControl (thisMenu);
  609.         }
  610.         else
  611.             break;
  612.         thisMenu = cmGetThisMenu (thisMenu.cmParentMenu, prefix);
  613.     }
  614. }
  615.  
  616. //
  617. // hide thisMenu as well as its sub menus if thisMenu is not
  618. // already hidden
  619. //
  620. function cmHideSubMenu (thisMenu, prefix)
  621. {
  622.     if (thisMenu.style.visibility == 'hidden')
  623.         return;
  624.     if (thisMenu.cmSubMenu)
  625.     {
  626.         var i;
  627.         for (i = 0; i < thisMenu.cmSubMenu.length; ++i)
  628.         {
  629.             cmHideSubMenu (thisMenu.cmSubMenu[i], prefix);
  630.         }
  631.     }
  632.     cmResetMenu (thisMenu, prefix);
  633.     thisMenu.style.visibility = 'hidden';
  634.     cmShowControl (thisMenu);
  635. }
  636.  
  637. //
  638. // hide a control such as IFRAME
  639. //
  640. function cmHideControl (tagName, subMenu)
  641. {
  642.     var x = cmGetX (subMenu);
  643.     var y = cmGetY (subMenu);
  644.     var w = subMenu.offsetWidth;
  645.     var h = subMenu.offsetHeight;
  646.  
  647.     var i;
  648.     
  649.     for (i = 0; i < document.all.tags(tagName).length; ++i)
  650.     {
  651.         var obj = document.all.tags(tagName)[i];
  652.         if (!obj || !obj.offsetParent || obj.type=='iframe')
  653.             continue;
  654.  
  655.         // check if the object and the subMenu overlap
  656.  
  657.         var ox = cmGetX (obj);
  658.         var oy = cmGetY (obj);
  659.         var ow = obj.offsetWidth;
  660.         var oh = obj.offsetHeight;
  661.  
  662.         if (ox > (x + w) || (ox + ow) < x)
  663.             continue;
  664.         if (oy > (y + h) || (oy + oh) < y)
  665.             continue;
  666.         //subMenu.cmOverlap.push (obj);
  667.         subMenu.cmOverlap[subMenu.cmOverlap.length] = obj;
  668.         obj.style.visibility = "hidden";
  669.     }
  670. }
  671.  
  672. //
  673. // show the control hidden by the subMenu
  674. //
  675. function cmShowControl (subMenu)
  676. {
  677.     if (subMenu.cmOverlap)
  678.     {
  679.         var i;
  680.         for (i = 0; i < subMenu.cmOverlap.length; ++i)
  681.             subMenu.cmOverlap[i].style.visibility = "";
  682.     }
  683.     subMenu.cmOverlap = null;
  684. }
  685.  
  686. //
  687. // returns the main menu or the submenu table where this obj (menu item)
  688. // is in
  689. //
  690. function cmGetThisMenu (obj, prefix)
  691. {
  692.     var str1 = prefix + 'SubMenu';
  693.     var str2 = prefix + 'Menu';
  694.     while (obj)
  695.     {
  696.         if (obj.className == str1 || obj.className == str2)
  697.             return obj;
  698.         obj = obj.parentNode;
  699.     }
  700.     return null;
  701. }
  702.  
  703. //
  704. // return true if this item is handled using default handlers
  705. //
  706. function cmIsDefaultItem (item)
  707. {
  708.     if (item == _cmSplit || item[0] == _cmNoAction)
  709.         return false;
  710.     return true;
  711. }
  712.  
  713. //
  714. // returns the object baring the id
  715. //
  716. function cmGetObject (id)
  717. {
  718.     if (document.all)
  719.         return document.all[id];
  720.     return document.getElementById (id);
  721. }
  722.  
  723. //
  724. // functions that obtain the coordinates of an HTML element
  725. //
  726. function cmGetX (obj)
  727. {
  728.     var x = 0;
  729.  
  730.     do
  731.     {
  732.         x += obj.offsetLeft;
  733.         obj = obj.offsetParent;
  734.     }
  735.     while (obj);
  736.     return x;
  737. }
  738.  
  739. function cmGetXAt (obj, elm)
  740. {
  741.     var x = 0;
  742.  
  743.     while (obj && obj != elm)
  744.     {
  745.         x += obj.offsetLeft;
  746.         obj = obj.offsetParent;
  747.     }
  748.     return x;
  749. }
  750.  
  751. function cmGetY (obj)
  752. {
  753.     var y = 0;
  754.     do
  755.     {
  756.         y += obj.offsetTop;
  757.         obj = obj.offsetParent;
  758.     }
  759.     while (obj);
  760.     return y;
  761. }
  762.  
  763. function cmGetYAt (obj, elm)
  764. {
  765.     var y = 0;
  766.  
  767.     while (obj && obj != elm)
  768.     {
  769.         y += obj.offsetTop;
  770.         obj = obj.offsetParent;
  771.     }
  772.     return y;
  773. }
  774.  
  775. //
  776. // debug function, ignore :)
  777. //
  778. function cmGetProperties (obj)
  779. {
  780.     if (obj == undefined)
  781.         return 'undefined';
  782.     if (obj == null)
  783.         return 'null';
  784.  
  785.     var msg = obj + ':\n';
  786.     var i;
  787.     for (i in obj)
  788.         msg += i + ' = ' + obj[i] + '; ';
  789.     return msg;
  790. }
  791.  
  792. /* JSCookMenu v1.23    1. correct a position bug when the container is positioned.
  793.                       thanks to Andre <anders@netspace.net.au> for narrowing down
  794.                       the problem.
  795. */
  796. /* JSCookMenu v1.22    1. change Array.push (obj) call to Array[length] = obj.
  797.                        Suggestion from Dick van der Kaaden <dick@netrex.nl> to
  798.                        make the script compatible with IE 5.0
  799.                     2. Changed theme files a little to add z-index: 100 for sub
  800.                        menus.  This change is necessary for Netscape to avoid
  801.                        a display problem.
  802.                     3. some changes to the DOM structure to make this menu working
  803.                        on Netscape 6.0 (tested).  The main reason is that NN6 does
  804.                        not do absolute positioning with tables.  Therefore an extra
  805.                        div layer must be put around the table.
  806. */
  807. /* JSCookMenu v1.21    1. fixed a bug that didn't add 'px' as part of coordinates.
  808.                        JSCookMenu should be XHTML validator friendly now.
  809.                     2. removed unnecessary display attribute and corresponding
  810.                        theme entry to fix a problem that Netscape sometimes
  811.                        render Office theme incorrectly
  812. */
  813. /* JSCookMenu v1.2.    1. fix the problem of showing status in Netscape
  814.                     2. changed the handler parameters a bit to allow
  815.                        string literals to be passed to javascript based
  816.                        links
  817.                     3. having null in target field would cause the link
  818.                        to be opened in the current window, but this behavior
  819.                        could change in the future releases
  820. */
  821. /* JSCookMenu v1.1.        added ability to hide controls in IE to show submenus properly */
  822. /* JSCookMenu v1.01.    cmDraw generates XHTML code */
  823. /* JSCookMenu v1.0.        (c) Copyright 2002 by Heng Yuan */
  824.