﻿(function ($) {

    $.fn.placeholder = function () {
        var input = document.createElement('input');
        if (!("placeholder" in input)) {
            $("[placeholder]").each(function () {
                var element = $(this);
                var placeholder = element.attr("placeholder");
                if (placeholder) {
                    element
                    .focus(function () {
                        if (element.val() == placeholder) {
                            element.val("");
                        }
                    })
                    .blur(function () {
                        if (element.val() == "") {
                            element.val(placeholder);
                        }
                    })
                    .blur();
                }
            });
        }
    };

    $(function () {
        $(document).placeholder();
        $("form").submit(function () {
            var inputs = $("form input");
            $.each(inputs, function () {
                if ($(this).val() == $(this).attr("placeholder")) {
                    $(this).val("");
                }
            });
        });
    });

})(jQuery);
