/**
 * Öffnet eine Seite eines bestimmten Moduls;
 * Wird gesteuert von der Funktion loadContent auf der Hauptseite
 */
function loadContentF(site, area, module, jsessionid, optAction, optActionModule) {
	tUrl			= site +"?module="+ module +"&area="+ area +"&jsessionid="+ jsessionid;
	if (typeof optAction != 'undefined') {
		tUrl	+= '&action='+optAction;
	}
	if (typeof optActionModule != 'undefined') {
		tUrl	+= '&actionmodule='+optActionModule;
	}
	location.href	= tUrl;
}

/**
 * Minimiert und Maximiert einen Panel
 */
function mmPanel(pid, name) {
	par = document.getElementById(name);
	
	for(i=0; i<par.childNodes.length; i++) {
		el = par.childNodes[i];
	
		if (el.nodeName == "TR") {
			if (el.style.display == "none") {
				el.style.display = (navigator.appName == "Microsoft Internet Explorer")?"block":"table-row";
				pid.src = "images/down-arrow.gif";
			}
			else {
				el.style.display = "none";
				pid.src = "images/right-arrow.gif";
			}
		}
	}
}

function getElement(id) {
	var result = document.getElementById ? document.getElementById(id) :
	document.all ? document.all(id) : null;
	//Nur zur Sicherheit: beim globalen Ersetzn könnte hier ein Fehler unterlaufen sein,
	//existiert das Element "abc123id" nicht, wird mit "abc123" (ohne "id") versucht
	if (result == null && id.lastIndexOf('id') == (id.length - 2)) {
		return getElement(id.substring(0, id.length - 2));
	}
	return result;
}

function getClientWidth() {
	return document.body && typeof document.body.clientWidth != 'undefined' ? 
	document.body.clientWidth : window.innerWidth ? innerWidth : null;
}

function getClientHeight() {
	return document.body && typeof document.body.clientHeight != 'undefined' ? 
	document.body.clientHeight : window.innerHeight ? innerHeight : null;
}

function centerIt(el_id, horiz_offset, vert_offset) {
	if (typeof horiz_offset == 'undefined') horiz_offset = 0;
	if (typeof vert_offset == 'undefined') vert_offset = 0;
	var el = getElement(el_id);
	var cW = getClientWidth();
	var cH = getClientHeight();
	
	if (cH == 0 && document.documentElement.clientHeight) {
		cH = document.documentElement.clientHeight;
	}
	
	if (el && el.style && cW && cH) {
		var el_lt = (cW - el.offsetWidth) / 2 + horiz_offset;
		var el_tp = (cH - el.offsetHeight) / 2 + vert_offset;
		el.style.left = String(el_lt + 'px');
		el.style.top = String(el_tp + 'px');
	}
}

function innerContent(elname, cont) {
	//if IE 4+
	if (document.all)
		document.all[elname].innerHTML = cont;
	else if (document.getElementById) {
		rng	= document.createRange();
		el	= document.getElementById(elname);
		rng.setStartBefore(el);
		htmlFrag = rng.createContextualFragment(cont);
		while (el.hasChildNodes())
			el.removeChild(el.lastChild);
		el.appendChild(htmlFrag);
	}
}

function localCheckForPopupBox(e) {
	if (!e) var e = window.event;
	parent.checkForPopupBox(e);
}


function submitForm(formid) {
	getElement(formid).submit();
}

document.onkeydown = localCheckForPopupBox;

/* bei der Bildern muss 'title' eingetragen werden, im normalfall das gleiche wie in 'alt', 
* hier werden alle Bilder mit 'alt' aber ohne 'title' gesucht und gefuellt */
$(function(){	
	$('IMG:not([alt=""]):[title=""]').each(function(){
		$(this).attr('title',$(this).attr('alt'))		
	});
});

/* Suche der Endung einer Datei */
function getFileExtension(sFileName)
{
	return /[^.]+$/.exec( sFileName )
}

/* Ein- und Ausblenden von Detail-Informationen */
function showHideDetails(aid) 
{	
	var oEl = $('#detailRow' + aid);
	var oImg = $('A[onclick*="showHideDetails('+aid+');"] IMG[src*="-details."]'); 

	if (oEl.css('display') == "none") 
	{
		oEl.show();
		oImg.attr('src', dirname(oImg.attr('src')) + '/close-details.' + getFileExtension(oImg.attr('src')) )
	}
	else 
	{
		oEl.hide();
		oImg.attr('src', dirname(oImg.attr('src')) + '/open-details.' + getFileExtension(oImg.attr('src')) )
	}
}
