// Высота линейки меню (нужно подогнать под размер шрифта)
var menuLineHeight = 27;
var menuLineHeightV = 28;

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 - 10;
   m.style.top = y + menuLineHeight;
}

function onfon(tdn,nn)
	{
		tdn.style.backgroundColor='#246E5B';
		tdn.style.cursor='hand';
		nn.style.color='#FFFFFF';
}
function outfon(tdn,nn)
	{
		tdn.style.backgroundColor='#28957A';
		tdn.style.cursor='';
		nn.style.color='#FFFFFF';
	}

	
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=5>');
}

function endSubMenu() {
   d.write('</table></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=\'#035701\' onMouseOver="this.style.backgroundColor=\'#7C8FD5\'" onMouseOut="this.style.backgroundColor=\'#035701\'""><span class="subMenu"><strong>',txt,'</strong></span></td>');
      if (subId >= (count / 2)) d.write('</tr>');
   }
   else {
      if (subId == 0) classTd = 'menuJSTop';
      else classTd = 'menuJS';
      d.write('<tr><td id="',classTd,'" bgcolor=\'#035701\' onMouseOver="this.style.backgroundColor=\'#7C8FD5\'" onMouseOut="this.style.backgroundColor=\'#035701\'" 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=\'#ff9c00\' onMouseOver="this.style.backgroundColor=\'#bb7200\'" onMouseOut="this.style.backgroundColor=\'#ff9c00\'" onClick="hideMenu(',idM,');"><a href="',hrf,'" ',texttarget,' class="subMenu" >',txt,'</a></td>');
      } else {
        d.write('<td id="',classTd,'" bgcolor=\'#ff9c00\' onMouseOver="this.style.backgroundColor=\'#bb7200\'" onMouseOut="this.style.backgroundColor=\'#ff9c00\'" 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=\'#ff9c00\' onMouseOver="this.style.backgroundColor=\'#bb7200\'" onMouseOut="this.style.backgroundColor=\'#ff9c00\'" onClick="hideMenu(',idM,');"><a href="',hrf,'" ',texttarget,' class="subMenu" >',txt,'</a></td></tr>');
      } else {
        d.write('<tr><td id="',classTd,'" bgcolor=\'#ff9c00\' onMouseOver="this.style.backgroundColor=\'#bb7200\'" onMouseOut="this.style.backgroundColor=\'#ff9c00\'" onClick="hideMenu(',idM,'); location.href=\'',hrf,'\';"><a href="',hrf,'" class="subMenu">',txt,'</a></td></tr>');
      }  
  }
}