oRcsf.RegisterObject('Module_Contact_Form');
var RCSF_Project_Module_Contact_Form =
{
	 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, $('contact_form')));
	}
	
	/**
	 * Submits the form
	 */
	,SubmitForm : function(oForm,event)
	{
		event.stop();
		//this.HideFieldErrors(oForm);
		
		Tips.remove($(oForm).down('label')); // element
		
		this.moModule.moCore.RequestServer(
			this.GetFormData(oForm)
			,{
				s_mode			: 'data'
				,s_module		: 'contact'
				,s_controller	: 'contact'
				,s_action		: 'submitform'
				,o_scope		: this
				,s_callback		: 'OnFormSubmitted'
			}
		);
		
		return false;
	}
	/**
	 * Handles form submit result
	 */
	,OnFormSubmitted : function(oData)
	{
		if (oData.s_status == 'done')
		{
			// Switch to upload phase
			$('contact_wrapper').update(oData.s_message);
		}
		else
		{
			this.ShowFieldErrors(oData).bind(this)
		}
	}
	
	/**
	 * Shows error messages
	 * 
	 * @param	Object	oData	return object with errors
	 */
	,ShowFieldErrors : 	function(oData)
	{
		this.HideFieldErrors(oData);
		//var o_error_msg = $$('#' + oData.s_form_id + ' .msg').first();
		//if(o_error_msg) o_error_msg.update(oData.s_message);		
		for (var s in oData.a_errors)
		{	
			var s_label_id = s + '-label';
			var o_input = $(s);
			// Create the tip with our tooltip system
			this.moCore.moTooltip.CreateErrorTip(s_label_id,oData.a_errors[s].s_message);
			
			// Show the tooltip immediately, dont wait on mouse
			$(s_label_id).prototip.show();
			
			// Check if we have more elements to observe
			var o_syns = ($$('#contact_form input[name="'+s+'"]'))
			// So this is a checkbox or radio
			if( o_syns.length > 1 && $(o_syns.first()).getAttribute('type') == 'radio')
			{
				o_syns.each(function(oEl){
					oEl.observe('click',$(s_label_id).prototip.remove );
				});
				return;
			}
			o_input.observe('click',$(s_label_id).prototip.remove );
		}
	}
}
	