var m_lFocusPosition;

function getFocusPosition()
{
	var lLoopCount = 0;
	var lErrorValue = -1;
	var lElementCount;
	var sFormType;
	var bFocusFound = false;
	var bSkipFocusSet = false;
	var bElementIsTextOrPassword = false;
	var bFoundNonHiddenElement = false;

	
	if (document.forms.length > 0)
		if (document.forms[0].elements.length > 0)
		{
			lElementCount = document.forms[0].elements.length;
			
			do
			{
				sFormType = document.forms[0].elements[lLoopCount].type;
				
				if (sFormType == "text" || sFormType == "password")
					bElementIsTextOrPassword = true;
				
				if (sFormType != "hidden" && sFormType != "")
					bFoundNonHiddenElement = true;
				
				if (bFoundNonHiddenElement)
				{
					if (bElementIsTextOrPassword)
					{
						bFocusFound = true;	
					}
					else
					{
						bSkipFocusSet = true;
					}
				}
				
				if (!bFocusFound)
					lLoopCount++;
			}
			while (lLoopCount < lElementCount && !bFocusFound && !bSkipFocusSet) 
			
		}
		
	if (bFocusFound)
		m_lFocusPosition = lLoopCount;
	else
		m_lFocusPosition = lErrorValue;
}

function doFocus()
{
	document.forms[0].elements[m_lFocusPosition].focus();
}

function setFormFocus()
{
	var lFocusPosition;
	
	getFocusPosition();
	
	if (m_lFocusPosition != -1)
		doFocus(m_lFocusPosition);
}