$(document).ready(function() {
    // The Toolbox - if no JS is enabled, it should be visible (to be useful)
    // so it's left visible by default and hidden with JS, then a simple click
    // function to get it to toggle on and off.
    $(".toolboxdiv, .toolboxdiv-nonmember").hide();
    $("#toolbox-clicker").append("&nbsp;&nbsp;<img class='tb-da' src='http://gfd.org/images/arrowdownwhite.png' alt='' />");
    $(".tb-da").attr('src', 'http://gfd.org/images/arrowdownwhite.png');
    $("#toolbox-clicker").click(function() {
        $(".toolboxdiv, .toolboxdiv-nonmember").slideToggle("slow");
        var img = $(".tb-da");
        var src = img.attr('src');
        if (src == 'http://gfd.org/images/arrowdownwhite.png') {
            img.attr('src', 'http://gfd.org/images/arrowupwhite.png');
        }
        else {
            img.attr('src', 'http://gfd.org/images/arrowdownwhite.png');
        }
    });

    // Making menus beautiful using the Superfish Jquery addon from http://users.tpg.com.au/j_birch/plugins/superfish/
    // The menu works in everything but IE without this addon, but this makes for nice easing.
    $("ul.topnav").superfish();
});

function WireAutoTab(CurrentElementID, NextElementID, FieldLength) {
    //Get a reference to the two elements in the tab sequence.
    var CurrentElement = $('#' + CurrentElementID);
    var NextElement = $('#' + NextElementID);

    CurrentElement.keyup(function (e) {
        //Retrieve which key was pressed.
        var KeyID = (window.event) ? event.keyCode : e.keyCode;

        //If the user has filled the textbox to the given length and
        //the user just pressed a number or letter, then move the
        //cursor to the next element in the tab sequence.   
        if (CurrentElement.val().length >= FieldLength && ((KeyID >= 48 && KeyID <= 90) || (KeyID >= 96 && KeyID <= 105)))
            NextElement.focus();
    });
}
