
// Make sure the function runs.
//
// Using the PHP WCMS onload settings for this, resulted
// in an Internet Explorer error.
window.onload = documentLoad;

// Selects the first field in the first active form for input.
function documentLoad()
{
   var doc = document;

   if (doc.forms[0]) 
   {
      var first_form = document.forms[0];

      // Look for a focus field
      var focus_field = null;

      for (i = 0; i < first_form.length; i++) 
      {
         if (focusType(first_form.elements[i]))
         {
            // Found a focus field
            if (focus_field == null) 
               focus_field = first_form.elements[i];

            var cssclass = first_form.elements[i].className;

            // Found an invalid element. Overrules first focus.
            if (cssclass.indexOf('elementInvalid') >= 0) 
            {
               focus_field = first_form.elements[i];
               break;   // No need to look further.
            }
         }
      }

      if (focus_field != null) 
      {
         try {
            focus_field.select();
         } catch (err) {}
         focus_field.focus();
      }
   }
}

function focusType(input_element)
{
   if (input_element.getAttribute("disabled")) 
      return false;

   if ((input_element.type == "submit") 
       || (input_element.type == "reset")
       || (input_element.type == "hidden")
       || (input_element.type == "button"))
      return false;

   return true;
}

