
window.onload = setFocusFirstField;

function setFocusFirstField() {
  // Get all input tags
  var els = document.getElementsByTagName('input');

  // How many input tags?
  var elCount = els.length;
  var elCurr = 0;
  var stillLooking = true;

  // Find the first text box
  while (elCurr < elCount && stillLooking) {
    // Get next input tag
    var el = els[elCurr];
    var elType = el.type.toLowerCase()

    // Is it of type 'text'
    if (elType == 'text' || elType == 'password') {
      // Set focus and stop the loop
      el.focus();
      stillLooking = false;
    }
    elCurr++;
  }
}
