// ***********************************************************
// 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
// ***********************************************************

//-------------------------------------------------------------------------------------------
// functions to move and show/hide layers
var actLayerName = "";
var layerTimer = null;
var isIE = false;
var isNS = false;
var isDOM = false;

if (document.layers)
{
    isNS = true;
}
else if (document.getElementById)
{
    isDOM = true;
}
else if (document.all)
{
    isIE = true;
}

function showToTopLink()
{
    if (getLayer("ToTop"))
    {
	showLayer ("ToTop", getPagePosY(self) > 0);
    }
}

function fitIntoWindow ()
{
    var args = fitIntoWindow.arguments;
    var layer = null;
    if (args != null && args.length > 0)
    {
	layer = getLayer (args[0]);
    }
    if (layer)
    {
	var width = String (layer.width);
	var height = String (layer.height);
	var x = String (layer.left);
	var y = String (layer.top);
	var winX = 0;
	var winY = 0;
	var winWidth = 600;
	var winHeight = 450;
	var pat = /^([-+0-9]+)(.*)$/;
	var unit = "";
	if (getPagePosX)
	{
	    winX = getPagePosX (self);
	}
	if (getPagePosY)
	{
	    winY = getPagePosY (self);
	}
	if (getWindowWidth)
	{
	    winWidth = getWindowWidth (self);
	}
	if (getWindowHeight)
	{
	    winHeight = getWindowHeight (self);
	}
	if (getPagePosY)
	{
	    winY = getPagePosY (self);
	}
	if (width)
	{
	    m = width.match (pat);
	    if (m && m.length > 0)
	    {
		width = parseInt (m[1]);
	    }
	}
	else if (args.length > 1)
	{
	    width = parseInt (args[1]);
	}
	else
	{
	    width = 0;
	}
	if (height)
	{
	    m = height.match (pat);
	    if (m && m.length > 0)
	    {
		height = parseInt (m[1]);
	    }
	}
	else if (args.length > 2)
	{
	    height = parseInt (args[2]);
	}
	else
	{
	    height = 0;
	}
	var m = null;
	if (x)
	{
	    m = x.match (pat);
	    if (m && m.length > 0)
	    {
		x = parseInt (m[1]);
		if (m.length > 1)
		{
		    unit = m[2];
		}
	    }
	}
	else
	{
	    x = 0;
	}
	if (y)
	{
	    m = y.match (pat);
	    if (m && m.length > 0)
	    {
		y = parseInt (m[1]);
		if (m.length > 1)
		{
		    unit = m[2];
		}
	    }
	}
	else
	{
	    y = 0;
	}
	/*alert (
	       "x: " + x + "\n" + 
	       "y: " + y + "\n" + 
	       "w: " + width + "\n" + 
	       "h: " + height + "\n" + 
	       "winX: " + winX + "\n" + 
	       "winY: " + winY + "\n" + 
	       "winW: " + winWidth + "\n" + 
	       "winH: " + winHeight
	       );*/
	if (x + width > winX + winWidth)
	{
	    x = winX + winWidth - width - 1;
	}
	if (y + height > winY + winHeight)
	{
	    y = winY + winHeight - height - 1;
	}
	if (x < 0)
	{
	    x = 0;
	}
	if (y < 0)
	{
	    y = 0;
	}
	layer.left = "".concat (String (x)).concat (unit);
	layer.top = "".concat (String (y)).concat (unit);
    }
}

function getLayer (layerName)
{
    var layer = null;
    if (isNS)
    {
	layer = document.layers[layerName];
    }
    else if (isDOM)
    {
	layer = document.getElementById (layerName);
	if (layer)
	{
	    layer = layer.style;
	}
    }
    else if (isIE)
    {
	layer = document.all[layerName];
	if (layer)
	{
	    layer = layer.style;
	}
    }
    return layer;
}

function moveLayer (strLayerName, intX, intY)
{
    var layer = getLayer (strLayerName);
    if (layer)
    {
	layer.left = intX;
	layer.top = intY;
    }
}	// ENDE moveLayer()


function showLayer (strLayerName, boolStatus)
{
    var layer = getLayer (strLayerName);
    if (layer)
    {
	var strVisProp = "inherit";
	if (boolStatus)
	{
	    strVisProp = "visible";
	}
	else if (!boolStatus)
	{
	    strVisProp = "hidden";
	}
	layer.visibility = strVisProp;
    }
}	// ENDE showLayer


function showMenu (strLayerName)
{
    showLayer (actLayerName, false);
    showLayer (strLayerName, true);
    actLayerName = strLayerName;
}


function activateLayer (layerName)
{
    clearLayerTimer ();
    if (layerName != actLayerName)
    {
	hideLayer ();
    }
    fitIntoWindow (layerName);
    showLayer (layerName, true);
    actLayerName = layerName;
}

function hideLayer ()
{
    showLayer (actLayerName, false);
}

function clearLayerTimer ()
{
    window.clearTimeout (layerTimer);
    layerTimer = null;
}

function setLayerTimer ()
{
    var timeSpan = 1500;
    var args = setLayerTimer.arguments;
    if (args != null && args.length > 0)
    {
	timeSpan = args[0];
    }

    layerTimer = window.setTimeout ("hideLayer ()", timeSpan);
}

function getLayerTimerAction ()
{
    if (isNS)
    {
	clearLayerTimer ();
	setLayerTimer ();
    }
}
