//Adds sprintf style formatter to strings
String.prototype.format = function() {
    var pattern = /\{\d+\}/g;
    var args = arguments;
    return this.replace(pattern, function(capture) { return args[capture.match(/\d+/)]; });
}

//jQuery addons
;(function($) {

    //Submit a form asynchronously with jQuery post
    //Updated for jQuery 1.3.2 (attr selectors and disabled filter)
    jQuery.fn.submitAjax = function(url, responseHandler) {
        var params = {};

        $(this).find("input[checked], input[type='text'], input[type='hidden'], input[type='password'], input[type='submit'], option[selected], textarea")
        .not(':disabled')
        .each(function() { params[this.name || this.id || this.parentNode.name || this.parentNode.id] = this.value; });

        $.post(url, params, responseHandler);

        return this;
    }

    //Clear all inputs to a form
    jQuery.fn.clearForm = function() {
        $(this).
        find("input[type='text'], input[type='password'], textarea").attr('value', '').end().
        find("input[type='checkbox'], input[type='radio']").attr('checked', false).end().
        find('select').attr('selectedIndex', -1);
    }

    jQuery.log = function(message, quiet) {
        if (window.console) {
            console.log(message);
        } else {
            if (!quiet) {
                alert(message);
            }
        }
    }

})(jQuery);