﻿var txt = {
	"søg": "Søg"
};

function checkfield() {
	var f = document.forms[0];
	for (var i in txt) {
	f[i].onfocus = ffocus;
	f[i].onblur = fblur;
	f[i].value = txt[i];
	}
}

function ffocus() {
	if (this.value==txt[this.name]) this.value="";
}

function fblur() {
	if (this.value=="") this.value=txt[this.name];
}

function sizePage(){
	var theInnerHeight = 0, thepagecontentHeight = 0, theBodyHeight = 0, theTopHeight = 0, bottomBarHeight = 0;
	var hasNewsBoxes = !!document.getElementById('newsboxHolder');
	var hasContentDiv = !!document.getElementById('content');
	
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		theInnerHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		theInnerHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		theInnerHeight = document.body.clientHeight;
	}

	theBodyHeight = document.body.offsetHeight
	theTopHeight = 127;
	bottomBarHeight = hasNewsBoxes ? 240 : 50;
	var textAreaHeight = hasContentDiv ? document.getElementById('content').offsetHeight : (document.getElementById('wrapper').offsetHeight - theTopHeight - bottomBarHeight);
	
	if (!hasNewsBoxes && textAreaHeight < 537) textAreaHeight = 537;
	if (!hasNewsBoxes) textAreaHeight = textAreaHeight + 20;

	contentHeight = textAreaHeight; //theInnerHeight - (theTopHeight + bottomBarHeight);

	if (hasContentDiv) {
		document.getElementById('contentBackground').style.height = contentHeight +'px';
	} else {
		//
	}
}

function calculateBottomBar() {
	sizePage();
	return;

// NOTE: REST OF FUNCTION NEVER RUNS	

	var theInnerWidth = 0, theInnerHeight = 0, theInnerHalfWidth = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		theInnerWidth = window.innerWidth;
		theInnerHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		theInnerWidth = document.documentElement.clientWidth;
		theInnerHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		theInnerWidth = document.body.clientWidth;
		theInnerHeight = document.body.clientHeight;
	}

	theInnerHalfWidth = (theInnerWidth)/2;
	var theBodyHeight = 0;
	theBodyHeight = document.getElementsByTagName('body')[0].offsetHeight;
	var theBottomBar = document.getElementById('footerHolder');
	
	if (theBodyHeight > theInnerHeight){
		var headerHeight = 77;
		var textAreaHeight = document.getElementById('mainContentText').offsetHeight;
		var bgColorHeight = headerHeight+textAreaHeight+30; //30 is cosmetic
		if((headerHeight+textAreaHeight+225)> theInnerHeight){//alert("test")
			bgColorHeight = headerHeight+textAreaHeight+30
			if(textAreaHeight+100>theInnerHeight){
				document.getElementsByTagName('body')[0].style.height=headerHeight+textAreaHeight+250+'px';
			}//else{
				//document.getElementsByTagName('body')[0].style.height=headerHeight+textAreaHeight+250+'px';
			//}
		}else{
			bgColorHeight = headerHeight+textAreaHeight+100
		}
		document.getElementById('contentBackground').style.height = bgColorHeight +'px';
	} else {
		var theCorrectPosition = theInnerHalfWidth - 443;
		var headerHeight = 77;
		var textAreaHeight = document.getElementById('mainContentText').offsetHeight;
		var bgColorHeight = headerHeight+textAreaHeight
		if(bgColorHeight<theInnerHeight ){
			bgColorHeight = theInnerHeight - (250)
		}
		if((headerHeight+textAreaHeight+220)> theInnerHeight){
			if(textAreaHeight<344){
				bgColorHeight = headerHeight+textAreaHeight-30
			}else{
				bgColorHeight = headerHeight+textAreaHeight+100
			}
			
			document.getElementsByTagName('body')[0].style.height=headerHeight+textAreaHeight+100+'px';

		}else{
			bgColorHeight = theInnerHeight-(headerHeight+127)
		}
		document.getElementById('contentBackground').style.height = bgColorHeight +'px';


	}
}



/* AKTIVERER DE FORSKELLIGE FUNKTIONER PÅ ONLOAD */
function activateFunctions(){
	//checkfield(); //skal aktivers når søg aktiveres
	calculateBottomBar();
}

//window.onload = activateFunctions;
