/**
/* © 2007 - 2008 Kupferwerk GmbH
/*
/* Standard JS File for new Ruby projects
/*
/* This file is available all over the project.
 */



/**
 * @fileOverview A collection of classes and functions for our projects.
 * Is shipped with MCC
 * @name Kupferwerk standard JS library
 */



ajax_request = false;



/**
 * Returns the extended DOM element with the ID given by value
 * or, if undefined, given by default_value
 * @param {html_object} element
 * @param {html_object} default_element
 * @return {html_object} Returns an html element
*/
function defaultElement(element, default_element) {
	if(element)
		element = $(element);
	else
		element = $(default_element);
		
	return element;
}

/**
 * Returns the string given by value
 * or, if undefined, given by default_value
 * @param {object} value
 * @param {object} default_value
 * @return {html_object} Returns an object
*/
function defaultValue(value, default_value) {
	if(!value)
		value = default_value;
		
	return value;
}



/**
 * the current auth token from the gloal js api pool
 * you need to post this with every post request as parameter authenticity_token
 * @return {string} the current authenticity_token, which must be sent with every post request
 */
function currentAuthToken() {
  if(auth_token && (!kupferwerk.auth_token || kupferwerk.auth_token == 'NOT SET'))
		return auth_token;
	else
		return kupferwerk.auth_token;
}

	/**
	 * Generates a new password
	 * @return {string} Password
	 */
function generatePassword(length, characters) {
	source_characters = characters || '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	string = '';

	(length).times(function(i) {
		string = string + source_characters.charAt(Math.round(Math.random() * source_characters.length));
	});

	return string;
}
	
/**
 * Checks whether a variable is a function or not
 * @return {boolean} true/false
 */
function callIfFunction(call_function, request) {
	if(call_function && Object.isFunction(call_function)) {
		call_function(request);
		return true;
	} else {
		return false;
	}
}



/**
 * @class Holds all Kupferwerk functionality.
*/
var Kupferwerk = {};

/**
 * Provides an overlay with AJAX-Content
 * @todo Busy-Message should be customizable
 * @class Scalable overlay for AJAX content
*/
Kupferwerk.Box = {
	
	options: {},
	
	/**
	 * var overlay = new Kupferwerk.Box.init(); to initialize the overlay.
	 * @constructor
	*/
	init: function() {
		document.observe('dom:loaded', function() {
			overlay = '<div id="overlay" style="display: none;"><div id="overlay_box"><div><div><div><div><div><div><div><div><img id="overlay_icon" src="/images/mcc/icons/close.png" alt="Close" title="Close this window" /><div id="overlay_box_content" class="clearfix"></div></div></div></div></div></div></div></div></div></div></div>';

			$$('body').first().insert(overlay);
		});
	},
	
	/**
	 * overlay.show(); to display the overlay.
	 * automatically center the overlay in the viewport
	 * @param {string} href URL for the AJAX-Request
	 * @param {hash} [options]
	 * @config {integer} [width] Width of the overlay in px
	 * @config {string} [icon] Image-Path to the close icon
	 * @return {boolean} Returns true/false
	*/
	show: function(href, options) {
		width = 0;
		this.options = options;
		default_icon = $('overlay_icon');
		$('overlay').setStyle({
			height: $$('body').first().getHeight() + 'px'
		}).show();
		
		if(typeof options == 'object') {
			if(options.icon)
				default_icon.replace(options.icon);
				
			width = options.width;
		}
		
		default_icon.observe('click', Kupferwerk.Box.hide);
		if(window.clipboardData && document.compatMode && window.XMLHttpRequest)
			new Ajax.Updater('overlay_box_content', href, {method: 'get', evalScripts: true, onComplete: function() { Kupferwerk.Box.resize(width); }});
		else
			new Ajax.Updater('overlay_box_content', href, {method: 'get', evalScripts: true, onLoading: Kupferwerk.Box.busy, onComplete: function() { Kupferwerk.Box.resize(width); }});
		
		Event.observe(window, 'resize', function() { Kupferwerk.Box.resize(width); });
		
		return false;
	},
	
	/**
	 * overlay.resize(); to resize the overlay to the given width.
	 * @param {integer} width Width of the overlay in px
	 * @private
	*/
	resize: function(width) {
		$('overlay_icon').show();
		$('overlay_box').setStyle({position: 'absolute'});
		
		overlay_height = document.viewport.getHeight();
		overlay_width = $('overlay').getWidth();
		popup_height = $('overlay_box').getHeight();
		popup_width = $('overlay_box').getWidth();
		if(width && width > 0) {
			popup_width = width + ($('overlay_box').getWidth() - $('overlay_box_content').getWidth());
			$('overlay_box_content').setStyle({
				width: width + 'px'
			});
		} else {
			popup_width = $('overlay_box').getWidth();
		}
		
		top = ((overlay_height - popup_height) / 2) + parseInt(document.viewport.getScrollOffsets().top, 10);
		if(top < 10)
			top = 10;
		
		$('overlay_box').setStyle({
			top: top + 'px',
			left: ((overlay_width - popup_width) / 2) + 'px'
		});
		
		$('overlay_icon').setStyle({
			position: 'absolute',
			left: (popup_width - $('overlay_icon').getWidth()) + 'px'
		});
	},
	
	/**
	 * Displays "Please wait…" while AJAX-Request is in progress
	 * @private
	*/
	busy: function() {
		$('overlay_icon').hide();
		$('overlay_box_content').update('Please wait…');
	},
	
	/**
	 * Hide the overlay and empty content
	 * @return {boolean} Returns true/false
	*/
	hide: function(retVal) {
		$('overlay').hide();
		$('overlay_box_content').update('');
		
		if(this.options['onHide']) {
		  this.options.onHide(retVal);
		}
		
		return false;
	}
};



/**
 * Provides an floating, styleable and good looking HTML title alternative
 * @todo Initializing should be without setting an event-handler
 * @class Floating HTLM title alternative
*/
Kupferwerk.EnhancedTitleTag = {

	/**
	 * var overlay = new Kupferwerk.Box.init(); to initialize the overlay.
	 * Use #{floating_id} (is replaced with an id)
	 * and #{floating_value} (is replaced with the content of parameter) in your template
	 * @param {selector} elements CSS3 Selection of elements which should use the container
	 * @param {hash} [options]
	 * @config {string} [parameter] content of parameter is used as content for the floating container
	 * @config {string} [tag] parameter of this HTML tag is used as content for the floating container
	 * @config {integer} [offsetX] X-Offset of the container relative to mouse position
	 * @config {integer} [offsetY] Y-Offset of the container relative to mouse position
	 * @config {boolean} [partial] Turns use of template returned by AJAX-Request on/off
	 * @config {string} [partial_per_ajax] URL for the AJAX-Request that provides the template
	 * @config {string} [template] Template as string. Is used if partial is true and partial_per_ajax is defined
	 * @config {html_element} [scope] Templates are insert after this html element
	 * @constructor
	*/
	init: function(elements, options) {		
		if(typeof options != 'object') {
			options = {};
		}
	
		options.offsetX = defaultValue(options.offsetX, 10);
		options.offsetY = defaultValue(options.offsetY, 10);
	
		if(options.partial && options.partial_per_ajax) {
			new Ajax.Request(options.partial_per_ajax, {
				onSuccess: function(response) {
					Kupferwerk.EnhancedTitleTag.setFloatingHandler(elements, response.responseText, options);
				}
			});
		} else {
			Kupferwerk.EnhancedTitleTag.setFloatingHandler(elements, defaultValue('<div id="#{floating_id}" class="floating_item"><p>#{floating_value}</p></div>', options.template), options);
		}
	},

	/**
	 * Sets event handler and generates the container
	 * @config {selector} elements Provided by constructor
	 * @config {string} partial Provided by constructor
	 * @config {hash} options Provided by constructor
	 * @private
	*/
	setFloatingHandler: function(elements, partial, options) {
		$$(elements).each(function(element) {
			if(options.tag) {
				element = element.down(options.tag);
			}
			
			if(!element[options.content].blank()) {
				element.floating_item_id = defaultValue(element.parentNode.id, element.parentNode.tagName) + '_' + defaultValue(element.id, element.tagName) + '_' + Math.round(Math.random() * 100000);

				element.observe('mouseover', function(event) {
					Kupferwerk.EnhancedTitleTag.showFloatingItem(this, event, partial, options);
				}).observe('mousemove', function(event) {
					Kupferwerk.EnhancedTitleTag.moveFloatingItem(this.floating_item_id, event, options);
				}).observe('mouseout', function(event) {
					Kupferwerk.EnhancedTitleTag.hideFloatingItem(this.floating_item_id, event, options);
				});
			}
		});
	},

	/**
	 * Show floating item and replace id and parameter_value in partial
	 * @config {html_element} element Provided by setFloatingHandler
	 * @config {event} event Provided by setFloatingHandler
	 * @config {string} partial Provided by setFloatingHandler
	 * @config {hash} options Provided by setFloatingHandler
	 * @private
	*/
	showFloatingItem: function(element, event, partial, options) {
		if(!options.content)
			options.content = 'title';
		
		if(!options.scope)
			options.scope = $$('body').first();
		else
			options.scope = $(options.scope);
			
		if(!$(element.floating_item_id)) {
			options.scope.insert(new Template(partial).evaluate({
				floating_id: element.floating_item_id,
				floating_value: element[options.content]
			}));
			
			if(options.content_empty)
				element[options.content] = '';
				
			element.title = '';
			element.alt = '';
		}
		floating_item = $(element.floating_item_id);
		
		coord_y = options.offsetY + event.pointerY();
		coord_x = options.offsetX + event.pointerX();
		
		floating_item.setStyle({
			position: 'absolute',
			top: coord_y + 'px',
			left: coord_x + 'px'
		});
		
		if(options.duration) {
			new Effect.Appear(floating_item, {duration: options.duration});
		} else {
			$(element.floating_item_id).show();
		}
	},

	/**
	 * Floating item moves with the cursor
	 * @config {html_element} element Provided by setFloatingHandler
	 * @config {event} event Provided by setFloatingHandler
	 * @config {hash} options Provided by setFloatingHandler
	 * @private
	*/
	moveFloatingItem: function(element, event, options) {
		if($(element)) {
			coord_y = options.offsetY + event.pointerY();
			coord_x = options.offsetX + event.pointerX();

			if((floating_item.getWidth() + coord_x) > document.viewport.getWidth())
				coord_x = event.pointerX() - options.offsetX - floating_item.getWidth();
				
			if((floating_item.getHeight() + coord_y) > document.viewport.getHeight())
				coord_y = event.pointerY() - options.offsetY - floating_item.getHeight();

			$(element).setStyle({
				position: 'absolute',
				top: coord_y + 'px',
				left: coord_x + 'px'
			});
		}
	},

	/**
	 * Hide floating item
	 * @config {html_element} element Provided by setFloatingHandler
	 * @config {event} event Provided by setFloatingHandler
	 * @config {hash} options Provided by setFloatingHandler
	 * @private
	*/
	hideFloatingItem: function(element, event, options) {
		if($(element)) {
			if(options.duration) {
				new Effect.Fade(element, {duration: options.duration});
			} else {
				$(element).hide();
			}
		}
	}
};



/**
 * Browser switch
 * Call acceptBrowser() with an array (or string) of allowed browsers
 * Codes of most used browsers:
 * ie6 - Internet Explorer 6
 * ie7 - Internet Explorer 7
 * f15 - Firefox 1.5
 * f20 - Firefox 2.0
 * f30 - Firefox 3.0
 * op8 - Opera 8
 * op8 - Opera 9
 * kq2 - Safari/Konquerer 2
 * sf3 - Safari 3
 * @class Browser Switch
*/
Kupferwerk.BrowserSwitch = {
	
	/**
	 * What browser do you have?
	 * @return {array} Returns an array with shortcut and full name of used browser
	 * @private
	*/
	init: function() {
		var x = [];
		if(document.ids) {
			x = ['nc4', 'Netscape Navigator 4'];
			if(!window.navigator.securityPolicy) x[1] += '.0'; else x[1] += '.5-4.8';
		}
		else if(document.all && !$) {
			if(!document.layers) x = ['ie4', 'Internet Explorer 4']; else x = ['ow4', 'OmniWeb 4.x'];
		}
		else if(window.opera && !document.createElement) x = ['op5', 'Opera 5'];
		else if(window.opera && window.getComputedStyle) {
			if(window.getSelection) x = ['op9', 'Opera 9'];
			else if(document.createRange) x = ['op8', 'Opera 8'];
			else if(window.navigate) x = ['op75', 'Opera 7.5']; else x = ['op72', 'Opera7.2'];
		}
		else if(window.opera && document.compatMode) x = ['op7', 'Opera 7'];
		else if(window.opera && document.releaseEvents) x = ['op6', 'Opera 6'];
		else if(document.contains && !window.opera) {
			x = ['kq3', 'Safari / Konqueror 3'];
			x[1] += window.print ? '.1/.2' : '.0';
			if(document.compatMode) x[1] = 'kq3.4';
		}
		else if(window.pkcs11 && window.XML) {
			x = x = window.postMessage ? 30 : 20;
			x = window.external ? ['f' + x, 'FireFox ' + x + ' / Gecko'] : ['f15', 'FireFox / Gecko Deer Park'];
		}
		else if(window.pkcs11 && document.compatMode) x = ['nn7', 'Mozilla - Firefox - Gecko '];
		else if(window.atob && document.defaultCharset) x = ['sf3', 'Safari 3'];
		else if(window.getSelection && window.atob) x = ['nn7', 'Mozilla - Gecko'];
		else if(window.getSelection && !document.compatMode) x = ['nn6', 'Netscape 6 - Mozilla Beta'];
		else if(window.clipboardData && document.compatMode) {
			x = window.XMLHttpRequest ? 7 : 6;
			x = ['ie' + x, 'Internet Explorer ' + x];
		}
		else if(window.clipboardData) {
			x = ['ie5', 'Internet Explorer 5.0']; 
			if(!document.createDocumentFragment) x = ['ie5.5', 'Internet Explorer 5.5'];
		}
		else if(document.doctype && !window.print ) x = ['ie5m', 'Internet Explorer 5Mac'];
		else if($ && !document.all) {
			x[0] = 'op4';
			x[1] = 'Opera 4';
			if(!window.RegExp) x[1] += '.0'; else x[1] += '.1';
		}
		else if(document.images && !document.all) x = ['nn3', 'Netscape Navigator 3'];
		else if(!document.images) x = ['2-3', 'NS 2, IE 3'];
		else if(document.clientWidth && !window.RegExp) x = ['kq2', 'Safari - Konqueror 2'];
		else x = ['???', 'undefined'];
		
		return x;
	},

	/**
	 * 
	 * @param {array} accepted_browsers Array of accepted browsers: %w(f15 f20 sf3)
	 * @return {hash} Returns an hash with .accepted => true/false, .browser_code and .browser_name
	 * @private
	*/
	acceptBrowser: function(accepted_browsers) {
		current_browser = Kupferwerk.BrowserSwitch.init();
		if(accepted_browsers.include(current_browser[0]))
			return {accepted: true, browser_code: current_browser[0], browser_name: current_browser[1]};
		else
			return {accepted: false, browser_code: current_browser[0], browser_name: current_browser[1]};
	}
};



/**
 * 
 * @todo This has to be documented
 * @class Some actions for form fields
*/
Kupferwerk.FormFields = {
	init: function(element, options) {
		options.default_value = defaultValue(options.default_value, 'Default value');
		
		$(element).onfocus = function() {
			Kupferwerk.FormFields.defaultValue(element, options);
		};
		
		$(element).onblur = function() {
			Kupferwerk.FormFields.defaultValue(element, options);
		};
		
		clear_icon = $(options.clear_icon);
		if(clear_icon) {
			clear_icon.onclick = function() {
				Kupferwerk.FormFields.clearField(element, options);
			};
		}
	},
	
	defaultValue: function(element, options) {
		field = $(element);
		field_value = $F(element);

		if(field_value == options.default_value) {
			field.value = '';
			field.removeClassName('default_value');
			field.type = options.default_type;
		} else if(field_value.empty() || options.empty) {
			field.value = options.default_value;
			field.addClassName('default_value');
			field.type = 'text';
		} else {
			field.removeClassName('default_value');
			Kupferwerk.FormFields.clearIcon(element, options);
		}
	},
	
	clearIcon: function(element, options) {
		field = $(element);
		field_value = $F(element);
		
		if(field_value !== '' || field_value == options.default_value) {
			$(options.clear_icon).show();
			$(options.clear_icon).onclick = function() {
				Kupferwerk.FormFields.clearField(element, options);
			};
		} else {
			$(options.clear_icon).hide();
		}
	},

	clearField: function(element, options) {
		$(options.clear_icon).hide();
		options.empty = true;
		Kupferwerk.FormFields.defaultValue(element, options);
		if(Object.isFunction(options.after_clear)) {
			options.after_clear();
		}
	},
	
	searchField: function(form, identifier, container) {
		new Ajax.Request(form.action, {
			parameters: Form.serialize(form),
			onLoading: function() {
				$('kupferwerk_formfield_search_busy_' + identifier).show();
			},
			onFailure: function() {
				if(container && !container.empty())
					$(container).update('<p class="message failure">We are sorry, but we can not find the requested page!</p>');
			},
			onSuccess: function(response) {
				if(container && !container.empty())
					$(container).update(response.responseText);
			},
			onComplete: function() {
				$('kupferwerk_formfield_search_busy_' + identifier).hide();
			}
		});
		
		return false;
	}
};



/**
 * 
 * @todo This has to be documented
 * @class Validation for user inputs
*/
Kupferwerk.Validation = {
	username_error: false,
	email_error: false,
	url_error: false,
	string_for_url_error: false,
	password_error: false,
	password_confirmation_error: false,
	presence_error: false,
	length_error: false,
	
	init: function(field, message_output, options) {
		message_output = $(message_output);
		value = $F(field);
		
		if(value.empty())
			return false;
	},
	
	updateMessageOutput: function(error, message_output) {
		if(error) {
			$w('success information warning failure').each(function(classname) {
				message_output.removeClassName(classname);
			});

			message_output.addClassName('failure');
			
			status = message_output.select('.status').first();
			if(status)
				status.update(FAILURE);
				
			defaultElement(message_output.select('.content').first(), message_output).update(error);			
			message_output.show();
		} else {
			message_output.hide();
			defaultElement(message_output.select('.content').first(), message_output).update(' ');
		}
	},
	
	username: function(field, message_output, options) {		
		if(!options || typeof options != 'object')
			options = {};
			
		Kupferwerk.Validation.init(field, message_output, options);
			
		message_output = $(message_output);
		value = $F(field);
		
		if(value.length < (options.min_length || 2))
			Kupferwerk.Validation.username_error = KUPERWERK_VALIDATION_USERNAME_TO_SHORT;
		else if (value.length > (options.max_length || 20))
			Kupferwerk.Validation.username_error = KUPERWERK_VALIDATION_USERNAME_TO_LONG;
		else if(value.empty())
			Kupferwerk.Validation.username_error = KUPERWERK_VALIDATION_USERNAME_EMPTY;
		else if(!value.match(/^[\w_]*[a-zA-Z]+[\w_]*$/))
			Kupferwerk.Validation.username_error = KUPERWERK_VALIDATION_USERNAME_SYNTAX;
		else
			Kupferwerk.Validation.username_error = false;
			
		Kupferwerk.Validation.updateMessageOutput(Kupferwerk.Validation.username_error, message_output);
	},
	
	email: function(field, message_output, options) {
		if(!options && typeof options != 'object')
			options = {};
			
		Kupferwerk.Validation.init(field, message_output, options);
			
		message_output = $(message_output);
		value = $F(field);
		
		if(!value.match(/^.+\@(((\w+\-+)|(\w+\.))*\w{1,63}\.[a-z]{2,6}$)/))
			Kupferwerk.Validation.email_error = KUPERWERK_VALIDATION_EMAIL_REGEX;
		else
			Kupferwerk.Validation.email_error = false;
		
		Kupferwerk.Validation.updateMessageOutput(Kupferwerk.Validation.email_error, message_output);
	},
	
	/* TODO: regex false */
	url: function(field, message_output, options) {
		if(!options && typeof options != 'object')
			options = {};
			
		Kupferwerk.Validation.init(field, message_output, options);
			
		message_output = $(message_output);
		value = $F(field);
		
		if(!value.match(/^.+\@(((\w+\-+)|(\w+\.))*\w{1,63}\.[a-z]{2,6}$)/))
			Kupferwerk.Validation.url_error = KUPERWERK_VALIDATION_URL_REGEX;
		else
			Kupferwerk.Validation.url_error = false;
		
		Kupferwerk.Validation.updateMessageOutput(Kupferwerk.Validation.url_error, message_output);
	},
	
	string_for_url: function(field, message_output, options) {
		if(!options && typeof options != 'object')
			options = {};
			
		Kupferwerk.Validation.init(field, message_output, options);
			
		message_output = $(message_output);
		value = $F(field);

		if(!value.match(/^[a-zA-Z0-9]+[a-zA-Z0-9\-]+[a-zA-Z0-9]+$/))
			Kupferwerk.Validation.string_for_url_error = KUPERWERK_VALIDATION_STRING_FOR_URL_REGEX;
		else
			Kupferwerk.Validation.string_for_url_error = false;
		
		Kupferwerk.Validation.updateMessageOutput(Kupferwerk.Validation.string_for_url_error, message_output);
	},
	
	password: function(field, message_output, options) {
		if(!options && typeof options != 'object')
			options = {};
			
		Kupferwerk.Validation.init(field, message_output, options);
			
		message_output = $(message_output);
		value = $F(field);
		
		if(value.length < (options.min_length || 3))
			Kupferwerk.Validation.password_error = KUPERWERK_VALIDATION_PASSWORD_TO_SHORT;
		else if (value.length > (options.max_length || 32))
			Kupferwerk.Validation.password_error = KUPERWERK_VALIDATION_PASSWORD_TO_LONG;
		else
			Kupferwerk.Validation.password_error = false;
		
		Kupferwerk.Validation.updateMessageOutput(Kupferwerk.Validation.password_error, message_output);
	},
	
	password_confirmation: function(field, message_output, options) {
		if(!options && typeof options != 'object')
			options = {};
			
		Kupferwerk.Validation.init(field, message_output, options);
			
		message_output = $(message_output);
		value = $F(field);
		confirmation_value = $F(options.password_field);
		
		if(value != confirmation_value)
			Kupferwerk.Validation.password_confirmation_error = KUPERWERK_VALIDATION_PASSWORD_CONFIRMATION;
		else
			Kupferwerk.Validation.password_confirmation_error = false;
		
			
		Kupferwerk.Validation.updateMessageOutput(Kupferwerk.Validation.password_confirmation_error, message_output);
	},
	
	presence: function(field, message_output, options) {
		if(!options && typeof options != 'object')
			options = {};
			
		Kupferwerk.Validation.init(field, message_output, options);
			
		message_output = $(message_output);
		value = $F(field);
		
		if(!value || value.blank())
			Kupferwerk.Validation.presence_error = KUPERWERK_VALIDATION_PRESENCE;
		else
			Kupferwerk.Validation.presence_error = false;

		Kupferwerk.Validation.updateMessageOutput(Kupferwerk.Validation.presence_error, message_output);
	},
	
	length: function(field, message_output, options) {
		if(!options && typeof options != 'object')
			options = {};
			
		Kupferwerk.Validation.init(field, message_output, options);
			
		message_output = $(message_output);
		value = $F(field);
		
		options.min_length = options.min_length || 3;
		options.max_length = options.max_length || 255;
		
		if(value.length < options.min_length || value.length > options.max_length)
			Kupferwerk.Validation.length_error = KUPERWERK_VALIDATION_LENGTH.gsub(/%min_length/, options.min_length).gsub(/%max_length/, options.max_length);
		else
			Kupferwerk.Validation.length_error = false;

		Kupferwerk.Validation.updateMessageOutput(Kupferwerk.Validation.length_error, message_output);
	}
};



/**
 * 
 * @todo This has to be finished
 * @class Live Response for forms and more
 * @ignore
*/
Kupferwerk.LiveResponse = {
	init: function(options) {		
		if(typeof options != 'object') {
			options = {};
		}
		
		options.template_id = 'live_response_' + defaultValue(options.template_id, 'standard');
		
		if(!$(options.template_id)) {
			if(!options.template) {
				options.template = '<div id="' + options.template_id + '" class="live_response"><h3 class="status"></h3><p class="content"></p></div>';
			}
			
			$('body').insert(options.template);
		} else {
			options.template = $(options.template_id);
		}
		
		return options;
	},
	
	response: function(element, options) {
		options = Kupferwerk.LiveResponse.init(options);
		options.url = defaultValue(options.url, '/ajax/check_username');
		
		new Ajax.Request(options.url, {
			parameters: {
				authenticity_token: currentAuthToken(),
				live_response: $F(element)
			},
			onComplete: function(response) {
				response = response.responseJSON;
				options.template.select('p.content').first().update(response.message);
				options.template.select('h3.status').first().update(response.message_status);
				options.template.addClassName(response.message_status).show();
			}
		});
		
		return false;
	}
};
