// Filename: layer.js
// Project : Javascript Library
//
// Description:
// A browser independent layer library.  Uses layers in Nav4 and absolute positioned
// divs in IE4+, Nav6 and Opera.
//
// Create layers using the following syntax or equivalent:
//  <div id="mylayer" style="position:absolute; left:400px; top:100px; width:300px; height:300px; visibility:hidden;">
//  	Now is the time for all good men to come to the aid of their country!
//	</div>
// In order to support NS4, divs cannot be nested for these functions, as the routines do not account for the
// sub-document hierarchy of layers.
//
// Revision History:
// 11FEB2001 - MJT - Initial development.

// LAYER_Available
// Determines if one of the three browser levels of support for layers/divs is available.
// Returns: TRUE if layers are supported 
function LAYER_Available( )
{
	return ( document.getElementById || document.all || document.layers );
}

// LAYER_ToValue
// Converts a definition of a coordinate (left, top, height, width) to a numeric value 
// so that we can modify it with mathematical functions
// strValue: string version of the value
// returns: numeric version of the value
function LAYER_ToValue( strValue )
{
	var i;
	var ch;
	var dblValue = "0";
	var strNumerics = '0123456789-';
	
	for ( i=0; i < strValue.length; i++ )
	{
		ch = strValue.charAt( i );
		if ( strNumerics.indexOf( ch ) == -1 )
		{
			return parseInt(dblValue, 10 );
		}
		dblValue += ch;
	}
	return parseInt( dblValue, 10 );
}

// LAYER_Get
// Retrieve a DOM independent layer for manipulation
// strId: target layer
// returns: access to the styles for the layer
function LAYER_Get( strId )
{
	if ( document.getElementById )
	{
		return document.getElementById( strId ).style;
	}
	else if ( document.all )
	{
		return document.all[ strId ].style;
	}
	else if ( document.layers )
	{
		return document.layers[ strId ];
	}
}

// LAYER_Hide
// Hide the layer specified by Id
// strId: target layer
// Returns: nothing
function LAYER_Hide( strId )
{
	LAYER_Get( strId ).visibility = 'hidden';
}

// LAYER_Show
// Show the layer specified by Id
// strId: target layer
// returns: nothing
function LAYER_Show( strId )
{
	LAYER_Get( strId ).visibility = 'visible';
}

// LAYER_MoveTo
// Move the specified layer to the supplied position. The position
// must be supplied in the coordinate format used when the layer/div
// was created.
// strId: target layer
// lngLeft: x position of top left corner
// lngTop: y position of top left corner
// returns: nothing
function LAYER_MoveTo( strId, lngLeft, lngTop )
{
	var e = LAYER_Get( strId )
	e.top = lngTop;
	e.left = lngLeft;
}

// LAYER_MoveBy
// Move the specified layer by the specified distance in x and y.  The
// format of the x and y coordinates should match the format established 
// when the layer was created.
// strId: target layer
// lngX: amount to move in X
// lngY: amount to move in Y
// returns: nothing
function LAYER_MoveBy( strId, lngX, lngY )
{
	var e = LAYER_Get( strId );
	var lngTop = LAYER_ToValue( e.top );
	var lngLeft = LAYER_ToValue( e.left );
	e.top = lngTop + lngY;
	e.left = lngLeft + lngX;
}

// LAYER_ResizeTo
// Resize the layer to the specified height and width.  The format of the 
// height and width should match the format established when the layer was
// created.
// strId: target layer
// lngWidth: new width of the layer
// lngHeight: new height of the layer
function LAYER_ResizeTo( strId, lngWidth, lngHeight )
{
	var e = LAYER_Get( strId );
	e.height = lngHeight;
	e.width = lngWidth;
}

// LAYER_ResizeBy
// Resize the layer by the specified height and width changes.  The format of 
// the height and width should match the format established when the layer was
// created.
// strId: target layer
// lngDeltaX: width change
// lngDeltaY: height change
// returns: nothing
function LAYER_ResizeBy( strId, lngDeltaX, lngDeltaY )
{
	var e = LAYER_Get( strId );
	var lngWidth = LAYER_ToValue( e.width );
	var lngHeight = LAYER_ToValue( e.height );
	e.width = lngWidth + lngDeltaX;
	e.height = lngHeight + lngDeltaY;
}
