/**
 * @class	W_NotificationForm
 * @author	Marco Troost
 */
var W_NotificationForm = new Class({
	
	/**
	 * initialize
	 * @param	string	root_node_id
	 * @return	void
	 */
	initialize: function(root_node_id, submit_btn_id, form_id)
	{
		// nodes
		this.body_node			= document.getElement('body');
		this.root_node			= !root_node_id ? this.body_node : $(root_node_id);
		this.submit_btn_node	= $(submit_btn_id);
		this.form				= $(form_id);
		this.filter_node		= $('notification_filter');
		this.loader_node		= $('notification_loader');
		this.popup_message		= $('notification_message');
		
		// id's
		this.root_node_id		= !root_node_id ? null : root_node_id;
		this.submit_btn_id		= submit_btn_id;
		
		// classes
		this.hide_class			= 'hide';
	},
	
	/**
	 * start
	 * @return	void
	 */
	start: function()
	{		
		if (this.root_node && this.submit_btn_id)
		{
			// set events
			this.setEvents();
		}
	},
	
	/**
	 * set events
	 * @return	void
	 */
	setEvents: function()
	{
		// set var as object
		var _this	= this;
		this.submit_btn_node.removeEvents();
		this.submit_btn_node.addEvent('click', function()
		{
			_this.submitForm();
		});		
	},
	
	/**
	 * submit login form
	 * @return	void
	 */
	submitForm: function()
	{
		// set var as object
		var _this	= this;
		if (this.form)
		{				
			// send form (ajax)
			this.form.set('send',
			{				
				onRequest: function()
				{	
					// show page filter and loader
					_this.filter_node.className	= '';
					_this.loader_node.className	= '';		
				},
				onSuccess: function(data)
				{
					// hide page filter and loader
					_this.filter_node.className	= _this.hide_class;
					_this.loader_node.className	= _this.hide_class;
					
					// decode JSON string and Hash it
					var json_data = new Hash(JSON.decode(data));
					if (json_data.has('status'))
					{
						var status	= json_data.get('status');

						if(status == 1) // save success
						{
							cs_tabs_1.loadContent("/http/customer_notifications.php");
						}
						else if (status == 2) // error message
						{
							if (json_data.has('message'))
							{
								var message	= json_data.get('message');
								_this.popup_message.set('text', message);
							}
						}
					}
				}				
			});
			
			this.form.send();
		}	
	}

});
