/**
*	Prepare form
**/
$(document).ready(function() 
{
	LoadContactForm();
});

// -----------------------------------------------------------------------
/**
*	Loads the form for adding/editing a recipient.
**/
function LoadContactForm() 
{
	HighlightActiveInput();		

	// Ajax form - login
	$('#user_form').ajaxForm(
	{
		beforeSubmit: CheckContactForm,
		success: function(msg)
		{
			if (msg == 'OK')
			{
				redirect(WEB_ROOT + '/contact/bedankt');
			}
			else
			{
				//redirect(WEB_ROOT + '/contact/foutmelding');
				$('#rec_process_error').html(msg).show();
			}
		}
	});
	
	$('#name').focus();
}
// -----------------------------------------------------------------------

/**
*	Validates the recipient form
**/
function CheckContactForm() 
{
	// Hide feedback
	$('.feedback').hide();

	var errors = new Array();

	// Check name
	if (!CheckNotEmpty('name')) 
	{
		errors.push(CreateValidationErrorObject('name', 'Er is geen naam ingevuld.'));
	}	

	// Check email
	if (!CheckValidEmail('email')) 
	{
		errors.push(CreateValidationErrorObject('email', 'Er is geen (geldig) emailadres ingevuld.'));
	}	

	// Check errors
	if (errors.length == 0)
	{
		return true;
	}
	else
	{	
		// Validation failed
		ShowValidationErrors(errors);
		return false;
	}
}