// Tim Reeves JavaScript for BiR - basics for every page

// - Vertical scrollbar elimination FF1.5
// - Call of ajaxOnload() if the page needs it (page then also needs ajax.js)
// - pgtop()

// Stand 2007-08-31

// FAUSTREGEL: READ an attribute and SET a style (with a text string) !!!

var loading = true;
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 */
	var curHeight = 0;
	var myDiv=getElemId('myhtml');
	if (myDiv != null && typeof myDiv.clientHeight == 'number') {
		curHeight = myDiv.clientHeight;
		}
	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) {
		nutzHoehe = tHoehe;
		getElemId('myhtml').style.height = nutzHoehe + 'px';
	}
	return;
}

function getFirefox() {
	var getFF = "Am Besten holen Sie den modernen Gratis-Browser \"Firefox\" \nper DownLoad. Wollen Sie jetzt Firefox herunterladen?"
	var ans = confirm(getFF);
	if (ans == true) location.href = 'http://www.mozilla-europe.org/de/products/firefox/';
	return;
}

function ctrImage() {
	// The hidden counter which gathers statistics
	// Insert the URL call as the source of an image which is added via DOM
	// 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=1800&ref=' + ref;
	// ctrImg.src = '/cgi-bin/counter.pl?id=1&rl=0&ref=' + ref;
	// The insertion into the DOM is not needed for FF1.5, IE6, IE7 and Opera9 -
	// it's enough to perform the "src" assignement to a non-linked-in node
	// But do it anyway, now we're here :)
	var ctrDiv = document.getElementById('ctrDiv');
	ctrDiv.appendChild(ctrImg);
	return;
}

function initPage() {
	// Set the window name to allow us to know if this is the inital website entry
	// alert('initPage: window.name = ' + window.name);
	var re = /^Biblische_Reisen_Website_de/;
	if (! re.test(window.name)) {
		// It IS the initial website entry - set the window name
		window.name = 'Biblische_Reisen_Website_de';
		// 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.
	// NOTE that the window name is tab-specific in browsers with tabs
	return;
}

function startUp() {
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf('firefox/1.5') != -1) {
		var tHoehe = getClientHeight();
		if (tHoehe > 0) {
			neuAufbau();
			window.onresize = neuAufbau;
		}
	}
	if (agent.indexOf('msie 6.0') != -1 && document.getElementById) {
		// MSIE 6.0 hat ein Darstellungs-Timing-Bug - refresh lower corner position
		var ecke = null;
		if (document.getElementById('ecke_oben')) {
			ecke = document.getElementById('ecke_oben');
			ecke.className = 'menu_ecke_unten';
			}
		if (document.getElementById('ecke_mitte')) {
			ecke = document.getElementById('ecke_mitte');
			ecke.className = 'menu_ecke_unten';
			}
		if (document.getElementById('ecke_unten')) {
			ecke = document.getElementById('ecke_unten');
			ecke.className = 'menu_ecke_unten';
			}
		}
	// Only call Ajax if there is Ajax work to do
	// i.e. look if the page contains an Email-Address, Reisenr. or Country List
	// Provisionspartner: Now we must always call it for html-files.
	var docpath = window.location.pathname;
	var pathlen = docpath.length;
	var docext = docpath.slice(pathlen-5);
	if (document.getElementById) {
		if (docext == '/' || docext == '.html' || document.getElementById('email1') ||
			 document.getElementById('tournr1') || document.getElementById('laenderabsatz')) {
			ajaxOnload();
			}
	}
	else {
		alert("Sie verwenden ein sehr veralteter Browser, mit\ndem diese Website nicht korrekt dargestellt wird.");
		getFirefox();
	}
	// Set window name and call the counter if initial website entry
	initPage();
	return;
}

function pgtop () {
	var obj = getElemId('contscroll');
	if (obj.scrollTop) obj.scrollTop=0;
	else window.location.href = window.location.href;
	return;
}
