/* Copyright (C) 2002-2008 by Home of the Brave
   Web http://home.of.the.brave.de
   E-Mail info@brave.de */
/* $Revision: 1.7 $ $Date: 2008/02/27 17:18:56 $ */


/*
 * Sets focus on INPUT, TEXTAREA or SELECT with class="autofocus"
 * dependencies: BodyEvents
 * owner: Simon.Leidig@brave.de
 *
 */

BodyEvents.addListener('load', function () {
	var f = function (l) {
		for (var i = 0; i < l.length; i++) {
			var c = l[i].getAttribute('class') || l[i]['className'];
			if (c && c.match(/\bautofocus\b/)) {
				l[i].focus();
				if (!(location.hash && location.hash.length > 1)) {
					l[i].scrollIntoView();
					document.body.scrollTop -= 20;
				}
				return true;
			}
		}
		return false;
	}
	f(document.getElementsByTagName('input'   )) ||
	f(document.getElementsByTagName('textarea')) ||
	f(document.getElementsByTagName('select'  ));
} );
