﻿
jQuery.fn.lockSubmit = function(options) {

    //Default text to change submit button too
    var settings = jQuery.extend({
        submitText: null,
        onAddCSS: null,
        onClickCSS: null
    }, options);

    //add CSS to this button
    if (settings.onAddCSS) { this.addClass(settings.onAddCSS); }

    return this.click(function(e) {


        //Hide current submit and insert a dummy submit which is disabled. The reason for doing this and not just disabling the normal submit, is that in some browsers the disabled submit will stop the form being submited at all.

        targetselect = jQuery(this);

        targetselect.lockSubmitReset();

        targetselect.hide();

        //new buttons value
        if (settings.submitText) { var newValue = settings.submitText; } else { var newValue = jQuery(this).val(); }

        //insert hidden field with name and value of submit
        targetselect.after("<button id='dummySubmit' class='medium load button' disabled='disabled' type='button' name='" + jQuery(this).attr("name") + "DUMMY'><span>&nbsp;</span></button>");

        //add onClick CSS
        if (settings.onClickCSS) {
            jQuery("#dummySubmit").addClass(settings.onClickCSS);
        }

        return true;
    });

};

jQuery.fn.lockSubmitReset = function() {
    this.show();
    jQuery("#dummySubmit").remove();
};


