/*
* jQuery AssignEnterKey Plug-in
*
* Summary      : This plug-in will attach a click/blur event to all input elements inside a parent container,
*                the events will add/remote a class to the parent container that is used to assign a submit/button
*                that will be triggered when the Enter key is pressed.
*
* Example      : $("FIELDSET").AssignEnterKey();
*
* Developed by : Zachary.Hunter@gmail.com
* Date         : 2009-05-29 23:05
*/
(function($) {
    $.fn.AssignEnterKey = function(options) {

        var defaults = {
            triggerExp: ":input",
            targetExp: ":submit,:button"
        };

        var options = $.extend(defaults, options);

        $(document).keypress(function(e) {
            if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                $(".EnterKeyAssigned")
					.find(options.targetExp)
					.click();
                return false;
            }
        });

        return this.each(function() {
            var obj = $(this);

            obj.find(options.triggerExp)
                    .click(function() { obj.addClass("EnterKeyAssigned"); })
                    .blur(function() { obj.removeClass("EnterKeyAssigned"); });
        });
    };
})(jQuery); 