// Tim Reeves JavaScript for vertical centering, Stand 2006-11-23
// with xml-compliant code to insert an img node for the counter

// FAUSTREGEL: READ an attribute and SET a style (with a text string) !!!

var nutzHoehe = 0;

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 getClientHeight() {
	/* Get the EFFECTIVE client height of an object, i.e. excluding any scrollbar */
	/* Note that offsetHeight (a) includes any scrollbar, and (b) in older browsers */
	/* is only available for the window itself (and maybe document.body) so in fact */
	/* our only chance is to see if the browser provides clientHeight or just give up */
	/* BTW: scrollHeight also includes the space of the scrollbars. */
	var curHeight = 0;
	var myDiv=getElemId('alles');
	if (myDiv != null) {
		if (typeof myDiv.clientHeight == 'number') {
			curHeight = myDiv.clientHeight;
			// alert('clientHeight: ' + curHeight);
			}
		}
	// return 0;
	return curHeight;
}

function neuAufbau() {
	/* Note that setting 'height' (if the object has that attribute) does not change */
	/* the objects clientHeight (that which is bequethed), but clientHeight is read only */
	var tHoehe = getClientHeight();
	if (nutzHoehe != tHoehe) {
		// alert('onresize clientHeight: ' + tHoehe);
		nutzHoehe = tHoehe;
		getElemId('mitte').style.height = nutzHoehe + 'px';
	}
	return;
}

function ctrImage(n) {
	// 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=' + n + '&rl=1200&ref=' + ref;
	// ctrImg.src = '/cgi-bin/counter.pl?id=' + n + '&rl=0&ref=' + ref;
	var ctrDiv = getElemId('ctrDiv');
	ctrDiv.appendChild(ctrImg);
	return;
}

// This is called by the onload-event of every page
function startUp(n) {
	// First we deal with the client height topic
	var agent=navigator.userAgent.toLowerCase();
	// MSIE gets it dealt with via CSS-Expressions
	if (agent.indexOf("msie") == -1) {
		// All other browsers get it via event handler
		var tHoehe = getClientHeight();
		if (tHoehe > 0) {
			neuAufbau();
			window.onresize = neuAufbau;
		}
	}
	// Then we look if the page contains an Email-Adress
	// Note that the page must then itself include the Ajax library
	if (getElemId('email1')) { ajaxOnload(); }
	// Finally the statistics counter - but only on initial website entry
	var re = /^Jacks_International/;
	if (! re.test(window.name)) {
		// It IS the initial website entry - set the window name
		window.name = 'Jacks_International';
		// And call the counter
		ctrImage(n);
	}
	// 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.
	return;
}

// Sweet little routine to scroll the page back to the top
function pgtop () {
	var obj = getElemId('contscroll');
	if (obj && typeof(obj.scrollTop) == 'number') obj.scrollTop = 0;
	else window.location.href = window.location.href;
	return;
}
