jQuery.fn.modalContactForm = function() { $(this).each(function(){ $(this).click(function () { $('body').prepend('\ \ \ '); Recaptcha.create( '6Lee8wUAAAAAAKBSqdHrSRSK44-aoft73eOrf_n9', 'recaptcha_placeholder', { theme: 'red', callback: Recaptcha.focus_response_field } ); $('div#modal_contact_form').css('margin-top', ($('div#modal_contact_form').height() + 26) * -1 / 2 + 'px').fadeIn(); $('div#modal_contact_form form').submit(function () { $('input#modal_form_submit').attr({disabled: 'disabled', value: 'Please wait...'}); $.ajax({ type: 'POST', url: '/scripts/forms/contact.json.php', dataType: 'json', data: $(this).serialize(), success: function (json) { if (json.success) { $('div#modal_contact_form form').hide(); $('div#modal_contact_form') .prepend(json.message).css('margin-top', ($('div#modal_contact_form').height() + 26) * -1 / 2 + 'px'); } else { $('input#modal_form_submit').attr({disabled: '', value: 'Submit'}); Recaptcha.reload(); alert('Error: ' + json.message); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert('There was an error sending your message.'); } }); return false; }); $('div#modal_mask').fadeTo(null, .75).click(function () { $('div#modal_contact_form').fadeOut(null, function () { $(this).remove(); }); $(this).fadeOut(null, function () { $(this).remove(); }); }); $('div#modal_close_button').click(function () { $('div#modal_contact_form').fadeOut(null, function () { $(this).remove(); }); $('div#modal_mask').fadeOut(null, function () { $(this).remove(); }); }); }) }); }