// Onload, setup validation.
$(bindValidator);


function showFeedbackForm()
{
    $('#MessageBoxShroud').show();
    $(window).bind('mousewheel', function() {return false;});
    //$('#FeedbackBox').bind('mousewheel', function() {return true;});

    $('#FeedbackFrame').show();

    return;
}


function hideFeedbackForm()
{
    $('#FeedbackFrame', top.document).hide();
    $('#MessageBoxShroud', top.document).hide();
}


function feedbackBeforeSubmit()
{
    alert('Feedback: before submit');

    return;
}


/**
 * Configures jQuery form validation.
 *
 * @return void
 */
function bindValidator() {
    // First, unbind existing submission handler.  This is a work around until form validation is defined
    // for all editor forms.
    $('#FeedbackForm').unbind('submit');

    $('#FeedbackForm').validate({
        focusInvalid:  true,
        submitHandler: function(form) {
            $(form).ajaxSubmit({
                dataType: 'xml',
                //beforeSubmit: feedbackBeforeSubmit,
                success: function()
                {
                   alert('Your feedback has been submitted successfully.  Thank you.')
                   hideFeedbackForm();
                   $('#FeedbackFormSubject').val('');
                   $('#FeedbackFormBody').val('');
                }
            });

            return false;
        },
        rules: {
            subject: {
                required: true
            },
            body: {
                required: true
            }
        },
        messages: {
            subject: {
                required: 'Please enter a message subject.'
            },
            body: {
                required: 'Please enter a message body.'
            }
        }
    });

    return;
}
