﻿function AverinaOnContentChanged(field, maxLength, counter)
{ 
	var span = document.getElementById(counter); 
	var text = document.getElementById(field);
	 
	var length;
	
	if(typeof(text) != "undefined")
	{
		length = text.value.length; 
	}
	
	if(typeof(length) != "undefined")
	{		
		if(maxLength - length < 0) 
		{ 
			var position = maxLength - 1;
			 
			while(position >= 0 && (text.value.charAt(position) == '\n' || text.value.charAt(position) == '\r'))
			{
				cutPos--;
			}
			
			var top  = text.scrollTop;
			var left = text.scrollLeft; 
			
			text.value = text.value.substring(0, position + 1);
			
			text.scrollTop  = top; 
		  	text.scrollLeft = left; 
		}
		
		span.innerHTML = maxLength - text.value.length; 
	}
}
