window.onload = Kf_Init;

function Kf_2D(v)
{	// prints a leading 0 (for 2 digits)
	return (v<=9) ? "0" + v : v;
}

function Kf_PrintLastModified(t)
{	// prints date&time of last modification of current document in the form DD.MM.YYYY
	var result = "unsupported!";
	if (document.lastModified) {
		var d = new Date (document.lastModified);
		var y;
		if (d.getYear() > 2000) {
			y = d.getYear();
		}
		else {
			y = d.getYear() + 1900;
		}
		result = t + Kf_2D(d.getDate()) + "." + Kf_2D(d.getMonth()+1) + "." + y + " " + Kf_2D(d.getHours()) + ":" + Kf_2D(d.getMinutes());
	}
	return result;
}

// Here we realize a MouseOver-Effect on all img-tags of or in id="MouseOver"
// all img-tags of class MouseOver toggle between filename.ext and filename_p.ext
// they only must be contained in e. g. a <div id="MouseOver">
var mover_suffix = "_p";	
var mover_id	 = "MouseOver";

// the following lovely code is mostly inhertied from http://www.quirksmode.org/js/mouseov.html
var w3cdom = (document.createElement && document.getElementsByTagName);
var imgs_norm  = new Array();
var imgs_mover = new Array();
var mover_suffix = "_p";	

function Kf_Init()
{
	if ( ! w3cdom)										// not for old browsers
		return;
	var movers = document.getElementById(mover_id);		// get all elements in document of class mover_id
	if ( ! movers)
		return;
	var imgs   = movers.getElementsByTagName("img");	// get all img-tags in them
	for (var i=0; i < imgs.length; i++ ) {				// parse all img-tags
		imgs[i].onmouseover = Kf_Mover;					// set onmouseover-Event-Handler
		imgs[i].onmouseout  = Kf_Mout;					// set onmouseout-Event-Handler
		var pi = imgs[i].src.lastIndexOf('.');			// get index of last '.' in original filename
		imgs_norm[i] = new Image();						// store normal image filename.ext
		imgs_norm[i].src = imgs[i].src;
		imgs_mover[i] = new Image();					// store partner image filename_p.ext
		imgs_mover[i].src = imgs[i].src.substring(0,pi) + mover_suffix + imgs[i].src.substring(pi);
		imgs[i].number = i;								// save number in new property of img-tags
	}
}

function Kf_Mover() { this.src = imgs_mover[this.number].src; }	// use filename_p.ext
function Kf_Mout()  { this.src = imgs_norm[this.number].src;  }	// use filename.ext

var mypopup = null;

// the following code opens a new info-window
function Kf_Info( url, title, w, h )
{
	var ow, oh;
	if (mypopup && (! mypopup.closed))
		mypopup.close();
	ow=w;
	oh=h;
	if (document.all) {	// this is an IE
		ow=w+20;
		oh=h+20;
	}
	ow+=10;
	// alert("w="+w+" ow="+ow+" h="+h+" oh="+oh);
	var pars =	"innerWidth="  +w+","
			+"innerHeight="+h+","
			+"width="+ow+","
			+"height="+oh+","
			+"dependent=yes,"
			+"location=no,"
			+"menubar=no,"
			+"resizable=yes,"
			+"scrollbars=yes,"
			+"status=no,"
			+"toolbar=no,";
	mypopup = window.open(url,title,pars);
	if (window.focus)	mypopup.focus();
	return false;
}

// the follwoing code builds array args from URL-parameters
// to be used as args = new Kf_Args(window.location.search)
// access to URL-parameters then by args["para2"]

function Kf_Args( url ) {
	if ( ! url || ! url.length)
		return;
	var r =	unescape(url).substr(1);
	var nvs = r.split("&");
	for ( var a = 0; a < nvs.length; a++ ) {
		// if ( a  == 0 ) {
		// 	alert(self.location + " ...");
		// }
		var nv = nvs[a];
		var i = nv.indexOf("=");
		var n = nv.substring(0,i);
		var v = nv.substring(i+1,nv.length);
		this[n]=v;
		// alert(">> " + n + "=" +v);
	}
}

function Kf_RebuildArgString() {
	var res = "";
	for (arg in args) {
			res += "&" + escape(arg) + "=" + escape(args[arg]);
	}
	return res;
}

function Kf_InitInputFromArg( args, name, readonly ) {
	if ( args[name] ) {
		var f = document.getElementById(name);
		if (f) {
			f.value=args[name];
			f.readOnly=readonly;
		}
	}
}

function Kf_GetCookieValue(name) {
	a = document.cookie;
	res = '';
	found = false;
	while (a != '' && ! found) {
		while (a.substr(0,1) == ' ') {
			a = a.substr(1,a.length);
		}
		cookiename = a.substring(0,a.indexOf('='));
		if (a.indexOf(';') != -1) {
			cookiewert = a.substring(a.indexOf('=')+1,a.indexOf(';'));
		}
		else {
			cookiewert = a.substr(a.indexOf('=')+1,a.length);
		}
		if (name == cookiename) {
			res = cookiewert;
			found = true;
			Kf_got_a_cookie = true;
		}
		i = a.indexOf(';')+1;
		if (i == 0) {
			i = a.length;
		}
		a = a.substring(i,a.length);
	}
	return res;
}

function Kf_InitInputFromCookie( name ) {
	var f = document.getElementById(name);
	if (f) {
		f.value = Kf_GetCookieValue(name);
	}
}

function Kf_InitInputFromDate( name ) {
	var d = new Date();
	var D = d.getDate();
	var M = d.getMonth() + 1;
	var Y = d.getYear();
	if (Y > 2000) {
		// this is IE
		Y -= 2000;
	}
	else {
		// this are the others
		Y -= 100;
	}
	var h = d.getHours();
	var m = d.getMinutes();
	var f = document.getElementById("DatAnm");
	f.value=Kf_2D(D)+"."+Kf_2D(M)+"."+Kf_2D(Y)+" "+Kf_2D(h)+":"+Kf_2D(m);
	f.readOnly=true;
}

function ToggleVisibility(id) {
	var o = document.getElementById(id);
	var v = o.style.visibility;
	if ( v == "visible" ) {
		v = "hidden";
	}
	else {
		v = "visible";
	}
	o.style.visibility = v;
}

function Statistics() {
	top.text.location="statistics.html";
}

function Kf_GetInnerWidth() {
	var myWidth = 0;
	if( typeof(window.innerWidth) == 'number' ) {
		// Non-IE
		myWidth = window.innerWidth;
	}
	else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		// IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	}
	else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		// IE 4 compatible
		myWidth = document.body.clientWidth;
	}
	// alert("w=" + myWidth);
	return myWidth;
}

function Kf_GetInnerHeight() {
	var myHeight = 0;
	if( typeof(window.innerHeight) == 'number' ) {
		// Non-IE
		myHeight = window.innerHeight;
	}
	else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		// IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	}
	else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		// IE 4 compatible
		myHeight = document.body.clientHeight;
	}
	return myHeight;
}

var args = new Kf_Args( window.location.search );


