function limitChars(textid, limit, infodiv)
{
	var text = $('#'+textid).val();	
	var textlength = text.length;
	if(textlength > limit)
	{
		$('#' + infodiv).html('You cannot write more then '+limit+' characters!');
		$('#'+textid).val(text.substr(0,limit));
		return false;
	}
	else
	{
		$('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');
		return true;
	}
}

$(function(){
 	$('#description').keyup(function(){
 		limitChars('description', 8000, 'description_limit');
 	})
	
	$('#messages').keyup(function(){
 		limitChars('messages', 1000, 'messages_limit');
 	})
	
		$('#title').keyup(function(){
 		limitChars('title', 100, 'title_limit');
 	})
		
			$('#website').keyup(function(){
 		limitChars('website', 100, 'website_limit');
 	})
			
					$('#address').keyup(function(){
 		limitChars('address', 100, 'address_limit');
 	})
							$('#telephone').keyup(function(){
 		limitChars('telephone', 50, 'telephone_limit');
 	})
							
									$('#times').keyup(function(){
 		limitChars('times', 100, 'times_limit');
 	})
									
			$('#location').keyup(function(){
 		limitChars('location', 100, 'location_limit');
 	})
});