﻿$(function () {
    showValidationSummaryDialog();

    $("form").bind('invalid-form.validate',
        function (form, validator) {
            showValidationSummaryDialog();
        }
    );

    function showValidationSummaryDialog() {
        $('.validation-summary-errors').dialog({
            title: 'Sign Up Error',
            modal: true,
            buttons: {
                Ok: function () {
                    $(this).dialog("destroy").prependTo($('form')); ;
                }
            }
        });
    }

    jQuery.fn.inputHints = function () {
        // hides the input display text stored in the title on focus
        // and sets it on blur if the user hasn't changed it.

        // show the display text
        $(this).each(function (i) {
            if ($(this).val().length == 0) {
                $(this).val($(this).attr('title'))
            .addClass('hint');
            }
        });

        // hook up the blur & focus
        return $(this).focus(function () {
            if ($(this).val() == $(this).attr('title'))
                $(this).val('')
                .removeClass('hint');
        }).blur(function () {
            if ($(this).val() == '')
                $(this).val($(this).attr('title'))
                .addClass('hint');
        });
    };

    $('input[title]').inputHints();
});
