﻿// This function resizes the height of the main page body DIV based on the height of the document
// options DIV. This is done to make sure the page body scroll bar remains flush-bottom on the page.
function ResizePageBody ()
{
	// Get Document Options div
	var objDocOptionsDiv = document.getElementById("divDocumentOptions");

	if (objDocOptionsDiv == null)
	{
		return;
	}

	// Set total height (including 15 pixel spacer + bottom shading)
	var iDocOptionsHeight = objDocOptionsDiv.offsetHeight + 15;

	// Return if div height <= 0
	if (iDocOptionsHeight <= 15)
	{
		return;
	}

	// Get main page body div element
	var objPageBodyDiv = document.getElementById("divPageBody");

	// Calculate new page body height
	var iNewHeight = objPageBodyDiv.offsetHeight - iDocOptionsHeight;

	// Set new div style height
	objPageBodyDiv.style.height = iNewHeight.toString() + 'px';

	// Try to get right navigation element
	objRightNav = document.getElementById("divRightNavigation");

	if (objRightNav != null)
	{
		// Set right nav height to be the same as the page body height
		objRightNav.style.height = iNewHeight.toString() + 'px';
	}
}

function FadeMenu (sTargetDiv, bFadeIn)
{
	if (bFadeIn == true) {
		for (var i=0; i<=10; i++) {
			self.setTimeout("SetDivOpacity('" + sTargetDiv + "'," + i + ")", 25*i);
		}
	}
	else
	{
		for (var i=10; i>=0; i--)
		{
			self.setTimeout("SetDivOpacity('" + sTargetDiv + "'," + i + ")", 25*i);
		}
	}
}

function SetDivOpacity(sTargetDiv, value)
{
	var divTargetDiv = document.getElementById(sTargetDiv);
	if (divTargetDiv != null)
	{
		divTargetDiv.style.opacity = value/10;
		divTargetDiv.style.filter = "alpha(opacity=" + value*10 + ")";
	}
}

var objSelectBoxesAutoHidden;
var bSelectBoxesAreAutoHidden = false;
function ChangeSelectBoxVisibility (sVisibility)
{
	var aobjSelectBoxes = document.getElementsByTagName("select");
	var iNumSelectBoxes = aobjSelectBoxes.length;
	var autoCompleteBox = document.getElementById("autoSuggestBox");
	
	var bDoHide = false;
	var j = 0;
	if (sVisibility.toLowerCase() == "hidden")
	{
		objSelectBoxesAutoHidden = new Array();
		bDoHide = true;
	}

	for (var i=0; i<iNumSelectBoxes; i++)
	{
		var objSelectBox = aobjSelectBoxes[i];
		if (bDoHide)
		{
			if (objSelectBox.style.visibility.toLowerCase() != "hidden")
			{
				objSelectBoxesAutoHidden[j++] = objSelectBox;
				objSelectBox.style.visibility = "hidden";
			}
		}
		else if (bSelectBoxesAreAutoHidden)
		{
			if (objSelectBox == objSelectBoxesAutoHidden[j])
			{
				j++;
				objSelectBox.style.visibility = "visible";
			}
		}
	}
	
	if (bDoHide)
	{
		bSelectBoxesAreAutoHidden = true;
		if(autoCompleteBox != null)
		{
			autoCompleteBox.style.visibility = "hidden";		
		}
	}
	else
	{
		bSelectBoxesAreAutoHidden = false;
		if(autoCompleteBox != null)
		{
			autoCompleteBox.style.visibility = "";
		}
	}
}

function ChangeVisibleMySubsList(sWhichList, sWhichOn, sWhichOff)
{
	var sWhichListOn = "tblMySubscriptions" + sWhichList + sWhichOn;
	var sWhichListOff = "tblMySubscriptions" + sWhichList + sWhichOff;
	var objWhichListOn = document.getElementById(sWhichListOn);
	var objWhichListOff = document.getElementById(sWhichListOff);
	objWhichListOn.style.display = "block";
	objWhichListOff.style.display = "none";
	setMySubscriptionsDivHeight();
}
