// Высота линейки меню (нужно подогнать под размер шрифта)
var menuLineHeight = 22;
var menuLineHeightV = 17;

var d = document;

function GEByID(id) { 
   return d.all ? d.all[id] : d.getElementById(id);
}

function relPosXX(e) { 
   return e.offsetLeft + (e.offsetParent != null && e.tagName != 'BODY' ? relPosXX(e.offsetParent) : 0);
}

function relPosYY(e) { 
   return e.offsetTop + (e.offsetParent != null && e.tagName != 'BODY' ? relPosYY(e.offsetParent) : 0);
}

function displayMenu(n,x,y) {
   m = GEByID("menu"+n);
   m.style.visibility = 'visible';
   m.style.left = x;
   m.style.top = y + menuLineHeight;
}

function displayMenuV(n,x,y) {
   m = GEByID("menu"+n);
   m.style.visibility = 'visible';
   m.style.left = x;
   m.style.top = y + menuLineHeightV;
}

function showMenu(n) {
   m = GEByID("menu"+n);
   m.style.visibility = 'visible';
}

function hideMenu(n) {
   m = GEByID("menu"+n);
   m.style.visibility = 'hidden';}
   
function newSubMenu(id) {
   d.write('<div id=menu',id,' style="z-index: 99; top:0; position:absolute; visibility:hidden;" onMouseOver="showMenu(',id,');" onMouseOut="hideMenu(',id,');">');
   d.write('<table border=0 cellspacing=0 cellpadding=3>');
}

function endSubMenu() {
   d.write('</table></div>');
}

function newSubMenuItem(hrf, txt, subId, count, idM) {
   if (count > 20) {
      if (subId < (count / 2)) classTd = 'menuJS';
      if (subId >= (count / 2)) classTd = 'menuJSNLeft';
      if (subId == 0) classTd = 'menuJSTop';
      if (subId == Math.ceil(count / 2)) classTd = 'menuJSTopNLeft';
      if (subId < (count / 2)) d.write('<tr>');
      d.write('<td id="',classTd,'" bgcolor=\'#E2E2E2\' onMouseOver="this.style.backgroundColor=\'#FFA200\'" onMouseOut="this.style.backgroundColor=\'#E2E2E2\'" onClick="hideMenu(',idM,'); location.href=\'',hrf,'\';"><a href="',hrf,'" class="subMenu">',txt,'</a></td>');
      if (subId >= (count / 2)) d.write('</tr>');
   }
   else {
      if (subId == 0) classTd = 'menuJSTop';
      else classTd = 'menuJS';
      d.write('<tr><td id="',classTd,'" bgcolor=\'#E2E2E2\' onMouseOver="this.style.backgroundColor=\'#FFA200\'" onMouseOut="this.style.backgroundColor=\'#E2E2E2\'" onClick="hideMenu(',idM,'); location.href=\'',hrf,'\';"><a href="',hrf,'" class="subMenu">',txt,'</a></td></tr>');
   }
}