deb('Entering layout.js');
if (!layoutDefined) {
  var G_topMarginHeight = 100;
  var G_leftMarginWidth = 170;
  var G_leftScrollerHdHeight = 22;
  var G_leftScrollerBodyHeight = 200;

  var scrollbarWidth;
  var windowHeightA;
  var windowWidthA;
  var windowHeight;
  var windowWidth;
  var windowHeightMin = 700;
  var windowWidthMin = 500;

  var G_windowHeightIeAdjustment = 5;
  var G_scrollbarWidthNs = 16;
  var G_scrollbarWidthIe = 20;
  var G_contentPadding = 20;

}
function calcSizes() {
  if (ns) {
    scrollbarWidth = G_scrollbarWidthNs;
    windowHeightA = window.innerHeight;
    windowWidthA = window.innerWidth;
    windowHeight = windowHeightA;
    windowWidth = windowWidthA;
  } else {
    scrollbarWidth = G_scrollbarWidthIe;
    windowHeightA = document.body.offsetHeight;
    windowWidthA = document.body.offsetWidth;
    windowHeight = windowHeightA - G_windowHeightIeAdjustment;
    windowWidth = windowWidthA - scrollbarWidth;
  }
  deb('Exiting calcSizes():' + windowWidthA + ', ' +
      windowWidth + ', ' + windowHeightA + ', ' + windowHeight);
}

function mainContentCompSetSize() {
  var content = document.getElementById("MainContentDiv");
  if (ns) {
    if (content.offsetHeight > windowHeight - G_topMarginHeight) {
      content.style.width = windowWidth - getRealLeft(content) -
	G_contentPadding*2 - scrollbarWidth;
    } else {
      content.style.width = windowWidth - getRealLeft(content) -
	G_contentPadding*2;
    }
  } else {
    content.style.width = windowWidth - getRealLeft(content);
  }

  return content;
}

function topMarginCompSetSize() {
  var element = document.getElementById("HeaderDiv");
  if (ns) {
    element.style.width="100%";
  } else {
    element.style.width=windowWidth;
  }
  return element;
}

deb('DEF: leftMarginCompSetSize()');
function leftMarginCompSetSize() {
  deb('Entering: leftMarginCompSetSize()');
  var element = document.getElementById("LeftMarginDiv");
  var content = document.getElementById("MainContentDiv");
  var dupa = windowHeight  + ',' + content.offsetHeight;
  deb('C: ' + content.offsetHeight);
  if (content.offsetHeight > windowHeight - G_topMarginHeight) {
    element.style.height = content.offsetHeight;
  } else {
    element.style.height = windowHeight - G_topMarginHeight
  }
  deb('E: ' + element.style.height);
  return element;
}

function leftScrollerCompSetPosition() {
  var element = document.getElementById('LeftMarginMenuDiv2');
  var header = document.getElementById('LMDH');
  /* 100 - header height, 200 - scroller height, 22 -
     / scroller header height. */

  /*element.style.top = windowHeight - 200 - 100 - 22;
   */
  if (ns) {
    //    element.style.position = "fixed";
    //    element.style.top = windowHeight - scrollHeight - scrollHdHeight;
    element.style.top = windowHeight - G_topMarginHeight - G_leftScrollerBodyHeight
      - 134
      - G_leftScrollerHdHeight
      + scrollbarWidth;

  } else {
    element.style.top = windowHeight - G_topMarginHeight - G_leftScrollerBodyHeight
      - 130
      - G_leftScrollerHdHeight 
      + scrollbarWidth;
;
  }
  return element;
}

function redrawDivs() {
  deb('Entering: redrawDivs()');
  calcSizes();
  var resizeFlag = 0;
  if (windowHeightA < windowHeightMin - 50) {
    resizeFlag = 1;
    windowHeightA = windowHeightMin + 100;
    windowWidthA += scrollbarWidth / 2; /* Heuristic increment  */
  } 
  if (windowWidthA < windowWidthMin - 50) {
    resizeFlag = 1;
    windowWidthA = windowWidthMin + 100;
    windowHeightA += 130;			/* Heuristic increment  */
  }
  if (resizeFlag == 1) {
    window.resizeTo(windowWidthA, windowHeightA);
    calcSizes();
  }

  var elem = topMarginCompSetSize();
  elem.style.display = "none";
  elem.style.display = "block";
  
  elem = leftMarginCompSetSize();
  elem.style.display = "none";
  elem.style.display = "block";
  
  elem = mainContentCompSetSize();
  elem.style.display = "none";
  elem.style.display = "block";

  elem = leftScrollerCompSetPosition();
  deb("Exiting: redrawDivs()");
  //  elem.style.display = "none";
  //  elem.style.display = "block"; 
}        

function subscribeToMailList() {
  if (!G_showSubscribeInvitation)
    return;
  document.write('<br><br><br><br>');
  document.write('<div class="sMail">');
  document.write('<table align=center  cellpadding=4>');
  document.write('<tr><td align="center" style="width:400;background-color:#cccccc;color:#777777" >');
  document.write('<script>linkTo("MailListMain", "Click here to learn about our mail list")</script>');
  document.write('</td><td width=50></td></tr>');
  document.write('</table></div>');
}
