//##############################################################################
// POPUP MODE FUNCTIONS
//##############################################################################

function dm_getMouseCoords(event)
// Returns mouse coords from event object
{
  var x=0, y=0;
  if (b_IE || b_OP)
  {
      x = event.clientX + (b_IEComp?docElement.scrollLeft:0);
      y = event.clientY + (b_IEComp?docElement.scrollTop:0);
  }
  else
  {
      x = event.pageX;
      y = event.pageY;
  }
  return [x,y];
}


function dm_popup(mInd, hidePause, event, x, y)
// Calls context menu (if popup mode is enabled)
{
  if (b_IE) event.returnValue = false;

  var menu  = dm_menu[mInd];
  var smVar = menu.m[1];                               // get the first submenu
  var xy   = (x&&y) ? [x,y] : dm_getMouseCoords(event);

  if (smVar)
  {
      var obj = dm_writeSubmenuHTML(smVar);
      if (obj.style.visibility=='visible')             // if this popup menu is visible already -> hide it
      {
          clearTimeout(menu.hideAllTimer);
          dm_hideMenu(menu.m[0].shownChildID);
          window.status='';
      }

      menu.m[0].shownChildID = smVar.id;
      dm_showMenu(smVar.id);

      var docSize  = dm_getClientSize(menu);
      var smSize = dm_getObjectSize(dm_getObjectByID(smVar.id+'tbl'));

      // Set submenu size
      with (smVar.smStyle)
      {
          var w = (smW ? parseInt(smW) : smSize[2]) + smVar.shadowLen;
          var h = (smH ? parseInt(smH) : smSize[3]) + smVar.shadowLen;
      }
      
      xy[0] = dm_correctSubmenuCoord(xy[0], w, docSize[0], docSize[2], 0);
      xy[1] = dm_correctSubmenuCoord(xy[1], h, docSize[1], docSize[3], 0);


      with (obj.style)
      {
          left = xy[0]+'px';
          top  = xy[1]+'px';
      }
      dm_showIFrame(obj);

      if (hidePause>0) menu.hideAllTimer = setTimeout("dm_hideMenu('" + menu.m[0].shownChildID + "');window.status='';", hidePause);
  }
  return false;
}
