function setIndexLength()
{
	/* Sets the length of the dropdown index.
	   Best used in the onload() and onresize() events of a document.
	   [example: /sites/antiquities/fullMap.htm]
	*/

	if ( document.getElementById )
	{
		var intLength = (document.all) ? document.body.clientHeight : window.innerHeight;

		document.getElementById("index").style.height = intLength - 150;
	}
}

function showLayer(numLayer)
{
	/* Toggles the display of <div> layers contained in a "mapLayer"
	   [example: /sites/antiquities/fullMap.htm]
	*/

	if ( document.getElementById )
	{
		/* First, search through all the <div>s in the mapLayer 
		   until you find the last visible one...
		*/
		var divisions = document.getElementById("mapLayer").getElementsByTagName("div");

		for ( var i=0; i < divisions.length; i++ )
		{
			if ( divisions[i].style.display != "none" )
			{
				/* ...then turn it off. */
				divisions[i].style.display = "none";
			}
		}

		/* Then show the specified layer. */
		document.getElementById(numLayer).style.display = "block";
	}
}

function showDot(intDot)
{
	/* Toggles the background image of <a>s contained in a "dots" layer
	   [example: /sites/antiquities/fullMap.htm]
	*/

	if ( document.getElementById )
	{
		/* First, search through all the <a>s in the dots layer 
		   until you find the one whose background image is not transparent...
		*/
		var dots = document.getElementById("dots").getElementsByTagName("a");

		for ( var i=0; i < dots.length; i++ )
		{
			if ( dots[i].style.backgroundImage != "url(../../images/spacer.gif)" )
			{
				/* ...then make it transparent. */
				dots[i].style.backgroundImage = "url(../../images/spacer.gif)";
			}
		}

		/* Then change the image of the specified <a>. */	
		document.getElementById(intDot).style.backgroundImage = "url(images/" + intDot + ".gif)";
	}
}

/* +------------------+
   | Cookie functions |
   +------------------+ */

function testCookie()
{
	document.cookie = "TestCookie=Yes;";

	if (getCookieValue("TestCookie")==null)
		window.open('../viewing.htm');
}

function getCookieValue(cookieName)
{
	var cookieValue = document.cookie;
	var cookieStartsAt = cookieValue.indexOf(" " + cookieName + "=");	// semicolons and spaces separate cookies in the cookie string

	if (cookieStartsAt==-1)		// then maybe the cookie you want is first in the object, in which case there would be no space
		cookieStartsAt = cookieValue.indexOf(cookieName + "=");

	if (cookieStartsAt==-1)		// then your cookie doesn't exist and/or cookies have been disabled
		cookieValue = null;
	else				// otherwise...
	{				// ...capture the value
		cookieStartsAt = cookieValue.indexOf("=", cookieStartsAt) + 1;	// the start will be the first equal sign after the beginning of our cookie
		var cookieEndsAt = cookieValue.indexOf(";",cookieStartsAt);	// the end will be the first semicolon

		if (cookieEndsAt==-1)	// unless there were no more semicolons...
			cookieEndsAt = cookieValue.length;	// ...meaning that the cookie is at the end of the string
								// (string's length = index of last string character)

		cookieValue = cookieValue.substring(cookieStartsAt, cookieEndsAt);
	}
	return cookieValue;
}


function isChildOf(event)
{
	/* courtesy of Dr. Lawrence W. Haynes */

	var parent = event.target || event.srcElement;
	var obj = event.relatedTarget || event.toElement;

	while (obj)
	{
		if (obj == parent)
			return true;

		obj = obj.parentNode;
	}

	return false;
}