(function($) {
    $.fn.extend({
        modalCheck: function(options) {
        
        	var defaults = {
        		theForm: "#modalForm" //The form we check for submission from
        	}
        	var options = $.extend(defaults, options);
        
        	return this.each(function() {
	        	var obj = $(this);
	        	var numberofchx = 0;
	        	
	        	obj.fadeIn();
	        	
	        	$(options.theForm + ' input[type=checkbox]').each(function(){
	        		numberofchx += 1;
	        	});
	        	
	        	
	        	$(options.theForm + ' input[type=checkbox]').click(function(){
	        			if( $(options.theForm + ' input[type=checkbox]:checked').length == numberofchx ){
	        				$(options.theForm + ' input[type=submit]').removeAttr('disabled');
	        			}
	        			else {
	        				$(options.theForm + ' input[type=submit]').attr('disabled', 'disabled');
	        			}
	        	});
	        	
	        	
	        	$(options.theForm).submit(function (){
	        		if( $(options.theForm + ' input[type=checkbox]:checked').length == numberofchx ){
	        			obj.fadeOut();
	        			return false;
	        		}
	        	});
	        	
	        	
	        	$(options.theForm + ' input#cancel').click(function(){
	        		window.location.replace = history.go(-1);
	        	});
	        	
	        });
        }
    });
})(jQuery);
