/* Placeholder plugin
------------------------------------------------------------------------------------------------ */

(function($) {

    $.fn.placeholder = function() {

        $(this).focus(function() {

            if (!$(this).data('defaultValue')) {
                $(this).data('defaultValue', $(this).attr('value'));
            }

            if ($(this).data('defaultValue') == $(this).attr('value')) {
                $(this).attr('value', '');
            }

        }).blur(function() {

            if (!$(this).attr('value').length) {
                $(this).attr('value', $(this).data('defaultValue'));
            }

        });
    };

})(jQuery);

/* Placeholder (HTML5 for old browsers)
------------------------------------------------------------------------------------------------ */

$.placeholder5 = function() {

    // Remove placeholder text from input on focus

    $('[placeholder]').focus(function() {

        var input = this;

        if ($(input).val() == $(input).attr('placeholder')) {
            $(input).val('');
            $(input).removeClass('placeholder');
        }
    });

    // Fill input with placeholder text on blur

    $('[placeholder]').blur(function() {

        var input = this;

        if ($(input).val() == '' || $(input).val() == $(input).attr('placeholder')) {
            $(input).addClass('placeholder');
            $(input).val($(input).attr('placeholder'));
        }
    });

    // Fill input with placeholder text on load
    
    $('[placeholder]').blur();

    // Don't send placeholder text on press submit button

    $('[placeholder]').parents('form').submit(function() {

        $(this).find('[placeholder]').each(function() {

            var input = this;

            if ($(input).val() == $(input).attr('placeholder')) {
                $(input).val('');
            }
        });
    });

};

