/* layerlib.js: Simple Layer library with basic
compatibility checking */

/* detect objects */
var layerobject = ((document.layers) ? (true) : (false));
var dom = ((document.getElementById) ? (true) : (false));
var allobject = ((document.all) ? (true) : (false));

/* detect browsers */
opera=navigator.userAgent.toLowerCase().indexOf('opera')!=-1;

/* return the object for the passed layerName value */
function MyLayergetElement(thedocument,layerName,parentLayer)
	{
	if(layerobject)
		{
		layerCollection = thedocument.layers;
		if (layerCollection[layerName])
			return layerCollection[layerName];
		/* look through nested layers */
		for(i=0; i < layerCollection.length;)
			return(thedocument.getElementById(layerName, layerCollection[i++]));
		}
	if (allobject)
		return thedocument.all[layerName];
		if (dom)
			return thedocument.getElementById(layerName);
}

/* hide the layer with id = layerName */
function MyLayerhide(thedocument,layerName)
	{
	var theLayer = thedocument.getElementById(layerName);

	if (theLayer != null)
 		{
		MyLayerJustShow(thedocument,layerName);
		MyLayersetURL(thedocument,layerName,"",".");

		if (layerobject)
			{
			theLayer.visibility = 'hide';
			}
		else
			theLayer.style.visibility = 'hidden';
		}
	}

/* show the layer with id = layerName */
function MyLayershow(thedocument,layerName,x1,y1,x2,y2)
	{
	var theLayer = thedocument.getElementById(layerName);

 	if (theLayer != null)
 		{
		MyLayersetX(thedocument,layerName,x1);
		MyLayersetY(thedocument,layerName,y1);
		MyLayersetHeight(thedocument,layerName,y2);
		MyLayersetWidth(thedocument,layerName,x2);
		//MyLayersetClip(thedocument,layerName,x1,y1,x2,y2);

		if (layerobject) theLayer.visibility = 'show';
		else theLayer.style.visibility = 'visible';
		}
	}

/* show the layer with id = layerName */
function MyLayerJustShow(thedocument,layerName)
	{
	var theLayer = thedocument.getElementById(layerName);

 	if (theLayer != null)
 		{
		if (layerobject) theLayer.visibility = 'show';
		else theLayer.style.visibility = 'visible';
		}
	}

/* show the layer with id = layerName
function MyAutoLayershow(thedocument,layerName)
	{
	var theLayer = thedocument.getElementById(layerName);

 	if (theLayer != null)
 		{
		MyLayersetX(thedocument,layerName,0);
		MyLayersetY(thedocument,layerName,0);
		MyLayersetHeight(thedocument,layerName,getDocumentHeight());
		MyLayersetWidth(thedocument,layerName,getDocumentWidth());

		if (layerobject) theLayer.visibility = 'show';
		else theLayer.style.visibility = 'visible';
		}
	}*/

/* set the x-coordinate of layer named layerName */
function MyLayersetX(thedocument,layerName, x)
	{
	var theLayer = thedocument.getElementById(layerName);

 	if (theLayer != null)
 		{
		if (layerobject)
			theLayer.left=x;
		else if (opera)
			theLayer.style.pixelLeft=x;
		else
			theLayer.style.left=x+"px";
		}
	}

/* set the y-coordinate of layer named layerName */
function MyLayersetY(thedocument,layerName, y)
	{
	var theLayer = thedocument.getElementById(layerName);

 	if (theLayer != null)
 		{
		if (layerobject)
			theLayer.top=y;
		else if (opera)
			theLayer.style.pixelTop=y;
		else
			theLayer.style.top=y+"px";
		}
	}

/* set the z-index of layer named layerName */
function MyLayersetZ(thedocument,layerName, zIndex)
	{
	var theLayer = thedocument.getElementById(layerName);

	if (theLayer != null)
 		{
		if (layerobject)
			theLayer.zIndex = zIndex;
		else
			theLayer.style.zIndex = zIndex;
		}
	}

/* set the height of layer named layerName */
function MyLayersetHeight(thedocument,layerName, height)
	{
	var theLayer = thedocument.getElementById(layerName);

 	if (theLayer != null)
 		{
		if (layerobject)
			theLayer.clip.height = height;
		else if (opera)
			theLayer.style.pixelHeight = height;
		else
			theLayer.style.height = height+"px";
		}
	}

/* set the width of layer named layerName */
function MyLayersetWidth(thedocument,layerName, width)
	{
	var theLayer = thedocument.getElementById(layerName);

 	if (theLayer != null)
 		{
		if (layerobject)
			theLayer.clip.width = width;
		else if (opera)
			theLayer.style.pixelWidth = width;
		else
			theLayer.style.width = width+"px";
		}
	}

/* set the clipping rectangle on the layer named layerName
defined by left, top, right, bottom */
function MyLayersetClip(thedocument,layerName, left, top, right, bottom)
	{
	var theLayer = thedocument.getElementById(layerName);

 	if (theLayer != null)
 		{
		if (layerobject)
			{
			theLayer.clip.top = top;
			theLayer.clip.right = right;
			theLayer.clip.bottom = bottom;
			theLayer.clip.left = left;
			}
		else
			theLayer.style.clip = "rect("+top+"px "+right+"px "+" "+bottom+"px "+left+"px)";
		}
	}

/* set the contents of layerName to passed content*/
function MyLayersetURL(thedocument,layerName, URL, imageloc, title)
	{
	var theLayer = thedocument.getElementById(layerName);

 	if (theLayer != null)
 		{
		if (layerobject)
			{
			theLayer.document.write("<html><head><script type='text/javascript' src='layerlib.js'></script></head><body><div style='position:absolute;top:3px;left:3px;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:70%;font-style:normal;line-height:normal;font-weight:bold;color:#46a3ff;z-index:10;'>" + title + "</div><div style='position:absolute;top:10px;right:20px;CURSOR:pointer;z-index:1;'><img '" + imageloc + "close.jpg' onclick='MyLayerhide(document,\"" + layerName + "\");' alt='Close page'></div></body></html>");
			theLayer.document.location.href = URL;
			theLayer.document.close();
			}
		else
			{
			theLayer.innerHTML = "<html><body><div style='position:absolute;top:3px;left:3px;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:70%;font-style:normal;line-height:normal;font-weight:bold;color:#46a3ff'>" + title + "</div><div style='position:absolute;top:2px;right:20px;CURSOR:pointer;z-index:1'><img src='" + imageloc + "close.jpg' onclick='MyLayerhide(document,\"" + layerName + "\");' alt='Close page'></div><nolayer><iframe src='" + URL + "' width='100%' height='95%' style='position:absolute;top:20px;left:0px;CURSOR:pointer;z-index:2'></iframe></nolayer></body></html>";
			}
		}
	}

/* set the contents of layerName to passed content*/
function MyLayersetNoCloseURL(thedocument,layerName, URL, frames, scrolling)
	{
	var theLayer = thedocument.getElementById(layerName);

 	if (theLayer != null)
 		{
		if (layerobject)
			{
			theLayer.document.write("");
			theLayer.document.location.href = URL;
			theLayer.document.close();
			return;
			}
		else
			{
			theLayer.innerHTML = "<html><body><nolayer><iframe src='" + URL + "' width='96%' height='100%' frameborder='" + frames + "' scrolling='" + scrolling + "' style='position:relative;top:0px;left:0px;CURSOR:pointer;z-index:1'></iframe></nolayer></body></html>";
			}
		}
	}
