/* DBAG JavaScript Library */
var ns4 = (document.layers)?1:0;
var dom = (document.getElementById && !document.all);
var ie4 = (document.all)?1:0;
var opr = navigator.userAgent.indexOf("Opera");
var moz = navigator.appName=="Netscape" && navigator.appCodeName=="Mozilla" && !document.all;
var mac = navigator.userAgent.indexOf("Mac")!= -1;

window.status = "Die Bahn"; // writes Javascript default message in browser status bar

// calculate the height of a layer
function getDivsHeight() {
	var iDivsHeight = 0;
	for(var i=0; i < arguments.length; i++) {
		if (document.getElementById(arguments[i]))
			iDivsHeight += document.getElementById(arguments[i]).offsetHeight;
	}
	return iDivsHeight;
}

// set the height of the back main layer in order to move the footer
function setDivContentMinHeight() {
	var oDivcontent, iWinInnerHeight, tmpHeight;
	var mozCorrection = moz ? -1 : 0;
	oDivcontent = document.getElementById(arguments[0]); //assumes first passed object as name for the content area layer
	oStopperDiv = document.getElementById(arguments[1]); // retrieve stopper div object
	
	iWinInnerHeight = document.body.clientHeight; // store window height of the inner browser area temporarily

	if (arguments.length == 4) {
		tmpHeight = getDivsHeight(arguments[2], arguments[3]);
	}
	else if (arguments.length == 3) {
		tmpHeight = getDivsHeight(arguments[2]);
	} // calculate the height of the page elements except the content area; using the getDivsHeight function
	
	if(oStopperDiv) {
		if (iWinInnerHeight > (tmpHeight + oStopperDiv.offsetTop + oStopperDiv.offsetHeight)) {
			oDivcontent.style.height = iWinInnerHeight - tmpHeight + mozCorrection;
		} else {
			oDivcontent.style.height = oStopperDiv.offsetTop + oStopperDiv.offsetHeight + mozCorrection;
		}
	}
		//if there is more space on the page than the header and footer height, than the main layer is set to a new height
}

// Wrapper function to apply the changes to the footer / main layers if DOM browser detected
// loadEvent triggers a bugfix for MSIE 5.0 and footer bar placement, "true" is for function calls in onLoad events,
// "false" is default and for onResize events
function gotopage(page){
	//alert(page);
	document.location=page;
}
function popupWin() {
	
	setTimeout('windowProp()', 0); 		// delay 3 seconds before opening
}
function windowProp() {
	//newWindow = window.open('festival.html','newWin','width=1000,height=500');
	//newWindow.document.write(text);
	window.open('festival.html','newWin','width=830,height=630');
	//newWindow.document.write(text);
	
	//window.open("festival.html");
	//setTimeout('closeWin(newWindow)', 50000);	// delay 5 seconds before closing
}
function closeWin(newWindow) {
	newWindow.close();				// close small window and depart
}

function init(loadEvent) {
	
	if (!ns4) {
		setDivContentMinHeight('main', 'stopper', 'header', 'footer');
		footero=document.getElementById('footer');
		if (footero)
			footero.style.visibility='visible';
	}
	if (loadEvent && ie4 && !ns4 && ((navigator.appVersion.indexOf("MSIE 5.0")!= -1) || (mac))) {
		window.resizeBy(1,1);
		window.resizeBy(-1,-1);
	}
	if (loadEvent)
		initImages(); // preload all portalnavigation images
}

// Wrapper function to apply the changes to the footer on the startpage
// only used in startpage because of different div-container structure
function initStart(loadEvent) {
	if (!ns4) {
		setDivContentMinHeight('content', 'stopper', 'header', 'footer');
		footero=document.getElementById('footer');
		footero.style.visibility='visible';
	}
	if (loadEvent && ie4 && !ns4 && ((navigator.appVersion.indexOf("MSIE 5.0")!= -1) || (mac))) {
		window.resizeBy(1,1);
		window.resizeBy(-1,-1);
	}
}

// onMouseOvers for the PortalNavigation
var initSet = false;

function initImages() {
	if (numPortalImages && imgInactNames && imgActNames) {
		for (var i=0; i< numPortalImages; i++) {
			var tempImage = new Image();
			tempImage.src = imgInactNames[i];
			tempImage.src = imgActNames[i];
		}
	}
}

function actImg(obj, num) {
	if (document.images && !ns4 && imgActNames) {
		document.getElementById(obj.id).src = imgActNames[num];
	}
}

function inActImg(obj, num) {
	if (document.images && !ns4 && imgInactNames) {
		document.getElementById(obj.id).src = imgInactNames[num];
	}
}

// popup window opener service function for standard content pages and large view on pictures
var marginWidth = 50;
var marginHeight = 300;
var top = 60;
var left = 80;
var picLarge;

function picLrgOpn(src, width, height) {
	var winWidth = width + marginWidth;
	var winHeight = height + marginHeight;
		
	if (picLarge!=null && !picLarge.closed) {
		picLarge.resizeTo(winWidth, winHeight);
		picLarge.location.href=src;
		picLarge.focus();
	} else {
		eval('picLarge = window.open(src, "_blank", "width=' + winWidth + ',height=' + winHeight + ',top=' + top + ',left=' + left + ',toolbar=no,scrollbars=yes,resizable=yes,menubar=no,location=no,dependent=no");');	
		picLarge.resizeTo(winWidth, winHeight);
		picLarge.focus();
	}
}

// print view opener
var printPopup;
var printPopupHeight=510;
var printPopupWidth=603;

function printOpen(src) {
	if (printPopup!=null && !printPopup.closed) {
		printPopup.location.href=src;
		printPopup.focus();
	} else {
		eval('printPopup = window.open(src, "_blank", "width=' + printPopupWidth + ',height=' + printPopupHeight + ',top=' + top + ',left=' + left + ',toolbar=no,scrollbars=yes,resizable=yes,menubar=no,location=no,dependent=no");');
		printPopup.focus();
	}	
}

// recommend view opener
var recommendPopupHeight=510;
var recommendPopupWidth=401;

function recommendOpen(src) {
	var recommendPopup = null;
	eval('recommendPopup = window.open(src, "_blank", "width=' + recommendPopupWidth + ',height=' + recommendPopupHeight + ',top=' + top + ',left=' + left + ',toolbar=no,scrollbars=yes,resizable=yes,menubar=no,location=no,dependent=no");');
	recommendPopup.focus();
}
	
// switch Element to visible when javascript is enabled, example: button bar in popup
function showElement(elemName) {
		if (!ns4) {
				elem=document.getElementById(elemName);
				if (elem != null)
					elem.style.visibility='visible';
		}
}
function simplifySpecialChars(s) {
	s = s.replace(/\xe4/, "ae");
	s = s.replace(/\xf6/, "oe");
	s = s.replace(/\xfc/, "ue");
	s = s.replace(/\xc4/, "Ae");
	s = s.replace(/\xd6/, "Oe");
	s = s.replace(/\xdc/, "Ue");
	s = s.replace(/\xdf/, "ss");
	return s;
}
function simplifyTimetable(formName, fromName, toName) {
	formular = document.forms[formName];
	from = formular.elements[fromName];
	from.value = simplifySpecialChars(from.value);
	
	to = formular.elements[toName];
	to.value = simplifySpecialChars(to.value);
}
// Set time and date as default for the ticketinfo-form on startpage
// Examples for 'strFormatDate':
// + dd.mm.yy --> 01.03.03 and 12.10.03
// + d.m.yyyy --> 1.3.2003 and 12.10.2003
// + yyyy/mm/dd --> 2003/03/01 and 2003/10/12
// ddd -- > dd , mmm --> mm, y --> yy, yyy --> yyyy 
// Examples for 'strFormatTime':
// + hh:mm --> 06:09 and 13:32
// + h:m --> 6:09 and 13:32
function setTimeAndDate(strFormatDate,strFormatTime,strFormName,strElementNameDate,strElementNameTime)
{
	var oToday = new Date();
	var day = oToday.getDate();
	var month = oToday.getMonth()+1;
	var year = oToday.getFullYear()+"";
	var hours = oToday.getHours();
	var minutes = oToday.getMinutes();

	strFormatDate = strFormatDate.toLowerCase();
	strFormatTime = strFormatTime.toLowerCase();
	
	regTemp = strFormatDate.match(/d/g);
	if(regTemp.length>=2)if(day<10)day="0"+day;
	strFormatDate = strFormatDate.replace(/d+/,day);
	
	regTemp = strFormatDate.match(/m/g);
	if(regTemp.length>=2)if(month<10)month="0"+month;
	strFormatDate = strFormatDate.replace(/m+/,month);

	regTemp = strFormatDate.match(/y/g);
	if(regTemp.length<3)year= year.slice(2);
	strFormatDate = strFormatDate.replace(/y+/,year);
	
	regTemp = strFormatTime.match(/h/g);
	if(regTemp.length>=2)if(hours<10)hours="0"+hours;
	strFormatTime = strFormatTime.replace(/h+/,hours);

	if(minutes<10)minutes="0"+minutes;
	strFormatTime = strFormatTime.replace(/m+/,minutes);

	if(dom)
	{
		oFormElementDate = document.getElementById(strElementNameDate);
		oFormElementTime = document.getElementById(strElementNameTime);
		oFormElementDate.value = strFormatDate;
		oFormElementTime.value = strFormatTime;
	}
	else
	{
		document.forms[strFormName].elements[strElementNameDate].value=strFormatDate;
		document.forms[strFormName].elements[strElementNameTime].value=strFormatTime;
	}
}
