// ClearOnFocus JQuery plugin:
// Unobtrusive solution to have default texts on textboxes that will go away
// when clicked. (When the user doesn't have JavaScript enabled, the textbox
// will be blank.)

;(function($) {
    $.clearOnFocus = function()
    {
        // For each input box with the default in the rel field (mostly search boxes),
        // and has the value attribute:
        $('input[rel*=default]').each(function()
        {
            // See if it's in the right format. Don't continue if it's not
            var match = (/\[default=([^\]]*)\]/).exec($(this).attr('rel'));
            if (!match) { return; }
        
            // Get the default text
            // this.originalText = match[1];
            this.originalText = $('[name=Ntt]').val();
        
            // When it's clicked...
            $(this).focus(function()
            {
                // And the text is the same as the default text...
                // if (this.originalText == $(this).val()) {
                    // Clear it, and remove the .default-text class.
                    $(this).val('');
                    $(this).removeClass('default-text');
                /*}
                // But if there's something in it...
                else {
                    // Select the whole thing
                    this.selectionStart = 0;
                    this.selectionEnd = this.value.length;
                }*/
            });
        
            // And when leaving the field...
            $(this).blur(function()
            {
                // And there's nothing in it...
                if (('' == $(this).val()) || (this.originalText == $(this).val())) {
                    // Switch it back to the default text.
                    $(this).val(this.originalText);
                    $(this).addClass('default-text');
                }
            });
        
            // Run the blur code (bad and lazy)
            $(this).blur();
        });
        return $;
    };
})(jQuery);

// On load:
// Initialize the clear-on-focus behavior.
$(function() {
    $.clearOnFocus();
});

