/*
    <form action="http://app.bronto.com/public/actionpage/subscriber_add/?fn=Mail_ActionPage_FormResponse&pid=h9vqfetp76dnouobb7j4eyyorc3kj&ssid=698">
    <input name="email"/>
    <input name="field_data[7233]" /> //fname
    <input name="field_data[7234]"/>  //lname
    </form>
    var callback = function () {
        alert('Subscribed!');
    }

    $(form).bronto(callback);
*/
(function ($) {
    jQuery.fn.bronto = function (callback) {
        return this.each(function () {
            $(this).submit(function (e) {
                    //this = form
                    e.preventDefault();
                    if(!$(this).find("input[name='email']").val().match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/)) {
                        if (typeof console != 'undefined') {
                            console.log('email failed validation.');
                        }
                        return false;
                    }
                    var querystring = $(this).serialize();
                    var src = $(this).attr('action').concat('&'+querystring);
                    var img = $('<img/>').attr({ height:0,width:0,border:0,src:src });
                    $(document.body).append(img);

                    if (typeof callback == 'function') {
                        callback();
                    }
            });
        });
    };
}) (jQuery);
