// main.js

var knMAIN_SIDE_TABS = 7;	// 7 for 2007 indoor!
function showTab(nWhich)
{
	indicatorOn(nWhich);
	
	var nIt = 1;
	for (; nIt <= knMAIN_SIDE_TABS; ++nIt)
	{
		var elTab = document.getElementById('tcontent' + nIt);
		if (elTab)
		{
			elTab.style.display = (nIt == nWhich ? 'block' : 'none');
		}
	}	
}

function indicatorOn(nWhich)
{
	var nIt = 1;
	for (; nIt <= knMAIN_SIDE_TABS; ++nIt)
	{
		var elIndicator = document.getElementById('tindicator' + nIt);
		if (elIndicator)
		{
			elIndicator.style.backgroundColor = (nIt == nWhich ? '#6f6' : '');
		}
	}
}

function extrainfoShow(trigger, sContent)
{
	var extra = document.getElementById('extrainfo');
	if (extra)
	{
		extra.style.display = 'block';

		var content = document.getElementById('extracontent');
		if (content)
		{
			content.innerHTML = sContent.replace(/~/g, "'");;
		}
	
		var aXY = findPosition(trigger);
		if (aXY)
		{
			extra.style.top = (aXY[1] - 6) + "px";
	
			aWindowSize = getWindowSizeXY();
			aWindowScroll = getWindowScrollXY();
			if (extra.offsetTop + extra.offsetHeight - aWindowScroll[1] > aWindowSize[1])
			{
				extra.style.top = extra.offsetTop - (extra.offsetTop + extra.offsetHeight - aWindowSize[1] - aWindowScroll[1]) + "px";
			}

//			window.status = extra.offsetTop + " + " + extra.offsetHeight + " = " + (extra.offsetTop + extra.offsetHeight) + " >? " + aWindowSize[1] + " - " + aWindowScroll[1] + " = " + (aWindowSize[1] - aWindowScroll[1]);

		}
	}
}

function extrainfoHide()
{
	var extra = document.getElementById('extrainfo');
	if (extra)
	{
		extra.style.display = 'none';
	}
}


function findPosition(oLink)
{
	if (oLink.offsetParent)
	{
		var sPath = '';
		for (var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent )
		{
			posX += oLink.offsetLeft;
			posY += oLink.offsetTop;
		}
		return [posX, posY];
	}
	else
	{
		return [oLink.x, oLink.y];	// Netscape 4, I believe
	}
}


// http://www.howtocreate.co.uk/tutorials/index.php?tut=0&part=16
function getWindowSizeXY() {
	var myWidth = 0, myHeight = 0;
	if (typeof(window.innerWidth) == 'number')
	{
		// Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else
	{
		if (document.documentElement && 
			(document.documentElement.clientWidth || document.documentElement.clientHeight))
		{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		}
		else
		{
			if (document.body && (document.body.clientWidth || document.body.clientHeight))
			{
				// IE 4 compatible
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
			}
		}
	}
	
	return [myWidth, myHeight];
}

function getWindowScrollXY()
{
	var scrOfX = 0, scrOfY = 0;
	if (typeof( window.pageYOffset) == 'number')
	{
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	}
	else
	{
		if (document.body && (document.body.scrollLeft || document.body.scrollTop))
		{
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		}
		else
		{
			if (document.documentElement &&
				(document.documentElement.scrollLeft || document.documentElement.scrollTop))
			{
				//IE6 standards compliant mode
				scrOfY = document.documentElement.scrollTop;
				scrOfX = document.documentElement.scrollLeft;
			}
		}
	}
	
	return [scrOfX, scrOfY];
}