/**
*	Prepare form
**/
$(document).ready(function() 
{
	// bel me terug button op de homepage
	$(".belmeterug_btn").click(function () {
		$(".belmeterug").css('left','25px');
		$(".belmeterug").modal({
			opacity:80,
			overlayClose:true,
			closeClass: "modalClose",
			/*closeHTML: '<div class="close"><a href="#" class="simplemodal-close">x</a></div>',*/
			overlayId: 'simplemodal-overlay-site',
			containerId: 'simplemodal-container-site',			
			overlayCss: {backgroundColor:"#ececec"},
			onClose: contact.close
		});
	});
	LoadContactForm();
});

// -----------------------------------------------------------------------
/**
*	Loads the form for adding/editing a recipient.
**/
function LoadContactForm() 
{

	// Ajax form - login
	$('#belmeterug_form').ajaxForm(
	{
		beforeSubmit: CheckContactForm,
		success: function(msg)
		{
			if (msg == 'OK')
			{
				$('#simplemodal-container-site form').fadeOut(200);
				$('#simplemodal-container-site #box_recipient_result').fadeOut(200, function () {
					$('#simplemodal-container-site .belmeterug_tekst').html('U wordt zo spoedig mogelijk teruggebeld!');
					$('#simplemodal-container-site .belmeterug_close_btn').fadeIn(200);
				});
			}
			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 voornaam
	if (!CheckNotEmpty('name')) 
	{
		errors.push(CreateValidationErrorObject('name', 'Er is geen naam ingevuld.'));
	}
	// Check telefoonnummer
	if (!CheckNotEmpty('telefoonnummer')) 
	{
		errors.push(CreateValidationErrorObject('telefoonnummer', 'Er is geen telefoonnummer ingevuld.'));
	}	

	// Check errors
	if (errors.length == 0)
	{
		return true;
	}
	else
	{	
		// Validation failed
		ShowValidationErrors(errors);
		return false;
	}
}

var contact = {
	message: null,
	close: function (dialog) {
		$('#simplemodal-container-site').fadeOut();
		$('#simplemodal-container-site form').fadeOut(200);
		$('#simplemodal-container-site .belmeterug').animate({
			height: 40
		}, function () {
			dialog.data.fadeOut(200, function () {
				dialog.container.fadeOut(200, function () {
					dialog.overlay.fadeOut(200, function () {
						$.modal.close();
						$(".belmeterug").css('left','-1000px');
					});
				});
			});
		});
	}
};
