var ctrlSelect = null;	// set by setFocus()
function selectCtrl(ctrl)
{
	if (ctrl)
		ctrlSelect = ctrl;
	if (ctrlSelect)
		if ((ctrlSelect.type == "text") || (ctrlSelect.type == "textarea") || (ctrlSelect.type == "file"))
			ctrlSelect.select();
	ctrlSelect = null;
}

function setFocusFromHidden(sHiddenID)
{
	var hidden = getById(sHiddenID);
	if (hidden)
		setFocusByID(hidden.value);
}

function setFocusByID(sID) { return setFocus(getById(sID)); }

function setFocusByName(sName)
{
	var ctrls = document.getElementsByName(sName);
	if (ctrls && ctrls.length > 0)
	{
		setFocus(ctrls[0]);
		return ctrls[0];
	}
	return null;
}

function setFocus(ctrl)
{
	if (ctrl && ctrl.style.visibility != "")
	{
		ctrl.focus();
		ctrlSelect = ctrl;
		
		// Allow the browser to catch up with window refreshing
		// tasks before selecting the contents.
		//
		window.setTimeout("selectCtrl();", 100);
	}
	return ctrl;
}
