var smooth_timer;

function showRow(i, href) {
  var trObj = (document.getElementById) ? document.getElementById('ihtr' + i) : eval("document.all['ihtr" + i + "']");
  var ifObj = (document.getElementById) ? document.getElementById('ihif' + i) : eval("document.all['ihif" + i + "']");
  if (trObj != null) {
    if (trObj.style.display=="none") {
      trObj.style.display="";
      if (!ifObj.src) ifObj.src = href;
      smoothHeight('ihif' + i, 0, 630,126, 'o');
    }
    else {
      smoothHeight('ihif' + i, 630, 0, 126, 'ihtr' + i);
    }
  }
}

function smoothHeight(id, curH, targetH, stepH, mode) {
  diff = targetH - curH;
  if (diff != 0) {
    newH = (diff > 0) ? curH + stepH : curH - stepH;
    ((document.getElementById) ? document.getElementById(id) : eval("document.all['" + id + "']")).style.height = newH + "px";
    if (smooth_timer) window.clearTimeout(smooth_timer);
    smooth_timer = window.setTimeout( "smoothHeight('" + id + "'," + newH + "," + targetH + "," + stepH + ",'" + mode + "')", 20 );
  }
  else if (mode != "o") ((document.getElementById) ? document.getElementById(mode) : eval("document.all['" + mode + "']")).style.display="none";
}

function hideBlock(idBlock)
{
  var block = document.getElementById(idBlock);
  block.style.visibility = "hidden";
  block.style.left = "0px";
  block.style.top =  "0px";
}

function showBlockCenter(idBlock) {
  var block = document.getElementById(idBlock);
  var button = document.getElementById(idButton);
  if (block.style.visibility == "visible") {
    return;
  }
  block.style.left = "45%";
  block.style.top =  "45%";
  block.style.visibility = "visible";
}

function showBlock(idBlock,idButton) {
  var block = document.getElementById(idBlock);
  var button = document.getElementById(idButton);
  if (block.style.visibility == "visible") {
    return;
  }
  x = findPosX(button) + 40;
  y = findPosY(button) + 95;

  var blockHeight = block.scrollHeight;
  var blockWidth = block.scrollWidth;
  var scrollSize = 20;
  var scrollTop = 0;
  var scrollLeft = 0;
  var clientHeight = 0;
  var clientWidth = 0;

  if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.clientHeight)) {
    scrollTop = document.documentElement.scrollTop;
    scrollLeft = document.documentElement.scrollLeft;
    clientHeight = document.documentElement.clientHeight;
    clientWidth = document.documentElement.clientWidth;
  } else if (document.body) {
    scrollTop = document.body.scrollTop;
    scrollLeft = document.body.scrollLeft;
    clientHeight = document.body.clientHeight;
    clientWidth = document.body.clientWidth;
  }
  if ((y + blockHeight) > (clientHeight + scrollTop)) {
    y = y - blockHeight;
  }
  if (y < scrollTop) {
    y = (clientHeight + scrollTop) - (blockHeight + scrollSize);
  }
  if (y < scrollTop) {
    y = scrollTop;
  }
  if ((x + blockWidth) > (clientWidth + scrollLeft)) {
    x = x - blockWidth;
  }
  if (x < scrollLeft) {
    x = (clientWidth + scrollLeft) - (blockWidth + scrollSize);
  }
  if (x < scrollLeft) {
    x = scrollLeft;
  }
  block.style.left = x + "px";
  block.style.top =  y + "px";
  block.style.visibility = "visible";
}

function findPosX(obj) {
  var curleft = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curleft += obj.offsetLeft - obj.scrollLeft;
      obj = obj.offsetParent;
    }
  } else if (obj.x) {
    curleft += obj.x;
  }
  return curleft;
}

function findPosY(obj) {
  var curtop = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curtop += obj.offsetTop - obj.scrollTop;
      obj = obj.offsetParent;
    }
  } else if (obj.y) {
  curtop += obj.y;
  }
  return curtop;
}

function showPanel(id) {
  var panel = document.getElementById("panel"+id);
  if (panel.style.visibility == "visible") {
    return;
  }
  panel.style.visibility = "visible";
}

function hidePanel(id) {
  var panel = document.getElementById("panel"+id);
  panel.style.visibility = "hidden";
}


/********************/
function showCol(i, href) {
  var tdObj = (document.getElementById) ? document.getElementById('ihtd' + i) : eval("document.all['ihtd" + i + "']");
  var ifObj = (document.getElementById) ? document.getElementById('ihif' + i) : eval("document.all['ihif" + i + "']");
  
  if (tdObj != null) {
    if (tdObj.style.display=="none") {
      tdObj.style.display="";
      if (!ifObj.src) ifObj.src = href;
        smoothWidth('ihif' + i, 0, 630,126, 'o');
    }
    else {
      smoothWidth('ihif' + i, 630, 0, 126, 'ihtd' + i);
    }
  }  
}

function smoothWidth(id, curW, targetW, stepW, mode) {
  diff = targetW - curW;
  if (diff != 0) {  
    newW = (diff > 0) ? curW + stepW : curW - stepW;
    ((document.getElementById) ? document.getElementById(id) : eval("document.all['" + id + "']")).style.width = newW + "px";
    if (smooth_timer) window.clearTimeout(smooth_timer);
    smooth_timer = window.setTimeout( "smoothWidth('" + id + "'," + newW + "," + targetW + "," + stepW + ",'" + mode + "')", 20 );
  }
  else if (mode != "o") ((document.getElementById) ? document.getElementById(mode) : eval("document.all['" + mode + "']")).style.display="none";
}

/*************************/
