/** @fileOverview Behaviors for Belle Plaine Nursery */

document.observe("dom:loaded", function () {
  /**
   * Blank out the default values of the username and password fields on the 
   * sidebar
   */
  (function () {
    /**
     * Clear an element based on a default value
     */
    var clear = function (el, val) { 
      if ($(el) && Object.isString(val)) { 
        el = $(el);
        if (el.value === val) { el.clear(); } 
      }
    }   

    if ($('username') && $('password')) {
      $('username').observe('click', function (evt) {
        clear(evt.element(), "User ID");
      });

      $('password').observe('click', function (evt) {
        clear(evt.element(), "Password");
      });
    }

  })();

  /**
   * Use hidden fields to authenticate and then redirect to the my orders page
   */
  (function () {
    var form = $("loginTrick");
    if (form) {
      form.request({
        onComplete : function () { form.update('<p>You are now logged in. <a href="/myorders">Go to My Orders</a>.</p>'); }
      });
    }
  })();
});
