
/******************************************************************************
 *
 *	PROJECT: Flynax Classifieds Software
 *	VERSION: 3.1
 *	LISENSE: FL4529UY8XHS - http://www.flynax.com/license-agreement.html
 *	PRODUCT: General Classifieds
 *	DOMAIN: clubannonces.ch
 *	FILE: MESSAGE.JS
 *
 *	This script is a commercial software and any kind of using it must be 
 *	coordinate with Flynax Owners Team and be agree to Flynax License Agreement
 *
 *	This block may not be removed from this file or any other files with out 
 *	permission of Flynax respective owners.
 *
 *	Copyrights Flynax Classifieds Software | 2010
 *	http://www.flynax.com/
 *
 ******************************************************************************/

textcounter = function(conf)
{
	this.maxLength = conf.max;
	this.minLength = conf.min;

	this.conf = conf;
}

textcounter.prototype = 
{
	init: function()
	{
		var obj = this;
		
		this.element = document.getElementById(this.conf.textarea);
		this.count = document.getElementById(this.conf.textarea+'_counter');

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

		if((this.minLength >= 0 && this.maxLength >= 0) || (isNaN(this.minLength) && this.maxLength >= 0))
		{
			this.count.value = this.maxLength;

			this.counting(true);

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

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

		if((this.minLength >= 0 && isNaN(this.maxLength)))
		{
			this.count.value = this.minLength;

			this.counting(false);

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

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

	counting: function(decrease)
	{
		if(decrease)
		{
			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;
			}
		}
		else
		{
			this.count.value = this.element.value.length;
		}
	}
}

