﻿//Form Input Focus
//Sets focus to first form input element of type text
//Copyright Coultard Ltd. 2009
//Prerequisit: EvenHandler.js

addEvent(window, 'load', focusInput); 

function focusInput(e)
{
  var foundFocus = false;
  if (document.getElementsByTagName('li')[0] != null
    && (document.getElementsByTagName('input')[0] != null
      || document.getElementsByTagName('select')[0] != null))
  {
    var lis = document.getElementsByTagName('li');
    for (var i = 0; i < lis.length; i++)
    {
      for (var n = 0; n < lis[i].childNodes.length; n++)
      {
        var element = lis[i].childNodes[n];
        if (element.nodeName == 'INPUT'
        || element.nodeName == 'SELECT')
        {
          foundFocus = true;
          element.focus();
          n = lis[i].childNodes.length;
        }
      }
      if (foundFocus) i = lis.length;
    }
  }
}
