jQuery(document).ready(function(){
    jQuery('textarea[maxlength]').keyup(function(){
        var max = parseInt(jQuery(this).attr('maxlength'));
        if(jQuery(this).val().length > max){
            jQuery(this).val(jQuery(this).val().substr(0, jQuery(this).attr('maxlength')));
        }

		var tmpl = jQuery(this).parent().find('.charsRemainingTemplate');

        jQuery(this).parent().find('.charsRemaining').html(tmpl.html().replace('#chars#',(max - jQuery(this).val().length)));
    });
});