// Tim Reeves JavaScript for 94% height, Stand 2009-05-25
// with xml-compliant code to insert an img node for the counter

function getElemId(ident) {
 var Elem;
 if (document.getElementById) { // DOM; IE5, NS6, Mozilla, Opera
     if (typeof document.getElementById(ident) == "object")
     Elem = document.getElementById(ident);
     else Elem = void(0);
     }
 else if (document.all) { // Proprietary DOM; IE4
     if (typeof document.all[ident] == "object")
     Elem = document.all[ident];
     else Elem = void(0);
   }
 else if (document[ident]) { //Netscape alternative
     Elem = document[ident];
   }
 else Elem = void(0);
 return(Elem);
}

function ctrImage() {
	// The hidden counter which gathers statistics
	// Insert the URL call as the source of an image which is added via DOM
	// Safari needs this picture or it misses the horizontal scroller
	// Note that this is outside the HV-Centering, contained in <alles>
	// alert('Counter-Call');
	var ref = '';
	if (document.images && document.referrer && document.referrer.length>0)
	 { ref += escape(document.referrer); }
	var fbt = '..', cookies = ' U';
	if (screen.colorDepth && screen.colorDepth != null) {
		fbt = screen.colorDepth;
		if (fbt.length == 1) { fbt = '0' + screen.colorDepth; }
		}
	if (typeof navigator.cookieEnabled == 'boolean')
		cookies = navigator.cookieEnabled ? ' J' : ' N';
	ref += '&sh='+screen.height+'&sw='+screen.width+'&user='+fbt+cookies;
	var ctrImg = document.createElement('img');
	ctrImg.width = 1;
	ctrImg.height = 1;
	ctrImg.src = '/cgi-bin/counter.pl?id=1&rl=1200&ref=' + ref;
	// ctrImg.src = '/cgi-bin/counter.pl?id=1&rl=0&ref=' + ref;
	var ctrDiv = getElemId('ctrDiv');
	ctrDiv.appendChild(ctrImg);
	return;
}

function neuAufbau() {
	var objBody = getElemId('mybody');
	var objAll  = getElemId('alles');
	var objSite = getElemId('website');
	var objMain = getElemId('main');
	var objHead = getElemId('kopf');

	// Min-Height tweak for old browsers
	var intBodyHeight = objBody.clientHeight;
	var intSiteHeight = objSite.offsetHeight;
	var intAllHeight = (intSiteHeight > intBodyHeight) ? intSiteHeight : intBodyHeight;
	objAll.style.height = intAllHeight + 'px';

	// IE and Opera need this tweak (otherwise always space for degrading scroller)
	objMain.style.overflow = 'hidden';

	// WebKit fails to recalculate 'auto' width when degrading scroller goes
	objHead.style.width = objMain.offsetWidth + 'px';

	// Zeige "Nach oben" wenn die Seite diesen Absatz enthält
	objNachOben = getElemId('nachoben');
	if (objNachOben != null) objNachOben.style.display = 'block';

	return;
}

// This is called by the onload-event of every page
function startUp(pathprefix,testforjavascript) {
	// First we deal with the client height topic
	var objMain = getElemId('main');
	if (objMain != null && typeof objMain.clientHeight == 'number') {
		neuAufbau();
		window.onresize = neuAufbau;
		}
	// Then we perform the ajax-based test for javascript
	if (testforjavascript) { ajaxStartUp(pathprefix); }
	// Now we look if the page contains an Email-Adress
	if (getElemId('email1')) { ajaxOnload(pathprefix); }
	// Finally the statistics counter - but only on initial website entry
	var re = /^Manawa_Birgid_Reviol/;
	if (! re.test(window.name)) {
		// It IS the initial website entry - set the window name
		window.name = 'Manawa_Birgid_Reviol';
		// And call the counter
		ctrImage();
	}
	// Caveat: Since hardly any site sets the window name, it tends to stay this way
	//         meaning that subsequent visits - even hours later - are not noted
	// The alternative is to have the counter called by every page and the data is
	// not recorded by the counter software if the IP address is (time-)locked out.
	// Display the font size selection elements
	// setUserOptions();
	return;
}

// This would be called by the onunload-event of every page
// Except that AdMuncher overwrites that event by default
function unLoadPage() {
	// loading = true;		// For colorflow
	// saveSettings();		// For font size
	return;
}

// Sweet little routines to scroll the page to the top or bottom
function pgtop(elem) {
	var obj = getElemId(elem);
	if (obj && typeof(obj.scrollTop) == 'number') obj.scrollTop = 0;
	else window.location.href = window.location.href;
	return;
}
function pgbot(elem) {
	var obj = getElemId(elem);
	if (obj && typeof(obj.scrollTop) == 'number') obj.scrollTop = obj.scrollHeight;
	return;
}

