function futunaQSKeepaliveActivate(seconds)
{
    window.setInterval("futunaQSKeepaliveExecute()", seconds * 1000);
}

var futunaQSKeepaliveCounter = 0;
var futunaQSKeepaliveXMLDoc = null;
function futunaQSKeepaliveExecute()
{
    try
    {

        var url = contextPath + "/keepalive?serviceconfig=default"
                + "&amp;random=" + (futunaQSKeepaliveCounter++) + "-" + Math.random();

        Browser.callURL(url);
    }
    catch(e)
    {
        // ignore
        alert("Error while sending keep alive request: " + e.message);
    }
}




function PopupObserver(popupname, popup, unloadurl)
{
	this.popupname = popupname;
	this.popup = popup;
	this.unloadurl = unloadurl;
	this.stopped = false;
}

PopupObserver.prototype.stop = function()
{
	if (!this.stopped)
	{
		this.stopped = true;
		Browser.callURLAsync(this.unloadurl);
	}
};

PopupObserver.prototype.check = function()
{
	if (this.popup.closed)
	{
		this.stop();
	}
	else
		this.checkobserver =
			window.setTimeout("Browser.checkPopup('" + this.popupname + "');", 100);
};


function BrowserUtil()
{
	this.ie = window.navigator.systemLanguage && !window.navigator.language;
	this.popupobserver = new Object();
}

BrowserUtil.prototype.addOnloadHandler = function(domNode, handler)
{
	if (this.ie)
		domNode.attachEvent("onload", handler);
	else
		domNode.addEventListener("load", handler, true);
};

BrowserUtil.prototype.addOnUnloadHandler = function(domNode, handler)
{
	if (this.ie)
		domNode.attachEvent("onunload", handler);
	else
		domNode.addEventListener("unload", handler, true);
};

BrowserUtil.prototype.isIE = function()
{
	return this.ie;
};

BrowserUtil.prototype.callURL = function(url)
{
	if (this.ie)
	{
		var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
		xmldoc.load(url);
	}
	else
	{
		var xmldoc = document.implementation.createDocument("", "", null);
		xmldoc.load(url);
	}
};

BrowserUtil.prototype.callURLAsync = function(url)
{
	window.setTimeout("Browser.callURL('" + url + "');", 1);
};

BrowserUtil.prototype.openCenteredWin = function(windowURL, name, width,
												 height, isResizable,
												 showScrollbars,
												 showMenubar,
												 showToolbar, unloadurl)
{
	var x,y;
	x = screen.width / 2 - (width / 2);
	y = screen.height / 2 - (height / 2);
	// Bei zu gro?en Fenstern muss verhindert werden, dass der Fensterrand au?erhalb des sichtbaren Bereichs
	// des Screen positioniert wird.
	if (x < 0)
		x = 0;
	if (y < 0)
		y = 0;

	var newWindow = Browser.openWindow(windowURL, name, width, height, x, y,
			isResizable, showScrollbars, showMenubar, showToolbar);

	if (unloadurl)
	{
		Browser.openPopup(name, newWindow, unloadurl);
	}

	return newWindow;
};


BrowserUtil.prototype.openWindow = function(windowURL, windowName, width, height, x, y, isResizable, showScrollbars, showMenubar, showToolbar)
{
	var winParamString = 'dependent=yes,';
	if (isResizable)
		winParamString = winParamString + 'resizable=yes,';
	else
		winParamString = winParamString + 'resizable=no,';

	if (showScrollbars)
		winParamString = winParamString + 'scrollbars=yes,';
	else
		winParamString = winParamString + 'scrollbars=no,';

	if (showMenubar)
		winParamString = winParamString + 'menubar=yes,';
	else
		winParamString = winParamString + 'menubar=no,';

	if (showToolbar)
		winParamString = winParamString + 'toolbar=yes,';
	else
		winParamString = winParamString + 'toolbar=no,';

	winParamString = winParamString + 'width=' + width + ',height=' + height + ",top=" + y + ",left=" + x;
	var newWindow = window.open(windowURL, windowName, winParamString);
	newWindow.focus();
	return newWindow;
};



BrowserUtil.prototype.getPopupObserver = function(name)
{
	return this.popupobserver[name];
};

BrowserUtil.prototype.checkPopup = function(name)
{
	var observer = this.getPopupObserver(name);
	if (observer != null)
		observer.check();
};

BrowserUtil.prototype.openPopup = function(name, popup, unloadurl)
{
	var observer = this.getPopupObserver(name);
	if (observer != null)
		observer.stop();

	observer = new PopupObserver(name, popup, unloadurl);
	this.popupobserver[name] = observer;
	observer.check();
};

Browser = new BrowserUtil();


function IFrameResizer(sId, iframeName, minWidth, divId, src)
{
	if (sId)
	{
		this.init(sId, iframeName, minWidth, divId, src);
	}
}
IFrameResizer.prototype.init = function(sId, iFrameId, minHeight, divId, src)
{
	var me = this;

	this.sId = sId;
	this.iFrameId = iFrameId;
	this.minHeight = minHeight;
	this.divId = divId;
	this.iFrame = null;
	this.src = src;

	this.iframeLoadListener = function(e)
	{
		var pageDocument = me.iFrame.contentWindow.document;
		var htmlElement = pageDocument.getElementsByTagName("BODY")[0];

		var height;

		if (Browser.isIE())
			height = htmlElement.scrollHeight;
		else
			height = htmlElement.offsetHeight + 15;

		// window.document.reload()

		if (height < me.minHeight)
			height = me.minHeight;

		this.height = height;

		me.iFrame.height = height;
		document.getElementById(me.divId).style["height"] = height + "px";

		return false;
	};
};













