jQuery(document).ready(function(){

	jQuery('.word_count .textbox').keyup(function(){
	limitChars('.word_count .textbox', 1000, '.counter');

	})

});


function limitChars(textid, limit, infodiv) {

	var text = jQuery(textid).val(); 
	var textlength = text.length;
	
	jQuery(infodiv).fadeIn('slow').css({display: 'block'});

	if(textlength > limit) {
		jQuery(infodiv).html('You cannot write more then '+limit+' characters!');
		jQuery(textid).val(text.substr(0,limit));
		jQuery('.submit').attr('disabled', 'disabled').css({background: "#cccccc"});
		return false;
	}

	else {
		jQuery(infodiv).html('You have '+ (limit - textlength) +' characters left.');
		jQuery('.submit').removeAttr('disabled').css({background: "#006699"});
		return true;
	}

}


