// ***********************************************************
// Copyright by MACRON Software Entwicklungs u. Marketing GmbH
//          Fichtestrasse 66-68, A-8020 Graz, Austria
//             Tel: +43-(0)316-931837  Fax: DW -20
//          http://www.macron.at     office@macron.at
// ***********************************************************

function frames_missing ()
{
    // Determine if document should be loaded into a frame
    return (
	    self == top && top.frames.length == 0 &&
	    (
		!opener ||
		(
			opener.location &&
			opener.location.hostname == self.location.hostname &&
			opener.location.href == self.location.href
		)
	    )
    );
}

function startScrollingDetector()
{
    if (showToTopLink)
    {
	setInterval("showToTopLink()", 250);
    }
}

function openWindow ()
{
    closeWindow ();
    var args = openWindow.arguments;
    
    if (args != null && args.length > 0)
    {
	var url = args[0];
	var name = "popUp";
	var winProps = "";
	var winProp = "";
	for (var i = args.length; i-- > 1; )
	{
	    if (i == 1)
	    {
		winProp = "width=" + args[i];
	    }
	    else if (i == 2)
	    {
		winProp = "height=" + args[i];
	    }
	    else if (i == 3)
	    {
		winProp = "menubar=" + args[i];
	    }
	    else if (i == 4)
	    {
		winProp = "toolbar=" + args[i];
	    }
	    else if (i == 5)
	    {
		winProp = "scrollbars=" + args[i];
	    }
	    else if (i == 6)
	    {
		winProp = "status=" + args[i];
	    }
	    else if (i == 7)
	    {
		winProp = "resizable=" + args[i];
	    }
	    else if (i == 8)
	    {
		winProp = "location=" + args[i];
	    }
	    else if (i == 9)
	    {
		winProp = "top=" + args[i];
	    }
	    else if (i == 10)
	    {
		winProp = "left=" + args[i];
	    }
	    else if (i == 11)
	    {
		name = args[i];
	    }
	    else
	    {
		winProp = "";
	    }
	    
	    if (winProps.length > 0)
	    {
		winProps += ",";
	    }
	    winProps += winProp;
	}
	attrs = new Array ("LOCALIZER_LANGUAGE", "_zsessionid");
	for (var i=attrs.length; i-- > 0; )
	{
	    if (get_url_attribute (url, attrs[i]) == "")
	    {
		attr = get_url_attribute (self.location.href, attrs[i]);
		if (attr != "")
		{
		    url = set_url_attribute (url, attrs[i], attr);
		}
	    }
	}
	popupWin = window.open (url, name, winProps);
    }
    else
    {
	alert ("openWindow requires at least one argument: url!\n\nOptional arguments are:\n  1.) width [pixel]\n  2.) height [pixel]\n  3.) menubar [yes|no]\n  4.) toolbar [yes|no]\n  5.) scrollbars [yes|no]\n  6.) status [yes|no]\n  7.) resizeable [yes|no]\n  8.) location [yes|no]\n  9.) top [pixel]\n 10.) left [pixel]\n 11.) name [string]\n");
    }
}

function closeWindow ()
{
    if (typeof (popupWin) == "object")
    {
	if (popupWin.closed == false)
	{
	    popupWin.close ();
	}
    }
}

function getWindowWidth (winObj)
{
    var intWidth = 0;
    
    if (winObj)
    {
	if (window.innerWidth)
	{
	    intWidth = winObj.innerWidth;
	}
	else if (document.all)
	{
	    intWidth = winObj.document.body.clientWidth;
	}
    }
    
    return intWidth;
}

function getWindowHeight (winObj)
{
    var intHeight = 0;
    
    if	(winObj)
    {
	if (window.innerHeight)
	{
	    intHeight = winObj.innerHeight;
	}
	else if (document.all)
	{
	    intHeight = winObj.document.body.clientHeight;
	}
    }
    
    return intHeight;
}


function getPagePosX (winObj)
{
    var posX = 0;
    
    if (document.all)
    {
	// IEs
	posX = winObj.document.body.scrollLeft;
    }
    else
    {
	// non IEs
	posX = winObj.pageXOffset;
    }
    
    return posX;
}


function getPagePosY (winObj)
{
    var posY = 0;
    
    if (document.all)
    {
	// IEs
	posY = winObj.document.body.scrollTop;
    }
    else
    {
	// non IEs
	posY = winObj.pageYOffset;
    }
    
    return posY;
}

function getMousePosX (e)
{
    var posX = 0;
    if (document.all)
    {
	posX = e.x + document.body.scrollLeft;
    }
    else if (document.layers || document.getElementById)
    {
	posX = e.pageX;
    }
    return posX;
}

function getMousePosY (e)
{
    var posY = 0;
    if (document.all)
    {
	posY = e.y + document.body.scrollTop;
    }
    else if (document.layers || document.getElementById)
    {
	posY = e.pageY;
    }
    return posY;
}


function startPrinting (message)
{
    if (window.print)
    {
	if (confirm (message))
	{
	    window.print ();
	}
    }
}


function popUp (url)
{
    openWindow (url, 650, 550, "no", "no", "yes", "yes");
}

function refresh ()
{
    var args = refresh.arguments;
    var winObj = self;
    if (args.length > 0)
    {
	winObj = args[0];
    }

    winObj.location.reload ();
}

function get_url_attribute (url, name)
{
    url = unescape (url).replace ("&amp;", "&");
    var value = "";
    var pos = url.indexOf ("?" + name + "=");
    if (pos == -1)
    {
	pos = url.indexOf ("&" + name + "=");
    }
    if (pos > -1)
    {
	pos += name.length + 2;

	var pos2 = url.indexOf ("&", pos + 1);
	if (pos2 == -1)
	{
	    pos2 = url.length;
	}
	value = url.substring (pos, pos2);
    }
    return value;
}

function set_url_attribute ()
{
    var args = set_url_attribute.arguments;
    var url = "";

    if (args != null && args.length > 2)
    {
	url = args[0].replace ("&amp;", "&");

	for (var i = 1; i < args.length; i += 2)
	{
	    var concatChar = "";
	    var name = args[i];
	    var value = args[i + 1];

	    if (url.indexOf ("?" + name + "=") > -1)
	    {
		concatChar = "?";
	    }
	    else if (url.indexOf ("&" + name + "=") > -1)
	    {
		concatChar = "&";
	    }
	    if (concatChar.length > 0)
	    {
		url = url.replace (concatChar + name + "=" + getUrlAttribute (url, name), concatChar + name + "=" + value);
	    }
	    else
	    {
		url += ((url.indexOf ("?") > -1)?"&":"?") + name + "=" + value;
	    }
	}
    }
    return url;
}
