/*
 * The problem with the code above is that it has a hard coded reference to
 * forms[0], so it will not work when the input you want to set the focus to 
 * is not within the first form. For example, a complex page might contain 
 * several forms for various purposes. My final solution was to use a nested 
 * loop that loops through all forms until it finds an input that is not 
 * hidden and not disabled. The code below has been tested in Internet 
 * Explorer 6.0 and Mozilla Firefox 1.0.4:
 *
 */
var bFound = false;

// for each form
for (f=0; f < document.forms.length; f++) {
	// for each element in each form
	for(i=0; i < document.forms[f].length; i++) {
		// if it's not a hidden element
		if (document.forms[f][i].type != "hidden" && document.forms[f][i].style.display != "none") {
			// and it's not disabled
			if (document.forms[f][i].disabled != true) {
				// and it's a textfield
				if( document.forms[f][i].type == "text" || document.forms[f][i].type == "password") {
					// set the focus to it
					document.forms[f][i].focus();
					bFound = true;	
				}
			}
		}
		// if found in this element, stop looking
		if (bFound == true)
			break;
	}
	// if found in this form, stop looking
	if (bFound == true)
		break;
}


