function getWindowSize() {
	
	if (typeof(window.innerWidth)!="undefined") {
		return {width: window.innerWidth, height: window.innerHeight}
	}
	if (typeof(document.body.offsetWidth)!="undefined") {
		return {width: document.body.offsetWidth, height: document.body.offsetHeight}
	}
	return null;
}
	
var flashWidth = 850;
var flashHeight = 526;
var console;
var topNavContainer;
var topNavForm;
var contextPath = "/";


function isChildOf(child, parent) {
	if (parent == child) return false;
	var c = child;
	try {
		while (c) {
			if (c==child.ownerDocument.body) return false;
			if (c==child.ownerDocument.documentElement) return false;
			if (c.parentNode==parent) return true;
			if (!c.parentNode) return false; 
			c = c.parentNode;
			
		}
	} catch (e) {
	}
	return false;
}



function toggleGenderCheckbox(element, otherElement) {
	if (element.checked && otherElement!=null) { 
		otherElement.onchange = function() {
			toggleGenderCheckbox(this, element);
		}
		otherElement.checked = null; 
	}
	if (element.checked) {
		element.onchange = function (event) {
			if (this.checked==false) this.checked = true;
		};
	}
}

function closeDialog() {
	var dialog = document.getElementById("dialog");
	if (dialog!=null) {
		dialog.style.display = "none";
	}
	document.body.style.overflow = "auto";
}

function closeFlashDialog() {
	closeDialog();
}

function redirect(redirectLocation) {
	
	window.location.href = contextPath+redirectLocation;
	console.log("redirect -> " + contextPath+redirectLocation);
}


/*
function layoutDialog() {
	var dialogWindow = document.getElementById("dialogWindow");
	if (dialogWindow!=null) {
		document.body.style.overflow = "hidden";
		var winSize = getWindowSize();
		if (winSize!=null) {	
			var x = (winSize.width-flashWidth)/2;
			var y = (winSize.height-flashHeight)/2;
			dialogWindow.style.position = "relative";
			dialogWindow.style.left = x+"px";
			dialogWindow.style.top = y+"px";
		}
	}
}

window.onresize = function(event) {
	layoutDialog();
}
*/

function imageReload(imageElement, baseURL) {
	if (imageElement==null) return;
	var rndInt = Math.floor(Math.random()*10000);
	var randomString = new Date()+"_"+rndInt;
	imageElement.setAttribute("src", baseURL+"?"+randomString);
}

function setImage(elementId, src, big) {
	var element = document.getElementById(elementId); 
	if (element!=null) {
		element.setAttribute("src", src);
		element.onclick = function() {
			showImage(big);
		}
	}
}

function showImage(src) {
	setDialogCaption("Großansicht");
	setDialogContent("<img width='800' height='600' src='"+src+"'/>");
	showDialog();
}

function setDialogCaption(caption) {
	var dialogCaption = document.getElementById('dialogCaption'); 
	if (dialogCaption!=null) {
		dialogCaption.innerHTML = "";
		var textNode = document.createTextNode(caption);
		dialogCaption.appendChild(textNode);
	}
}

function setDialogCloseLink(href) {
	var dialogCloseButton = document.getElementById('dialogCloseButton'); 
	if (dialogCloseButton!=null) {
		dialogCloseButton.setAttribute(href);
	}
}

function setDialogContent(contentHTML) {
	var dialogContent = document.getElementById('dialogContentCell'); 
	if (dialogContent!=null) {
		dialogContent.innerHTML = contentHTML;
	}
}

function showDialog() {
	var dialog = document.getElementById("dialog");
	dialog.style.display = "block";
}

//cross-browser http-request
function getHttpRequest() {
	var httpRequest;
	if (typeof (XMLHttpRequest) != "undefined") {
   		httpRequest = new XMLHttpRequest();
  	} else if (typeof (ActiveXObject) != "undefined") {
      	httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
	}
	// error
	return httpRequest;
}

function sendRequest(url) {
	var httpRequest = getHttpRequest();
	httpRequest.open("GET", url, false);
	httpRequest.send(null);
} 

function printFrame(frameElement) {
	if (frameElement!=null) {
		if (frameElement.contentWindow!=null) {
			frameElement.contentWindow.focus();
			frameElement.contentWindow.print(); 
		}
	}
}


function validateMaxLength(element, maxlen) {
  return (element != null && element.value.length <= maxlen);
}

/* INIT SCRIPTS */
var c = 0;
function init() {
	topNavContainer = document.getElementById('topNavigationBox');
	topNavForm = document.getElementById('topNavigationForm');
	if (topNavContainer!=null && topNavForm!=null) {
		topNavContainer.onmouseover = function (event) {
			topNavForm.style.display = "block";
		}
		
		function mouseOverHandler(event) {
			var eventObject = (typeof(event)!="undefined") ? event : window.event;
			var eventTarget = (typeof(eventObject.target)!="undefined") ? eventObject.target : eventObject.srcElement;
			
			
			if (eventTarget!=null && !isChildOf(eventTarget, topNavContainer)) {
				topNavForm.style.display = "none";
			}
		}
		
		document.onmouseover = mouseOverHandler;
	}
}
