//
function addLoadEvent(func){
	var oldonload=window.onload;
	if (typeof window.onload!='function'){
		window.onload=func;
	}else{
		window.onload=function(){
			oldonload();
			func();
		}
	}
	return;
}
//
function addEvent_lnw(objNode,evtType,funcHandler, uCapture){
	if(objNode.addEventListener){
		(!uCapture) ? objNode.addEventListener(evtType,funcHandler,false):objNode.addEventListener(evtType,funcHandler,uCapture);
		return true;
	}else if(objNode.attachEvent){
		return(objNode.attachEvent('on'+evtType,funcHandler));
	}else{
		objNode['on'+evtType]=funcHandler;
	}
	return;
}
//
var programm_lnw = false;
addLoadEvent(init_lnw);
//
function init_lnw()
{
	resize_lnw();
	addEvent_lnw(top.window,'resize',resize_lnw,false);
}
//
function resize_lnw()
{
	if (programm_lnw)
	{
		setDivHeight('col1_content',250);
	} else
	{
		setDivHeight('col1_content',226);
	}
}
//
function setDivHeight(container, diff)
{
	scrHeight = document.getElementById(container).scrollHeight;
	divHeight = f_clientHeight() < (diff+15) ? 1 : f_clientHeight()-diff-15;
	divHeight = divHeight > scrHeight ? scrHeight : divHeight;
	document.getElementById(container).style.height = divHeight + 'px';
	//alert(divHeight + ' ' + scrHeight);
	getTab();
}
//
function f_clientHeight()
{
	return f_filterResults
	(
	window.innerHeight ? window.innerHeight : 0,
	document.documentElement ? document.documentElement.clientHeight : 0,
	document.body ? document.body.clientHeight : 0
	);
}
//
function f_filterResults(n_win, n_docel, n_body)
{
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
//
function showHide(list)
{
	document.getElementById(list).style.display=="block" ? document.getElementById(list).style.display="none" : document.getElementById(list).style.display="block";
	resize_lnw();
}
//
function showTab(tab)
{
	document.getElementById('li_route').style.display = 'inline';
	document.getElementById('li_stationen').style.display = 'inline';
	document.getElementById('li_slideshow').style.display = 'inline';
	document.getElementById('li_route_in').style.display = 'none';
	document.getElementById('li_stationen_in').style.display = 'none';
	document.getElementById('li_slideshow_in').style.display = 'none';
	//
	document.getElementById(tab).style.display = 'block';
	document.getElementById('li_'+tab).style.display = 'none';
	document.getElementById('li_'+tab+'_in').style.display = 'inline';
}
//
function switchTab(tab)
{
	document.cookie = 'lnw_tabs2010='+tab+'; expires=Sat, 04 Jul 2020 09:00:30 GMT;';
	document.getElementById('route').style.display = 'none';
	document.getElementById('stationen').style.display = 'none';
	document.getElementById('slideshow').style.display = 'none';
	showTab(tab);
}
//
function getTab() {
	tab = readCookie('lnw_tabs2010');
	tab = tab!= '' ? tab : 'slideshow';
	showTab(tab);
}
//
function saveEvent(id)
{
	events = readCookie('lnw_my_events2011');
	if (events.search(id) > 0)
	{
		message = 'Diese Veranstaltung wurde schon einmal vorgemerkt!';
	}
	else
	{
		events = events ? events+'#'+id : '#'+id;
		document.cookie = 'lnw_my_events2011='+events+'; expires=Sat, 29 Jul 2011 09:00:30 GMT;';
		message = 'Die Veranstaltung wurde unter "Mein Programm" vorgemerkt.';
		document.getElementById('my_prog_count').innerHTML = events.split('#').length-1;
	}
	alert(message);
	
}
//
function readCookie(name) {
   var nothing = '';
   var lnwCookie = document.cookie;

   // startposition of key=value pair
   var posName = lnwCookie.indexOf("; " + name + "=");
   if (posName == -1) {
      // first entry in list?
      if (lnwCookie.indexOf(name + "=") == 0) posName = 0;
      // no? return null
      else return nothing;
   }

   // search start- and endpostion of value
   var wertAnfang = lnwCookie.indexOf("=", posName)+1;
   var wertEnde = lnwCookie.indexOf(";", posName+1);
   if (wertEnde == -1) wertEnde = lnwCookie.length;

   // read value and return it
   var wert = lnwCookie.substring(wertAnfang, wertEnde);
   return unescape(wert);
}

