var fieldFocused = false;

function focusObject(obObject)
{
	var strTagName = obObject.tagName.toUpperCase();

	if (('TABLE' != strTagName) && ('TR' != strTagName) && ('TD' != strTagName) && ('TBODY' != strTagName))
	{
		if (obObject.focus)
		{ 
			try
			{
				obObject.focus();
				fieldFocused = true;
			}
			catch(e)
			{
			}
		};
		if (obObject.select)
		{ 
			var bIsButton = false;
			if ('INPUT' == obObject.nodeName.toUpperCase())
			{
				if (
					('SUBMIT' == obObject.attributes['type'].value.toUpperCase()) ||
					('BUTTON' == obObject.attributes['type'].value.toUpperCase())
				)
				{
					bIsButton = true;
				}
			}
			if ('BUTTON' == obObject.nodeName.toUpperCase())
			{
				bIsButton = true;
			}
			if (false == bIsButton)
			{
				obObject.select();
				fieldFocused = true;
			}
		};
	}

	if (false == fieldFocused)
	{
		if(obObject.all)
		{
			if (obObject.all.length)
			{
				for(var i = 0; i < obObject.all.length; i++)
				{
					if (false == fieldFocused)
					{
						focusObject(obObject.all[i]);
					}
				}
			}
		}
	}
}

function FocusField(fieldName)
{
	if (true == fieldFocused)
	{
		return;
	}

	for(var i = 0; i < document.forms.length; ++i) 
	{
		var obObject = document.forms[i].elements[fieldName];
		obObject = document.getElementById(fieldName);
		if (obObject)
		{
			if ((obObject.length) && ("SELECT" != obObject.tagName.toUpperCase()))
			{ 
				for(var k = 0; k < obObject.length; k++)
				{
					if (false == fieldFocused)
					{
						focusObject(obObject[k]); 
					}
				}
			}
			else
			{
				focusObject(obObject);
			}
		};
	};
}