function SwitchTopSheetListState(img, div) {
  if (typeof img != 'object') {
    img = document.getElementById(img);
  }
  if (typeof div != 'object') {
    div = document.getElementById(div);
  }
  if (!div) return;
  if (div.style.display != 'block') {
    div.style.display = 'block';
    img.src = '/Img/TreeM.gif';
  }
  else {
    div.style.display = 'none';
    img.src = '/Img/TreeP.gif';
  }
}

function SwitchDocPart(DivID)
{
  SwDiv = document.getElementById(DivID);
  var t = SwDiv.innerHTML;
//  alert(t);

  if (typeof DocPartArr[DivID] != 'string') { 
    DocPartArr[DivID] = t.substring(0, t.indexOf('<!---->')) + 
      '&nbsp;&nbsp;<a href="javascript: SwitchDocPart(\'' + DivID + '\')\">' +
      '<img src="' + image_path + 'Detal-Arow.gif" border=0 align=bottom></a></p>';
  }
  SwDiv.innerHTML = DocPartArr[DivID];
  DocPartArr[DivID] = t;
}

function SwitchDocPartAll() {
  for (DivID in DocPartArr) SwitchDocPart(DivID);
}

function getAbsoluteLeft(obj) 
{
  if (typeof obj != 'object') {
    obj = document.getElementById(obj);
  }
  var x = 0;
  if (obj){
    while (obj.offsetParent !== null) {
      x += obj.offsetLeft;
      obj = obj.offsetParent;
    }
    x += obj.offsetLeft;
  }
  return x;
}

function getAbsoluteTop(obj) 
{
  if (typeof obj != 'object') {
    obj = document.getElementById(obj);
  }
  var y = 0;
  if (obj){
    while (obj.offsetParent !== null) {
      y += obj.offsetTop;
      obj = obj.offsetParent;
    }
    y += obj.offsetTop;
  }
  return y;
}

var CurrDisplPopupDiv = null;
var CurrActiveImg = null;
var CurrMenu = null;
var CurrentTimeoutID = null;

function ClearTimeoutToShow()
{
  if (CurrentTimeoutID != null)
    clearTimeout(CurrentTimeoutID);
  CurrentTimeoutID = null;
}

function HideDiv()
{
  ClearTimeoutToShow();
  if (CurrDisplPopupDiv) {
    CurrDisplPopupDiv.style.display = 'none';
  }
  if (CurrActiveImg) {
    CurrActiveImg.style.display = 'none';
  }
}

/*function ShowDiv(Menu, ActImg, Div)
{
  HideDiv();
  if (typeof Div != 'object') 
    Div = document.getElementById(Div);
  CurrDisplPopupDiv = Div;
//  alert(CurrDisplDiv.offsetWidth);
  if (typeof Menu != 'object') 
    Menu = document.getElementById(Menu);
  CurrMenu = Menu;
  if (typeof ActImg != 'object') 
    ActImg = document.getElementById(ActImg);
  CurrActiveImg = ActImg;
  if (CurrDisplPopupDiv) {
    CurrDisplPopupDiv.style.display = 'block';
    if (CurrMenu.id < RightMenuStart) 
      CurrDisplPopupDiv.style.left = getAbsoluteLeft(Menu) + ' px';
    else
      CurrDisplPopupDiv.style.left = getAbsoluteLeft(Menu) + Menu.offsetWidth - CurrDisplPopupDiv.offsetWidth  + ' px';
//    CurrDisplPopupDiv.style.top = getAbsoluteTop(Menu) + <?php echo $img_size["BubleH"]-1; ?> + ' px';
    CurrDisplPopupDiv.style.top = getAbsoluteTop(Menu) + BubleH + ' px';
    CurrActiveImg.style.display = 'block';
  }
}/**/


//---------------------------------------------------------
function HideTopSheetsPopupDiv()
{
//  alert('123');
  var TopSheetsDiv = document.getElementById('TopSheetsDiv');
  ClearTimeoutToShow();
  if (TopSheetsPopupDiv) {
    TopSheetsPopupDiv.style.display = 'none';
  }
  if (CurrActiveImg) {
    CurrActiveImg.style.display = 'none';
  }
}

function BuildDictPopupList(CharCatNum)
{
  var s = '<table class="TopSheetList">' +
    '<tr><td colspan=2>&nbsp;&nbsp;&nbsp;<b>Выберите словарь:</b></td></tr>';
  for (i=0; i<CharCatList[CharCatNum].length; i++) {
    if (CharCatList[CharCatNum][i] != '')
      s = s + '<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td nowrap>' +
        '<a class="TopSheetList" href="/' + DictList[i][1] + '/' + CharCatList[CharCatNum][i] + '/">' + DictList[i][0] +
        '</a>&nbsp;&nbsp;&nbsp;</td></tr>';
  }
  s = s + '</table>';
  return s;
}

function BuildTopSheetsList(CharCatNum)
{
  var s = '';
  for (i=1; i<TopSheetsList[CharCatNum].length; i++) {
    s = s + '<tr>';
    for (j=0; j<TopSheetsList[CharCatNum][i].length; j++) 
      if (TopSheetsList[CharCatNum][i][j][1] != '')
//        if (TopSheetsList[CharCatNum][i][j][0] != '')
        if (TopSheetsList[CharCatNum][i][j][0] != SelectedTopSheet)
          s = s + '<td nowrap>&nbsp;&nbsp;&nbsp;<a class="TopSheetList" href="' + TopSheetsList[CharCatNum][0] +
            TopSheetsList[CharCatNum][i][j][0] + '.html">' +
            TopSheetsList[CharCatNum][i][j][1] + '</a>&nbsp;&nbsp;&nbsp;</td>';
        else
          s = s + '<td nowrap>&nbsp;&nbsp;&nbsp;<b>' +
            TopSheetsList[CharCatNum][i][j][1] + '</b>&nbsp;&nbsp;&nbsp;</td>';
      else
        s = s + '<td nowrap>&nbsp;</td>';
    s = s + '</tr>';
  }
  s = '<table class="TopSheetList">' + s + '</table>';
  return s;
}

function DoShowTopSheetsPopupDiv(Menu, ActImg, CharCatNum)
{
  HideTopSheetsPopupDiv();
//  var TopSheetsPopupDiv = document.getElementById('TopSheetsPopupDiv');
  var TopSheetsPopupDiv = document.getElementById('TopSheetsPopupDiv');
  var TopSheetsDiv = document.getElementById('TopSheetsDiv');
/*  if (typeof Div != 'object') 
    Div = document.getElementById(Div);
  CurrDisplPopupDiv = Div;/**/
//  alert(CurrDisplDiv.offsetWidth);
  if (typeof Menu != 'object') 
    Menu = document.getElementById(Menu);
  CurrMenu = Menu;
  if (typeof ActImg != 'object') 
    ActImg = document.getElementById(ActImg);
  CurrActiveImg = ActImg;
  switch (PopupMenuBuildMode) {
    case 0 : TopSheetsDiv.innerHTML = BuildDictPopupList(CharCatNum); break;
    case 1 : TopSheetsDiv.innerHTML = BuildTopSheetsList(CharCatNum); break;
  }
  if (TopSheetsPopupDiv) {
    TopSheetsPopupDiv.style.display = 'block';
    if (CurrMenu.id < RightMenuStart) 
      TopSheetsPopupDiv.style.left = getAbsoluteLeft(Menu) + 'px';
    else
      TopSheetsPopupDiv.style.left = getAbsoluteLeft(Menu) + Menu.offsetWidth - TopSheetsPopupDiv.offsetWidth  + 'px';
//    TopSheetsPopupDiv.style.top = getAbsoluteTop(Menu) + <?php echo $img_size["BubleH"]-1; ?> + ' px';
    TopSheetsPopupDiv.style.top = getAbsoluteTop(Menu) + BubleH + 'px';
    CurrActiveImg.style.display = 'block';
  }
}
function ShowTopSheetsPopupDiv(Menu, ActImg, CharCatNum)
{
  ClearTimeoutToShow();
//  HideDiv();
  CurrentTimeoutID = setTimeout('DoShowTopSheetsPopupDiv(' + Menu + ',' + ActImg + ',' + CharCatNum + ')', 250);
}




