jQuery.fn.dodosTextCounter=function(a,b){b=$.extend({counterDisplayElement:"span",counterDisplayClass:"dodosTextCounterDisplay",addLineBreak:true},b);$(this).each(function(i){updateCounter(this,a,b,i);$(this).keyup(function(){updateCounter(this,a,b,i);return this})});return this};function updateCounter(a,b,c,d){var e=0;var f=$(a).val();if(f){e=f.length}if(e>b){$(a).val(f.substring(0,b))}else{var g=b-e;var h=c.counterDisplayElement+"."+c.counterDisplayClass+":eq("+d+")";var i=$(h).length==0;if(i){var j=document.createElement(c.counterDisplayElement);if(c.counterDisplayElement=='input'){$(j).val(g.toString())}else{$(j).html(g.toString())}$(a).parent().append($(j).addClass(c.counterDisplayClass));if(c.addLineBreak){$(a).after("")}}else{if(c.counterDisplayElement=='input'){$(h).val(g.toString())}else{$(h).html(g.toString())}}}}