//
// *****************************************************************
//  Copyright (c) 2002 ORISA Software GmbH All Rights Reserved.
// ORISA Software GmbH
// www.orisa.de
// ****************************************************************
var applicationTop = null;
var gpZIndex = 32000;
var wTB = 8;

function openWindow(url, wName, settings)
{
	var isIOS = parent && parent.bV && parent.bV.OS == "iOS";
	var wTop = 0;
	var wLeft = 0;
	var wWidth = 100;
	var _wWidth = settings.width? settings.width: 100;
	var wHeight = 100;
	var _wHeight = settings.height? settings.height: 100;
	var showTransparentBorder = settings.hasBorder;
	if(typeof(showTransparentBorder) == "undefined" || showTransparentBorder == null)
		showTransparentBorder = true;

	if (typeof(_wHeight)=="string")
		wHeight = parseInt(_wHeight);
	else
		wHeight = _wHeight;

	if (typeof(_wWidth)=="string")
		wWidth = parseInt(_wWidth);
	else
		wWidth = _wWidth;
	
	wStatus = settings.status? settings.status: false;
	wResizable = settings.resize? settings.resize: false;
	wBaseIndex = settings.zIdx? settings.zIdx: 0;
	if(settings.top)
		wTop = settings.top;
	if(settings.left)
		wLeft = settings.left;

	var appendRT = true;
	if (typeof(settings.appendRT)!="undefined" && settings.appendRT==false)
		appendRT = false;
	// append time parameter
	if(url && appendRT)
	{
		if(url.indexOf("?") > -1)
			url += "&dialogId="+wName;
		else
			url += "?dialogId="+wName;
		url += "&RT="+new Date().getTime();
	}
	// open window
	// tsc/slz: PVA not as IFrame; @TODO: bessere Unterscheidung als Fenstername==PVA
	if (wName=="PVA" || (settings.isExternal && settings.isExternal==true))
	{
		if(screen.availHeight)
			wTop = (screen.availHeight - wHeight)/2;
		if(screen.availWidth)
			wLeft = (screen.availWidth - wWidth)/2;
		var wScroll = settings.hasScrollbars && settings.hasScrollbars==true?1:0;
		win = window.open(url, wName,'toolbar=0,location=0,directories=0,status=' + (wStatus == true? 1:0) + ',menubar=0,scrollbars=' + wScroll + ',resizable=' + (wResizable==true? 1:0) + ',left=' + wLeft + ',top=' + wTop + ',width=' + wWidth + ',height=' + wHeight);
	}
	else
	{	
		var fInfo = parent.getFrameInfo(parent);
		var center = (wTop == 0 && wLeft == 0);

		var offset = wTop + (showTransparentBorder?2*wTB:0);
		
		// IOS - no resize!
		if(!isIOS && fInfo.offsetHeight < (wHeight + offset))
			wHeight = fInfo.offsetHeight - offset;
			
		if(center && fInfo.offsetHeight > (wHeight + offset))
			wTop = Math.floor((fInfo.offsetHeight - (wHeight + offset))/2);
		wTop += showTransparentBorder?wTB:0;
		
		if ((settings.allowClose || settings.showCaption) && wTop>13)
		{
			wHeight += 25;
			wTop -= 13;
		}
		
		offset = wLeft + (showTransparentBorder?2*wTB:0);
		
		// IOS - no resize!
		if(!isIOS && fInfo.offsetWidth < (wWidth + offset))
			wWidth = fInfo.offsetWidth - offset;
		
		if(center && fInfo.offsetWidth > (wWidth + offset))
			wLeft = Math.floor((fInfo.offsetWidth - (wWidth + offset))/2);
		wLeft += showTransparentBorder?wTB:0

		var dialogZIndex = getNewZIdx();
		
		// #50461
		var sessionInfo = document.forms["SessionInfo"];
		// #80350
		var completeURL = url;
		if(url.indexOf("soundWindow") == -1 && url.indexOf("zoom") == -1)
			completeURL =  rootURL + "ui/pva/application/" + (typeof(settings.wrap)!="undefined"?"dlgWrapper":"dialog_frame") + ".jsp" + sessionId + "?content=" + escape(url) + "&name=" + wName + "&width=" + wWidth + "&height=" + wHeight + "&LANG="+sessionInfo.LANG.value;
		if(settings.showCaption)
			completeURL += "&caption=" + settings.showCaption;
		if(settings.allowClose)
			completeURL += "&allowClose=" + settings.allowClose;
		if(settings.closeButton)
			completeURL += "&closeButton=" + settings.closeButton;
		win = parent.document.createElement('iframe');

		if(typeof(settings.wrap)!="undefined")
			win.style.visibility = "hidden";
		// Transparent border around dialogs - begin
		
		if (showTransparentBorder)
		{
			var pTransTop = wTop-wTB;
			var pTransLeft = wLeft-wTB;
			var opacity = 14;
			var transBorder = parent.document.createElement(isGecko?'iframe':'div'); // iframes will be shown in front of plugin content (although not transparent)
			transBorder.id = wName + "___transBorder";
			transBorder.style.backgroundColor = "black";	
			transBorder.style.position = "absolute";
			transBorder.style.top = pTransTop;
			transBorder.style.left = pTransLeft;
			transBorder.style.width = wWidth + (2*wTB);
			transBorder.style.height = wHeight + (2*wTB);
			transBorder.style.opacity = "0."+opacity;
			transBorder.style.MozOpacity = "0."+opacity;
			transBorder.style.filter = "Alpha(opacity="+opacity+")";
			transBorder.style.zIndex = dialogZIndex - 1;
			transBorder.innerHTML = "&nbsp;";
			parent.document.body.appendChild(transBorder);		
			if(typeof(settings.wrap)!="undefined")
				transBorder.style.visibility = "hidden";
			// both IE and Gecko don't display transparent divs in front of the plugin;
			// Gecko works if you use an iframe (will not be transparent, but visible)
			// IE doesn't even display a transparent iframe; so an extra, specifically non-transparent iframe is needed
			if (parent.flashInfo && parent.flashInfo.loaded)
			{
				var fPlugIn = {top:42, left:22, width:680, height:340}; // aus bpModule_offer.jsp!
				fPlugIn.top += parent.f_bpmodule.frameElement.offsetTop;
				fPlugIn.left += parent.f_bpmodule.frameElement.offsetLeft;
				if(parent.f_bpmodule.frameElement.offsetParent)
				{
					fPlugIn.top += parent.f_bpmodule.frameElement.offsetParent.offsetTop;
					fPlugIn.left += parent.f_bpmodule.frameElement.offsetParent.offsetLeft;
				}

				var widthOverPlugin = (fPlugIn.left + fPlugIn.width - pTransLeft);
				var maxWidth = wWidth + (2*wTB);
				var heightOverPlugin = (fPlugIn.top + fPlugIn.height - pTransTop);
				var maxHeight = wHeight + (2*wTB);
				if(widthOverPlugin > 0 && heightOverPlugin)
				{
					var transBorderFix = parent.document.createElement('iframe');
					transBorderFix.id = wName + "___transBorderFix";
					transBorderFix.src = rootURL + "ui/pva/shadowFix.html";
					transBorderFix.allowTransparency = false;
					transBorderFix.frameBorder = "0";
					transBorderFix.style.position = "absolute";
					transBorderFix.style.top = pTransTop;
					transBorderFix.style.left = pTransLeft;
					if(typeof(settings.wrap)!="undefined")
						transBorderFix.style.visibility = "hidden";
					transBorderFix.style.width = widthOverPlugin<maxWidth?widthOverPlugin:maxWidth;
					transBorderFix.style.height = heightOverPlugin<maxHeight?heightOverPlugin:maxHeight;
					transBorderFix.style.zIndex = dialogZIndex - 1;
					parent.document.body.appendChild(transBorderFix);
				}
			}
	
			if(isGecko)
			{
				// dialogs may need own glasspane because main glasspane covers only lower half
				var dialog = getLastDialog();
				var gp = parent.document.getElementById("glasspane");
				if(dialog && dialog.style)
				{
					var dialogGP = parent.document.createElement('div');
					dialogGP.id = wName + "___dialogGlasspane";
					dialogGP.style.position = "absolute";
					dialogGP.style.left = dialog.offsetLeft - wTB;
					dialogGP.style.top = dialog.offsetTop - wTB;
					dialogGP.style.width = dialog.offsetWidth + (2*wTB);
					dialogGP.style.height = dialog.offsetHeight + (2*wTB);
					dialogGP.style.zIndex = dialogZIndex - 2;
					
					dialogGP.style.backgroundColor = "#ffffff";
					dialogGP.style.opacity = "0.66";
					dialogGP.style.cursor = "wait";
	
					if (gp && gp.style)
					{
						dialogGP.style.height = gp.offsetTop - dialog.offsetTop + wTB;
					}
	
					
					dialogGP.innerHTML = "&nbsp;";
					parent.document.body.appendChild(dialogGP);
					
				}			
			}
		}
		// Transparent border around dialogs - end
		
		if(isGecko)//Absturz ICC
			setTimeout('win.src = "' + completeURL + '";',50);
		else
			win.src = completeURL;
		win.name = wName;
		win.id = wName;

		if (win.style)
			win.style.zIndex = dialogZIndex;
		parent.document.body.appendChild(win);
		win.opener = self;
		if (win.allowTransparency) win.allowTransparency = false;
		with(win.style)
		{
			position="absolute";
			top = wTop;
			left = wLeft;
			width = wWidth;
			height = wHeight;
	
			// 2005-01-25, tsc; Mozilla needs this:
			//win.style.backgroundColor = "#FFFFFF";
	
			// 2005-01-27, tsc; KHTML needs that:
			//if (isKHTML)
			//	win.style.opacity = 0.99;
		}
	}
	return win;
	//return container;
}
function getDialogCount()
{
	var c=0;
	for(var key in dialogWin)
	{
		if(dialogWin[key])
			c++;
	}
	for(var key in nonmodalWin)
	{
		if(nonmodalWin[key])
			c++;
	}
	return c;
}
function getNewZIdx()
{
	return gpZIndex+2*(getDialogCount()+1);
}
function BrowserDescription()
{
	this.OS	= null;
	this.version = 0;
	this.org = null;
	this.family	= null;
	this.addressCap = "32";

	this.init = detectBrowser;
}
function detectBrowser()
{
	var	platform = null;
	if (typeof(window.navigator.platform) != 'undefined')
	{
		platform = window.navigator.platform.toLowerCase();
		if (platform.indexOf('win') != -1)
			this.OS = 'win';
		else if (platform.indexOf('mac') != -1)
			this.OS = 'mac';
		else if (platform.indexOf('unix') != -1 || platform.indexOf('linux') != -1 || platform.indexOf('sun') != -1)
			this.OS = 'nix';
	}

	var i = 0;
	var ua = window.navigator.userAgent.toLowerCase();
	var foundKHTML = false;
	try
	{
		var _testStr = window+"";
	}
	catch (e)
	{
		foundKHTML = true;
	}
	if (ua.indexOf('safari')!=-1)
	{
		this.family = 'khtml';
		this.org = 'khtml';
		if (foundKHTML)
			// 20050701; tsc; fixed version detection for safari
			// 20080425, bly: notwendig damit auch safari 1 erkannt wird
			this.version = parseFloat(ua.replace(/^.*safari\/(\d+)\.(\d+).*$/, "$1.$2"), 10);
		else
			//20080425, bly: safari (2,3) detection
			this.version = parseFloat(ua.replace(/^.*version\/(\d+)(\.*\d*)(\.*\d*) safari.*$/, "$1$2$3"), 10);
	}
	else if (ua.indexOf('opera') != -1)
	{
		i = ua.indexOf('opera');
		this.family	= 'opera';
		this.org		= 'opera';
		this.version	= parseFloat('0' + ua.substr(i+6), 10);
	}
	else if ((i = ua.indexOf('msie')) != -1)
	{
		this.org		= 'microsoft';
		this.version	= parseFloat('0' + ua.substr(i+5), 10);

		if (this.version < 4)
			this.family = 'ie3';
		else
			this.family = 'ie4'
		if(this.version > 8.0 && (ua.indexOf("win64")> -1 && ua.indexOf("x64")> -1 ))
			this.addressCap = "64";
	}
	else if (typeof(window.controllers) != 'undefined' && typeof(window.locationbar) != 'undefined')
	{
		i = ua.lastIndexOf('/')
		this.version = parseFloat('0' + ua.substr(i+1), 10);
		this.family = 'gecko';

		// 20050701; tsc; fixed version detection for firefox; begin
		if (ua.indexOf('firefox') != -1)
		{
			if (isNaN(this.version = parseFloat(ua.replace(/^.*firefox\/(\d+)\.(\d+)\.(\d+).*$/, "$1.$2$3"), 10)))
				this.version = parseFloat(ua.replace(/^.*firefox\/(\d+)\.(\d+).*$/, "$1.$2"), 10);

			this.org = 'firefox';
		}
		// 20050701; tsc; fixed version detection for firefox; end
		else if (ua.indexOf('netscape') != -1)
			this.org = 'netscape';
		else if (ua.indexOf('compuserve') != -1)
			this.org = 'compuserve';
		else
		{
			this.org = 'mozilla';
			// 20050701; tsc; better version detection for mozilla; begin
			if (ua.match(/rv:\d+\.\d+\.\d+\)/)!=null)
				this.version = parseFloat(ua.replace(/^.*rv:(\d+)\.(\d+)\.(\d+)\).*$/, "$1.$2.$3"));
			// 20050701; tsc; better version detection for mozilla; end;
		}
	}
	if(this.OS == null && this.org == 'khtml')
	{
		var k = navigator.userAgent.indexOf('iPhone') != -1?1:navigator.userAgent.indexOf('iPod') != -1?2:navigator.userAgent.indexOf('iPad') != -1?4:0;
		if(k > 0)
		{
			this.OS = 'iOS';
			this.org = 'mac';
			//this.family = k==1?"iPhone":k==2?"iPod":"iPad";
		}
	}
}

// add/ update field value in specified form
function addEntryToForm(form, id, value)
{
	var entry = form.elements[id];
	if(typeof entry == "undefined" && value != null)
	{
		entry = document.createElement('INPUT');
		entry.type = "hidden";
		entry.name = id;
		entry.id = id;
		form.appendChild(entry);
		
	}
	if(entry)
		entry.value = value;
}
// check access to superviced frame
// call swapServer function if access is denied.
var disableResponseCheck = {};
function checkResponse(svFrame, ctrlPath, fName)
{
	try
	{
		var c = svFrame.document.cookie;
	}
	catch (e)
	{
		//  IE throws security exception because it loads a local Error-HTML page,
		// so that indicates that requested page could not be retrieved	
		if (ctrlPath && !disableResponseCheck[fName])
			ctrlPath.swapServer();
	}
}
function supplantRival(wName, src)
{
    var cF = document.createElement("FORM");
    document.body.appendChild(cF);
    cF.action = src;
    cF.target = wName;
    cF.submit();
}
function getUnicodeMessage(s)
{
	s = s.replace(/\'/g, "\\'");
	s = s.replace(/\"/g, "\\\"");
	return eval(("\"" + s + "\"").replace(/&#(\d+);/g, "\"+String.fromCharCode(parseInt(\"$1\",10))+\"").replace(/\n/g, "\\n"));	
}
// Reihenfolge beachten!
function convJsToHTML(s)
{
	//s = s.replace(/&/g, "&amp;");
	s = s.replace(/</g, "&lt;");
	s = s.replace(/>/g, "&gt;");
	s = s.replace(/\n/g, "<br/>");
	//s = s.replace(/\"/g, "&quot;");
	//s = s.replace(/\'/g, "&#39;");
	return s;
}
// Pugin-Informationen bündeln:
function PluginInfo(s, f, unity)
{
	this.shockwave = {req: s, version: "", installed: false};
	this.flash = {req: f, version: "", installed: false};
	this.unity = {req: unity, version: "", installed: false};
	
	this.setVersion = function(key, version)
	{
		var cP = this[key];
		if(cP)
    	{
			cP.version = version;
			cP.installed = this.compVersion(cP.version, cP.req); 
		}
	}
	this.getVersion = function(key)
	{
		if(this[key].version)
			return this[key].version;
		return "";
	}
	this.isInstalled = function(key)
	{
		if(key && this[key])
			return this[key].installed;
		return false;
	}
	// Vergleich von Versionsnummern (die kürzere bestimmt die zu vergleichende Länge)
	this.compVersion = function(cV, reqV)
	{
		rV = false;
		if(cV)
		{
			rV = true;
			var cArr = cV.split(".");
			var rArr = reqV.split(".");
			var min = cArr.length < rArr.length? cArr.length: rArr.length;
			for(var i=0; (rV == true && i < min); i++)
			{
				var cComp = parseInt(cArr[i]);
				var rComp = parseInt(rArr[i]);
				if(cComp > rComp)
					break;
				else if(cComp < rComp)
					rV = false;
			}
		}
		return rV;
	}
}

function getPageOffset(cntrl, pos)
{
    while (cntrl)
    {
        pos.y += cntrl.offsetTop - cntrl.scrollTop;
        pos.x += cntrl.offsetLeft;
        cntrl = cntrl.offsetParent;
    }
    return pos;
}

function getAbsOffset(cObj, pos)
{
	// offset caused by parent frames
	while(cObj && cObj.frameElement)
	{
		pos.y  -= cObj.document.body.scrollTop;
		pos.x  -= cObj.document.body.scrollLeft;
		getPageOffset(cObj.frameElement, pos);
		if(cObj.name != top.name)
			cObj = cObj.parent;
		else
			cObj = null;
	}
	return pos;
}

function getPos(win, evt)
{
	var pos={x:0,y:0};
	if (evt)
	{
		if (typeof(evt.pageX) == 'number'){
			pos.x = evt.pageX;
			pos.y = evt.pageY;
		}
		else {
			pos.x = evt.clientX;
			pos.y = evt.clientY;
			if (!top.opera){
				if ((!win.document.compatMode) || (win.document.compatMode == 'BackCompat')){
					pos.x += win.document.body.scrollLeft;
					pos.y += win.document.body.scrollTop;
				}
				else {
					pos.x += win.document.documentElement.scrollLeft;
					pos.y += win.document.documentElement.scrollTop;
				}
			}
		}
	}
	return pos;
}

