function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { 
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	return {pageWidth:pageWidth, pageHeight:pageHeight, windowWidth:windowWidth, windowHeight:windowHeight};
}
function getPageScroll() {
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	return yScroll;
}
function getBrowserType() {
	var ua = navigator.userAgent;
	this.isMSIE = (navigator.appName == "Microsoft Internet Explorer");
	this.isMSIE5 = this.isMSIE && (ua.indexOf('MSIE 5') != -1);
	this.isMSIE5_0 = this.isMSIE && (ua.indexOf('MSIE 5.0') != -1);
	this.isGecko = ua.indexOf('Gecko') != -1;
	this.isSafari = ua.indexOf('Safari') != -1;
	this.isOpera = ua.indexOf('Opera') != -1;
	this.isMac = ua.indexOf('Mac') != -1;
	this.isNS7 = ua.indexOf('Netscape/7') != -1;
	this.isNS71 = ua.indexOf('Netscape/7.1') != -1;
	if (this.isOpera) {
		this.isMSIE = false;
		this.isGecko = false;
		this.isSafari =  false;
	}
}
var browserType = new getBrowserType();


function createFrame(lnk) {
	var contentFrame = document.getElementById('contentFrameSrc');
	if (contentFrame) {
		contentFrame.src = lnk;
		return;
	}	
	
	var holder = document.createElement("div");
	holder.setAttribute('id', 'contentFrame');
	holder.style.position = 'absolute';	
	holder.style.display = 'block';	
	holder.style.zIndex = '999';	
	holder.innerHTML = '<a href="#" onClick="hideModalWnd()" style="font-size:10px;color:#40729B;font-family:Verdana, Helvetica, sans-serif;background-color:#EAEAEA;padding-left:10px;padding-top:5px;padding-right:5px">X (CLOSE)</a><br>';	
	document.body.appendChild(holder); 
	
	var iframeCode = '<iframe name="iframeCode"></iframe>';
	if (!(browserType.isMSIE)) {
		iframeCode = 'iframe';
	}	
	var modalFrame = document.createElement(iframeCode);
	modalFrame.setAttribute('id', 'contentFrameSrc');
	modalFrame.setAttribute('src', lnk);
	modalFrame.setAttribute('border', '0');
	if (!(browserType.isMSIE)) {
		modalFrame.setAttribute('name', 'contentFrameSrc');
	}	
	modalFrame.setAttribute('frameBorder', '0');
	modalFrame.setAttribute('marginWidth', '0');
	modalFrame.setAttribute('marginHeight', '0');
	modalFrame.setAttribute('leftMargin', '0');
	modalFrame.setAttribute('topMargin', '0');
	modalFrame.setAttribute('width', "100%");
	modalFrame.setAttribute('height', "100%");
	holder.appendChild(modalFrame); 
}

 // Init Globals
var doResizeModal = 0;
var initYScroll = 0;
var modalFixHeight = 0;
var modalFixWidth = 0;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Modal anzeigen
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function showModalWnd(modalLink, modalWidth, modalHeight) {

 // Merken Breite
	if (!modalWidth) {
		modalWidth = 0;
	}
	modalFixWidth = parseInt(modalWidth);

 // Merken Höhe
	if (!modalHeight) {
		modalHeight = 0;
	}
	modalFixHeight = parseInt(modalHeight);

 // Selectboxen im IE ausblenden
	if (browserType.isMSIE) { 
		var selectElms = document.getElementsByTagName("select");
		for (i = 0; i < selectElms.length; i++) {
			selectElms[i].style.visibility = "hidden";
		}
	}	

 // Iframes Opera ausblenden
	if (browserType.isOpera) { 
		var iframeElms = document.getElementsByTagName('iframe');
	    for (i = 0; i < iframeElms.length; i++) {
	    	if (iframeElms[i].id != 'contentFrame') {
				iframeElms[i].style.visibility = 'hidden';
			}	
		}
	}

 // evtl. Rand nach rechts setzen, wenn scrollrand gleich wegfallen würde
	var yScroll = getPageScroll();
	initYScroll = yScroll;
	var pageSize = getPageSize();
	var bodyElm = document.getElementsByTagName('body')[0];
	if (pageSize.windowHeight < pageSize.pageHeight) {
		bodyElm.style.marginRight = '14px';
	}		

 // Vor Überlagerung deaktivieren scrollen
	bodyElm.style.overflow = 'hidden';

 // Das setzen von overflow=hidden führt dazu, das der browser nach oben springt.
 // Also zurück zur ermittelten Stelle. Scheint hier nur im IE zu greifen
	if (browserType.isMSIE) { 
		window.scrollTo(0, initYScroll);
	}	
	createFrame(modalLink);
	doResizeModal = window.setInterval("resizeModal()", 500);  	
	return false;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// aktualisieren pos, breiten und höhen
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function resizeModal(isInit) {
	if (!isInit) {
		//return;
	}	
	var contentFrame = document.getElementById('contentFrame');
	if (!(contentFrame)) {
		//alert('kill1')
		hideModalWnd(false);
		return;
	}	

 // Versuchen Scroll Position auf Ursprung zu bringen
	var yScroll = getPageScroll();
	if (isInit) {
		yScroll = initYScroll;
	}
	else {
		if (yScroll != initYScroll) {
			window.scrollTo(0, initYScroll);
		}
	}	

 // Werte ermitteln
	var pageSize = getPageSize();

 // Layer Breite auf Browserbreite setzen oder horizontal zentrieren
	var contentLayerLeft = 6;
	var contentLayerWidth = pageSize.windowWidth - 17;
	if (modalFixWidth > 0) {
		if (modalFixWidth < contentLayerWidth) {
			contentLayerWidth = modalFixWidth;
			contentLayerLeft = ((pageSize.windowWidth - contentLayerWidth) / 2);
		}	
	}

 // Layer Höhe auf Browserhöhe setzen oder vertikal zentrieren
	var contentHeaderHeight = 21;
	var contentLayerTop = yScroll + 6;
	var contentLayerHeight = pageSize.windowHeight - 17;
	if (modalFixHeight > 0) {
		if (modalFixHeight < contentLayerHeight) {
			contentLayerHeight = modalFixHeight + contentHeaderHeight;
			contentLayerTop = ((pageSize.windowHeight - contentLayerHeight) / 2) + yScroll;
			if (contentLayerTop < yScroll) {
				contentLayerTop = yScroll;
			}	
		}	
	}

 // Layer darf nicht hoeher als der verfuegbare Platz sein
	if (contentLayerHeight > pageSize.windowHeight) {
		contentLayerHeight = pageSize.windowHeight;
	}	
	contentLayerLeft = (contentLayerLeft < 0) ? 0 : contentLayerLeft;
	contentLayerTop = (contentLayerTop < 0) ? 0 : contentLayerTop;
	contentLayerWidth = (contentLayerWidth < 0) ? 0 : contentLayerWidth;
	contentLayerHeight = (contentLayerHeight < 0) ? 0 : contentLayerHeight;

 // neue Layer Daten einsetzen
	contentFrame.style.left = contentLayerLeft + "px";
	contentFrame.style.top = (contentLayerTop < 0) ? "0px" : contentLayerTop + "px";
	contentFrame.style.width = contentLayerWidth + 'px';
	contentFrame.style.height = contentLayerHeight + 'px';
	contentFrame.style.display = 'block';
	if (isInit) {
		yScroll = initYScroll;
		window.scrollTo(0, yScroll);
	}
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Modal beenden
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function hideModalWnd() {
	
 // Iframe auf Init
	var contentFrame = document.getElementById('contentFrame');

 // evtl. Interval loeschen
	if (doResizeModal) {
		window.clearInterval(doResizeModal);
	}	

 // IFRAME entfernen und Layer unsichtbar machen, nur im Ie vorher unsichtbar machen, Player bleibt manchmal haengen
	var contentLayer = document.getElementById('contentFrame');
	contentLayer.style.display = 'none';

 // Checkboxen wieder einblenden
	if (browserType.isMSIE) { 
		var selectElms = document.getElementsByTagName('select');
	    for (i = 0; i < selectElms.length; i++) {
			selectElms[i].style.visibility = 'visible';
		}
	}	

 // Iframes Opera wieder einblenden
	if (browserType.isOpera) { 
		var iframeElms = document.getElementsByTagName('iframe');
	    for (i = 0; i < iframeElms.length; i++) {
			if (iframeElms[i].id != 'contentFrame') {
				iframeElms[i].style.visibility = 'visible';
			}	
		}
	}		

 // Dokument wieder scrollbar machen
	var bodyElm = document.getElementsByTagName('body')[0];
	bodyElm.style.height = '';
	bodyElm.style.overflow = '';
	bodyElm.style.marginRight = '0px';
	resetScroll();

 // Intervall für evtl. Rücksprung Scroll setzen
	setTimeout('resetScroll()', 300);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Reset Scroll für z.B. Opera
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function resetScroll() {
	var yScroll = getPageScroll();
	if (yScroll != initYScroll) {
		window.scrollTo(0, initYScroll);
	}
}


