// Copyright 2006 Master Kitchen GmbH

var gSbarRHeight; // remember the minimum height for the right sidebar

function DoLoadActions() {
	gSbarRHeight = parseInt(document.getElementById('sidebarRight').offsetHeight);
	AdjustContentHeight();
}


function AdjustContentHeight() {
	var margContent = 45;
	var fcMargTop = 22;
	var fcMargBtm = 18;
	var t = document.getElementById('wrapMiddle').offsetTop;
	var fc = 0; //document.getElementById('fixedContent').offsetHeight;
	var b = document.getElementById('wrapFooterLeft').offsetHeight;
	var ih = document.getElementById('imageBottom').offsetHeight;
	
	// remember height of right column
	//var old_chr = document.getElementById('sidebarRight').offsetHeight;
	//old_chr = parseInt(old_chr);
	// make content as high to fit the window height
	var h = getViewportHeight() - t - b;
	//document.getElementById('wrapMiddle').style.height = h + "px";
	var ch = h - margContent - fc + fcMargTop + fcMargBtm;
	if (ch < 1)
		ch = 1;
	document.getElementById('contentLeft').style.height = ch + "px";
	if (document.getElementById('contentMiddleCol')) {
		var textH = document.getElementById('contentText').offsetHeight;
		if (textH + 30> ch) {
			document.getElementById('contentMiddleCol').style.height = textH + 38 + "px";
		} else {
			document.getElementById('contentMiddleCol').style.height = ch + "px";
		}
	}
	
	// Position image on bottom right
	var hr = getViewportHeight() - t - ih;
	//document.getElementById('sidebarRight').style.height = hr + "px";
	var chr = hr - margContent - fc + fcMargTop + fcMargBtm;
	if (chr < 1)
		chr = 1;
	//document.getElementById('sidebarRight').style.height = chr + "px";
	if (chr > gSbarRHeight) {
		document.getElementById('sidebarRight').style.height = chr + "px";
	} else {
		document.getElementById('sidebarRight').style.height = gSbarRHeight + "px";
		ch = gSbarRHeight +	document.getElementById('imageBottom').offsetHeight - document.getElementById('wrapFooterLeft').offsetHeight;
		// set height of content
		document.getElementById('contentLeft').style.height = ch + "px"; 
	}
}

function getViewportWidth() {
	var theWidth = 0;
	if( document.documentElement && document.documentElement.clientWidth ) {
		theWidth = document.documentElement.clientWidth;
	}
	else if( document.body && document.body.clientWidth ) {
		theWidth = document.body.clientWidth;
	}
	else if( window.innerWidth ) {
		theWidth = window.innerWidth - 18;
	}
	return theWidth;
}

function getViewportHeight() {
	var theHeight = 0;
	if( document.documentElement && document.documentElement.clientHeight ) {
		theHeight = document.documentElement.clientHeight;
	}
	else if( document.body && document.body.clientHeight ) {
		theHeight = document.body.clientHeight;
	}
	else if( window.innerHeight ) {
		theHeight = window.innerHeight - 18;
	}
	return theHeight;
}

function getDocHeight() {
  var  myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
 return myHeight;
}

function getDocWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

var gBrowserType = navigator.userAgent.toLowerCase();
SelectCSS();

function SelectCSS() {
	//if((gBrowserType.search("msie")!= -1) && (gBrowserType.search("firefox")!= -1)) {
	if(gBrowserType.search("safari")!= -1) {
		document.write('<link href="fileadmin/Templates/BGG_MainT_v2/BGG_simpleBrw.css" rel="stylesheet" type="text/css" />');
	}	
}

function HasAdvancedFunctions() {
	var hasAdvanced = false;
	if(gBrowserType.search("msie")!= -1) {
		if (navigator.appVersion.substring(22, 23) > "4") {
			hasAdvanced = true;
		}
	}
	else if (gBrowserType.search("firefox")!= -1) {
			hasAdvanced = true;
	}
	return hasAdvanced;
}

if (HasAdvancedFunctions()) {
	onresize=AdjustContentHeight;
}