// JavaScript Document

/**
* css hack for different browsers
*/
// Internet Explorer
if(returnBrowserType() == "ie") {
	document.write('<link rel="stylesheet" type="text/css" href="fileadmin/template/css/ie.css">');
	if(returnBrowserVersion() == "6") document.write('<link rel="stylesheet" type="text/css" href="fileadmin/template/css/ie6.css">');
}
// Safari
if(returnBrowserType() == "sa") {
	isSafari3 = false;
	if(window.devicePixelRatio) isSafari3 = true;
	if(isSafari3) document.write('<link rel="stylesheet" type="text/css" href="fileadmin/template/css/safari3.css">');
}
// Firefox
/*if(returnBrowserType() == "ff") {
	document.write('<link rel="stylesheet" type="text/css" href="fileadmin/template/css/ff.css">');
}*/
// Opera
if(returnBrowserType() == "op") {
	document.write('<link rel="stylesheet" type="text/css" href="fileadmin/template/css/op.css">');
}

/**
* return string representing browser type
*/
function returnBrowserType() {
	if(window.navigator.userAgent.toLowerCase().indexOf("opera") != -1) {
		return "op";
	}
	if(window.navigator.userAgent.toLowerCase().indexOf("msie") != -1) {
		return "ie";
	}
	if(window.navigator.userAgent.toLowerCase().indexOf("firefox") != -1) {
		return "ff";
	}
	if(window.navigator.userAgent.toLowerCase().indexOf("safari") != -1) {
		return "sa";
	}
}

/**
* return string representing browser version
*/
function returnBrowserVersion() {
	// convert all characters to lowercase to simplify testing
    var agt=window.navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    var is_major = parseInt(window.navigator.appVersion);
    var is_minor = parseFloat(window.navigator.appVersion);

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
    // If you want to allow spoofing, take out the tests for opera and webtv.
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                   && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && (is_major >= 4));
    var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) );
    var is_nav6 = (is_nav && (is_major == 5));
    var is_nav6up = (is_nav && (is_major >= 5));
    var is_gecko = (agt.indexOf('gecko') != -1);


    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
	
	if(is_ie6) return "6";
	else return "";
}
		
/**
* Find top pixel offset of HTML element relative to window
* @param {HTML Element} obj	an HTML element to calculate offset of
* @returns {string} 		[y] offset of html element 'obj'
*/
function findElementPositionTop(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curtop += obj.offsetTop
		}
	}
	return curtop;
}
	
/**
* Get the pixel height of any given HTML object
* @param {HTML Element} el	an HTML element
* @returns {string}		[y] representing object height
*/
function getHeight(el) {
	var y = 0;
	if(document.all) {
		y = el.offsetHeight;
	} else {
		y = parseInt(document.defaultView.getComputedStyle(el,"").getPropertyValue("height"));
	}
	return y;
}

function calculateImpressumHeight() {
	var wrapHeight = getHeight(wrap);
	var impTop = findElementPositionTop(impressum);
	var impHeight = wrapHeight - impTop;
	
	switch(returnBrowserType())
	{
		case "op" : break;
		case "ie" : impHeight = impHeight + 7; break;
		case "ff" : if(wrapHeight < 797) {
						impHeight = impHeight + 2;
					} else { 
						impHeight = impHeight + 3; 
					} 
					break;
		case "sa" : impHeight = impHeight + 2; break;
	}

	return impHeight;
}

function calculateContentHeight() {
	var leftHeight = getHeight(left_detail);
	var contentHeight = leftHeight;
	
	return contentHeight;
}

function calculateRightHeight() {
	var mainHeight = getHeight(main);
	var rightHeight = mainHeight;

	switch(returnBrowserType())
	{
		case "op" : break;
		case "ie" : break;
		case "ff" : if(mainHeight > 132 && mainHeight < 168) {
						rightHeight++;
					} 
					break;
		case "sa" : break;
	}
	
	return rightHeight;
}
			
/** 
* evaluate 'input' string as css 
* @param {string} input		an input string to evaluate as css (selector(s) followed by rules)
*/
function evalCss(input) {
	try {
		this.insertStyleRule(input);
	} catch (e) {
		//window.alert(e.message);
	}
}

/** 
* make 'input' string to update height of <div id="right"> 
*/
function updateRightHeight() {
	var input = '#right { height: ' + calculateRightHeight() + 'px; }'
	evalCss(input);
}

/** 
* make 'input' string to update height of <div id="impressum"> 
*/
function updateImpressumHeight() {
	var input = '#left_detail #impressum { height: ' + calculateImpressumHeight() + 'px; }'
	evalCss(input);
}

/** 
* make 'input' string to update height of <div id="wrap"> 
*/
function updateContentHeight() {
	var input = '#content_detail { height: ' + calculateContentHeight() + 'px; }'
	evalCss(input);
}

/**
* Write style rule in stylesheet
* @param {string} rule 		a series of selectors and rules separated by the newline character '\n'
*/
function insertStyleRule(rule) {
	var lastStyleSheetIndex = document.styleSheets.length - 1;
	if(document.getElementById("cssStyleInput") == null) {
		this.styleInputTag = document.createElement("style");
		this.styleInputTag.id = "cssStyleInput";
		this.styleInputTag.type = "text/css";
		document.body.appendChild(this.styleInputTag);
	}
	if(returnBrowserType() == "ff" || returnBrowserType() == "op") {
		/* wow, I can't believe this works in FF and Opera. It shouldn't */ 
		this.styleInputTag.innerHTML += rule + "\n";
	} else if (returnBrowserType() == "ie" || returnBrowserType() == "sa") {
		/* in IE, stylesheets are added to the top of the stack */
		if(returnBrowserType() == "ie") {
			var i = 0;
		} else if (returnBrowserType() == "sa") {
			var i = document.styleSheets.length - 1;
		}
		/* create array of rules */
		var rulesArray = rule.split("}");
		for(var t = 0; t < rulesArray.length; t++) {
			var ruleSplit = rulesArray[t].split("{");
			/* IE wont take multiple selectors in one rule in addRule */
			var selectors = ruleSplit[0].split(",");
			for(var k = 0; k < selectors.length; k++) {
				document.styleSheets[i].addRule(selectors[k],ruleSplit[1]);
			}
		}
	}
}

/**
* functions for handling visibility of the map layers
*/
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}



//function for search
function gotoSelect() {
    var s = document.getElementById('fast_access');
    var index = s.selectedIndex;
    var url = s.options[index].value;
    if( url != 'nothing' ) {
        window.location = url;
    }
}
