
/*
	aktiviert einen Menüpunkt per CSS-Zuweisung an die ID
*/
function activateNav(aActive) {
	if(aActive != "" && document.getElementById(aActive)) {
		appendClass(aActive, "active");
		
		if(aActive.indexOf("_")) {
			var mainNav = aActive.substring(0, aActive.indexOf("_"));
			appendClass(mainNav, "active");
		}
	}
}


/*
	erweitert das Attribut "class" eines Elementes
*/
function appendClass(aElem, aClass) {
	if(typeof aElem == "string" && document.getElementById(aElem)) aElem = document.getElementById(aElem);
	if(typeof aElem != "object") return false;
	
	var oldClass = aElem.className;
	if(oldClass != "") {
		if(oldClass.indexOf(aClass) < 0) aElem.className = oldClass + " " + aClass;
	}
	else {
		aElem.className = aClass;
	}
	
	return true;
}


/*
	getStyle()	=>	liest CSS-Eigenschaften und gibt Farben als HEX zurück
	----------------------------------------------------------------------
		versucht zunächst die Style-Angaben im <style> Attribut auszulesen
		dann Abfrage über getComputedStyle für Gecko
		dann Abfrage über currentStyle für MSIE
	
	parameter:	Objekt, abzufragende Style-Eigenschaft
	return:		Wert der Eigenschaft
*/
function getStyle(which, style) {
	if(typeof which == "object") obj = which;
	if(typeof which == "string") obj = document.getElementById(which);
	if(obj == null) return false;
	
	var value = obj.style[convCSStoJSSS(style)];
    if(!value) {
			if(document.defaultView) {
			value = document.defaultView.getComputedStyle(obj, null).getPropertyValue(style);
			if(style.indexOf("color") >= 0) value = convRGBtoHEX(value);		// RGB => HEX bei Moz
		}
		else if(obj.currentStyle) {
			value = obj.currentStyle[convCSStoJSSS(style)];
			if(style.indexOf("color") >= 0) value = value.toUpperCase();		// HEX => toUpperCase bei MSIE
		} 
	}
	
	return value;
}


/*
	convCSStoJSSS()	=>	konvertiert Namenskonventionen von CSS-Eigenschaften in JS-Konventionen
	-------------------------------------------------------------------------------------------
		convCSStoJSSS("z-index");				=>	return zIndex
		convCSStoJSSS("border-bottom-style");	=>	return borderBottomStyle.
	
	parameter:	str(CSS-Eigenschaft)
	return:		str(JS-Eigenschaft)
*/
function convCSStoJSSS(input) {
	var pieces_arr = input.split('-');
	if(pieces_arr.length == 1) return pieces_arr[0];
		
	var output = "";
	for(var i = 0; i < pieces_arr.length; i++) {
		if(i > 0) output += pieces_arr[i].charAt(0).toUpperCase() + pieces_arr[i].substring(1);
		else output += pieces_arr[i];
	}
	
	return output;
}


/*
	convRGBtoHEX()	=>	konvertiert einzelne Werte oder ganze RGB-Angaben inach HEX
	-------------------------------------------------------------------------------
		convRGBtoHEX(255);						=>	return FF
		convRGBtoHEX("0, 153, 255");			=>	return #0099FF
		convRGBtoHEX("rgb(0, 153, 255)");		=>	return #0099FF
	
	parameter:	int(R) oder int(G) oder int(B)
	return:		str(HEX)
	
	parameter:	str("rgb(1,2,3)") oder str("1,2,3")
	return:		str(#HEX)
*/
function convRGBtoHEX(val)
{
	if(val > 255) return null;
	if(val < 0) return null;
	
	var RGB = new Array(256);
	var k = 0;
	var HEX = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");
	var output = "";
	
	for(var i = 0; i < 16; i++) {
		for(var j = 0; j < 16; j++) {
			RGB[k] = HEX[i] + HEX[j];
			k++;
		}
	}
	
	// konvertiert eine Zahl nach HEX
	if(typeof val == "number") output = RGB[val];
	
	// konvertiert einen übergebenen RGB-String nach HEX
	else if(typeof val == "string" && val.indexOf(",") > 0) {
		output = "#";
		var rgb_arr = val.split(",");
		
		for(var v in rgb_arr) {
			var rgb_val = rgb_arr[v].match(/[0-9]+/);
			output += RGB[rgb_val];
		}
	}
	
	return output;
}


/*
function showTooltip(elem, vis) {
	tooltipElem = elem;
	document.getElementById(elem).style.display = (vis) ? "block" : "none";
	document.onmouseover = mouseWatch;
	document.onmousemove = mouseWatch;
}
*/
var tooltipElem;
function mouseWatch(ereignis) {
	if(!document.getElementById || !tooltipElem) return false;
	if(!ereignis) ereignis = window.event;
	
	var offsetLeft = 5;
	var offsetTop = -5;
	
	var posLeft = parseInt(ereignis.clientX);
	var posTop = parseInt(ereignis.clientY);
	
	var elemWidth = document.getElementById(tooltipElem).offsetWidth;
	var elemHeight = document.getElementById(tooltipElem).offsetHeight;
	
	if(document.all) {
		posLeft = posLeft - 2;
		posTop = posTop - elemHeight - 1;
	}
	else {
		posTop = posTop - elemHeight + 1;
	}
	
	posLeft = posLeft + offsetLeft;
	posTop = posTop + offsetTop;

	if(typeof window.pageXOffset == "number") {
		document.getElementById(tooltipElem).style.left = posLeft + parseInt(window.pageXOffset) + "px";
	}
	else {
		document.getElementById(tooltipElem).style.left = posLeft + document.documentElement.scrollLeft + "px";
	}
	
	if(typeof window.pageYOffset == "number") {
		document.getElementById(tooltipElem).style.top = posTop + parseInt(window.pageYOffset) + "px";
	}
	else {
		document.getElementById(tooltipElem).style.top = posTop + document.documentElement.scrollTop + "px";
	}
	
	return true;
}


/*
	alternateTableRows()	=>	weist jeder zweiten Tabellenzeile eine andere Klasse zu
	------------------------------------------------------------------------------------
		alternateTableRows('theTable', 'reihe2');						=>	alternierende Tabelle
		alternateTableRows('theTable', 'reihe2', 'hover');	=>	alternierende Tabelle mit Zeilenrollover
		alternateTableRows('theTable', '', 'hover');				=>	Tabelle mit Zeilenrollover
	
	parameter:	Objekt oder ID, alternierende CSSKlasse, Hover-CSSKlasse (optional)
*/
function alternateTableRows(which, class1, class2, hoverClass, linkID, tooltip) {
	if(!document.getElementById) return null;
	
	var obj = (typeof which == "object") ? which : document.getElementById(which);
	
	for(var i = 0; i < obj.getElementsByTagName('TR').length; i++) {
		/* alternateTableRows */
		var tr = obj.getElementsByTagName('TR')[i];
		
		var deactivated = false;
		if(tr.id.indexOf('-deactivated') > 0) deactivated = true;
		
		for(var j = 0; j < tr.getElementsByTagName('TD').length; j++) {
			var td = tr.getElementsByTagName('TD')[j];
			
			if(td.id.indexOf('-deactivated') <= 0) {
				if(i % 2 != 0) td.className = (deactivated) ? class1 + "-deactivated" : class1;
				else td.className = (deactivated) ? class2 + "-deactivated" : class2;
			}
			
		}
		/* END alternateTableRows */
		
		/* hoverTableRows */
		if(typeof hoverClass == "string" && hoverClass != "" && !deactivated) {
			tr.onmouseover = function() {
				this.hoverTDs('hover');
				
				if(this.id && tooltip) this.showTooltip(this.id + "Tooltip", true);
			}
				
			tr.onmouseout = function() {
				this.hoverTDs('out');
				
				if(this.id && tooltip) this.showTooltip(this.id + "Tooltip", false);
			}
			
			tr.onclick = function() {

				if(this.getElementsByTagName('A').length > 0) {
					var linkHref = '';
					var linkTarget = '';
					
					// keine bestimmte ID => erster Link in TR
					if(linkID == '') {
						linkHref = this.getElementsByTagName('A')[0];
						linkTarget = this.getElementsByTagName('A')[0].getAttribute('target');
					}
					else {
						for(var i = 0; i < this.getElementsByTagName('A').length; i++) {
							// bestimmter Link in TR
							var id = this.getElementsByTagName('A')[i].id;
							if(id.indexOf(linkID) >= 0) {
								linkHref = this.getElementsByTagName('A')[i];
								linkTarget = this.getElementsByTagName('A')[i].getAttribute('target');
							}
						}
					}
					
					if(linkHref.getAttribute('onclick')) {
						var onclickOrig = linkHref.getAttribute('onclick').toString();
						var onclick = onclickOrig;
						
						onclick = onclick.replace(/return document.MM_returnValue/, "");	// GP_AdvOpenWindow
						onclick = onclick.replace(/return false/, "");
						onclick = onclick.replace(/return false;/, "");
						
						if(onclick.indexOf('anonymous') >= 0) {
							onclick = onclick.substring(onclick.indexOf('{') + 1, onclick.length);
							onclick = onclick.substring(0, onclick.lastIndexOf('}'));
							onclick = onclick.replace(/ /, "");
						}
						
						var theEval = eval(onclick);
						
						if(onclickOrig.indexOf('return document.MM_returnValue') >= 0 || onclickOrig.indexOf('return false') >= 0 || onclickOrig.indexOf('return false;') >= 0) return;
					}
					
					if(!linkTarget || linkTarget == '' || linkTarget == '_self') document.location.href = linkHref;
					else window.open(linkHref, linkTarget);
				}
			}
			
			tr.hoverTDs = function(mode) {
				for(var j = 0; j < this.getElementsByTagName('TD').length; j++) {
					var td = this.getElementsByTagName('TD')[j];
					if(mode == "hover") td.alteKlasse = td.className;
					td.className = (mode == "hover") ? hoverClass : td.alteKlasse;
				}
			}
			
			tr.showTooltip = function showTooltip(elem, vis) {
				//if(vis) tooltipElem = elem;
				//else tooltipElem = false;
				tooltipElem = elem;
				
				if(document.getElementById(elem)) {
					document.getElementById(elem).style.display = (vis) ? "block" : "none";
					document.onmouseover = mouseWatch;
					document.onmousemove = mouseWatch;
				}
			}
			
		}
		/* END hoverTableRows */
	}
	return null;
}


function GP_AdvOpenWindow(theURL,winName,features,popWidth,popHeight,winAlign,ignorelink,alwaysOnTop,autoCloseTime,borderless) { //v2.0
  var leftPos=0,topPos=0,autoCloseTimeoutHandle, ontopIntervalHandle, w = 480, h = 340;  
  if (popWidth > 0) features += (features.length > 0 ? ',' : '') + 'width=' + popWidth;
  if (popHeight > 0) features += (features.length > 0 ? ',' : '') + 'height=' + popHeight;
  if (winAlign && winAlign != "" && popWidth > 0 && popHeight > 0) {
    if (document.all || document.layers || document.getElementById) {w = screen.availWidth; h = screen.availHeight;}
		if (winAlign.indexOf("center") != -1) {topPos = (h-popHeight)/2;leftPos = (w-popWidth)/2;}
		if (winAlign.indexOf("bottom") != -1) topPos = h-popHeight; if (winAlign.indexOf("right") != -1) leftPos = w-popWidth; 
		if (winAlign.indexOf("left") != -1) leftPos = 0; if (winAlign.indexOf("top") != -1) topPos = 0; 						
    features += (features.length > 0 ? ',' : '') + 'top=' + topPos+',left='+leftPos;}
  if (document.all && borderless && borderless != "" && features.indexOf("fullscreen") != -1) features+=",fullscreen=1";
  if (window["popupWindow"] == null) window["popupWindow"] = new Array();
  var wp = popupWindow.length;
  popupWindow[wp] = window.open(theURL,winName,features);
  if (popupWindow[wp].opener == null) popupWindow[wp].opener = self;  
  if (document.all || document.layers || document.getElementById) {
    if (borderless && borderless != "") {popupWindow[wp].resizeTo(popWidth,popHeight); popupWindow[wp].moveTo(leftPos, topPos);}
    if (alwaysOnTop && alwaysOnTop != "") {
    	ontopIntervalHandle = popupWindow[wp].setInterval("window.focus();", 50);
    	popupWindow[wp].document.body.onload = function() {window.setInterval("window.focus();", 50);}; }
    if (autoCloseTime && autoCloseTime > 0) {
    	popupWindow[wp].document.body.onbeforeunload = function() {
  			if (autoCloseTimeoutHandle) window.clearInterval(autoCloseTimeoutHandle);
    		window.onbeforeunload = null;	}  
   		autoCloseTimeoutHandle = window.setTimeout("popupWindow["+wp+"].close()", autoCloseTime * 1000); }
  	window.onbeforeunload = function() {for (var i=0;i<popupWindow.length;i++) popupWindow[i].close();}; }   
  document.MM_returnValue = (ignorelink && ignorelink != "") ? false : true;
}