oRcsf.RegisterObject('Module_Contact_Keepinformedform');
var RCSF_Project_Module_Contact_Keepinformedform =
{
	 msExtends	: 'RCSF_Base_Form'
 	
	/**
	 * Handles things that should be done after the document has fully loaded
	 */
	,OnDomLoaded : function()
	{
		// Assign form handlers
		var o_contact_form = $('btn_submit');
		o_contact_form.observe('click', this.SubmitForm.bind(this, $('keepinformed_form')));
	}
	
	/**
	 * Submits the form
	 */
	,SubmitForm : function(oForm,event)
	{
		event.stop();
		this.HideFieldErrors(oForm);

		this.moModule.moCore.RequestServer(
			this.GetFormData(oForm)
			,{
				s_mode			: 'data'
				,s_module		: 'contact'
				,s_controller	: 'keepinformed'
				,s_action		: 'send'
				,o_scope		: this
				,s_callback		: 'OnFormSubmitted'
			}
		);
		return false;
	}
	/**
	 * Handles form submit result
	 */
	,OnFormSubmitted : function(oData)
	{
		if (oData.s_status == 'done')
		{
			// Switch to upload phase
			$('keepinformed_h').update(oData.s_h);
			$('keepinformed_left_wrapper').update(oData.s_message);
		}
		else
		{
			this.ShowFieldErrors(oData).bind(this)
		}
	}
	
	
	/**
	 * Hides previously marked errors
	 */
	,HideFieldErrors : function(oData)
	{
		var o_error_msg = $('errmsg_container');
		if(o_error_msg) 
		{
			o_error_msg.update('');	
			o_error_msg.style.display = 'none';
		}
		/*$$('#' + oData.s_form_id + ' .field').each(function(s) { 
			s.style.border = "1px solid #666666";
		});
		*/
		$$('#' + oData.s_form_id + ' .error_arrow').each(function(s) { 
			s.hide();
		});
	}
	
	/**
	 * Handles error messages
	 */
	,ShowFieldErrors : 	function(oData)
	{
		this.HideFieldErrors(oData);
		var o_error_msg = $('errmsg_container');
		if(o_error_msg) 
		{
			o_error_msg.update(oData.s_message);	
			o_error_msg.style.display = 'block';
		}
		for (var s in oData.a_errors)
		{	
			var o_error = $(s);			

			var o_arrow = $(s + '-arrow');
			if (o_arrow) 
			{
				o_arrow.update('<');
				o_arrow.show();
			}
		}
	}
	
	/**
	 * 
	 */
	,ViewPrivacy : function()
	{
		this.moModule.moCore.RequestServer(
			{ i_id  : 1 }
			,{
				 s_mode			: 'data'
				,s_module		: 'content'
				,s_controller	: 'texts'
				,s_action		: 'load'
				,o_scope		: this
				,s_callback		: 'OnPrivacyViewed'
			}
		);
	}
	
	/**
	 * 
	 */
	,OnPrivacyViewed : function(oData)
	{
		if (oData.s_status == 'done')
		{
			// Create a div, position it in the middle of the overlayer
			if($('preview')) $('preview').remove();
			var o_div = '<div id="preview" class="preview_container"><div class="header"><a class="btn_closepopup" href="javascript:;" onclick="$(\'preview\').hide();return false;"><span>Sluiten</span> X</a></div><div id="preview_content" class="content scrollbar-y"><h1>'+oData.a_result.a_text.s_title+'</h1><p>'+oData.a_result.a_text.s_text+'</p></div></div>';
			
			//new Element('div', { id : 'preview_email'});
			$('main_container').insert({'after' : o_div});
			//o_div.update(oData.a_result.s_html);
			new Dialog.Box('preview',
				{
				 	 dimmingOpacity 	: 0.8
					,dimmingBackground 	: '#16476c'
				}
			);
			$('preview').show();
			this.moCore.moCustomscroll.InsertVerticalScrollbar($('preview_content'));
		}
		else
		{
			this.ShowFieldErrors(oData);
		}
	}
}
	
