$(function () {
    var lastSent = false;
    $('#{id}').submit(function () {
        var form = $(this);
        var data = form.serialize();
        if (lastSent != data) {
            $.post('/ajax/rtform/ajax/add', data, function (response) {
                form.find('.label-success').remove();
                form.find('.label-danger').remove();
                if (response.hash !== undefined) {
                    form.find('input[name="hash"]').remove();
                    form.append(response.hash);
                }
                if (response.success !== undefined) {
                    form.append('<label class="label label-success">' + response.success + '</label>');
                    form.find('input[type="text"], input[type="email"], input[type="phone"], textarea').val('');
                }
                if (response.error !== undefined) {
                    form.append('<label class="label label-danger">' + response.error + '</label>');
                }

                lastSent = form.serialize();
            });
        }
        return false;
    });
});