/// <history>
///		<change date="2004-06-18" author="Darrin Morgan">Original Version</change>
/// </history>

var _RowHighlightColor = "threedlightshadow"; //"ghostwhite";

/// <summary>
/// When the mouse moves over an html element set its background color
/// to indicate our position.
/// </summary>
function RowHighLight(sender) 
{
	if (sender.style.backgroundColor != "pink")
		sender.style.backgroundColor = _RowHighlightColor;
}

/// <summary>
/// When the mouse moves out of an html element set its background color
/// back to a default state.
/// </summary>
function RowLowLight(sender) 
{
	if (sender.style.backgroundColor == _RowHighlightColor)
		sender.style.backgroundColor = "";
}



/// <summary>
/// Expand the selected Menu, and collapse the others.
/// </summary>
function ToggleMenu( menuId )
{
	var menus = document.getElementsByTagName("DIV");
	var menu = 0;
	var prefix;
	for ( menu=0; menu < menus.length; menu++ )
	{
		if ( menus[menu].id != "" )
			if ( menus[menu].id.substring(0,4) == "MENU" )
			{
				document.getElementById(menus[menu].id).style.display = "none";
			}
	}

	document.getElementById( "MENU" + menuId ).style.display = "";

	return;
}


/// <summary>
/// Set focus to the specified control, but don't crash if we can't.
/// </summary>
/// <remarks>
/// </remarks>
function SetFocus( ctrl )
{
	try
	{
		if (ctrl == null) return;
		if (!ctrl.isDisabled) ctrl.focus();
	}
	catch(ex)
	{
		window.status = "Cannot set focus to: " + ctrl.id + "\n" + ex;
	}
}


/// <summary>
/// Handle the "onkeydown" event for a form and, if the key is the Enter key,
/// cancel the default action (the first button on the form), and instead "click"
/// the specified button.
/// </summary>
/// <remarks>
/// There is no way with html to indicate which button is the "default" button.  
/// The form will simply post using the first button on the form.  By using the
/// javascript onkeydown event of the form we can interrupt this process and
/// instead trigger the button that should be the default.  To use this routine
/// you will need to add the onkeydown attribute to a form. e.g.
/// [form id="frmList" method="post" runat="server" onkeydown="DefaultButtonHandler(btnFind)"]
/// </remarks>
function DefaultButtonHandler(btn)
{
    // process only the Enter key
    if (event.keyCode == 13)
    {
        // cancel the default submit
        event.returnValue = false;
        event.cancel = true;

        // submit the form by programmatically clicking the specified button
        btn.click();
    }
}

/// <summary>
/// This is a utility function. Given a Start and End color and
/// a percentage fade it returns a color in between the 2 colors.
/// </summary>
/// <remarks>Inspired by code found on www.JavaScript-FX.com</remarks>
/// <param name="startColor">The Start Color (in the form "RRGGBB" e.g. "FF00AC")</param>
/// <param name="endColor">The End Color (in the form "RRGGBB" e.g. "FF00AC")</param>
/// <param name="percent">The percent (0-100) of the fade between StartColor & EndColor</param>
/// <returns>color in the form "#RRGGBB" e.g. "#FA13CE"</returns>
function ColorPhase(startColor, endColor, percent)
{
	function hex2dec(hex) { return(parseInt(hex,16)); }
	function dec2hex(dec) { return (dec < 16 ? "0" : "") + dec.toString(16); }

	var r1 = hex2dec(startColor.slice(0,2)), g1=hex2dec(startColor.slice(2,4)), b1=hex2dec(startColor.slice(4,6));
	var r2 = hex2dec(endColor.slice(0,2)),   g2=hex2dec(endColor.slice(2,4)),   b2=hex2dec(endColor.slice(4,6));

	var pc = percent / 100;

	var r  = Math.floor(r1+(pc*(r2-r1)) + .5), g=Math.floor(g1+(pc*(g2-g1)) + .5), b=Math.floor(b1+(pc*(b2-b1)) + .5);

	return("#" + dec2hex(r) + dec2hex(g) + dec2hex(b));
}

/// <summary>
/// This function cycles the color of an html element between two colors.
/// </summary>
/// <remarks>Inspired by code found on www.JavaScript-FX.com</remarks>
/// <param name="startColor">The Start Color (in the form "RRGGBB" e.g. "FF00AC").</param>
/// <param name="endColor">The End Color (in the form "RRGGBB" e.g. "FF00AC").</param>
/// <param name="elementId">Id of the html element whose color is to be phased.</param>
/// <param name="percent">The percent (0-100) of the fade between StartColor & EndColor.</param>
function ColorCycle(startColor, endColor, elementId, percent)
{
//	try
//	{
		if (percent == 100)
		{
			tempColor = startColor;
			startColor = endColor;
			endColor = tempColor;
			percent = 0;
		}

		element = document.getElementById(elementId)
		element.style.backgroundColor = ColorPhase(startColor, endColor, percent);

		percent = percent + 5;

		statement = "ColorCycle('"+startColor+"','"+endColor+"','"+elementId+"',"+percent+")"
		setTimeout(statement, 50);
//	}
//	catch { /* ignore errors */ }
}

function ResizeHtcTable(id, amount)
{
	var table = document.getElementById(id);
	var div = table.getElementsByTagName("DIV");
	var element = div[0]

	if (element != null)
	{
		var originalHeight =  element.style.height;
		var newHeight = document.body.clientHeight - amount;
		if (element.style.height < originalHeight) newHeight = originalHeight;
		element.style.height = "" + newHeight + "px";
	}
}
