// layout3.js
// Cross-Browser.com & SitePoint.com - Equal Column Height Demo (3 Column)

if (document.getElementById || document.all) { // minimum dhtml support required
  window.onload = winOnLoad;
}
function winOnLoad()
{
  var ele = xGetElementById('leftColumn');
  if (ele && xDef(ele.style, ele.offsetHeight)) { // another compatibility check
    adjustLayout();
    xAddEventListener(window, 'resize', winOnResize, false);
  }
}
function winOnResize()
{
  adjustLayout();
}
function adjustLayout()
{
  // Get content heights
  var cHeight = xHeight('centerColumnContent');
  var lHeight = xHeight('leftColumnContent');
  lHeight = lHeight + 100;
  var rHeight = xHeight('rightColumnContent');
  var breite = xWidth('centerColumnContent');

  // Find the maximum height
  var maxHeight = Math.max(cHeight, Math.max(lHeight, rHeight));
  if (maxHeight < 550){
  	maxHeight = 550;
  }
  var headerHeight = 201;
  
  var clientHeight = xClientHeight()- headerHeight;
  
  if (maxHeight > clientHeight)
  {
	  // Assign maximum height to all columns (bei Scrollbalken || langen Seiten)
	  xHeight('leftColumn', maxHeight+25);
	  xHeight('centerColumn', maxHeight);
	  xHeight('rightColumn', maxHeight+25);
	  ausrichten(maxHeight + headerHeight,breite);
	}else{
	  // Assign maximum height to all columns
	  xHeight('leftColumn', clientHeight+7);
	  xHeight('centerColumn', clientHeight-18);
	  xHeight('rightColumn', clientHeight+7);
	  ausrichten(clientHeight + headerHeight - 20,breite);
	}


}


function ausrichten (oben, breite) {
	if (document.getElementById("untertitel") != null){
	  //document.getElementById("untertitel").style.top = oben;
	  //document.getElementById("untertitel").style.left = breite/2+150;
	  document.getElementById("drucklayout").style.top = oben-30;
	}
}

function xWidth(e,w)
{
  if(!(e=xGetElementById(e))) return 0;
  if (xNum(w)) {
    if (w<0) w = 0;
    else w=Math.round(w);
  }
  else w=-1;
  var css=xDef(e.style);
  if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
    w = xClientWidth();
  }
  else if(css && xDef(e.offsetWidth) && xStr(e.style.width)) {
    if(w>=0) {
      var pl=0,pr=0,bl=0,br=0;
      if (document.compatMode=='CSS1Compat') {
        var gcs = xGetComputedStyle;
        pl=gcs(e,'padding-left',1);
        if (pl !== null) {
          pr=gcs(e,'padding-right',1);
          bl=gcs(e,'border-left-width',1);
          br=gcs(e,'border-right-width',1);
        }
        // Should we try this as a last resort?
        // At this point getComputedStyle and currentStyle do not exist.
        else if(xDef(e.offsetWidth,e.style.width)){
          e.style.width=w+'px';
          pl=e.offsetWidth-w;
        }
      }
      w-=(pl+pr+bl+br);
      if(isNaN(w)||w<0) return;
      else e.style.width=w+'px';
    }
    w=e.offsetWidth;
  }
  else if(css && xDef(e.style.pixelWidth)) {
    if(w>=0) e.style.pixelWidth=w;
    w=e.style.pixelWidth;
  }
  return w;
}

