// Determine browser.

var isAppNS4 = (navigator.appName.indexOf("Netscape") >= 0 && parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
var isAppIE4 = (document.all) ? 1 : 0;
var isAppIE5 = (isAppIE4 && navigator.appVersion.indexOf("5.")) >= 0 ? 1 : 0;

//-----------------------------------------------------------------------------
// Layer visibility.
//-----------------------------------------------------------------------------

function hideLayer( oLayer)
{
	if (isAppNS4)	oLayer.visibility		= "hide";
	if (isAppIE4)	oLayer.style.visibility	= "hidden";
}


function showLayer( oLayer)
{
	if (isAppNS4)	oLayer.visibility = "show";
	if (isAppIE4)	oLayer.style.visibility = "visible";
}

function isVisible( oLayer)
{
	if (isAppNS4 && oLayer.visibility == "show")				return true;
	if (isAppIE4 && oLayer.style.visibility == "visible")	return true;
	return false;
}

//-----------------------------------------------------------------------------
// Layer positioning.
//-----------------------------------------------------------------------------
function moveLayerTo(oLayer, x, y)
{
	if (isAppNS4)	oLayer.moveTo(x, y);
	if (isAppIE4)
	{
		oLayer.style.left = x;
		oLayer.style.top  = y;
	}
}

function moveLayerBy(oLayer, dx, dy)
{
	if (isAppNS4)	oLayer.moveBy(dx, dy);
	if (isAppIE4)
	{
		oLayer.style.pixelLeft += dx;
		oLayer.style.pixelTop  += dy;
	}
}

function getLeft(oLayer)
{
	if (isAppNS4)	return oLayer.left;
	if (isAppIE4)	return oLayer.style.pixelLeft;
	return -1;
}

function getTop(oLayer)
{
	if (isAppNS4)	return oLayer.top;
	if (isAppIE4)	return oLayer.style.pixelTop;
	return -1;
}

function getRight(oLayer)
{
	if (isAppNS4)	return (oLayer.left + getWidth(oLayer));
	if (isAppIE4)	return (oLayer.style.pixelLeft + getWidth(oLayer));
	return -1;
}

function getBottom(oLayer)
{
  if (isAppNS4)			return (oLayer.top + getHeight(oLayer));
  else if (isAppIE4)	return (oLayer.style.pixelTop + getHeight(oLayer));
  return -1;
}

function getPageLeft(oLayer)
{
	if (isAppNS4)	return oLayer.pageX;
	if (isAppIE4)	return oLayer.offsetLeft;
	return -1;
}

function getPageTop(oLayer)
{
	if (isAppNS4)	return oLayer.pageY;
	if (isAppIE4)	return oLayer.offsetTop;
	return -1;
}

function getWidth(oLayer)
{
	if (isAppNS4)
	{
		if (oLayer.document.width)
			return oLayer.document.width;
		else
			return oLayer.clip.right - oLayer.clip.left;
	}
	if (isAppIE4)
	{
		if (oLayer.style.pixelWidth)
			return oLayer.style.pixelWidth;
		else
			return oLayer.clientWidth;
	}
	return -1;
}

function getHeight(oLayer)
{
	if (isAppNS4)
	{
		if (oLayer.document.height)
			return (oLayer.document.height);
		else
			return (oLayer.clip.bottom - oLayer.clip.top);
	}
	if (isAppIE4)
	{
		if (false && oLayer.style.pixelHeight)
			return(oLayer.style.pixelHeight);
		else
			return(oLayer.clientHeight);
	}
	return -1;
}

function getzIndex(oLayer)
{
	if (isAppNS4)	return oLayer.zIndex;
	if (isAppIE4)	return oLayer.style.zIndex;
	return -1;
}

function setzIndex(oLayer, z)
{
	if (isAppNS4)	oLayer.zIndex		= z;
	if (isAppIE4)	oLayer.style.zIndex	= z;
}

//-----------------------------------------------------------------------------
// Layer clipping.
//-----------------------------------------------------------------------------

function clipLayer(oLayer, clipleft, cliptop, clipright, clipbottom) {

  if (isAppNS4) {
    oLayer.clip.left   = clipleft;
    oLayer.clip.top    = cliptop;
    oLayer.clip.right  = clipright;
    oLayer.clip.bottom = clipbottom;
  }
  if (isAppIE4)
    oLayer.style.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
}

function getClipLeft(oLayer)
{
	if (isAppNS4)	return(oLayer.clip.left);
	if (isAppIE4)
	{
		var str =  oLayer.style.clip;
		if (!str) return(0);
		var clip = getIEClipValues(oLayer.style.clip);
		return(clip[3]);
	}
	return -1;
}

function getClipTop(oLayer)
{
	if (isAppNS4)	return(oLayer.clip.top);
	if (isAppIE4)
	{
		var str =  oLayer.style.clip;
		if (!str) return(0);
		var clip = getIEClipValues(oLayer.style.clip);
		return(clip[0]);
	}
	return -1;
}

function getClipRight(oLayer)
{
	if (isAppNS4) return(oLayer.clip.right);
	if (isAppIE4)
	{
		var str =  oLayer.style.clip;
		if (!str) return(oLayer.style.pixelWidth);
		var clip = getIEClipValues(oLayer.style.clip);
		return(clip[1]);
	}
	return -1;
}

function getClipBottom(oLayer)
{
	if (isAppNS4) return(oLayer.clip.bottom);
	if (isAppIE4)
	{
		var str =  oLayer.style.clip;
		if (!str) return(oLayer.style.pixelHeight);
		var clip = getIEClipValues(oLayer.style.clip);
		return(clip[2]);
	}
	return -1;
}

function getClipWidth(oLayer)
{
	if (isAppNS4) return(oLayer.clip.width);
	if (isAppIE4)
	{
		var str = oLayer.style.clip;
		if (!str) return(oLayer.style.pixelWidth);
		var clip = getIEClipValues(oLayer.style.clip);
		return(clip[1] - clip[3]);
	}
	return -1;
}

function getClipHeight(oLayer)
{
	if (isAppNS4)	return(oLayer.clip.height);
	if (isAppIE4)
	{
		var str =  oLayer.style.clip;
		if (!str) return(oLayer.style.pixelHeight);
		var clip = getIEClipValues(oLayer.style.clip);
		return(clip[2] - clip[0]);
	}
	return -1;
}

function getIEClipValues(str)
{
	var i;
	var clip = new Array();

	// Parse out the clipping values for IE layers.
	i = str.indexOf("(");
	clip[ 0] = parseInt(str.substring(i + 1, str.length), 10);
	
	i = str.indexOf(" ", i + 1);
	clip[ 1] = parseInt(str.substring(i + 1, str.length), 10);
	
	i = str.indexOf(" ", i + 1);
	clip[ 2] = parseInt(str.substring(i + 1, str.length), 10);
	
	i = str.indexOf(" ", i + 1);
	clip[ 3] = parseInt(str.substring(i + 1, str.length), 10);
	return clip;
}

//-----------------------------------------------------------------------------
// Layer scrolling.
//-----------------------------------------------------------------------------
function scrollLayerTo(oLayer, iPosX, iPosY, iBound)
{
	var iDx = getClipLeft(oLayer) - iPosX;
	var iDy = getClipTop(oLayer) - iPosY;
	scrollLayerBy(oLayer, -iDx, -iDy, iBound);
}

function scrollLayerBy(oLayer, dx, dy, bound)
{
	var cl = getClipLeft(oLayer);
	var ct = getClipTop(oLayer);
	var cr = getClipRight(oLayer);
	var cb = getClipBottom(oLayer);

	if (bound)
	{
		if (cl + dx < 0)
			dx = -cl;
		else if (cr + dx > getWidth(oLayer))
			dx = getWidth(oLayer) - cr;
		if (ct + dy < 0)
			dy = -ct;
		else if (cb + dy > getHeight(oLayer))
			dy = getHeight(oLayer) - cb;
	}
	clipLayer(oLayer, cl + dx, ct + dy, cr + dx, cb + dy);
	moveLayerBy(oLayer, -dx, -dy);
}

//-----------------------------------------------------------------------------
// Layer background.
//-----------------------------------------------------------------------------

function setBgColor(oLayer, color)
{
	if (isAppNS4)	oLayer.bgColor = color;
	if (isAppIE4)	oLayer.style.backgroundColor = color;
}

function setBgImage(oLayer, src)
{

	if (isAppNS4)	oLayer.background.src = src;
	if (isAppIE4)	oLayer.style.backgroundImage = "url("+ src +")";
}

//-----------------------------------------------------------------------------
// Layer utilities.
//-----------------------------------------------------------------------------
function getLayer(name)
{
	if (isAppNS4)	return findLayer(name, document);
	if (isAppIE4)	return eval('document.all.' + name);
	return null;
}

function findLayer(name, doc)
{
	var i, oLayer;
	for (i = 0; i < doc.layers.length; i++)
	{
		oLayer = doc.layers[i];
		if (oLayer.name == name)	return oLayer;
		if (oLayer.document.layers.length > 0)
		{
			oLayer = findLayer(name, oLayer.document);
			if (oLayer != null)	return oLayer;
		}
	}
	return null;
}

//-----------------------------------------------------------------------------
// Window and page properties.
//-----------------------------------------------------------------------------
function getWindowWidth()
{
	if (isAppNS4)	return window.innerWidth;
	if (isAppIE4)	return document.body.clientWidth;
	return -1;
}

function getWindowHeight()
{
	if (isAppNS4)	return window.innerHeight;
	if (isAppIE4)	return document.body.clientHeight;
	return -1;
}

function getPageWidth()
{
	if (isAppNS4)	return document.width;
	if (isAppIE4)	return document.body.scrollWidth;
	return -1;
}

function getPageHeight()
{
	if (isAppNS4)	return document.height;
	if (isAppIE4)	return document.body.scrollHeight;
	return -1;
}

function getPageScrollX()
{
	if (isAppNS4)	return(window.pageXOffset);
	if (isAppIE4)	return document.body.scrollLeft;
	return -1;
}

function getPageScrollY()
{
	if (isAppNS4)	return window.pageYOffset;
	if (isAppIE4)	return document.body.scrollTop;
	return -1;
}



