Event.observe(window, 'load', function() {
  $('sblogon').observe('submit', logonFormQuickCheck);
  initSBFields();
});

// {{{ logonFormQuickCheck(ev)
function logonFormQuickCheck(ev) {
  var errors = new Array();
  var un = $('auth_user_name');
  if(un && un.value) {
    if(!un.value.match(/^[a-z0-9_A-Z]{1,20}$/))
      errors.push('An Invalid Username was entered.');
  } else {
    errors.push('No Username was entered.');
  }

  var pw = $('auth_password');
  if(!pw || !pw.value) {
    errors.push('No Password was entered.');
  }

  if(errors.length) {
    ev.stop();
    var txt = '';
    errors.each(function(e){ if(txt) txt += "\n"; txt += '* ' + e; });
    alert(txt);
  }
} // }}}

// {{{ initSBFields()
function initSBFields() {
 inputAsLabel('auth_user_name');
 inputAsLabel('auth_password');

 if(GetCookie('remember_login')) {
   if($('auth_user_name') && GetCookie('username'))
     $('auth_user_name').value = GetCookie('username');

   if($('auth_password') && GetCookie('password'))
     $('auth_password').value = GetCookie('password');

   if($('admin_button') && GetCookie('admin_button'))
     $('admin_button').checked = true;
 }
} // }}}
