/********************************************************
 *  Warhammer Realm War									*
 *														*
 *  Form Option Box Javascript							*
 ********************************************************/

var timers = new Object();  //Timeout object to close drop-down box
var currentFrame = "";

/**
 * optionToggle takes an option box id and turns the drop-down
 * layer on or off depending on its current display state.
 * 
 * @param boxId - Id of the box to open/close the options pane for
 */
function optionToggle(boxId)
{
	var optionBox = document.getElementById(boxId + "Options");
	
	if(optionBox.style.display == "block")
	{
		optionBox.style.display = "none";
	}
	else
	{
		optionBox.style.display = "block";
		optionBox.style.zIndex = 5;
	}
}

/**
 * optionOff takes an option box id and turns off the
 * drop-down pane
 * 
 * @param boxId - Id of the box to close the options pane for
 */
function optionOff(boxId)
{
	var optionBox = document.getElementById(boxId + "Options");
	
	optionBox.style.display = "none";
}

/**
 * optionOn takes an option box id and turns on the
 * drop-down pane
 * 
 * @param boxId - Id of the box to close the options pane for
 */
function optionOn(boxId)
{
	var optionBox = document.getElementById(boxId + "Options");
	
	optionBox.style.display = "block";
}

/**
 * optionSelected changes the label of the selected drop-down box
 * 
 * @param boxId - Id of the box of the label to change
 * @param optionValue - Value of selected item (Not currently used)
 * @param optionText - Text of selected item
 */
function optionSelected(boxId,optionValue,optionText)
{
	var optionLabel = document.getElementById(boxId + "Label");

	optionLabel.innerHTML = "";
	optionLabel.innerHTML = optionText;
}

/**
 * optionBlur turns off the selected drop-down pane if focus is blurred
 * 
 * @param boxId - Id of the box to turn off the option pane for
 */
function optionBlur(boxId)
{
	timers[boxId] = setTimeout("optionOff('"+boxId+"')", 250);	
}

/**
 * optionFocus clears the timeout and keeps the drop-down pane
 * open if focus is reattained before optionBlur is performed
 * 
 * @param boxId - Id of the box to keep option pane alive for
 */
function optionFocus(boxId)
{
	clearTimeout(timers[boxId]);
}

/**
 * Show layer switches layers to display or turn off an
 * one layer and show another
 * 
 * @param hidePane - Layer id to hide
 * @param showPane - Layer id to display
 */
function showLayer(hidePane,showPane)
{
	if(hidePane != null && hidePane != "")
		document.getElementById(hidePane).style.display = "none";
	
	if(showPane != null && showPane != "")
		document.getElementById(showPane).style.display = "block";
}

/**
 * Shows a frame (from a div tag) and hides the previous one
 * 
 * @param hidePane - Layer id to hide
 * @param showPane - Layer id to display
 */
function flipFrame(prefixPaneName,frameId)
{
	var newFrameToShow = prefixPaneName + frameId;

	// Hide current frame, show new frame
	if(document.getElementById(currentFrame) != null)
	{
		document.getElementById(currentFrame).style.display = "none";
	}
	if(document.getElementById(newFrameToShow) != null)
	{
		document.getElementById(newFrameToShow).style.display = "block";
	}
	// Current frame is now new frame
	currentFrame = newFrameToShow;
}