SetInputFocus();

//Sets the focus to a pre-determined input field on the form.
function SetInputFocus()
{
	//Do we have the hidden field with our custom focus element?
	if(document.getElementById('hffocusRequired') != null)
	{
		var defFocus = document.getElementById(document.getElementById('hffocusRequired').value);
		
		//Does the value of the custom focus actually exist as an element?
		if(defFocus != null)
		{
			defFocus.focus();
		}
	}
	else //Set focus to the first input/select element on form.
	{
		for (var i = 0; i < document.forms[2].elements.length; i++)
		{
			//Set the first input/select that is visible or not hidden input.
			if( (document.forms[2].elements[i].tagName == 'INPUT' ||
			   document.forms[2].elements[i].tagName == 'SELECT') 
			   && document.forms[2].elements[i].type != 'hidden'  )
			{
				try
				{
					document.forms[2].elements[i].focus();
					break;
				}
				catch(e){}
			}
		}
	}
}