/*s*
* A helper class for limiting text area input length.
*
* Usage:  new AGTextAreaLimit('#textAreaId', 250);
*
* @author Caine
* @version 1.0
* @param {String} options.selector - The selector for the elements to set the limit on.
* @param {Number} options.maxLength - The maximum length for the textarea.
*/
var LFTextAreaLimit = function(options) {
	
	this.construct = function(options) {
		self.options = options;
		$(options.selector).unbind('keyup', self.checkLimit);
		$(options.selector).bind('keyup', self.checkLimit);
		return self;
	};
	
	/**
	 * Binds the selectors.
	 * 
	 * @access private
	 **/
	this.checkLimit = function() {
		if (this.value.length > self.options.maxLength) {
			this.value = this.value.substring(0, self.options.maxLength);
		}
	}

	var self = this;
	self.construct(options);
};

var SINGLE_CLICK_TRIGGER = false;
// For single-click only form buttons.
$(document).ready(function () {
	$('input.single-click').click(function() {
		if (SINGLE_CLICK_TRIGGER) {
			this.disabled = true;
			return false;
		}
		SINGLE_CLICK_TRIGGER = true;
	});
});

var DOUBLE_CLICK_TRIGGER = false;
// For double-click only form buttons.
$(document).ready(function () {
	$('input.double-click').click(function() {
		if (DOUBLE_CLICK_TRIGGER) {
			this.disabled = true;
			return false;
		}
		if (SINGLE_CLICK_TRIGGER) {
			DOUBLE_CLICK_TRIGGER = true;
		}
		SINGLE_CLICK_TRIGGER = true;
	});
});

// Reset single and double click form buttons.
$(document).ready(function () {
	$('input.reset-clicks').click(function() {
		DOUBLE_CLICK_TRIGGER = false;
		SINGLE_CLICK_TRIGGER = false;
	});
});