document.write('<script type="text/javascript" src="/javascripts/jquery.block.ui.js"></script>');

$(document).ready(function() {
    $('#new_contact, #new_email_entry').submit(function() {
        $.blockUI({ message: '<h1> Aguarde...</h1>' });
        
        var model = $(this).attr('id').substr(4)
        var options = {
            success: showResponse,
            url:     '/create_'+model
        };
        $(this).ajaxSubmit(options);
        $(this).resetForm();
        return false;
    });
    $('#new_comment').submit(function() {
        var model = $(this).attr('id').substr(4)
        var options = {
            success: showResponseComment,
            url:     '/create_'+model
        };
        $(this).ajaxSubmit(options);
        $(this).resetForm();
        return false;
    });
});

function showResponse(responseText, statusText, xhr, $form)  {
    $.unblockUI();
    $('input', $form).blur();
    alert(responseText);
}

function showResponseComment(responseText, statusText, xhr, $form)  {
    alert(responseText);
    $('input', $form).blur();
    $('.list_of_comments').load('/site/load_comments/'+$('#post_id', $form).val(), function()
    {
      $('.bt-comentarios').html($('.box-comentario', this).size() + " comentários")
    });

}

