// Высота линейки меню (нужно подогнать под размер шрифта)
var menuLineHeight = 29;
var menuLineHeightV = 17;
var d = document;
var eVersions = 0;
if (navigator.appName == "Microsoft Internet Explorer") eVersions = 1;

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.left = x;
   m.style.top = y + menuLineHeight;
   if (eVersions == 1) {
     i = GEByID("ifr"+n);
     i.style.height=m.offsetHeight;
   }  
   m.style.visibility = 'visible';
}

function displayMenuV(n,x,y) {
   m = GEByID("menu"+n);
   m.style.left = x;
   m.style.top = y + menuLineHeightV;
   if (eVersions == 1) {
     i = GEByID("ifr"+n);
     i.style.height=m.offsetHeight;
   }  
   m.style.visibility = 'visible';
}

function showMenu(n) {
   m = GEByID("menu"+n);
   m.style.visibility = 'visible';
}

function hideMenu(n) {
   var menuVersion = 0;
   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; filter: progid:DXImageTransform.Microsoft.Shadow(direction=127,color=#000000,strength=2)" onMouseOver="showMenu(',id,');" onMouseOut="hideMenu(',id,');">');
   if (eVersions == 1) {
     d.write('<iframe id=ifr',id,' frameborder="0" class="hmframe"></iframe><div class="hmdiv">');
   }  
   d.write('<table border=0 cellspacing=0 cellpadding=3>');
}

function endSubMenu() {
   d.write('</table></div>');
   if (eVersions == 1) {
     d.write('</div>');
   }  
}

function newSubMenuItem1(hrf, txt, subId, count, idM, target) {
   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>');
   }
}

function newSubMenuItem(hrf, txt, subId, count, idM, target) {
  if (target == 1) {
    texttarget =' target=_blank';
  } else {
    texttarget='';
  } 
  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>');
      if (target == 1) {
        d.write('<td id="',classTd,'" bgcolor=\'#E2E2E2\' onMouseOver="this.style.backgroundColor=\'#FFA200\'" onMouseOut="this.style.backgroundColor=\'#E2E2E2\'" onClick="hideMenu(',idM,');"><a href="',hrf,'" ',texttarget,' class="subMenu" >',txt,'</a></td>');
      } else {
        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,'" ',texttarget,' class="subMenu">',txt,'</a></td>');
      }  
      if (subId >= (count / 2)) d.write('</tr>');
  } else {
      if (subId == 0) classTd = 'menuJSTop';
      else classTd = 'menuJS';
      if (target == 1) {
        d.write('<tr><td id="',classTd,'" bgcolor=\'#E2E2E2\' onMouseOver="this.style.backgroundColor=\'#FFA200\'" onMouseOut="this.style.backgroundColor=\'#E2E2E2\'" onClick="hideMenu(',idM,');"><a href="',hrf,'" ',texttarget,' class="subMenu" >',txt,'</a></td></tr>');
      } else {
        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>');
      }  
  }
}
