/**
* JQuery plugin to limit the number of characters that can be input.
**/
(function($){
	$.fn.charLimit = function(o){
		o = $.extend({
			limit: 0,
			charsLeftId: null,
			limitType: 'chars'
		},o || {});
		$(this).keyup(function(e){
			if(o.limitType == 'chars'){
				str = new String($(this).val());
				strLength = str.length;
				charsLeft = parseFloat(o.limit) - parseFloat(strLength);
				if(length > o.limit){
					charsLeft = 0;
					$(this).val($(this).val().substring(0,o.limit));
				}
			}else if(o.limitType == 'words'){
				text = $(this).val();
				words = text.split(' ');
				charsLeft = o.limit - words.length;
				if(words.length > (o.limit)){
					charsLeft = 0;
					words.pop();
					newText = words.join(' ');
					$(this).val(newText);
				}
			}
			$('#'+o.charsLeftId).text(charsLeft);
		});
	};
})(jQuery);

