

function TextFieldLengthCounter(textfname,textlenfname,formname,maxlen)
{
	this.textfname = textfname;
	this.textlenfname = textlenfname;
	this.formname = formname;
	this.maxlen = maxlen;

	this.registerEvents = function ()
	{
		
		
		
		addEvent(document.forms[this.formname][this.textfname],"keyup",this.updateCounterText,false);
		
		
	};

	this.clip = function(maxlen)
	{
		this.value = this.value.substr(0,maxlen); 
	};
	
	
	this.updateCounterText = function()
	{
		
		var len;
		var o;

		if(this.event)
			o = this.event.srcElement;
		else
			o = this;

		var srcname = o.name;
		var formname = o.form.name;
		
		var textcountname = srcname + "_char_count";
		
		len = o.value.length + findnewline(o.value);
		
		document.forms[formname][textcountname].value = len;
	
		if(len > o.txtfield_length_controller.maxlen)
		{
			o.clip(o.txtfield_length_controller.maxlen - findnewline(o.value));
			
			len = o.value.length + findnewline(o.value);
		
			document.forms[formname][textcountname].value = len;
			
		}
	};

	
	document.forms[this.formname][this.textfname].txtfield_length_controller = this;
	document.forms[this.formname][this.textfname].clip = this.clip;
	document.forms[this.formname][this.textfname].updateCounterText = this.updateCounterText;
	
	document.forms[this.formname][this.textfname].updateCounterText();
}




