function charCountLimit(count, e, id){
		//var key = evt.charCode || evt.keyCode || 0;
		//alert(key)
		if(!e)
			return true;
		else{
			var charTyped = e.value.length;
			var remained = count - charTyped;
			var name = e.name;
			
			if(remained >= 0 && remained <= count)
			{
				document.getElementById(id ).innerHTML = remained;

				return true;
			}
			else
				return false;
		}
	}

	$(document).ready(function(){
		// find all inputs that have maxChar
		$('input').filter(function() { return $(this).attr('maxChar'); }).each(function() {
		  // matched an input with maxChar
		  //$(this.parentNode).append('<div id="charCount_' + this.name + '">' + $(this).attr('maxChar') + ' character(s) remained.</div>');
		  //$(this).bind('keyup', function(e) {return charCountLimit($(this).attr('maxChar'), this, e.which) } );
		  
		  this.setAttribute("maxLength", $(this).attr('maxChar') );
		  this.setAttribute("maxlength", $(this).attr('maxChar') );
		});
		$('textarea').filter(function() { return $(this).attr('maxChar'); }).each(function() {
		  // matched a textarea with maxChar
		  //$(this.parentNode).append('<div id="charCount_' + this.name + '">' + $(this).attr('maxChar') + ' character(s) remained.</div>');
		  //$(this).bind('keyup', function(e) {return charCountLimit($(this).attr('maxChar'), this, e.which) } );
		  $(this).bind('keypress', function(event){
		  var key = event.which;

		  if(key >= 33 || key == 13) {
				var maxLength = $(this).attr("maxChar");
				var length = this.value.length;
				if(length >= maxLength) {
					event.preventDefault();
				}
				}
			});
		});
		//alert()
		
	});
