/**
 * This document.ready block runs all the below functions
 *
/**
 * If someone is in the username field, clear it. If they leave (and it's empty)
 * then put the default message back (Username).
 */
$(document).ready(function() {
    $("ul li:first-child").addClass("firstchild");
    $("ul li:last-child").addClass("lastchild");

    $.fn.focus_blur = function() {
        return this.focus(function() {
            if( this.value == this.defaultValue ) {
                this.value = "";
            }
        }).blur(function() {
            if( !this.value.length ) {
                this.value = this.defaultValue;
            }
        });
    };

    $("#login_username").focus_blur();
    clearLoginFormBrowserMemory();

});

/**
 * These functions are to hide/show the input textbox (showing password) and
 * replace with a proper input password field (on focus).
 */
function pwdFocus() {
    $('#login_password_fake').hide();
    $('#login_password').show();
    $('#login_password').focus();
}

function pwdBlur() {
    if ($('#login_password').attr('value') == "") {
        $('#login_password').hide();
        $('#login_password_fake').show();
        $('#login_password_fake').attr('value') = "Password";
    }
}

/**
 * Client specified they don't want the login forms to allow remembered
 * credentials. As a result we're setting autocomplete to off for login form
 * inputs (however this is done on document.ready, after the browser has already
 * populated the fields, so we clear them manually too).
 */
function clearLoginFormBrowserMemory() {
    // If login form is on the page, set the inputs to have autocomplete off
    if ($("#login").length > 0) {
        $("#login input").attr("autocomplete", "off");
        $("#login input#username").attr("value", "");
        $("#login input#password").attr("value", "");
    }
}
