<script type="text/javascript">
  document.oncontextmenu = showMenu;
  document.onclick = hideMenu;

  function mousePos(evt)
  {
    //treść funkcji mousePos
  }

  function showMenu(evt)
  {
    var div = document.getElementById('menuDiv');
    if(!div) return;

    var xy = mousePos(evt);
    div.style.left = xy.x + "px";
    div.style.top = xy.y + "px";
    div.style.display = 'block';

    return false;
  }
  
  function hideMenu()
  {
    var div = document.getElementById('menuDiv');
    if(div) div.style.display = 'none';
  }
</script>