/**
 * © Copyright 2007 MVSD BV
 * Author: J.L. Ferdinandus ( ferdinandus@mvsd.nl )
 *
 * Contains a form script which sets the focus to the first focusable formfield.
 */
var focus_oldOnload = null;
var focus_strControlId = null;

function setFocusable(strControlId)
{
    focus_strControlId = strControlId;
    focus_oldOnload = document.body.onload;
	document.body.onload = newOnload;
}

function newOnload()
{
    if (focus_oldOnload != null)
    {
        focus_oldOnload();
    }
    
    var objElement = document.getElementById(focus_strControlId);
    if (null != objElement && objElement.focus)
    {
        objElement.focus();
    }
}

function findFocusable()
{
	var form = document.forms[0];
	findFocusableInForm(form);
}

function findFocusableInForm(form)
{
	var frmForm = form;
	
	var focusable = -1;
	focusable++;
	done = false;
	
	var count = frmForm.elements.length;
	while (!done && focusable < count)
	{
		var element = frmForm.elements[focusable];
		var type = element.type;
		
		if (type == "text" || type == "submit" || type == "select-one" ||  
					type == "textarea" || type== "checkbox"  || type== "radio" || type == "password")
		{
			// Disabled items can not have the focus.
			if (!element.disabled)
			{
				done = true;
				element.focus();
			}
		}
	
		focusable++;
	}
}