// Lock a submit button when clicked from being clicking again and change the value of the submit to a message, while preserving the submits name and value in a hidden input.
// License: http://www.gnu.org/licenses/lgpl.txt
// Homepage: http://blog.leenix.co.uk/2009/09/jquery-plugin-locksubmit-stop-submit.html
// Version 1.02

jQuery.fn.lockSubmit = function(options) {

	//Default text to change submit button too
	var settings = jQuery.extend({
		submitText: null,
		onAddCSS: null,
		onClickCSS: null
	}, options);

	var clicked=false;

	//add CSS to this button
	if(settings.onAddCSS) {	this.addClass(settings.onAddCSS); }

	return this.click(function(e) {		
		if(clicked) {
			return false;
		}
		else
		{
			clicked=true;			
		
			//insert hidden field with name and value of submit
			jQuery(this).after("<input type='hidden' name='"+jQuery(this).attr("name")+"' value='"+jQuery(this).val()+"'>");
		
			//change text of the submit button
			if(settings.submitText) { jQuery(this).val(settings.submitText); }
			
			//add onClick CSS
			if(settings.onClickCSS) {
				if(settings.onAddCSS) {	jQuery(this).removeClass(settings.onAddCSS); }
				jQuery(this).addClass(settings.onClickCSS);
			}
		
			//rename and disable the submit button
			jQuery(this).attr("name", jQuery(this).attr("name")+"DISABLED");				
			
			return true;
		}
	});
};


