// Tim Reeves JavaScript for horizontal centering, Stand 2007-11-28
// 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;
var nutzBreite = 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 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 alles=getElemId('alles');
	var aktBreite = alles.clientWidth;
	var istKleiner = false;
	if (nutzBreite != aktBreite) {
		if (aktBreite < nutzBreite) istKleiner = true;
		nutzBreite = aktBreite;
		var useBreite = (aktBreite < 886) ? 886 : aktBreite;
		getElemId('horbalken').style.width = useBreite + 'px';
		getElemId('allestext').style.width = useBreite + 'px';
		}
	var aktHoehe = alles.clientHeight;
	if (nutzHoehe != aktHoehe) {
		if (aktHoehe < nutzHoehe) istKleiner = true;
		nutzHoehe = aktHoehe;
		var useHoehe = (aktHoehe < 583) ? 583 : aktHoehe;
		getElemId('allestext').style.height = useHoehe + 'px';
		}
	if (istKleiner && (aktHoehe > 583 || aktBreite > 886)) {
		// FF has a nasty problem, scrollers appear although not needed
		var agent=navigator.userAgent.toLowerCase();
		if (agent.indexOf("firefox") != -1)
			window.location.href = window.location.href;
		}
	// if (aktHoehe > 583 && alles.clientHeight != alles.scrollHeight)
	// 	alert(useHoehe + ' / ' + alles.clientHeight + ' / ' + alles.scrollHeight);
	return;
}

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 startUp(pathprefix,testforjavascript) {
	// First we perform the ajax-based test for javascript
	if (testforjavascript) { ajaxStartUp(pathprefix); }
	// Then 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 alles = getElemId('alles');
		if (alles != null && typeof alles.clientHeight == 'number') {
			neuAufbau();
			window.onresize = neuAufbau;
			}
	// }
	// Then 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 = /^Tim_Reeves_Internet_Technologie/;
	if (! re.test(window.name)) {
		// It IS the initial website entry - set the window name
		window.name = 'Tim_Reeves_Internet_Technologie';
		// 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.
	return;
}

function buggyBrowser() {
	var msie = "Sie surfen mit Microsoft Internet Explorer 5 oder 6. Mit diesem\nveralteten Browser wird diese Website nicht optimal dargestellt.\nWenn möglich steigen Sie auf einen modernen Browser um!"
	alert(msie);
	getFirefox();
	return;
}

function ie6repos() {
	// alert('Compensate nasty little IE6 hover / reflow positioning bug');
	// Try setting the focus on all first-level menu elements
	return;
}

function findPos(obj) {
	// In this case, relative to div.main
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			if (obj.className == 'main') break;
			// alert(obj.tagName + ' ' + obj.id + ' ' + obj.className + ' : ' + obj.offsetTop);
			if (obj.tagName == 'TABLE') {
				// Only IE5 / IE6 have a table, they miss counting an LI Element
				curleft += obj.parentElement.parentElement.offsetLeft;
				curtop += obj.parentElement.parentElement.offsetTop;
				}
			else {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
				}
		}
	}
	return [curleft,curtop];
}

var currentflyoutsublevel = 0;
var currentTimerHandle = null;

function showtip(currobj,sublevel,addleft,addtop,text) {
	// alert(currobj.tagName + ' ' + currobj.id + ' ' + currobj.className + ' ' + sublevel);
	if (sublevel < currentflyoutsublevel) return;
	currentflyoutsublevel = (text == '') ? sublevel - 1 : sublevel;
	showtipwork(currobj,addleft,addtop,text);
	return true;
}

function displaytip() {
	var tip = getElemId('fotooltip');
	tip.style.display = 'block';
	currentTimerHandle = null;
	return true;
}

function showtipwork(currobj,addleft,addtop,text) {
	var tip = getElemId('fotooltip');
	if (text == '') {
		if (currentTimerHandle != null) {
			window.clearTimeout(currentTimerHandle);
			currentTimerHandle = null;
			}
		tip.style.display = 'none';
		return true;
		}
	var arrpos = findPos(currobj);
	// alert(arrpos[0] + ' ' + arrpos[1]);
	tip.style.left = (arrpos[0]+addleft) + 'px';
	tip.style.top = (arrpos[1]+addtop) + 'px';
	tip.firstChild.data = text;
	currentTimerHandle = window.setTimeout('displaytip()',600);
	return true;
}

function tipflow(sublevel,addleft,addtop,text,ti,cssclass) {
	if (sublevel < currentflyoutsublevel) return;
	currentflyoutsublevel = (text == '') ? sublevel - 1 : sublevel;
	var obj = getElemId('link' + ti);
	showtipwork(obj,addleft,addtop,text);
	if (!loading) {
		// alert('flow ' + ti + ' ' + cssclass);
		if (cssclass != '') flowup(ti,cssclass); else flowdn(ti);
		}
	return true;
}

// 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;
}

