/*
textinputfeedback
Let's you know how many characters you have used in an input of type text
*/

(function($) {
	
	$.fn.textinputfeedback = function(){	
		return this.each(function(){ 
			// if there isn't a max length....
			n_chars = $(this).val().length;
			size = $(this).attr('maxlength');
			if(size == -1){size="";}
			else{size = "/"+size;}
			i = $('input[@type="text"]').index($(this)[0])
			$('#tif'+i).remove()
			$(this).after('<span class="tif" id="tif'+i+'" style="font-size:0.8em; color:silver;">'+n_chars+size+' </span>')

			/* Attach a keyup listener to update the feedback*/
			$(this).keyup(function(){ 
				n_chars = $(this).val().length;
				size = $(this).attr('maxlength');
				if(size == -1){size="";}
				else{size = "/"+size;}
				i = $('input[@type="text"]').index($(this)[0])
				$('#tif'+i).remove()
				$(this).after('<span class="tif" id="tif'+i+'" style="font-size:0.8em; color:silver;">'+n_chars+size+' </span>')
			});
			
		});
	}; 

})(jQuery);

