(function($) {
	jQuery.fn.charactersLimit = function(limit, target) {
		$.fn.checkCharacters = function(event) {
			var ctrl = event.ctrlKey;
			var chr = event.which;
			if ((limit <= this.lenght()) || (ctrl == 1)) {
				if ((33 <= chr && chr <= 40) || (chr == 8) || (chr == 46)) {
					//target.html(chr);
				} else {
					event.preventDefault();
				}
			} else {
				//target.html(chr);
			}
		};
		$.fn.showRemain = function() {
			result = limit - this.lenght();
			target.html(result);
		};
		$.fn.lenght = function() {
			return $(this).val().length;
		};
		return this.each(function() {
			$(this).keyup(function() {
				$(this).showRemain();
			});
			$(this).keypress(function() {
				$(this).showRemain();
			});
			$(this).keydown(function(event) {
				$(this).checkCharacters(event);
			});
		});
	};
})(jQuery);
