var isIE = isIExp();
var allMenuItem = [];
var DELTA_TOP   = 4;
var DELTA_BOT   = 4;
var DELTA_LEFT  = 4;
var DELTA_RIGHT = 4;
var BACKGROUND= '#EEE8D9';
var FOREGROUND='black';
var BORDER='1px solid black';
var delay = 500;
var globClear=null;
function MenuTree()
{
  this.addMenu = function(
    parent,
    align,    // right,left,top,bottom
    captions,
    links,
    hints,
    maxHeight,
    isDecorate
  ) //----> [A-childs]
{
    var ret = [];
    if (!parent.parentMenu)
    {
      var ind = allMenuItem.indexOf(parent);
      if (ind == -1) {
        allMenuItem.push(parent);
        ind = allMenuItem.length - 1;
        if (parent.attachEvent) {
          parent.attachEvent('onmouseover',enterTopItem);
          parent.attachEvent('onmouseout', exitTopItem);
        }
        else {
          parent['onmouseover'] = enterTopItem;
          parent['onmouseout']  = exitTopItem;
        }
      }
    }
    var rc = document.createElement('DIV');
    try {
      rc.style.zIndex = 1000;
    }
    catch( ex ) {
    }
    rc.setAttribute('id','div__menu_'+allMenuItem.length);
    parent.divMenu = rc;
    rc.alignMenu = align;
    rc.style.border=BORDER;
    rc.style.backgroundColor=BACKGROUND;
    rc.style.color=FOREGROUND;
    if (maxHeight) {
      rc.style.width    = maxHeight;
      rc.style.overflow = 'auto';
    }
    rc.style.position='absolute';
    var table = document.createElement('TABLE');
    var tbody = document.createElement('TBODY');
    table.setAttribute('cellspacing','0');
    table.setAttribute('cellpadding','0');
    rc.appendChild(table);
    table.appendChild(tbody);
    table.style.backgroundColor=BACKGROUND;
    table.style.color=FOREGROUND;
    parent.childsMenu = [];
    for (var i=0;i < links.length;i++)
    {
       var caption = captions[i];
       var link    = links[i];
       var hint    = hints[i];
       var isEnabled = (link != null && link != '');
       var tr = document.createElement('TR');
       var td = document.createElement('TD');
       td.setAttribute('align','center');
       tbody.appendChild(tr);
       tr.appendChild(td);
       var a = null;
       if (isEnabled) {
          a = createLink(caption,isDecorate);
       }
       else {
         a = document.createElement('A');
         a.innerHTML=caption;
       }
         //document.createElement('A');
         //createLink(caption,isDecorate);
       ret.push(a);
       parent.childsMenu.push(a);
       a.parentMenu = parent;
       allMenuItem.push(a);
       var ind = allMenuItem.length - 1;
       if (a.attachEvent) {
         a.attachEvent('onmouseover',enterTopItem);
         a.attachEvent('onmouseout', exitTopItem);
       }
       else {
         a['onmouseover']= enterTopItem;
         a['onmouseout'] = exitTopItem;
       }
       td.appendChild(a);
       if (isEnabled) {
          a.setAttribute('href',link);
       }
       a.setAttribute('title',hint);
    } // for (var i=0;i <= links.length;i++)
    return ret;
 }
}

findParent=function(n,k){

  if(!n)return null;

  k = k.toUpperCase();

  while(n.parentNode)

  {

    if(n.nodeName.toUpperCase() == k) return n;

    n=n.parentNode

  }

  return null

};

function enterTopItem(e)
{
  var src = e;
  if (e.srcElement) {
    src = e.srcElement;
  }
  else if (e.target) {
    src = e.target;
  }
  src = findParent(src,'A');
  var ind = allMenuItem.indexOf(src);
  try {
    hideTree();
    if (src.parentMenu) {
      releaseTree(ind);
    }
    else {
      hideAllMenu();
    }
    show(ind);
  }
  catch(ex) {
    alert(ex.message);
  }

}
function debug(s)
{
    var d = document.createElement("div");
    d.appendChild(document.createTextNode(s));
    getElementById("spot").appendChild(d);
}

function show (ID)
{
  var a = allMenuItem[ID];
  if (!a.divMenu) return;
  if (!a.divMenu.parentNode != document.body)
  {
    try {
      a.divMenu.parentNode.removeChild(a.divMenu);
    }
    catch( ex ) { }
    document.body.appendChild(a.divMenu);
    a.divMenu.style.visibility = "visible";
    setPosition(a,a.divMenu);
    if (globClear) {
      clearTimeout(globClear);
    }
    globClear = setTimeout('hideAllMenu()',5000);
  }
}

function setPosition(parent,div)
{
    var align = div.alignMenu;
    var xy = getAbsoluteXY(parent);
    var x= xy.x;
    var y= xy.y;
    var w=parent.offsetWidth;
    var h=parent.offsetHeight;
    try {
      div.style.position = 'absolute';
    }
    catch( ex ) {
      alert(ex+'\n'+div);
    }
    var x1,y1;
    if      (align=='top') {
       x1 = x;
       y1 = y - DELTA_TOP - div.offsetHeight;
    }
    else if (align=='bottom') {
       x1 = x;
       y1 = y+h+DELTA_BOT;
    }
    else if (align=='left') {
       x1 = x - div.offsetWidth - DELTA_LEFT;
       y1 = y;
    }
    else if (align=='right')
    {
       x1 = x + w + DELTA_RIGHT ;
       y1 = y;
    }
    else {
      alert('Error 1');
    }
    div.style.left  = x1;
    div.style.top   = y1;
}

function hideTree()
{
 for(var i = 0;i < allMenuItem.length; i++) {
   var item = allMenuItem[i];
   if (!item.parentMenu) continue;
   if (item.style.visibility != 'visible') continue;
   hideTreeItem(item);
 }
}

function getSubTree(item,subtree)
{
  subtree.push(item);
  var childsMenu = item.childsMenu;
  if (!childsMenu) return;
  for(var i = 0;i < childsMenu.length; i++) {
    getSubTree(childsMenu[i],subtree);
  }
}

function hideTreeItem(item)
{
  var subtree = [];
  getSubTree(item,subtree);
  for(var i = subtree.length - 1;i >= 0; i--) {
    var ind = allMenuItem.indexOf(subtree[i]);
    if (subtree[i].style.visibility == 'visible') {
      hideMenu(ind);
    }
  }
}

function exitTopItem(e)
{
  var src = e;
  if (e.srcElement) {
    src = e.srcElement;
  }
  else if (e.target) {
    src = e.target;
  }
  src = findParent(src,'A');
  //--------------------------
  var ind = allMenuItem.indexOf(src);
  var div = src.divMenu;
  //findParent(src,'DIV');
  if (div) {
    var ind0 = allMenuItem.indexOf(src.childsMenu[0]);
    //if (!div.timerID)
       div.timerID = setTimeout ('hideMenu (' + ind0 + ')', delay);
  }
  var divThis = findParent(src,'DIV');
  if (divThis) {
     //if (!divThis.timerID)
        //..divThis.timerID = setTimeout ('hideMenu (' + ind + ')', 5000);
  }
}

function releaseTree(ID)
{
        if (ID == -1) return;
        try {
          var item = allMenuItem[ID];
          var div = findParent(item,'DIV');
          if (div) {
            if (div.timerID)
              clearTimeout(div.timerID);
            div.timerID = null;
          }
        }
        catch( e ) {
        }
        var parent = allMenuItem[ID].parentMenu
        if (parent) {
            var ind = allMenuItem.indexOf(parent);
            releaseTree(ind);
        }
}

function hideMenu(ind)
{
  var src = allMenuItem[ind];
  if (!src.parentMenu) return;
  var div = findParent(src,'DIV');
  if (!div) return;
  try {
    div.style.visibility = 'hidden';
    div.parentNode.removeChild(div);
  }
  catch( ex ) { }
}

document.onmousedown = mouseDownCheckMenu;
document.onmousemove = mouseMoveCheckMenu;
try {
  document.body.onscroll = hideAllMenu;
}
catch( ex ) {}
if (document.captureEvents) // NS
   document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE);
function mouseMoveCheckMenu() {
  //..
  // To Future : if point no in A or Div --> Clear All
}

function mouseDownCheckMenu()
{
  setTimeout(hideAllMenu,500);
}

function hideAllMenu() {
  for(var i = 0;i < allMenuItem.length; i++)
  {
    var item = allMenuItem[i];
    if (!item.parentMenu) continue;
    var div = findParent(item,'DIV');
    if (!div) continue;
    div.style.visibility != 'hidden';
    try {
      if (div.parentNode)
         div.parentNode.removeChild(div);
      var timerID = div.timerID;
      if (!timerID) continue;
      clearTimeout(timerID);
      div.timerID = null;
    }
    catch( ex ) {}
  }
}

function getAbsoluteXY(html) 
{
  var rc = {x:0,y:0};
  var leftpos = html.offsetLeft;
  var toppos  = html.offsetTop;
  var aTag = html;
  do {
     aTag     = aTag.offsetParent;
     leftpos += aTag.offsetLeft;
     toppos  += aTag.offsetTop;
  } while(aTag.tagName.toUpperCase() != "BODY");
  rc.x = leftpos;
  rc.y = toppos;
  return rc;
}

function isIExp() {
  try {
    var nav_vendor  = navigator.appName.substring(0,8).toUpperCase();
    return (!(nav_vendor == "NETSCAPE"));
  }
  catch(ex) {
    return false;
  }
}

Array.prototype.indexOf=function(s)
{
  for(var a=0;a<this.length;a++)if(this[a]==s) return a;
  return -1;
};
//------------------------------------
Array.prototype.remove = function(obj)
{
  var index = this.indexOf(obj);
  if (index > -1) {
    this.splice(index,1);
  }
};
//======================================
parseIntSize = function(str)
{
  str = str+"";
  var rc = 0;
  try {
    str = str.replace(/px/g,"");
    str = str.replace(/pt/g,"");
    rc = Number(str);
  }
  catch(ex) {
  }
  return rc;
};

function printObj(obj)
{
  var s = '';for (a in obj) {s+=(a+'='+obj[a]);}
  return s;
}
//================================================
//  Main Part
//================================================
//var isIE = isIExp();
var MENU_BG_COLOR='#EEE8D9';
var INDEXES = {
  MAIN      : 0,
  NEWS      : 1,
  COMPOSITE : 2,
  THEORY    : 3,
  GAMES     : 4,
  CHAMPIONS : 5,
  HUMOR     : 6,
  LINKS     : 7,
  DOWNLOAD  : 8,
  GUESTBOOK : 9,
  AUTOR     : 10
};
var menuTree = new MenuTree();
//-
//..//__
var MENU_INFO = [
 ["index.html",'Главная','На главную страницу',1,null],
 ["News.html",     'Новости','',               0,null],
 ["Compozite.html",'Композиция','',            1,null],
  //..compoziteSubMenu],
 ["Theory.html",   'Теория',    '',            1,null],
  //..TheorySubMenu],
 ["Games.html",'Партии','',1,null],
 //..gamesSubMenu],
 ["Champions.html",'Чемпионы мира', '',        1,null],
 //..champsSubMenu],
 ["Humor.html",'Юмор','',1,null],
  //..humorSubMenu],
 ["Links.html",'Ссылки','Ссылки на другие шахматные сайты (и не только шахматные)',1,null],
 ["Download.html",'Скачать','',0,null],
 ["http://www.64chess.com/GuestBook/index.php",'Гостевая книга','Гостевая книга,контакты с администрацией сайта',1,null],
 ["Autor.html",'Автор','',1,null]
];

function compoziteSubMenu(a,isTop,isDecorate) {
  var align = 'bottom'; if (!isTop) align = 'top';
  var dir = getMainDir();
  var childs = menuTree.addMenu(
        a,
        align,
        ['Задачи','Этюды'],
        [dir+'CompoziteHtml/Tasks/newd.htm',
         dir+'CompoziteHtml/Etuds/newd.htm'],
        ['Шахматные Задачи','Шахматные Этюды'],
        null,
        isDecorate
 );
}

function TheorySubMenu(a,isTop,isDecorate) {
  var align = 'bottom'; if (!isTop) align = 'top';
  var dir = getMainDir();
  var captions =
  ['Типичные комбинации',
          'Партии 21-го века (11 партий)',
          'Партии 20-го века (20 партий)',
          'Вариант Рубинштейна во французкой защите',
          'Открытые дебюты',
          'Венская партия (10 партий)',
          'Защита двух коней (6 партий)',
          'Итальянская парти (3 партии)',
          'Русская защита (5 партий)',
          'Полуоткрытые дебюты',
          'Сицилианска защита (часть 1,4 партии)',
          'Сицилианска защита (часть 2,26 партий)',
          'Французка защита (26 партий)',
          'Разные начала (4 партии)'
         ];
     var hrefs =
       ['',
          dir+'Theory/Typical_Combination/blund-01/0/newd_game1.htm',
          dir+'Theory/Typical_Combination/blund-02/0/newd.htm',
          dir+'Theory/french_rubinshtein/0/newd.htm',
          '',
          dir+'Theory/Enschpil/Open/Venskaj/0/newd.htm',
          dir+'Theory/Enschpil/Open/TwoHorse/0/newd.htm',
          dir+'Theory/Enschpil/Open/Italian/0/newd.htm',
          dir+'Theory/Enschpil/Open/Russian/0/newd.htm',
          '',
          dir+'Theory/Enschpil/PartOpen/Sicilian/0_rus/newd.htm',
          dir+'Theory/Enschpil/PartOpen/Sicilian/0_eng/newd.htm',
          dir+'Theory/Enschpil/PartOpen/French/0_eng/newd.htm',
          dir+'Theory/Enschpil/Open/Other/0/newd.htm'
         ];
       var hints = ['','','','','','','','','','','','','',''];
  var childs = menuTree.addMenu(
         a,
         align,
         captions,
         hrefs,
         hints,
         null,
         isDecorate
  );
}

function gamesSubMenu(a,isTop,isDecorate) {
  var align = 'bottom'; if (!isTop) align = 'top';
  var dir = getMainDir();
  var childs = menuTree.addMenu(
         a,
         align,
         ['Партии 1992-1998 годов',
          'Партии 2002-2003 годов (Часть 1)',
          'Партии 2002-2003 годов (Часть 2)',
          'Партии 2002-2003 годов (Часть 3)',
          'Партии 2002-2003 годов (Часть 4)',
          'Партии 2002-2003 годов (Часть 5)'
         ],
         ["javascript:pgnOpen('Games/elite/dirinfo.js','Партии элиты 1992-1998 г.')",
          "javascript:pgnOpen('Games/jan1_03/dirinfo.js','Партии 2002-2003 г. Часть 1')",
          "javascript:pgnOpen('Games/jan2_03/dirinfo.js','Партии 2002-2003 г. Часть 2')",
          "javascript:pgnOpen('Games/jan3_03/dirinfo.js','Партии 2002-2003 г. Часть 3')",
          "javascript:pgnOpen('Games/feb1_03/dirinfo.js','Партии 2002-2003 г. Часть 4')",
          "javascript:pgnOpen('Games/feb2_03/dirinfo.js','Партии 2002-2003 г. Часть 5')"
         ],
         ['',
          '',
          '',
          '',
          '',
          ''
         ],
         null,
         isDecorate
  );
}

function pgnOpen(file,title)
{
        var dir = getMainDir();
        var locate =
          dir +
          "Common/Viewer_PGN/ltpgnboardMulti.html?"+
          "SetTitle="+title+"&"+
          "AllowRecording=true&"+
          "ApplyDirInfoFile="+dir+file;
          window.location.href = locate;
}

function champsSubMenu(a,isTop,isDecorate) {
  var align = 'bottom'; if (!isTop) align = 'top';
  var dir = getMainDir();
  var childs = menuTree.addMenu(
         a,
         align,
         ['Вильгельм Стейниц &#8594;',
          'Эммануил Ласкер &#8594;',
          'Хосе Рауль Капабланка &#8594;',
          'Александр Алехин &#8594;',
          'Макс Эйве &#8594;',
          'Михаил Ботвинник &#8594;',
          'Василий Смыслов &#8594;',
          'Михаил Таль &#8594;',
          'Тигран Петросян &#8594;',
          'Борис Спасский &#8594;',
          'Роберт Фишер &#8594;',
          'Анатолий Карпов &#8594;',
          'Гарри Каспаров &#8594;',
          'Владимир Крамник &#8594;'
         ],
         [dir+'Champs/steinitz.html',
          dir+'Champs/lasker.html',
          dir+'Champs/capablanca.html',
          dir+'Champs/alehin.html',
          dir+'Champs/euwe.html',
          dir+'Champs/botvinnik.html',
          dir+'Champs/smyslov.html',
          dir+'Champs/tal.html',
          dir+'Champs/petrosian.html',
          dir+'Champs/spassky.html',
          dir+'Champs/fisher.html',
          dir+'Champs/karpov.html',
          dir+'Champs/kasparov.html',
          dir+'Champs/kramnik.html'
         ],
         ['',
          '',
          '',
          '',
          '',
          '',
          '',
          '',
          '',
          '',
          '',
          '',
          '',
          ''
         ],
         null,
         isDecorate
  );
  menuTree.addMenu(
     childs[0],
     'right',
     ['Партии Стейницa'],[dir+"Champs/Games/steinitz/champs_game1.htm"],[''],null,isDecorate);
  menuTree.addMenu(
     childs[1],
     'right',
     ['Партии Ласкерa'],[dir+"Champs/Games/lasker/champs_game1.htm"],[''],null,isDecorate);
  menuTree.addMenu(
     childs[2],
     'right',
     ['Партии Капабланки'],[dir+"Champs/Games/capablanca/champs_game1.htm"],[''],null,isDecorate);
  menuTree.addMenu(
     childs[3],
     'right',
     ['Партии Алехина'],[dir+"Champs/Games/alehin/champs_game1.htm"],[''],null,isDecorate);
  menuTree.addMenu(
     childs[4],
     'right',
     ['Партии Эйве'],[dir+"Champs/Games/euve/champs_game1.htm"],[''],null,isDecorate);
  menuTree.addMenu(
     childs[5],
     'right',
     ['Партии Ботвинника'],[dir+"Champs/Games/botvinnik/champs_game1.htm"],[''],null,isDecorate);
  menuTree.addMenu(
     childs[6],
     'right',
     ['Партии Смыслова'],[dir+"Champs/Games/smyslov/champs_game1.htm"],[''],null,isDecorate);
  menuTree.addMenu(
     childs[7],
     'right',
     ['Партии Таля'],[dir+"Champs/Games/tal/champs_game1.htm"],[''],null,isDecorate);
   menuTree.addMenu(
     childs[8],
     'right',
     ['Партии Петросяна'],[dir+"Champs/Games/petrosian/champs_game1.htm"],[''],null,isDecorate);
   menuTree.addMenu(
     childs[9],
     'right',
     ['Партии Спасского'],[dir+"Champs/Games/spassky/champs_game1.htm"],[''],null,isDecorate);
   menuTree.addMenu(
     childs[10],
     'right',
     ['Партии Фишера'],[dir+"Champs/Games/fisher/champs_game1.htm"],[''],null,isDecorate);
   menuTree.addMenu(
     childs[11],
     'right',
     ['Партии Карпова'],[dir+"Champs/Games/karpov/champs_game1.htm"],[''],null,isDecorate);
   menuTree.addMenu(
     childs[12],
     'right',
     ['Партии Каспарова'],[dir+"Champs/Games/kasparov/champs_game1.htm"],[''],null,isDecorate);
   menuTree.addMenu(
     childs[13],
     'right',
     ['Партии Крамника'],[dir+"Champs/Games/kramnik/champs_game1.htm"],[''],null,isDecorate);
}
function humorSubMenu(a,isTop,isDecorate) {
  var align = 'bottom'; if (!isTop) align = 'top';
  var dir = getMainDir();
  var childs = menuTree.addMenu(
         a,
         align,
         ['Шаржи',
          'Карикатуры',
          'Веселые истории',
          'Крылатые выражения',
          'Шахматная азбука Тартаковера',
          'Из записной книжки Юрия Авербаха'
         ],
         [dir+'Humor/Sharji.html',
          dir+'Humor/Karikaturi.html',
          dir+'Humor/History.html',
          dir+'Humor/Cases.html',
          dir+'Humor/Tartokover.html',
          dir+'Humor/Averbax.html'
         ],
         ['',
          '',
          '',
           '',
           '',
           ''
          ],
          null,
          isDecorate
   );
}  

function uverture() {
 //+
}
function pageOnLoad(
          isTopMenu,
          isBottMenu,
          menuItemsExclude,
          menuSubItemsExclude,
          isDecorate
         )
{
  if (!document.createElement)  return;
  if (!document.appendChild)    return;
  if (!document.createTextNode) return;
  if (!document.body)           return;
  if (!document.removeChild)    return;
  if (!document.getElementById &&
      !document.all            &&
      !document.layers)         return;
  //-------------------------------------
  uverture();
  setupMenu(isTopMenu, 'tLinksTop'   ,menuItemsExclude,menuSubItemsExclude,isDecorate);
  setupMenu(isBottMenu,'tLinksBottom',menuItemsExclude,menuSubItemsExclude,isDecorate);
}

function pageOnLoadN(
          isTopMenu,
          isBottMenu,
          menuItemsExclude,
          n
         )
{
  // Отключено за ненадобностью
  /*
  n = 3;
  uverture();
  setupMenuN(isTopMenu, 'tLinksTop'   ,menuItemsExclude,n);
  setupMenuN(isBottMenu,'tLinksBottom',menuItemsExclude,n);
  */
}

function setupMenuN(isExists,id,listExclude,n)
{
  var table = getElementById(id);
  if (!table) return;
  if (!isExists) {
   try {table.parentNode.removeChild(table);} catch( ex ) {}
   return;
  }
  normalizeTable(table);
  table.style.visibility='visible';
  if (!table) return;
  var tbody = table.childNodes[0];
  var countItems = 0;
  for(var i = 0;i < MENU_INFO.length; i++) {
    var elem = MENU_INFO[i];
    var href  = elem[0];
    var text  = elem[1];
    var title = elem[2];
    var isExists = elem[3];
    if (isExists == 0) continue;
    if (listExclude) {
      if (listExclude.indexOf(i) > -1) {
        continue;
      }
    }
    countItems++;
  }
  var countItemsInRow = (countItems / n);
  countItemsInRow = 3;
  countItemsInRow = Math.round(countItemsInRow);
  var currentItemsInRow = 0;
  var tr = null;
  for(var i = 0;i < MENU_INFO.length; i++) {
    var elem = MENU_INFO[i];
    var href  = elem[0];
    var text  = elem[1];
    var title = elem[2];
    var isExists = elem[3];
    if (isExists == 0) continue;
    if (listExclude) {
      if (listExclude.indexOf(i) > -1) {
        continue;
      }
    }
    if (currentItemsInRow == countItemsInRow) {
      currentItemsInRow = 0;
    }
    if (currentItemsInRow == 0) {
      tr = document.createElement('TR');
      tbody.appendChild(tr);
    }
    var td = document.createElement('TD');
    td.setAttribute('align','middle');
    td.setAttribute('bgColor',MENU_BG_COLOR);
    tr.appendChild(td);
    var a = createLink(text);
    a.setAttribute('title',title);
    td.appendChild(a);
    if (href.substring(0,5) != 'http:') {
      a.setAttribute('href',"javascript:gotoPage('"+href+"')");
    }
    else {
      a.setAttribute('href',href);
      a.setAttribute('target','new');
    }
    currentItemsInRow++;
  }
}
function gotoPage(href,isNoFrame)
{
  if (href.substring(0,7) == "http://") {
    gotoPageAbs(href);
    return;
  }
  if (!isNoFrame)
      try {
        window.parent.location.href = getMainDir()+href;
      }
      catch(ex) {
        window.location.href = href;
      }
  else
      window.location.href = getMainDir()+href;
}

function gotoPageAbs(href) {
  window.parent.location.href = href;
}

function setupMenu(isExists,
                   id,
                   listExclude,
                   menuSubItemsExclude,
                   isDecorate)
{
  var table = getElementById(id);
  if (!table) return;
  if (!isExists) {
   try {table.parentNode.removeChild(table);} catch( ex ) {}
   return;
  }
  var isTopMenu = (id == 'tLinksTop');
  normalizeTable(table);
  table.style.visibility='visible';
  if (!table) return;
  var tbody = table.childNodes[0];
  var tr = tbody.childNodes[0];
  var n = tr.childNodes.length;
  for (i=n-1; i >= 0;i--) {
     try {
       tr.removeChild(tr.childNodes[i]);
     }
     catch( ex ) {}
  }
  for(var i = 0;i < MENU_INFO.length; i++)
  {
    var elem = MENU_INFO[i];
    var href     = elem[0];
    var text     = elem[1];
    var title    = elem[2];
    var isExists = elem[3];
    var fnCreateSubMenu = elem[4];
    if (isExists == 0) continue;
    if (listExclude) {
      if (listExclude.indexOf(i) > -1) {
        continue;
      }
    }
    var td = document.createElement('TD');
    td.setAttribute('align','middle');
    td.setAttribute('bgColor',MENU_BG_COLOR);
    tr.appendChild(td);
    var a = createLink(text,isDecorate);
    a.setAttribute('title',title);
    td.appendChild(a);
    if (href.substring(0,5) != 'http:') {
      a.setAttribute('href',getMainDir()+href);
    }
    else {
      a.setAttribute('href',href);
      a.setAttribute('target','new');
    }
    if (fnCreateSubMenu)
    {
      if (menuSubItemsExclude) {
        if (menuSubItemsExclude.indexOf(i) > -1) {
           continue;
        }
      }
      fnCreateSubMenu(a,isTopMenu,isDecorate);
    }
  }
}
function normalizeTable(elem)
{
  if (isIE) return;
  if (!elem) return;
  var childs = elem.childNodes;
  if (!childs) return;
  for(var i = childs.length - 1;i >=0 ;i--)
  {
    var child = childs[i];
    elem.removeChild(child);
  }
  var tbody = document.createElement('TBODY');
  elem.appendChild(tbody);
  var tr = document.createElement('TR');
  tbody.appendChild(tr);
}
function createLink(text,isDecorate)
{
  var rc = document.createElement('A');
  if (isIE && !isDecorate)
    {
       rc.innerHTML = text;
    }
    else {
       rc.style.cursor='pointer';
       rc.style.color = 'blue';
       rc.innerHTML = '<U><B>'+text+'</U></B>';
    }
    return rc;
  }
  function getMainDir()
  {
    var rcLocal = 'file:///c:/Program Files/Apache Group/Apache2/htdocs/64chess.com/';
    var rcHttp  = 'http://www.64chess.com/';
    var rc = rcHttp;
    if (''+window.parent.location.href.substring(0,5)=='file:') {
       rc = rcLocal;
    }
    return rc;
  }

function isIExp()
{
  try {
    var nav_vendor  = navigator.appName.substring(0,8).toUpperCase();
    return (!(nav_vendor == "NETSCAPE"));
  }
  catch(ex) {
    return false;
  }
}
function printObj(obj) {
  var s = '';
  for (a in obj) {s+=(a+'='+obj[a]);}
  return s;
}
//===================================================
function getElementById(id) {
  var d = document;
  var m = null;
  if(d.getElementById)
  {
     m=d.getElementById(id)
  }
  else if(d.all)
  {
     m=d.all[id]
  }
   else if(d.layers)
   {
     m=d.layers.eval(id)
   }
   return m;
 }
