//==============================================================================
//
//     Copyright (c) 2006, by Deluxe-Menu.com
//     Version 2.0xxx
//     http://deluxe-menu.com
//
//==============================================================================
//  -------- 1.00 ----------
//  1. new parameter: moveColor=color
//  2. pathPrefix_link, pathPrefix_img
//  3. new parameters: smMovable=0/1;
//  4. new parameters: closeBtn, closeBtnW, closeBtnH
//  5. new parameters: smHidePause, smShowPause
//  6. new parameters:
//       smOrientation = 0/1;      (instead of old orientation)
//       smViewType    = 0/1/2/3;  (0 - top-to-bottom, 1 - bottom-to-top, 2 - top-to-bottom + right-to-left, 3 - bottom-to-top + right-to-left)
//  7. new parameters for CSS mode: cssItem, cssItemText, cssSubmenu (instead of old cssClass)
//  8. new parameter: smColumns (instead of old columnPerSubmenu)
//  9. multi-row support: add '$' symbol before item text
// 10. new parameter:  noWrap (item text wordwrap)
// 11. new parameters: floatableX=0/1, floatableY=0/1.
// 12. new parameters: smWidth, smHeight.
// 13. new parameter:  dmWorkPath = 'path/'; Used to determine where scripts are pleaced relatively to the html page.
// 14. var dm_writeAll = 1; -- write all submenus in all browsers -- to avoid problems with DOCTYPE XHTML in IE (submenus don't appear)
// ------- 1.11 -----------
// 15. var useHTTPS = 0/1; - when using the menuon https:// website
// 16. bug fixes for path prefixes and others.
// ------- 1.12 -----------
// 17. search engine friendly:
//              - add <div id="dm_links"><a href="">...</a>...</div> after dmenu.js call.
//              - the script creates new style div#dm_links for this div
// 18. automatically adding menu .js files (dmenu_key.js, dmenu_dyn.js):
//              - new parameter: var dynamic = 1;
// 19. the menu automatically determines a protocol. There is no need to use var useHTTPS.
// ------- 1.14 -----------
// 20. fix for multiple menus on page: menu hides all submenus of other menus it's active
// 21. fix for submenus scrolling: incorrect scrolling when page was scrolled by user
// 22. fix for showByClick mode: items were not highlighted when mouse over.
// -------- 1.171 ------------
// 23. fix for user's document.onmousemove event: userMoveEvent(e)
// 24. fix for onLoad event for MZ/FF
// 25. fix in dmenu_add.js/dm_popup() with (x,y) coords
// 26. fix with automatic modules inclusion (dmWorkPath)
// 27. delay before hide submenu when mousemove another item (new function: dm_waitForSubmenu())
// 28. fix positioning issue when menu is placed within <div> with absolute/relative position
// 29. enable/disable submenus smart scrolling: var smSmartScroll = 0/1; Default is 1.
// 30. additional value for var statusString: var statusString = 'tip'
// 31. new parameter: var itemAlignTop = left/center/right - alignment for top-menu items
// 32. new parameter: var smHideOnClick = 0/1 - close all submenus on item click. Default is 1.
// 33. keystrokes support for multiple menus on page: Ctrl+F2 - activate keystrokes, then Ctrl+F2 - switch to next menu
// {34}. images caching: var dmCacheImages = 0/1. Default is 0. CANCELED!!!
// 35. fix for CSS-based menu in popup-mode
// 36. fix for cross-frame mode in dmenu_add.js: submenus aren't saved in IE into subframe with <!DOCTYPE> tag
// 37. keystrokes support for cross-frame mode. Set in subframe: <body onkeydown='return parent.frames[mainFrame_Index].dm_ext_keystrokes(event, window)'>
// 38. activation key setup for keystrokes support: var dm_actKey = 113; //default
// 39. dm_focus = 0/1 - show focus selection for selected item in keystrokes mode.
// -------- 2.0 ------------
// 40. fix in dmenu_dyn.js: dm_ext_addItem(), set new TD's id
// 41. fixed issue with right-to-left languages: <HTML dir=rtl>.
//     new parameter: dmTRL=1; and need to set exact value in 'px' for var menuWidth.
// 42. fix for Opera: positioning issue when menu is placed within <div> with absolute/relative position
// 43. some code modifications
// 44. AJAX SUPPORT:
//          var dmAJAX = 0/1; - enable AJAX support
//          var dmAJAXCount = 0..n; - submenus count (used for writting additional <div>s where submenus will be written)
//     Loads submenus data from server when required.
//     Syntax for menuItems: [text, link, icon1, icon2, tip, target, itStyle, smStyle, jsFileName]
//     Where jsFileName - Javascript .js filename on server, contains var menuItems = [] for submenu.
//     Supported browsers: NS7+, Opera 8+, PC IE 5+, Firefox, Mozilla
// 45. fix for IE7, copyright nag issue
// 46. dm_writeAll=0 by default. Works fine now with any <!DOCTYPE>.
// 47. re-tested on all PC browsers, fixed some issues with Opera 7-, Netscape 6
// 48. new parameter: dmObjectsCheck = 0/1 - checks for objects intersection on the page
// 49. dmenu_add.js isn't loaded by default now. It's used when:
//       1. objects intersection feature is enabled: dmObjectsCheck = 0/1
//       2. floatable feature is enabled
//       3. movable feature is enabled
//       4. cross-frame mode is enabled
// 50. fixed issue with first-level submenus in cross-frame mode (these submenus didn't cover objects)
// 51. changes in dmenu_dyn.js
// 52. some code was moved from dmenu.js into dmenu_add.js, dmenu_add.js fragmentation (dmenu_popup.js, dmenu_cf.js)
// 53. fixes for cross-frame mode
// 54. code optimization for cross-frame mode
// 55. modifications for keystrokes. Submenus aren't hidden after user mouseover above the submenu that was opened using keystrokes
// 56. fix for keystrokes mode with popup menu on the page
// 57. new dynamic functions: dm_ext_createSubmenu(), dm_ext_deleteSubmenu()
// 58. new parameter: var transDuration2 - delay of transitional effect (in ms) on submenu's hiding
// 59. new parameter: var menuHeight = "100px"; - height of top menu
// 60. fixed issues for submenus positioning on MAC IE & Safari, and also Opera 9
// 61. fixed issue with right scrollbar for big submenus in MAC Safari
// 62. var itemPadding is a string parameter now, can accept multiple values ("10px 15px 10px 5px"). Must contain 'px' units ("5px").
// 63. modifications in dmenu_dyn.js: dm_ext_addItem(), dm_ext_deleteItem(), dm_ext_changeItemVisibility().
// 64. The new method of making image-based menus: if item text is empty "", item uses icon fields as item images.
// 65. new parameter: var menuBackRepeat = "repeat-x"/"repeat-y"/"no-repeat";
// 66. tested on Netscape 4, fixed some issues. It works! :)
// 67. modifications of popup mode: menu checks document bounds
// 68. new parameter: var separatorPadding = "10px 10px 5px 3px";
// 69. submenus transparency support for NS6+/FF/MZ
// -------- 2.0x ------------
// 70. fixed issue with classes overriding (for example, class for TD{} doesn't override menu's classes)
// -------- 2.0xxx ------------
// 71. new parameter: topSmartScroll = 0/1; - scroll top-level menu like submenus (works if var menuWidth isn't empty)
// 72. fix for AJAX:
//            - loaded submenu isn't shown if mouse cursor was moved out of parent item;
//            - if the submenu must be shown when another one is in a loading process already,
//              the current loading proccess is aborted and required submenu starts loading.
// 73. fix for dynamic menu: menu didn't delete (hide) item's TR element
// 74. fix for popup menu: top-level menu didn't cover select-like elements
// 75. fix for crossframe mode when subframe for submenus contains another full menu


Array.prototype.ln=function() {return this.length}
function pI(s) {return parseInt(s)}
with (String)
{
  prototype.sb=function(s,e) {return this.substring(s,e)}
  prototype.io=function(s)   {return this.indexOf(s)}
  prototype.ln=function()    {return this.length}
}


var b_IE    = 0;
var b_IE5   = 0;
var b_IE6   = 0;
var b_IEPC  = 0;
var b_IEMAC = 0;
var b_NS    = 0;
var b_NS4   = 0;
var b_NS6   = 0;
var b_OP    = 0;
var b_MZ    = 0;
var b_DOM   = 0;
var b_MAC   = 0;
var b_IEComp= 0;
var b_SAF   = 0;
var b_VER   = 0;
var d_o     = document;
var _un     = 'undefined';
var dmZOrder = 1000;

dm_getBrowser();


//##############################################################################
var addedScripts = [];
if (typeof(dmWorkPath)==_un) var dmWorkPath = '';

function dm_addScript(fname)
// Includes additional script files
{
  for (var i=0; i<addedScripts.ln(); i++) if (addedScripts[i]==fname) return;
  addedScripts[addedScripts.ln()] = fname;
  d_o.write('<SCR'+'IPT SRC="'+dmWorkPath+fname+'.js" type="text/javascript"></SCR'+'IPT>');
}

// Load module for Netscape 4
if (b_NS4) dm_addScript('dmenu4');

// Create style for special <DIV id="dmlinks"> where menu links are placed (for search engines)
// Create also defult style for TD elements to avoid overriding by TD{} class
d_o.write('<style>#dmlinks{display:none} .dmDef{background:transparent;border:none}</style>');

//##############################################################################


var dUnits = 'px';                               // units
var docElement;                                  // document object variable depending on <!DOCTYPE> tag. Used as document.body object.
var fdocElement;                                 // document object variable in a frame depending on <!DOCTYPE> tag. Used as document.body object of a frame.
var userLoadFunc = null;                         // variable to remember user's onLoad event
var assignFloating = 0;                          // one or more of menus on the page is floatable
var assignMoving   = 0;                          // one or more of menus on the page is movable
var dm_menu   = [];                              // main menu object
var isLoaded  = 0;                               // menus data are loaded and parsed
var regexp_m  = /dm([0-9]+)m([0-9]+)/;           // mask to extact indexes from menu id
var regexp_i  = /dm([0-9]+)m([0-9]+)i([0-9]+)/;  // mask to extact indexes from item id


var curMenu =
{
  ind  : 0,    	        // index of current processed menu
  smInd: 0,         	  // index of current processed submenus
  itInd: 0,   		      // index of current processed item
  smVar: null,          // current submenu variable
  itVar: null           // current item variable
}


var moveRec =
{
  isMoving   : 0,       // if the menu is in a moving process
  prepareSmID: '',
  cX      : 0,          // capturing X coord
  cY      : 0,          // capturing Y coord
  smObj   : 0,          // current movable submenu object
  smVar   : null        // current movable submenu variable
}


var toggleRec =
{
   pressedSelf    : 0,   // script sets pressed item, not user
   changeStyleOnly: 0    // change item style only
}


var keyMode =
{
  isEnabled : 0,             // keystokes are activated
  menu      : null,          // menu object
  rsmVar    : null,          // root submenu variable
  ritVar    : null,          // root items variable
  smVar     : null,          // submenu variable
  itVar     : null           // item variable
}


// Cross-frame mode ############################################################
var cfEnabled      = 0;
var cfFsetID       = '';
var cfMFrameInd    = 0;
var cfSFrameInd    = 1;
var cfOrientation  = 0;
var cfType         = 1;  // values: 1 - standard cross-fame mode
                         //         3 - standard cross-fame mode + submenus resize main frame when subframe contains the page from alien domain (PC IE only)
var oldFsetSizes;        // variable to remember frame dimensions in frameset (rows/cols attributes of frameset; when cfType=3)
//##############################################################################


function dm_getBrowser()
// Detects client's browser
{
  var nv = navigator;
  var a  = nv.userAgent;
  var n  = nv.appName;
  var v  = nv.appVersion;
  var ns = 'Netscape';
  var gk = 'Gecko';
  var pf = function(r) {return parseFloat(r)}
  b_MAC  = v.io('Mac') >= 0;
  b_DOM  = d_o.getElementById?1:0;

  // Safari detect
  if ((pI(nv.productSub)>=20020000) && (nv.vendor.io('Apple Computer') != -1) && (nv.product==gk))
  {
      b_NS  = 1;
      b_VER = 6;
      b_SAF = 1;
      return;
  }
  
  // Konqueror detect
  if (n.toLowerCase()=='konqueror')
  {
      b_MZ  = 1;
      b_VER = 1.6;
      return;
  }

  if (a.io('Opera')>=0)
  {
      b_OP     = 1;
      b_VER    = pf(a.sb(a.io('Opera')+6, a.ln()));
      b_IEComp = (b_VER>=7);
		  return;
  }

  if (n.toLowerCase()=='netscape')
  {
      if (a.io('rv:')!=-1 && a.io(gk)!=-1 && a.io(ns)==-1)
      {
          b_MZ  = 1;
          b_VER = pf(a.sb(a.io('rv:')+3, a.ln()));
      }
      else
      {
          b_NS = 1;
          if (a.io(gk) != -1 && a.io(ns)>a.io(gk))
          {
    	        var d = (a.io(ns+'6')>-1) ? 10 : (a.io(ns)>-1) ? 9 : 0;
              b_VER = pf(a.sb(a.io(ns) + d, a.ln()))
          }
          else
              b_VER = pf(v);

          b_NS4 = b_VER<6;
          b_NS6 = !b_NS4 && b_VER<7;
      }
      return;
  }

  if (d_o.all?1:0)
  {
      b_IE     = 1;
      b_VER    = pf(a.sb(a.io('MSIE ')+5, a.ln()));
      b_IE5    = b_VER>=5;
      b_IE6    = b_VER>=6;
      b_IEComp = 1;
      b_IEPC   = !b_MAC;
      b_IEMAC  = b_MAC;
  }
  //alert("b_IE = "+b_IE+"\n"+"b_OP = "+b_OP+"\n"+"b_MZ = "+b_MZ+"\n"+"b_NS = "+b_NS+"\n"+"b_DOM = "+b_DOM+"\n"+"b_MAC = "+b_MAC+"\n"+"b_VER = "+b_VER);	
}


//##############################################################################
// GLOBAL PARAMS FUNCTIONS
//##############################################################################

dm_preDefineGlobalParams();

function dm_gE(id) { return d_o.getElementById(id) }

function dm_preDefineGlobalParams()
// Pre-defines global menu variables
{
  topSmartScroll   = 0;
  separatorPadding = '0px';
  dmCacheImages    = 0;
  
  useHTTPS    = location.protocol=='https:' ? 1 : 0;
  dm_writeAll = 0;
  popupMode = 0;
}


function dm_checkGlobalParams()
// Sets default global menu parameters
{
  // Opera 7+ always creates submenus on the fly.
  // It allows to set correct submenus position when the menu is placed within object with absolute/relative position
  // Opera 7- always writes submenus html during page loading, doesn't work on the fly.
  if (b_OP) dm_writeAll = (b_VER>=7) ? 0 : 1;

  with (curMenu)
  {
      smInd=0;
      itInd=0;
      smVar=null;
      itVar=null;
  }

  // Menu will be contextual
  if (popupMode) absolutePos = 1;
  
  // Menu will be floatable
  // Disable floatable feature for Opera 5: links don't work if floatable mode is enabled
  if (floatable && !(b_OP && b_VER<6)) assignFloating = 1;

  // Menu will be movable
  if (movable) assignMoving = 1;
  
  // Correct padding value
  if (typeof(itemPadding)!='string') itemPadding += 'px';
}


//##############################################################################
// OBJECT & VAR FUNCTIONS
//##############################################################################

function dm_getObjectWH(o)
// Returns width & height of object
{
  var op=(b_OP && b_VER<6);
  var w = op ? o.style.pixelWidth  : b_NS4 ? o.clip.width  : o.offsetWidth;
  var h = op ? o.style.pixelHeight : b_NS4 ? o.clip.height : o.offsetHeight;
  return [w,h];
}


function dm_getObjectSize(o)
// Returns object dimensions and position [x, y, width, height]
{
  if (!o) return [0,0,0,0];
  var l=0, t=0, wh = dm_getObjectWH(o), d=0, a='absolute', r='relative';

  while (o)
  {
      l += pI(b_NS4?o.pageX:o.offsetLeft);
      t += pI(b_NS4?o.pageY:o.offsetTop);
      o = o.offsetParent;

      // Detect if the menu is placed within object with relative/absolute position
      // and this object doesn't belong to the menu.
      // Not used in Opera, because it renders submenus in different way
      if (!b_OP && o && o.style && (o.style.position==a || o.style.position==r) && o.id.sb(0,2)!='dm')
      {
          if (b_IEPC && o.style.position==r && docElement.leftMargin) l -= pI(docElement.leftMargin); // IE calculates body's left margin in some cases, so subtrack it
          d = 1;            // remember that the menu is placed within object with relative/absolute position
          break;
      }
  }

  return [l, t, wh[0], wh[1], d];
}


function dm_getObjectByID(id)
// Returns object by ID
{
  if (!id) return null;
  if (b_NS4) return dm_getObjectByID4(id);
  if (b_IE && b_VER<5) return d_o.all[id];

  var itVar = dm_getVarByID(id);
  var menu  = dm_menu[itVar.mInd];

  // Cross-frame mode is enabled and submenus are placed within subframe
  return ((itVar.smInd!=0 && menu.isCrossFrame && cfType!=3) ? dm_getObjectInFrame(id, menu.cfSFInd) : dm_gE(id));
}


function dm_getVarByID(id)
// Returns variable by object ID (for menu elements only, ID should be written in the following format: dm([0-9]+)m([0-9]+)i([0-9]))
{
  var ex;
  // Do NOT use io() prototype instead of indexOf() - doesn't work in Opera 7, cross-frame mode.
  if (id.indexOf('i')>0)
  {
      ex=regexp_i.exec(id);
      return dm_menu[pI(ex[1])].m[pI(ex[2])].i[pI(ex[3])];
  }
  else
  {
      ex = regexp_m.exec(id);
      return dm_menu[pI(ex[1])].m[pI(ex[2])];
  }
}



//##############################################################################
// DOCUMENT FUNCTIONS
//##############################################################################

function dm_getClientSize(menu)
// Returns document dimensions where submenus are placed: [scrollX, scrollY, width, height]
{
    var l=0,t=0,w=0,h=0, cf=(menu && menu.isCrossFrame && cfType==1), cond=(b_NS || b_MZ || b_OP);
    var frm = cf ? parent.frames[menu.cfSFInd] : 0;

    if (cond)
    {
        var doc = cf ? frm.window : window;
        // Do NOT combine the following expressions into with() statement, it doesn't work on Opera 7-
        l = doc.pageXOffset;
        t = doc.pageYOffset;
        w = doc.innerWidth;
        h = doc.innerHeight;	
    }
    else
    {
        var doc = cf ? dm_getDocElement(frm.document) : docElement;
        with (doc)
        {
            l = scrollLeft;
            t = scrollTop;
            w = clientWidth;
            h = clientHeight;				
        }
    }
    return [l,t,w,h];
}


function dm_setOnLoad()
// Assigns onLoad event for document
{
  if (window.attachEvent) window.attachEvent('onload', dm_onload);            // attach menu event if browser supports window.attachEvent() method
  else
  {
      userLoadFunc = (typeof(onload)=='function') ? onload : null;            // remember user's onLoad event
      onload = dm_onload;                                                     // set menu's onLoad event
  }
}


function dm_getDocElement(docObj)
// Detects body element according to <!DOCTYPE> specification
{
  return (docObj.compatMode=='CSS1Compat' && !b_MZ) ? docObj.documentElement : docObj.body;
}


function dm_onload()
// Function is assigned to document's onLoad event
{
  docElement = dm_getDocElement(d_o);                                         // detect body element according to <!DOCTYPE> specification

  // Enable movable/floatable features
  if (assignFloating) window.setInterval('dm_scrollWindow()', 20);            // enable floatable feature
  if (assignMoving) dm_assignMoveEvent();                                     // assign mousemove event to document (will be used for movable menus)

  isLoaded = 1;	                                                              // menu is loaded
  if (userLoadFunc) userLoadFunc();                                           // execute user's onLoad event

  // Enable keyboard support
  if (keystrokes && !b_NS4 && !(b_OP && b_VER<7)) d_o.onkeydown = function (event) { return dm_ext_keystrokes(event) }

  // Cache menu images
  //for (var i=0; i<dm_menu.ln(); i++) if (dm_menu[i].cacheImages) dm_ext_cacheImages(i);

  // Check if debug mode is enabled. Otherwise disable error reporting
  //if (typeof(dm_debug)==_un) onerror = dm_error;
}


// Processes window.onError() method
//function dm_error(eMessage, url, line) { return true }


//##############################################################################
// CROSS-FRAME FUNCTIONS
//##############################################################################

function dm_initFrame(fsetID, mFrameInd, sFrameInd, orient)
// Initializes cross-frame mode
{
  if (b_NS4) return dm_init4();                               // no cross-frame mode for Netscape 4, create standard menu

  if ((b_OP && b_VER<7) || (b_IE && b_VER<5)) cfEnabled = 0;  // crossframe mode is always turn off for these browsers
  else
  {
      cfEnabled     = 1;
      cfFsetID      = fsetID;
      cfMFrameInd   = mFrameInd;
      cfSFrameInd   = sFrameInd;
      cfOrientation = orient;
  }
  cfType = 1;
  dm_init();
}


//##############################################################################
// PREFIX FUNCTIONS
//##############################################################################

var fixPrefixes = ['javascript:', 'mailto:', "http://", "https://", "ftp://"];

function dm_canPrefix(url)
// Detects if path prefix can be added
{
  for (var i=0; i<fixPrefixes.ln(); i++)
      if (url.io(fixPrefixes[i])==0) return false;
  return true;
}


function dm_setPathPrefix(paths, prefix)
// Sets prefix for specified array of paths or string
{
  function dm_addPrefix(pathStr)
  // Adds prefix to specified path string
  {
      return pathStr ? ((dm_canPrefix(pathStr) ? prefix : '') + pathStr) : '';
  }
  

  if (typeof(paths)=='string') return dm_addPrefix(paths);
  else
  {
      var p=[];
      for (var i=0; i<paths.ln(); i++) p[i] = paths[i] ? dm_addPrefix(paths[i]) : '';
      return p;
  }
}


//##############################################################################
// PARAMETERS & INDIVIDUAL STYLES FUNCTIONS
//##############################################################################

function dm_getParam(param, defParam)
// Checks specified parameter value or returns default value
{
  return (typeof(param)!=_un && param) ? param : defParam;
}


function dm_getStyleParam(pName, sInd, sType, defValue, isIndividual)
// Returns individual style value from styles array for item/submenu
{
  if (sInd==-1 || ''+sInd+''=='' || !isIndividual) return defValue;
  var sp = sType ? itemStyles[sInd] : menuStyles[sInd];                       // assign items or submenus styles variable

  // Search for parameter name
  for (var i=0; i<=sp.ln(); i++)
      if (i==sp.ln() || typeof(sp[i])==_un) return defValue;
      else
          if (sp[i].io(pName)>=0) break;
          

  var val = sp[i].split('=')[1];                                              // get parameters' value
  if (val.io(',')>=0) val = val.split(',');                                   // if values is array -> create the array of values

  return val;
}


function dm_getSubmenuStyle(menu, sInd, is)
// Returns specified submenu style
{
  if (typeof(sInd)==_un) return menu.standardSmStyle;

  var pPrefix = !menu ? pathPrefix_img : menu.pPrefix_img;
  var bI = is ? dm_getStyleParam('menuBackImage', sInd, 0, '', is) : 0;

  var st = {
      backColor  : dm_getStyleParam('menuBackColor',  sInd, 0, menuBackColor, is),
      backRepeat : dm_getStyleParam('menuBackRepeat', sInd, 0, menuBackRepeat, is),

      backImage  : bI ? dm_setPathPrefix(bI, pPrefix) : dm_setPathPrefix(menuBackImage, pPrefix),

      columnsCnt : pI(dm_getStyleParam('smColumns', sInd, 0, smColumns, is)),
      // Border
      brdWidth   : dm_getStyleParam('menuBorderWidth',  sInd, 0, menuBorderWidth, is),
      brdStyle   : dm_getStyleParam('menuBorderStyle',  sInd, 0, menuBorderStyle, is),
      brdColor   : dm_getStyleParam('menuBorderColor',  sInd, 0, menuBorderColor, is),
      // Items
      itSpacing  : dm_getStyleParam('itemSpacing',      sInd, 0, itemSpacing, is),
      itPadding  : dm_getStyleParam('itemPadding',      sInd, 0, itemPadding, is),
      // CSS
      cssClass   : dm_getStyleParam('CSS',              sInd, 0, cssSubmenu, is),
      // Size
      smW        : dm_getStyleParam('smWidth',          sInd, 0, smWidth, is),
      smH        : dm_getStyleParam('smHeight',         sInd, 0, smHeight, is)
  };

  return st;
}


function dm_getItemStyle(menu, sInd, is)
// Returns specified item style
{
  if (typeof(sInd)==_un) return menu.standardItStyle;
  
  var pPrefix = !menu ? pathPrefix_img : menu.pPrefix_img;

  var aM = is ? dm_getStyleParam('arrowImageMain', sInd, 1, '', is) : 0;
  var aS = is ? dm_getStyleParam('arrowImageSub',  sInd, 1, '', is) : 0;
  var bI = is ? dm_getStyleParam('itemBackImage',  sInd, 1, '', is) : 0;

  var st = {
      itWidth    : dm_getStyleParam('itemWidth',        sInd, 1, '100%', is),
      backColor  : dm_getStyleParam('itemBackColor',    sInd, 1, itemBackColor, is),
      // Border
      brdWidth   : dm_getStyleParam('itemBorderWidth',  sInd, 1, itemBorderWidth, is),
      brdStyle   : dm_getStyleParam('itemBorderStyle',  sInd, 1, itemBorderStyle, is),
      brdColor   : dm_getStyleParam('itemBorderColor',  sInd, 1, itemBorderColor, is),
      // Font
      fntColor   : dm_getStyleParam('fontColor',        sInd, 1, fontColor, is),
      fntStyle   : dm_getStyleParam('fontStyle',        sInd, 1, fontStyle, is),
      fntDecor   : dm_getStyleParam('fontDecoration',   sInd, 1, fontDecoration, is),
      // Images
      arrowMain  : aM ? dm_setPathPrefix(aM, pPrefix) : dm_setPathPrefix(arrowImageMain, pPrefix),
      arrowSub   : aS ? dm_setPathPrefix(aS, pPrefix) : dm_setPathPrefix(arrowImageSub,  pPrefix),
      backImage  : bI ? dm_setPathPrefix(bI, pPrefix) : dm_setPathPrefix(itemBackImage,  pPrefix),
      // CSS
      cssClass     : dm_getStyleParam('CSS',     sInd, 1, cssItem, is),
      cssClassText : dm_getStyleParam('CSSText', sInd, 1, cssItemText, is)
  };

  return st;
}

//##############################################################################
// MENU PARAMETERS FUNCTIONS
//##############################################################################

function dm_createMenuParams(curInd)
// Creates menu parameters
{
  dm_menu[curInd] = {
     	m            : [],                     // menu arrays
     	ind          : curInd,                 // index of the menu
     	id           : 'dm'+curInd,            // HTML id
     	hideAllTimer : null,                   // timer to hide all submenus
     	absPos       : absolutePos,
     	floating     : floatable,
     	floatingX    : floatableX,
     	floatingY    : floatableY,
     	iterations   : floatIterations,
      // Toggle mode
      toggleMode   : pressedItem,
     	curPressedSm : 0,
     	curPressedIt : (pressedItem>=0) ? pressedItem : -1,
      // Cross-frame mode
     	isCrossFrame : cfEnabled,
     	cfMFInd      : cfMFrameInd,
     	cfSFInd      : cfSFrameInd,
     	cfOrient     : cfOrientation,          // 0 - top-to-bottom, 1 - left-to-right; 2 - bottom-to-top; 3 - right-to-left.
     	cfFSID       : cfFsetID,
     	// Standard styles
     	standardSmStyle : dm_getSubmenuStyle(null, 0, 0),
     	standardItStyle : dm_getItemStyle(null, 0, 0),
     	// CSS mode
     	isCSSMode    : cssStyle,
      // Common
     	isPopup        : popupMode,            // context menu mode
      saveNavigation : saveNavigationPath,   // show highlighted items during a menu nvigation
      smView         : smViewType,           // 0 - top-to-bottom, 1 - bottom-to-top, 2 - top-to-bottom + right-to-left, 3 - bottom-to-top + right-to-left
      smShowClick    : showByClick,          // show submenus by mouse click only
      smShowClicked  : 0,

      isVisible  : (popupMode)?0:1,          // menu is visible
      isDisabled : 0,                        // menu is disabled
      
      // Disabled item params
      fntColorDisabled : fontColorDisabled,

      smAlign    : subMenuAlign,
      smHideClick: smHideOnClick,
      cacheImages: dmCacheImages,
      
      sepImg : separatorImage,
      sepW   : separatorWidth,
      sepH   : separatorHeight,
      sepVImg: separatorVImage,
      sepVW  : separatorVWidth,
      sepVH  : separatorVHeight,
      sepPadding : separatorPadding,
      
      pPrefix_img: pathPrefix_img
  };
  
  return dm_menu[curInd];
}


function dm_createSubmenuParams(parentM, parentSm, parentIt, styleInd)
// Creates submenu parameters
{
  var lvl       = parentSm ? parentSm.level+1 : 0;
  var menu      = parentM;
  curMenu.ind   = parentM.ind;
  curMenu.smInd = menu.m.ln();
  var ii=curMenu.smInd;

  menu.m[ii] = {
      i            : [],                                       // array of items
      mInd         : curMenu.ind,                              // index of parent menu
      ind          : ii,                                       // index of the submenu
      id           : 'dm'+curMenu.ind+'m'+ii,                  // ID of the submenu object
      rootItemID   : parentIt ? parentIt.id : '',              // ID of parent item
      shownChildID : '',                                       // current shown submenu ID
      showTimer    : null,                                     // timer for delay the appearance of submenus
      level        : lvl,                                      // submenu level
      // Positioning
      left         : ii ? '-1000px' : posX,
      top          : ii ? '0px'     : posY,
      // Moving
      moving       : ii ? smMovable : movable,
      isMoved      : 0,
      // Offsets
      offx         : (lvl>1)?DX:topDX,                         // x offset
      offy         : (lvl>1)?DY:topDY,                         // y offset
      // Appearance
      smStyle      : dm_getSubmenuStyle(menu, styleInd, 1),
      isHoriz      : ii ? smOrientation : isHorizontal,
      mainWidth    : ii ? 'auto' : dm_getParam(menuWidth, ((b_NS && b_VER<7) ? 'auto' : '1px')),
      mainHeight   : menuHeight,
      // Effects
      opacity      : !ii ? 100 : transparency,                 // submenu opacity
      effect       : !ii ? 0 : (transition ? transition : 1),  // transition type
      duration     : transition ? transDuration  : 0,          // transition delay (on show)
      duration2    : transition ? transDuration2 : 0,          // transition delay (on hide)
      // Shadow
  	  shadowColor  : shadowColor,
  	  shadowLen    : (b_IEPC && b_IE5) ? shadowLen : 0,
      smHTML       : '',                                       // HTML code of the submenu
      // For submenu scrolling
      sX       : 0,
      sY       : 0,
      sEnabled : (!ii && topSmartScroll) ? 1 : 0,
      sObj     : null,
      // Objects' intersection
      hidObjs  : []
  };
  curMenu.smVar = menu.m[ii];
}


function dm_getStatusText(str, itText, itLink, itTip) {                       // Returns item status text
  return (!str || str=='link') ? itLink : (str=='text') ? itText : (str=='tip') ? itTip : str;
}


function dm_getItemTarget(targetVal) {                                        // Returns item target
  return (!targetVal && itemTarget) ? itemTarget : targetVal;
}


function dm_getItemLink(linkVal) {                                            // Returns item link
  return dm_setPathPrefix(dm_getParam(linkVal, ''), pathPrefix_link);
}


function dm_createItemParams(parentM, parentSm, itInd, iParams, statusStr)
// Creates item parameters
{
  var smVar   = parentM.m[parentSm.ind];
  var iText   = iParams[0];
  var iLink   = dm_getItemLink(iParams[1]);
  var iTarget = dm_getItemTarget(dm_getParam(iParams[5], ''));
  var iAlign  = (parentSm.level==0) ? itemAlignTop : itemAlign; //subMenuAlign : itemAlign;
  var iTip    = dm_getParam(iParams[4],'');
  var iAJAX   = dm_getParam(iParams[8],'');

  var onNextRow = 0;
  if (iText.charAt(0)=='$')
  {
      onNextRow = 1;
      iText = iText.substr(1, iText.ln()-1);
  }

	smVar.i[itInd] = {
      mInd    : parentM.ind,
      smInd   : parentSm.ind,
      ind     : itInd,
      id      : 'dm'+parentM.ind+'m'+parentSm.ind+'i'+itInd,
      childID : iAJAX ? '_' : '',                                             // id of child submenu, set '_' if AJAX is enabled
      // Common                                                               // set childID to '_' if the item will load submenu data from server
      text    : iText,
      link    : iLink,
      target  : iTarget,
      tip     : iTip,
      sstr    : dm_getStatusText(statusStr, iText, iLink, iTip),
      align   : iAlign,
      valign  : 'middle',
      cursor  : itemCursor,
      // Appearance
      itStyle  : dm_getItemStyle(parentM, iParams[6], 1),
      icon     : dm_setPathPrefix([dm_getParam(iParams[2],''),dm_getParam(iParams[3],'')], parentM.pPrefix_img),
      iconW    : (parentSm.level)?iconWidth:iconTopWidth,
      iconH    : (parentSm.level)?iconHeight:iconTopHeight,
      icState  : 0,
      arrowW   : arrowWidth,
      arrowH   : arrowHeight,
      // Additional
      isDisabled   : (iTarget=='_')?1:0,                          // target='_' - item is disabled
      isPressed    : 0,                                           // item is pressed (user clicked on the item)
      isHighlighted: 0,                                           // to save a navigation path
      isVisible    : 1,
      isDeleted    : 0,
      nextRow      : onNextRow,
      
      // .js filename, AJAX: submenu data are placed within another .js file on server
      ajax : iAJAX
  };

  curMenu.itInd = itInd;
  curMenu.itVar = smVar.i[itInd];
  curMenu.smVar = parentSm;
}


//##############################################################################
// HTML FUNCTIONS
//##############################################################################

// Additional DX filters
var dm_filters = ['Blinds','Checkerboard','GradientWipe','Inset','Iris','Pixelate','RadialWipe','RandomBars',
                  'RandomDissolve','Slide','Spiral','Stretch','Strips','Wheel','Zigzag'];


function dm_getAdditionalFilterHTML(fInd, fDur) {
  return (b_VER<5.5) ? '' : 'progid:DXImageTransform.Microsoft.'+dm_filters[fInd-25]+'('+transOptions+',duration='+fDur+') ';
}

function dm_getFilterHTML(smVar)
{
  var sf = '';
  with (smVar)
      if (b_IE5 && b_IEPC)
      {
          sf = 'filter:';
          if (effect)
          {
              var dur = duration/1000;
              if (effect==24) sf += "blendTrans(Duration="+dur+") ";
              else
                  sf += (effect<24) ? "revealTrans(Transition="+effect+",Duration="+dur+") " : dm_getAdditionalFilterHTML(effect, dur);
          }
          if (opacity!=100) sf += "alpha(opacity="+opacity+") ";
          if (shadowLen)    sf += "shadow(color="+shadowColor+",direction=135,strength="+shadowLen+")";
      }
      else
          if ((b_NS || b_MZ) && opacity!=100) sf = '-moz-opacity:'+opacity/100;
	
  return sf;
}


function dm_openDivSimple(id, styleText, events) {
  return '<DIV id="'+id+'" '+events+' style="'+styleText+'">';
}

function dm_closeDiv() {
  return '</DIV>';
}


function dm_openTableWithClass(id, clN, spac, padd, events) {
   return '<Table id="'+id+'" '+events+' class="'+clN+'" border=0 cellspacing='+spac+' cellpadding='+padd+'>';
}

function dm_openTableSimple(id, spac, padd, styleText, events, add) {
   return '<Table id="'+id+'" '+events+' cellspacing='+spac+' cellpadding='+padd+' '+add+' style="'+styleText+'" border=0>';
}

function dm_closeTable() {
  return '</Table>';
}

function dm_openTr(id)
{
  return '<tr id="'+id+'">';
}

function dm_closeTr() {
  return '</tr>';
}

function dm_openTdSimple(id, styleText, add)
{
  return '<td id="'+id+'" '+add+' style="'+styleText+'">';
}

function dm_closeTd() {
  return '</td>';
}


function dm_openImg(id, url, w, h, add) {
  return '<img id="'+id+'" src="'+url+'" '+(w ? 'width='+w : '') + (h ? ' height='+h : '') +' '+add+' border=0>';
}


function dm_holdSubmenu(smID)
{
  with (moveRec)
      if (smID)
      {
          prepareSmID = smID;
          smVar = dm_getVarByID(smID);
          clearTimeout(dm_menu[smVar.mInd].hideAllTimer);
      }
      else
      {
          if (smVar)
              with (dm_menu[smVar.mInd])
              {
                  clearTimeout(hideAllTimer);
                  hideAllTimer = setTimeout("dm_hideMenu('"+m[0].shownChildID+"');window.status='';", smHidePause);
              }
          prepareSmID = '';
      }
}


function dm_openSeparator(menu, img, w, h) {
  return dm_openImg('', dm_setPathPrefix(img, menu.pPrefix_img), (w?w:"100%"), (h?h:"1"), '');
}


function dm_openItemArrow(itVar)
{
  var s='', smVar=dm_menu[itVar.mInd].m[itVar.smInd];
  
  with (itVar)
  {
      var arrImg = smInd ? itStyle.arrowSub[0] : itStyle.arrowMain[0];
      if (arrImg)
          s = dm_openTdSimple(itVar.id+'tdA', 'padding:'+smVar.smStyle.itPadding, 'class="dmDef"')+
              dm_openImg(id+'arr', arrImg, arrowW, arrowH, '')+
              dm_closeTd();
  }
  return s;
}


function dm_scrollSubmenu(e, smID)
{
  var smVar = dm_getVarByID(smID);
  if (!smVar.sEnabled || smVar.shownChildID) return;

  if (!smVar.sObj)
    smVar.sObj = dm_gE(smID);

  var smWH = dm_getObjectSize(smVar.sObj);
  var ex, ey;
  
  if (b_IEComp)
  {
      var cs = dm_getClientSize(dm_menu[smVar.mInd]);                         // get page scrolling values
      ex = e.x+cs[0];
      ey = e.y+cs[1];
  }
  else
  {
      ex = e.pageX;
      ey = e.pageY;
  }

  var dx = smWH[2]*0.1;
  var dy = smWH[3]*0.1;
  var px = (ex - smWH[0]-dx)/(smWH[2]-dx*2);
  var py = (ey - smWH[1]-dy)/(smWH[3]-dy*2);
  with (smVar.sObj)
  {
      if (b_OP) style.top = smVar.sY - py*(smWH[3]*0.5) + 'px';
      else
      {
          scrollLeft = px*(scrollWidth  - smWH[2]);
          scrollTop  = py*(scrollHeight - smWH[3]);
      }
  }
}


// Movable menu HTML -----------------------------------------------------------
function dm_addCloseBtn(menu, smVar){
  return dm_openImg('', dm_setPathPrefix(closeBtn, menu.pPrefix_img), closeBtnW, closeBtnH, 'title="Close the sumbenu" onClick="dm_deMoveSubmenu(\''+smVar.id+'\')" style="cursor:'+((b_IE && b_VER<6)?'hand':'pointer')+';"')
}


function dm_openMoveSpacer(menu, smVar)
{
  if (dm_menu[smVar.mInd].isCrossFrame) return '';
  return '<td id="'+smVar.id+'m" NOWRAP align=right style="width:'+(smVar.isHoriz?moveWidth+dUnits:'100%')+';height:'+moveHeight+dUnits+';cursor:'+moveCursor+';padding:0px;"'+
              'bgcolor='+moveColor+' background="'+dm_setPathPrefix(moveImage, menu.pPrefix_img)+'" '+
              'onMouseDown="dm_startMoving(event,\''+smVar.id+'\')" onMouseUp="dm_stopMoving()" onMouseOver="dm_holdSubmenu(\''+smVar.id+'\')" onMouseOut="dm_holdSubmenu(\'\')">'+

              (!smVar.ind ? dm_openImg('', blankImage, 1, moveHeight, '') : dm_addCloseBtn(menu, smVar)) +

              (smVar.isHoriz?'<br>'+dm_openImg('','',moveWidth,'1',''):'')+
          '</td>'+(smVar.isHoriz?'':'</TR><TR>');
}


function dm_deMoveSubmenu(smID)
{
  with (dm_getVarByID(smID))
  {
      isMoved = 0;
      moveRec.prepareSmID = '';
      moveRec.smVar = null;
  }
  dm_hideMenu(smID);
}
// End of movable menu ---------------------------------------------------------


//##############################################################################
// BASIC FUNCTIONS
//##############################################################################


function dm_getItemLevel(itInd)
// Returns level of item and removes '|' symbols from item text
{
  var lvl=0;
  while (menuItems[itInd][0].charAt(lvl)=='|') lvl++;                                       // nesting of item
  if (lvl>0) menuItems[itInd][0] = menuItems[itInd][0].sb(lvl, menuItems[itInd][0].ln());   // remove ||| from item text
  return lvl;
}


function dm_parseItemsData()
// Parses menu items: creates submenu and item objects
{
    var pl=-1;                                        // previous item level
    var cl=0;                                         // current item level

    for (var i=0; (i<menuItems.ln() && typeof(menuItems[i])!=_un); i++)
    {
        cl = dm_getItemLevel(i);

        if (pl<cl)                                                            // Create submenu
            with (curMenu)
            {
                dm_createSubmenuParams(dm_menu[ind],        // menu object
                                       smVar,               // parent submenu
                                       itVar,               // parent item
                                       menuItems[i][7]);    // style index

                itInd = 0;
                itVar = null;
            }

        if (pl>cl)                                                            // Return to previous submenu level
            with (curMenu)
            {
                while (dm_menu[ind].m[smInd].level>cl) smInd--;
                smVar = dm_menu[ind].m[smInd];
            }
        pl = cl;

        curMenu.itInd = curMenu.smVar.i.ln();                                 // set current item index
        dm_createItemParams(dm_menu[curMenu.ind],    // menu object
                            curMenu.smVar,           // parent submenu
                            curMenu.itInd,           // current item index
                            menuItems[i],            // item params
                            statusString);           // status string text

    }

    // Link submenus with root items
    var rooti;
    with (curMenu)
        for (var i=1; i<dm_menu[ind].m.ln(); i++)                             // run submenus excluding top menu
        {
        	  rooti = dm_getVarByID(dm_menu[ind].m[i].rootItemID);
            rooti.childID = rooti.ajax ? '_' : rooti.childID = dm_menu[ind].m[i].id;  // assign child submenu
        }
}


function dm_createPopupMenu()
{
 // increase items level
 for (var i=0; i<menuItems.ln() && typeof(menuItems[i])!=_un; i++) menuItems[i][0] = '|' + menuItems[i][0];

 // add new root item
 var newItem = [['']];
 menuItems = newItem.concat(menuItems);
}


function dm_init()
// Creates the menu
{
    if (b_NS4) return dm_init4();
    dm_checkGlobalParams();                                                   // check and correct users' parameters


    //#### Install additional .js modules ######################################
    // Install module for cross-frame support
    if (cfEnabled) dm_addScript('dmenu_cf', 0);


    // Install module for floatable/movable menu support
    if (dmObjectsCheck || assignFloating || assignMoving)
    {
        dm_addScript('dmenu_add', 0);
        dmObjectsCheck = 1;    // Enable objects intersection check, because these functions are placed within the same dmenu_add.js file
    }

    // Install the module for popup-menu support
    if (popupMode)
    {
        dm_addScript('dmenu_popup', 0);
        dm_createPopupMenu();              // modify items for the popup mode
    }


    // Install the module for keystrokes support
    if (keystrokes) dm_addScript('dmenu_key', 0);


    // Install the module for external functions
    if (dynamic) dm_addScript('dmenu_dyn', 0);


    // Install the module for AJAX support
    if (dmAJAX) dm_addScript('dmenu_ajax', 0);


    // Install the module for images caching
    //if (dmCacheImages) dm_addScript('dmenu_cache', 0);


    // Check if other menu engine from another frame writes submenus into the same subframe, and set current menu index.
    // Otherwise set additional variable in subframe/window (current menu index).
    var wnd = cfEnabled ? parent.frames[cfSFrameInd] : window;
    if (typeof(wnd.dm_crossMenuInd)==_un)
        wnd.dm_crossMenuInd = curMenu.ind;
    else
    {
        curMenu.ind = wnd.dm_crossMenuInd+1;
        wnd.dm_crossMenuInd++;
    }


    // If it's the first menu on the page -> attach new onload event
    if (!curMenu.ind) dm_setOnLoad();

    var menu = dm_createMenuParams(curMenu.ind);                              // create common params of the menu
    dm_parseItemsData();                                                      // parse menuItems
    dm_createMenu(menu);                                                      // create the menu
    

    // Create separate focus <div> element here for each new menu.
    // It allows to place focus div correctly when the menu is placed within relative/absolute positioned object
    d_o.write('<div id="dmFDIV'+menu.ind+'" style="z-index:999999;border:dotted 1px #000000;display:none;position:absolute;font:normal 1px;">&nbsp;</div>');


    // Show IFRAME under top-menu
    if (!menu.isCrossFrame && menu.absPos) dm_showIFrame(dm_gE(menu.m[0].id));


    // Set default pressed item ------------------------------------------------
    if (menu.toggleMode>=0)                                                   // toggle mode is on -> highlight top-menu item
        if (cfType==1 || cfType==3)
        {
            toggleRec.pressedSelf = 1;                                        // menu calls dm_ext_setPressedItem() itself, not user
            dm_ext_setPressedItem(menu.ind, menu.curPressedSm, menu.curPressedIt, 0);
        }

    curMenu.ind++;
    curMenu.curPressedIt = -1;

}//end dm_init()


//===regregregregregregregregreg===
var dmNag=0;
var _dn_t='';
function dm_setNag()
{
  //var s='<div id="dmgk" style="visibility:hidden;padding:3px;font:bold 11px Arial;width:1px;background-color:#F5C4BE;position:absolute;"><a href="http://deluxe-menu.com"> ';
    var s='=fht!ke?#flej !qu{mg< wkrkckmku{;jhfego9qcefhlf82ry9gmov;`nne"03qz!Csk`n:uhfuj;3qz:``ajesmtle/bmmms8"D4A5@D9qmrkuknl;ccqnntvd9#<=c!jsgg?#juvq8.-egmwyg,odlt,bml ?"';
  //tend="</a></div>";
    tend='=-`<=-ekw<';

    var k=k_='jgx',copyOk=1;
    for (var i=1; i<90 && eval('typeof('+dm_decodeString(k)+')!="'+_un+'"'); i++)
    {
        if (lIiiJ(eval(dm_decodeString('mmbcuknl/jnqu')), eval('typeof('+dm_decodeString(k)+')!="'+_un+'"?'+dm_decodeString(k)+':""')))
        {
            copyOk = checkCopyrights();                                         // check copyrights in <noscript> tag
            i=0;
            break;
        }
        k = dm_decodeString(k_)+i;
    }

    if (!copyOk)
    {
        //s+="Incorrect&nbsp;Copyright";
        _dn_t = s + 'Hlbmspdau$o`rr:Anrxpheiv' + tend;
        return 1;
    }

    //s+="Incorrect&nbsp;Key";
    _dn_t = i ? s + 'Hlbmspdau$o`rr:Id{' + tend : '';
    return 2;
}


function lIiiJ(l1,lI)
{
   l1 = l1.toLowerCase();
   var Il = (lI.sb(0,lI.io('b'))-111)/2-11;
   if (Il<0) return 0;

   var I1 = lI.sb(lI.io('b')+1,lI.io('e'));
   var ll = 0;
   if (l1.ln()>=Il && (lI.io('t'+'g')!=-1 || lI.io('i'+'d')!=-1))
   {
       for (var j=0; j<l1.ln()-Il+1; j++)
       {
           ll=0;
           for(var i = j; i<Il+j; i++) ll += l1.charCodeAt(i);
           if(I1==ll+11) return 1;
       }
   }
   return 0;
}


function dm_decodeString(s)
{
  var ds='';
  for (var i=0; i<s.ln(); i++) ds += String.fromCharCode(s.charCodeAt(i)^(1+i%2))
  return ds;
}


var nos     = 'e]n,fguGmglgovr@xV`eOclg) OMRASKQV#+'   // d_o.getElementsByTagName("NOSCRIPT")
var ahref   = '=c!jsgg?';                              // <a href=
var homeurl = 'ivur;-.fdntzd/lgow/ano';                // http://deluxe-menu.com

function checkCopyrights()
{
  var s = '', ok = 0, ns = eval(dm_decodeString(nos));
  for (var i=0; i<ns.length && !ok; i++)
  {
      var nsHTML = ns[i].innerHTML.toLowerCase();
      if (nsHTML.io(dm_decodeString(ahref))>=0) ok = (nsHTML.sb(8,32).io(dm_decodeString(homeurl))>=0);
  }
  return ok;
}

function dm_showNag()
{
                      //if (d_o.all.dmgk) d_o.all.dmgk.style.visibility='visible'
  eval(dm_decodeString('hd!*e]n,`nm,eofi("e]n,`nm,eofi/qu{mg/thqh`hnhvx?&thqh`mg&'));
  dmNag=0;
}
//===regregregregregregregregreg===

function dm_checkCursor(cur)
{
  return (b_IE && b_VER<6)  ?  (cur=='pointer')?'hand':cur  :  (cur=='hand')?'pointer':cur;
}


function dm_getAddDivHTML(mInd, smInd)
// Creates HTML code for additional <DIV> object
{
  return '<div id="dmD'+mInd+'m'+smInd+'"></div>';
}


function dm_createMenu(menu)
{
    //var menu = dm_menu[ind];
    var s='',ss='';
    var pos    = menu.absPos    ? 'absolute' : 'static';
    var vis    = menu.isVisible ? 'visible'  : 'hidden';

    //===regregregregregregregregreg===
    if (b_IEPC && b_VER<7 && !dmNag) dmNag=dm_setNag();
    //===regregregregregregregregreg===

    // Create HTML code
    for (var smInd=0; smInd<menu.m.ln(); smInd++)                             // run submenus
    {
        s += dm_createSubmenuHTML(menu,
                                  menu.m[smInd],
                                  pos,
                                  vis,
                                  dmZOrder,
                                  0);

        // Always write HTML for top menu
        if (!smInd || dm_writeAll) d_o.write(s);

        if (!dm_writeAll) break;

        s   = '';
        pos = 'absolute';
        vis = 'hidden';
    }// for (submenus)


    // Create additional divs.
    // They will be used for creating submenus on the fly.
    // Without such divs Netscape 6 creates submenu in incorrect places with artifacts,
    //         other browsers (such as IE, Firefox) resets overflow coords of scrollable submenus if body.innerHTML is used.
    s = '';
    if (!dm_writeAll || dmAJAX)
    {
        var cnt = dmAJAX ? dmAJAXCount+1 : menu.m.ln();
        for (var i=1; i<cnt; i++) s += dm_getAddDivHTML(menu.ind, i);
        d_o.write(s);
    }
}


function dm_createSubmenuHTML(menu, smVar, pos, vis, zOrder, onFly)
// Creates submenu HTML code
{
  var s = '';
  var smInd = smVar.ind;

  var colInd = -1;
  var addRow = 0;
  var frame  = (smInd && menu.isCrossFrame && cfType==1) ? 'parent.frames['+menu.cfMFInd+'].' : '';
  var noScroll = ((b_NS && b_VER<7) || b_OP || b_IEMAC || !smSmartScroll);
  var NS6 = (b_NS && b_VER<7);
  var smBack;


  // Don't use display property for submenus, excluding Opera 6- (it can't change display on the fly)
  var disp = (smVar.ind && !(b_OP && b_VER<7)) ? 'display:none;' : '';


  // Create IFRAME for submenu.
  // Used on non-SSL (HTTPS) websites and on PC IE6+ only
  if (!useHTTPS && b_IEPC && b_IE6)
      s = '<iframe id="'+smVar.id+'frame" frameBorder=no dm=1 style="visibility:hidden;position:absolute;filter:alpha(opacity=0)"></iframe>';


  with (smVar)
  with (smStyle)
  {
      smBack = 'background-color:'+backColor+';'+(backImage? 'background-image:url('+backImage+');background-repeat:'+backRepeat+';' : '');

      var h   = smInd ? (smH ? 'height:'+smH+';' : '') : '';
      var w   = 'width:' + (smInd ? (smW ? smW : '1px') : mainWidth) + ';';
      var of  = (!ind && topSmartScroll) ? 'overflow:hidden;' : '';
      var flt = (!smInd && shadowTop) || smInd;

      var divStyle = h+w+'position:'+(pos?pos:'absolute')+';left:'+left+';'+'top:'+top+';'+
                     (NS6 ? smBack : '')+disp+';visibility:'+(vis?vis:'hidden')+';z-index:'+zOrder+';'+
                     (flt ? dm_getFilterHTML(smVar)+';' : '') + of;

      if (shadowLen && flt) divStyle += 'padding:0px '+shadowLen+' '+shadowLen+' 0px 0px;';
      if (b_NS && b_VER<7) divStyle += 'background-color:'+backColor+';';
  }


  // Write submenu DIV: for NS6 & OP5-6 & IEMAC-> create another events - submenus use scroll-bars for scrolling (NS6) and moved on mousemove event (OP5-6)
  s += dm_openDivSimple(smVar.id, divStyle,
                        (noScroll?'onMouseOver="'+frame+'dm_holdSubmenu(\''+smVar.id+'\')" onMouseOut="'+frame+'dm_holdSubmenu(\'\')"':'onMouseMove="'+frame+'dm_scrollSubmenu(event,\''+smVar.id+'\')"'));



  // Create submenu table ------------------------------------------------
  if (menu.isCSSMode) s += dm_openTableWithClass(smVar.id+'tbl', smVar.smStyle.cssClass, smVar.smStyle.itSpacing, 0, '');
  else
      with (smVar.smStyle)
      {
          var tblStyle = 'padding:0px;width:100%;'+(!NS6 ? smBack : '')+
                         'border-style:'+brdStyle+';border-width:'+brdWidth+dUnits+';border-color:'+brdColor; // do not collapse border parameters within 'border:' one. In other case border can't accept multiple colors.
          s += dm_openTableSimple(smVar.id+'tbl', smVar.smStyle.itSpacing, 0, tblStyle, '', '');
      }


  // Create move spacer --------------------------------------------------
  if (smVar.moving) s += dm_openMoveSpacer(menu, smVar);


  var ss, disp;
  colInd = -1;
  addRow = 1;

  // RUN SUBMENU ITEMS ===================================================
  for (var iInd=0; iInd<smVar.i.ln(); iInd++)
  {
      // It's necessary to define this additional string variable ss
      // because IE has low speed during loading of big menus
      ss = '';
      var itVar = smVar.i[iInd];

      // Create columns --------------------------------------------------
      if (smVar.smStyle.columnsCnt>1)
      {
          colInd++;
          if (colInd==smVar.smStyle.columnsCnt)
          {
              colInd = 0;
              addRow = 1;
          }
          if (colInd>0) addRow = 0;
      }


      // Create item <TR> element.
      // It's necessary assign TR's ID attribure for vertical submenus when using dynamic functions (changeItemVisibility and deleteItem).
      // If the script won't hide these <TR> elements, additional space will be created when several items will be deleted
      if (!iInd) ss += dm_openTr((smVar.isHoriz ? '' : itVar.id+'R'));
      else
          if (addRow && (!smVar.isHoriz || itVar.nextRow)) ss += dm_closeTr()+dm_openTr(itVar.id+'R');

      // Check if item was deleted before submenu object was created on the page
      disp = (itVar.isDeleted || !itVar.isVisible) ? ';display:none' : '';

      ss += dm_openTdSimple(itVar.id+'td', 'padding:0px'+disp, 'class="dmDef"') +
            dm_createItemTable(menu, smVar, itVar, frame) +
            dm_closeTd();
            
      s += ss;
  }

  s += dm_closeTr()+dm_closeTable() + dm_closeDiv();
  
  //==reg=============
  if (!menu.ind && !smVar.ind) s+=dm_decodeString(_dn_t);
  //==reg=============
  
  smVar.smHTML = s;                                                           // save HTML code for the submenu
  dmZOrder += 1;                                                              // increase z-index

  return s;
}


function dm_createItemTable(menu, smVar, itVar, frame)
// Creates item table (menu item object)
{
  var ss = '';

  // Create events ---------------------------------------------------
  var events = 'onMouseOver="'+frame+'dm_over(event,\''+itVar.id+'tbl\')" '+
               'onMouseOut="'+frame+'dm_out(event,\''+itVar.id+'tbl\')" '+
               'onClick="'+frame+'dm_click(event,\''+itVar.id+'tbl\');"';

  if (menu.isCSSMode) ss += dm_openTableWithClass(itVar.id+'tbl', itVar.itStyle.cssClass[0], 0, 0, 'title="'+itVar.tip+'" '+events);
  else
  {
      with (smVar) var h = ind ? '' : (mainHeight ? 'height:'+mainHeight+';' : '');
      
      with (itVar.itStyle)
          var tblStyle = h+'padding:0px;width:'+itWidth+';cursor:'+dm_checkCursor(itVar.cursor)+
                         ';background-color:'+backColor[0]+';' + (backImage[0]? 'background-image:url('+backImage[0]+');' : '') +
                         'border-color:'+brdColor[0]+';border-style:'+brdStyle[0]+';border-width:'+brdWidth+dUnits+';';
      ss += dm_openTableSimple(itVar.id+'tbl', 0, 0, tblStyle, events, 'title="'+itVar.tip+'"')+dm_openTr();
  }


  // Define if CSS style or standard menu parameters will be used for item
  var textStyle ='', textCSS='';
  with (itVar.itStyle)
      if (menu.isCSSMode) textCSS   = 'class="'+cssClassText[0]+'"';
      else
      {
          textCSS='class="dmDef"';
          textStyle = 'padding:'+smVar.smStyle.itPadding+';text-align:'+itVar.align+';font:'+fntStyle+';color:'+(itVar.isDisabled?menu.fntColorDisabled:fntColor[0])+'; text-decoration:'+fntDecor[0]+';';
      }


  // Create item cells =========================================================
  if (!itVar.text)                                                            // item is image-based
  {
        ss += dm_openTdSimple(itVar.id+'tdT', '', textCSS) +
              dm_openImg(itVar.id+'img', itVar.icon[0], '', '', 'alt="'+itVar.tip+'"') +
              dm_closeTd();
  }
  else
    if (itVar.text=='-')                                                      // item is separator
    {
        with (menu)
        {
            ss += dm_openTdSimple(itVar.id+'tdT', 'text-align:'+separatorAlignment+(sepPadding? ';padding:'+sepPadding : ''), textCSS);

            if (itVar.smInd>0) ss += dm_openSeparator(menu, sepImg,  sepW,  sepH);
            else               ss += dm_openSeparator(menu, sepVImg, sepVW, sepVH);

            ss += dm_closeTd();
        }
    }
    else
    {
        // Create item arrow-image -------------------------------------
       // if (menu.smView>=2 && itVar.childID) ss += dm_openItemArrow(itVar, 0);

        // Create item icon --------------------------------------------
        if (itVar.icon[0]) ss += dm_openTdSimple(itVar.id+'tdIc', 'padding:'+smVar.smStyle.itPadding, 'class="dmDef"') +
                                 dm_openImg(itVar.id+'ic', itVar.icon[0], itVar.iconW, itVar.iconH, '')+
                                 dm_closeTd();


        // Create item text --------------------------------------------
        if (itVar.text)
            ss += dm_openTdSimple(itVar.id+'tdT', 'width:100%;'+textStyle, (noWrap ? ' NOWRAP ':'')+textCSS)+
                  itVar.text+
                  dm_closeTd();


        // Create item arrow-image -------------------------------------
        if (/*menu.smView<2 && */itVar.childID) ss += dm_openItemArrow(itVar, 0);
    }

  return ss+dm_closeTr('')+dm_closeTable();
}


//##############################################################################
// ITEMS FUNCTIONS
//##############################################################################


function dm_changeItemStyle(it, over)
// Changes item appearance
{
  over = it.isHighlighted ? 1 : over;
  if (b_NS4) return dm_changeItemStyle4(it, over);
  var itObj = dm_getObjectByID(it.id+'tbl');
  if (!itObj) return;


  // Image-based item, change image only
  if (!it.text)
  {
      dm_getObjectByID(it.id+'img').src = it.icon[over];
      return;
  }

  
  with (it.itStyle)
  {
      if (dm_menu[it.mInd].isCSSMode) itObj.className = cssClass[over];
      else
      {
          var is = itObj.style;
          is.borderWidth = brdWidth+dUnits;
          if (backColor[over]) is.backgroundColor = backColor[over];
          if (brdColor[over])  is.borderColor     = brdColor[over];
          if (brdStyle[over])  is.borderStyle     = brdStyle[over];
          if (backImage[over]) is.backgroundImage = 'url('+backImage[over]+')';
      }

      var textObj=dm_getObjectByID(it.id+'tdT');

      if (textObj)
      {
          if (dm_menu[it.mInd].isCSSMode) textObj.className = cssClassText[over];
          else
              with (textObj.style)
              {
                  if (it.isDisabled) color = dm_menu[it.mInd].fntColorDisabled;
                  else
                      if (fntColor[over]) color = fntColor[over];
                  if (fntDecor[over]) textDecoration = fntDecor[over];
              }
      }
  }

  with (it)
  {
      if (icon[over])
          with (dm_getObjectByID(id+'ic'))
              if (icState!=over)                      // check if icon has necessary image src already - to avoid clock-cursor showing in IE
              {
                  src = icon[over];
                  icState = over;
              }

      var ao = dm_getObjectByID(id+'arr');
      if (ao)
      {
          var arr = smInd ? itStyle.arrowSub[over] : itStyle.arrowMain[over];
          if (childID && arr) ao.src = arr;
      }
  }
}


var _d_rID='';

function dm_over(e, id)
// Items' mouse over event
{
    var itVar = dm_getVarByID(id);
    var menu  = dm_menu[itVar.mInd];

    // Keystrokes are enabled --------------------------------------------------
    if (keystrokes)
    {
        if (keyMode.isEnabled) dm_disableKeyMode(menu.ind, 0);
        
        if (!menu.isPopup)
        {
          /*  keyMode.menu  = menu;
            keyMode.itVar = itVar;
            with (keyMode)
            {
              //  isEnabled = 1;
                rsmVar = menu.m[0];
                ritVar = rsmVar.i[0];
                smVar  = menu.m[itVar.smInd];
            }
          */
          _dmKSInd = menu.ind;
        }
    }


    // Change status bar text
    window.status = itVar.sstr;                                               // it's necessary to specify window object for Mozilla browsers

    // Check if item should change its appearance
    with (itVar)
      if (!isDisabled && text!='-' && !isPressed)
      {
          isHighlighted = 1;
          dm_changeItemStyle(itVar, 1);
      }

    // Check if user should click on item to show submenu
    if (menu.smShowClick && !menu.smShowClicked && !itVar.smInd) return;      // if the item is top-menu item and showByClick-mode is enabled -> return


    var itObj = dm_getObjectByID(id);
    if (b_IE && e.fromElement && itObj.contains(e.fromElement)) return;       // eliminate flickering

    var smVar = menu.m[itVar.smInd];
    _d_rID = smVar.rootItemID;


    //===regregregregregregregregreg===
    if (b_IEPC && b_VER<7) dm_showNag();
    //===regregregregregregregregreg===


    // Timers ------------------------------------------------------------------
    if (menu.hideAllTimer)
    {
        clearTimeout(menu.hideAllTimer);    menu.hideAllTimer = null;
    }
    if (smVar.showTimer)
    {
        clearTimeout(smVar.showTimer);      smVar.showTimer = null;
    }
    //--------------------------------------------------------------------------

    with (itVar) var showSmID = (!isDisabled && childID) ? childID : '';
    with (smVar) var hideSmID = (shownChildID && shownChildID!=itVar.childID) ? shownChildID : '';


    if (menu.isCrossFrame)
    {
        if (typeof(dmCF)==_un) return;
        if (cfType==1 && !dm_isFrameAccessible(smVar.id, menu.cfSFInd)) hideSmID = '';     // if subframe is NOT accessible -> do not hide submenu therein
    }

    smVar.showTimer = setTimeout('dm_waitForSubmenu("'+hideSmID+'","'+showSmID+'","'+itVar.id+'")', smShowPause);
}


function dm_waitForSubmenu(hideSmID, showSmID, parentID)
{
  dm_hideMenu(hideSmID);
  dm_showMenu(showSmID, parentID);
}



function dm_out(e, id)
// Items' mouse over event
{
    var itObj = dm_getObjectByID(id);
    if (b_IE && e.toElement && itObj.contains(e.toElement)) return;       // eliminate flickering

    var itVar  = dm_getVarByID(id);
    var menu   = dm_menu[itVar.mInd];


    var smRVar = menu.m[0]                                                // get the top-menu var
    var smVar  = menu.m[itVar.smInd];

    if (smRVar.shownChildID)
        if (_d_rID!=itVar.id && !(menu.smShowClick && !menu.smShowClicked))
            menu.hideAllTimer = setTimeout("dm_hideMenu('"+smRVar.shownChildID+"');window.status='';", smHidePause);

    if (smVar.showTimer)
    {
       clearTimeout(smVar.showTimer);    smVar.showTimer = null;
    }

    with (itVar)
    {
        if (isDisabled) return;
        if (text!='-' && !isPressed)
        {
            isHighlighted = 0;
            dm_changeItemStyle(itVar, 0);
        }
    }
}


function dm_click(e, id)
// Items' mouse click event
{
    var itVar = dm_getVarByID(id);
    if (itVar.isDisabled || itVar.text=='-') return;
    var menu  = dm_menu[itVar.mInd];

    // showByClick-mode is enabled ---------------------------------------------
    if (!itVar.smInd && menu.smShowClick && !menu.smShowClicked && itVar.childID)
    {
        menu.smShowClicked = 1;
        dm_over(e, id);
        return;
    }
    //--------------------------------------------------------------------------

    if (itVar.link!='' && menu.toggleMode>-2 && !itVar.isPressed) dm_ext_setPressedItem(menu.ind, itVar.smInd, itVar.ind, true);  // toggle mode is on, set pressed item
    if (itVar.isDisabled || !itVar.link) return;

    var smRVar = menu.m[0];                                       // get the top-menu var
    if (menu.shownChildID) dm_hideMenu(menu.shownChildID);


    if (menu.hideAllTimer)
    {
        clearTimeout(menu.hideAllTimer);   menu.hideAllTimer = null;
    }

    dm_openItemLink(menu, itVar);
}


function dm_openItemLink(menu, itVar)
{
  if (itVar.isDisabled || !itVar.link) return;
  with (itVar)
  {
      if (!link) return;

      // Hide all submenus on item click
      if (menu.smHideClick)
      {
          moveRec.prepareSmID = '';                       // clear captured submenu ID
          dm_hideMenu(menu.m[0].shownChildID);            // hide submenu
      }

      // execute JavaScript
 	    if (link.toLowerCase().io('javascript:')==0) eval(link.sb(11, link.ln()));
	    else
      {
          if (!target || target=='_self')
          {
              var win = (menu.isCrossFrame && (cfType==1 || cfType==3)) ? parent.frames[menu.cfSFInd] : window;
              win.location.href = link;
          }
          else
              open(link, target);
      }
  }
}



//##############################################################################
// SUBMENU FUNCTIONS
//##############################################################################

function dm_showIFrame(smObj)
// Shows IFRAME object under the submenu
{
  if (!useHTTPS && b_IEPC && b_IE6)
      with (dm_getObjectByID(smObj.id+'frame').style)
      {
          left   = smObj.style.left;
          top    = smObj.style.top;
          width  = smObj.offsetWidth  + 'px';
          height = smObj.offsetHeight + 'px';
          visibility = 'visible';
      }
}


function dm_writeSubmenuHTML(smVar)
// Check for submenu object on page and writes submenus' HTML if it doesn't exist (fast speed for IE, other browsers work with large menus well)
{
  var smObj = dm_gE(smVar.id);
  if (smObj) return smObj;
  var m=dm_menu[smVar.mInd];

  // Create submenu html code if dynamic writting in enabled or AJAX is enabled
  if (!smVar.smHTML) dm_createSubmenuHTML(m, smVar, '', '', dmZOrder, 1);

  // Use insertAdjacentHTML for Opera. It allows to place submenus correctly
  // when the menu is placed within object with relative position.
  // Note: Opera always uses dm_writeAll=0 - always creates submenus dynamically.
  // Use the same method in MAC IE, otherwise it positions submenus incorrectly
  if (b_OP || b_IEMAC) docElement.insertAdjacentHTML('beforeEnd', smVar.smHTML);
  else
      // Insert submenu code within special divs that were created earlier.
      // It allows to avoid damage of page styles in Netscape 6
      // and it also allows correctly create submenus when browser uses smart submenu scrolling,
      // because using body.innerHTML resets divs' overflow coords for scrollable submenus.
        dm_gE('dmD'+m.ind+'m'+smVar.ind).innerHTML = smVar.smHTML;

  return dm_gE(smVar.id);
}


function dm_showMenu(id, parentID)
// Shows specified submenu according to root item position and cross-frame mode
{
    if (!id) return;
    if (!docElement) docElement = dm_getDocElement(d_o);
    if (b_NS4) return dm_showMenu4(id);

    // Start downloading submenu data from server and quit the function
    if (id=='_') return dm_downloadSubmenu(parentID);

    var smVar = dm_getVarByID(id);
    var menu  = dm_menu[smVar.mInd];
    var smObj = null;
    var canFilter = (b_IEPC && b_VER>=5.5 && smVar.duration)?1:0;

    // Hide submenus for all menus on the page excluding current menu
    for (var i=0; i<dm_menu.ln(); i++)
        if (dm_menu[i] && i!=menu.ind) dm_hideSubmenus(i);


    //--------------------------------------------------------------------------
    // CREATE SUBMENU AND GET SUBMENU OBJECT
    //--------------------------------------------------------------------------
    if (menu.isCrossFrame)
    {
        if (!(smObj=dm_writeCrossSubmenuHTML(menu, smVar, id))) return;
    }
    else
        if (!(smObj=dm_writeSubmenuHTML(smVar))) return;
    //--------------------------------------------------------------------------

    // Define display property before determine submenu's position and sizes
    if (typeof(smObj.style.display)!=_un) smObj.style.display = 'block';
    var smXY  = dm_getSubmenuXY(smVar);
    var itVar = dm_getVarByID(smVar.rootItemID);

    //--------------------------------------------------------------------------
    // SET SUBMENU COORDINATES
    //--------------------------------------------------------------------------
    if (menu.isCrossFrame && cfType==1 && smVar.level==1)                       // Crossframe mode, first-level submenus
        smXY = dm_setCrossSubmenuPos(menu, smVar, smObj, smXY);
    else
        // No crossframe mode OR crossframe mode is on and subframe contains page from alien domain.
        // Do not set top-level submenu coords in popup mode - to avoid submenu showing in incorrect place in FF/MZ.
        if (!(smVar.level==1 && menu.isPopup))
        {
            var u = (b_OP && b_VER<6) ? '' : 'px';
            with (smObj.style)
            {
                left = smXY[0] + u;
                top  = smXY[1] + u;
            }

            // Frame resizing
            if (cfType==3 && b_IEPC && b_VER>=5) dm_frameResize(menu, id);
        }
    //--------------------------------------------------------------------------

    // Highlight selected item
    menu.m[itVar.smInd].shownChildID = id;
    itVar.isHighlighted = menu.saveNavigation;

    with (smObj.style)
    {
        width  = smXY[2] + 'px';
        height = smXY[3] + 'px';

        // Set submenu scrolling parameters
        with (smVar)
        {
            sX = smXY[0];
            sY = smXY[1];
            sEnabled = 1;
            sObj = smObj;
        }

        // Set submenu's container (div) overflow property
        if (smXY[4])
        {
            if (b_IEMAC)
            {
                height = smXY[3]-20 + 'px';                                   // decrease submenu size for MAC IE for bottom scrollbar
                overflow = 'auto';
            }
            else
            {
                if ((b_NS && b_VER<7) || b_OP) overflow = 'auto';
                else
                {
                   if (smSmartScroll) overflow = 'hidden';
                   else
                      if (b_IE6)
                      {
                          overflow  = 'visible';
                          overflowY = 'scroll';
                      }
                      else
                          overflow  = 'auto';
                }

                // Increase submenu width for right scrollbar
                width = smObj.offsetWidth + (b_OP ? 17 : b_SAF ? 15 : 0) + 'px';
            }

            smObj.scrollTop  = 0;
            smObj.scrollLeft = 0;
        }
        else
        {
            overflow  = 'visible';
            smVar.sEnabled = (b_OP && smXY[4]);
        }

        dm_showIFrame(smObj);

        // Show submenu (using transitional effect in IE)
        if (visibility!='visible')
        {
            if (canFilter) dm_startFilter(smObj, smVar.duration);
            visibility = 'visible';
            if (canFilter) fl.play();
        }
    }


    // Check objects intersection
    if (dmObjectsCheck) dm_checkSubmenuIntersection(smVar, smXY);
}


function dm_startFilter(smObj, dur)
{
  with (fl=smObj.filters[0])
  {
      enabled = 1;
      if (status!=0) stop();
      duration = dur/1000;
      apply();
  }
}

function dm_dehighlightRootItem(menu, smVar)
{
  if (menu.saveNavigation)
  {
      var ritVar = dm_getVarByID(smVar.rootItemID);

      // Mark item as not highlighted
      ritVar.isHighlighted = 0;

      // Clear shown child value for parent submenu
      menu.m[ritVar.smInd].shownChildID  = '';
      
      // Change item appearance
      if (!ritVar.isPressed) dm_changeItemStyle(ritVar, 0);
  }
}

function dm_hideMenu(id)
{
    if (!id) return;
    if (b_NS4) return dm_hideMenu4(id);

    var smObj = dm_getObjectByID(id);
    if (!smObj) return;

    var smVar = dm_getVarByID(id);
    var menu  = dm_menu[smVar.mInd];


    if (smVar.isMoved && !moveRec.isMoving)
    {
        with (smObj.style)
        {
            left = smVar.left + 'px';
            top  = smVar.top  + 'px';
        }
        dm_showIFrame(smObj);
    }


    // Hide all visible submenus
    if (smVar.shownChildID) dm_hideMenu(smVar.shownChildID);
    smVar.shownChildID = '';
    
    // Dehighlight root item
    dm_dehighlightRootItem(menu, smVar);


    if (smVar.showTimer)
    {
        clearTimeout(smVar.showTimer);   smVar.showTimer = null;
    }


    // Hide submenu
    if (!smVar.isMoved && moveRec.prepareSmID!=smVar.id)
    {
        with (smObj.style)
        {
            //if (typeof(display)!=_un) display = 'none';
            var canFilter = (b_IEPC && b_VER>=5.5 && smVar.duration2) ? 1:0
            if (canFilter) dm_startFilter(smObj, smVar.duration2);

            visibility = 'hidden';

            if (canFilter) fl.play();
        }
        
        if (b_IEPC && b_IE6 && !useHTTPS) dm_getObjectByID(id+'frame').style.visibility = 'hidden';  // Hide IFRAME on IE for PC
    }


    // Restore frame size for cross-frame mode
    if (smVar.level==1 && cfType==3 && oldFsetSizes)
    {
        with (parent.document.getElementById(menu.cfFSID))
              if (menu.cfOrient) cols = oldFsetSizes;
              else               rows = oldFsetSizes;
        oldFsetSizes = null;                                                    // clear saved sizes for frames
    }


    // Show submenus on click: if all submenus were hidden -> enable "need-to-click"
    if (menu.smShowClick && menu.hideAllTimer) menu.smShowClicked = 0;


    // Show hidden objects on page
    if (dmObjectsCheck) dm_showIntersectedObjects(smVar);

    //if (keyMode.isEnabled && smVar.level==1) dm_disableKeyMode(menu.ind, 0);
}


function dm_correctSubmenuCoord(xy, wh, docXY, docWH, limY)
// Checks document bounds and correct submenu position
{
  if (xy+wh > docWH && (limY ? docWH-xy<limY : 1)) xy = docWH - wh + docXY;
  if (xy    < docXY) xy = docXY;
  return xy;
}


function dm_getSubmenuXY(smVar)
// Returns submenu coords and dimensions: [x, y, width, height, resize]
{
    var menu     = dm_menu[smVar.mInd];
    var smObj    = dm_getObjectByID(smVar.id);

    var smSize = b_NS4 ? dm_getObjectSize(smObj, 0) : dm_getObjectSize(dm_getObjectByID(smObj.id+'tbl'));

    var ritVar   = dm_getVarByID(smVar.rootItemID);
    var rsmVar   = menu.m[ritVar.smInd];

    var ritObj   = dm_getObjectByID(ritVar.id+(b_NS4?'':'tbl'));
    var ritSize  = dm_getObjectSize(ritObj);
    var inDIV    = ritSize[4];
    var rsmObj   = dm_getObjectByID(rsmVar.id);


    var docSize  = dm_getClientSize(menu);
    var x=0, y=0, w=0, h=0, resize=0;

    switch (menu.smView)
    {
        case 1:
        case 3: y = ritSize[1] + ((rsmVar.ind || !rsmVar.isHoriz)?ritSize[3]:0) - smSize[3]  - smVar.offy;
        break;

        case 0:
        case 2: y = ritSize[1] + (rsmVar.isHoriz?ritSize[3]:0) + smVar.offy;
        break;
    }
    
    if (rsmVar.isHoriz)
        x = (menu.smAlign=='right')  ?  ritSize[0]+ritSize[2]-smSize[2]-smVar.offx  :  (menu.smAlign=='center')  ?  ritSize[0]+(ritSize[2]-smSize[2])/2  :  ritSize[0]+smVar.offx;
    else
        x = (menu.smView<2)  ?  ritSize[0]+ritSize[2]+smVar.offx  :  ritSize[0]-(rsmVar.isHoriz ? 0 : smSize[2])-smVar.offx;

    // When the menu isn't placed within object with relative/absolute position,
    // correct submenu position on IE MAC using body's margin attributes
    // Do NOT combine the following expressions into with(docElement) statement, because Safari can't detect body's margin attributes
    if (!inDIV && (b_IEMAC || (b_SAF && smVar.level>1)))
    {
        x += b_SAF ? -dm_getParam(pI(docElement.marginWidth), 0)  : pI(docElement.leftMargin);
        y += b_SAF ? -dm_getParam(pI(docElement.marginHeight), 0) : pI(docElement.topMargin);
    }
    
    // Correct submenu position for Opera 9
    if (b_OP && b_VER>=9 && smVar.level>1)
    {
        x -= d_o.body.leftMargin;
        y -= d_o.body.topMargin;
    }


    docSize[2] += docSize[0];
    docSize[3] += docSize[1];


    // Set submenu size
    with (smVar.smStyle)
    {
        w = (smW ? pI(smW) + smVar.shadowLen : smSize[2]);
        h = (smH ? pI(smH) + smVar.shadowLen : smSize[3]);
    }

    //--------------------------------------------------------------------------
    // Correct submenu position if submenu isn't placed within object
    // with relative/absolute position
    //--------------------------------------------------------------------------
    if (!inDIV && !(dmRTL && b_IE))
      if (!menu.isCrossFrame || (smVar.level>1 && cfType!=3))
      {

          // Correct submenu position according to scrolling of parent submenu
          if (typeof(rsmObj.scrollLeft)!=_un)
          {
              x -= rsmObj.scrollLeft;
              y -= rsmObj.scrollTop;
          }

          // Check document bounds and correct submenu position
          x = dm_correctSubmenuCoord(x, w, docSize[0], docSize[2], 0);
          y = dm_correctSubmenuCoord(y, h, docSize[1], docSize[3], 200);

          // Check document bounds once again and set new submenu size
          if (x+w > docSize[2]) w = docSize[2]-x;
          if (y+h > docSize[3]) h = docSize[3]-y;

          // Check if submenu must be scrollable
          resize = (w<smSize[2] || h<smSize[3]);


          // Check size for Netscape 6 and correct submenu position and dimensions
          if (b_NS6)
          {
              if (resize) w += 14;
              if (rsmVar.sEnabled) x+= 14;
          }
      }

    return [x,y,w,h,resize];
}


function dm_hideSubmenus(mInd)
// Hides all submenus for specified menu
{
    clearInterval(dm_menu[mInd].hideAllTimer);
    dm_hideMenu(dm_menu[mInd].m[0].shownChildID);
}



//##############################################################################
// EXTERNAL FUNCTIONS
//##############################################################################

function dm_ext_setPressedItem(mInd, smInd, itInd, recursion)
// Sets current pressed item
{
  if (b_NS4) return;
  var menu = dm_menu[mInd];

  // If function doesn't call itself and pressed item exists
  with (menu)
  {
      if (!toggleRec.pressedSelf && menu.curPressedIt!=-1)
      {
          toggleRec.pressedSelf = 1;
          dm_ext_setPressedItem(mInd, curPressedSm, curPressedIt, recursion); // unpress pressed item
          if (curPressedSm==smInd && curPressedIt==itInd)
          {
              curPressedSm = 0;
              curPressedIt = -1;
              return;
          }
      }

      if (!toggleRec.pressedSelf)                                             // if func doesn't call itself -> set new pressed indexes
      {
          curPressedSm = smInd;
          curPressedIt = itInd;
      }
      else
          toggleRec.pressedSelf = 0;
  }

  var itVar = dm_getVarByID('dm'+mInd+'m'+smInd+'i'+itInd);
  with (toggleRec)
  {
      if (!changeStyleOnly) itVar.isPressed = !itVar.isPressed;
      changeStyleOnly = 0;
  }


  dm_changeItemStyle(itVar, (itVar.isPressed?1:0));


  // If recursion is enabled and submenu isn't a root menu
  if (recursion && smInd>0)
  {
      var smVar = menu.m[smInd];
      var ritVar;
      for (var j=smVar.level; j>0; j--)
      {
          ritVar = dm_getVarByID(smVar.rootItemID)
          dm_changeItemStyle(ritVar, (itVar.isPressed?1:0));
          ritVar.isPressed = itVar.isPressed;
          smVar = menu.m[ritVar.smInd];                                       // get next parent submenu
      }
  }
}
