// JavaScript Document

var amountx;
var amounty;
var len;
var def1="mouseover";
function showDefinition(defnum, listnum) {
 amountx = findPosX(listnum);
 amounty = findPosY(listnum);
 len = document.getElementById(listnum).lang.length;
 len = len*7;
 amountx = amountx + len;
var tempElement = document.getElementById(defnum);

	if (tempElement != null) {
		tempElement.style.display = 'inline';
		tempElement.style.position = 'absolute';
		tempElement.style.left = amountx;
		tempElement.style.top = amounty-20;
		tempElement.style.zindex = -1;
		}
}

function showDefinition2(title, def, defnum, listnum) {
 amountx = findPosX(listnum);
 amounty = findPosY(listnum);
 len = document.getElementById(listnum).lang.length;
 len = len*7;
 amountx = amountx + len;
var tempElement = document.getElementById(defnum);

	if (tempElement != null) {
		tempElement.style.display = 'inline';
		tempElement.style.position = 'absolute';
		tempElement.style.left = amountx;
		tempElement.style.top = amounty-20;
		tempElement.style.zindex = -1;
		}

	var sText = "<table width='215' cellpadding='0' cellspacing='0'><tr><td background='images/defboxtoppng.png' style='color:#ffffff; font-weight:bold; padding-top:7px;' align='center' height='37'>" + title + "</td></tr><tr><td class='definition' background='images/defboxmiddlepng.png'>" + def + "</td></tr><tr><td><img src='images/defboxbottompng.png' /></td></tr></table>";
		document.getElementById(defnum).innerHTML = sText; 
			}
function hideDefinition(defnum) {
		if (document.getElementById(defnum) != null)
		document.getElementById(defnum).style.display = 'none';
}
function findPosX(obj)
{
obj = document.getElementById(obj);
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
obj = document.getElementById(obj);
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function retrieveCookie( cookieName ) {
	/* retrieved in the format
	cookieName4=value; cookieName3=value; cookieName2=value; cookieName1=value
	only cookies for this domain and path will be retrieved */
	var cookieJar = document.cookie.split( "; " );
	for( var x = 0; x < cookieJar.length; x++ ) {
		var oneCookie = cookieJar[x].split( "=" );
		if( oneCookie[0] == escape( cookieName ) ) { return unescape( oneCookie[1] ); }
	}
	return null;
}

function setCookie( cookieName, cookieValue, lifeTime, path, domain, isSecure ) {
	if( !cookieName ) { return false; }
	if( lifeTime == "delete" ) { lifeTime = -10; } //this is in the past. Expires immediately.
	/* This next line sets the cookie but does not overwrite other cookies.
	syntax: cookieName=cookieValue[;expires=dataAsString[;path=pathAsString[;domain=domainAsString[;secure]]]]
	Because of the way that document.cookie behaves, writing this here is equivalent to writing
	document.cookie = whatIAmWritingNow + "; " + document.cookie; */
	document.cookie = escape( cookieName ) + "=" + escape( cookieValue ) +
		( lifeTime ? ";expires=" + ( new Date( ( new Date() ).getTime() + ( 1000 * lifeTime ) ) ).toGMTString() : "" ) +
		( path ? ";path=" + path : "") + ( domain ? ";domain=" + domain : "") + 
		( isSecure ? ";secure" : "");
	//check if the cookie has been set/deleted as required
	if( lifeTime < 0 ) { if( typeof( retrieveCookie( cookieName ) ) == "string" ) { return false; } return true; }
	if( typeof( retrieveCookie( cookieName ) ) == "string" ) { return true; } return false;
}
  //==== TAB FUNCTIONS ====// 
  //Tab ID's:     t1,t2,t3,t4
  //Content ID's: c1,c2,c3,c4
	
	var maxTabNumber = 20;//this number must be greater than the max number of tabs
	function setOpen(cook) {
		var cookval = retrieveCookie("openList");
		showContent(cookval, 'c','img')
	}
	function hideorshow(c, cGroup, iGroup) {
	var opened = 0;
	var tempElement = document.getElementById(cGroup+c);
		if (tempElement != null) {
			if  (tempElement.style.display == 'block') 
			{
				hideAllContent(cGroup, iGroup);
			}
			else
			{
				showContent(c, cGroup, iGroup); 
			} 
		}
	}
	function showContent(c, cGroup, iGroup) {
		hideAllContent(cGroup, iGroup);//use when only one content block is shown at a time.
		if (document.getElementById(cGroup+c) != null)
		document.getElementById(cGroup+c).style.display = 'block';
		if (document.getElementById(iGroup+c) != null)
		document.getElementById(iGroup+c).src = 'images/opened.gif';
		setCookie("openList",c,null,null,null,null);

	}
	function hideContent(c, cGroup, iGroup) {
		var tempElement = document.getElementById(cGroup+c);
		if(tempElement != null) tempElement.style.display = 'none';
		var tempimgElement = document.getElementById(iGroup+c);
		if (tempimgElement != null) tempimgElement.src = 'images/closed.gif';
	}
	function hideAllContent(cGroup, iGroup) {
		for( var i = 0; i < maxTabNumber; i++ ) {
			var tempElement = document.getElementById(cGroup+i);
			var tempimgElement = document.getElementById(iGroup+i);
			if (tempimgElement != null) tempimgElement.src = 'images/closed.gif';
			if(tempElement != null) tempElement.style.display = 'none';
		}
	}

