
	/**
	*	Contactform-handler
	*/

  	$(".submit-button").mouseup(function()
	{
		alert('test');
		/**
		*	Validate form_fields
		*/
		var name = $('input#contact_name').val();
		var email = $('input#contact_email').val();


		var errors = new Array();
		if(name == '') { errors += 'Naam'; }
		else {  }
		
		if(email == '') { errors += ',E-mail'; }
		else {  }
		
		
		if(errors.length > 0)
		{
			/* There are errors, show them in specific elements*/
			split = errors.split(',');
			
			if(split[0] != '')
			{
				var input_name = $('input#contact_name');
				input_name.css('border','1px solid #A05F5F');
				input_name.css('background','#CCADB0');
			}
			
			if(split[1] != '')
			{
				var input_name = $('input#contact_email');
				input_name.css('border','1px solid #A05F5F');
				input_name.css('background','#CCADB0');
			}
		}
		else
		{
			/**
			*	If there are no errors @ all
			*	Execute ajax call, submit the form and display succes message
			*/
			
			if(data = fetchDataFromFields())
			{
				console.log(data);

				$.ajax({
		      		type: "POST",
		      		url: "app/webroot/ajax/process_contact.php",
		      		data: 'test',
		      		success: function() {
						// Display success-message
						//$("#hidden_link").fancybox().trigger('click');
		      		}
		     	});
				return false;
			}
			else
			{
				// Bericht niet verzonden, probeer het aub nogmaals.
			}
		}
	});
	
	
	function fetchDataFromFields()
	{
		var data = new Array();
		
		/**
		*	name, street, number, zipcode, city, email, phone and message
		*/
		data[0] = $('input#contact_name').val();
		data[1] = $('input#contact_email').val();
		data[2] = $('input#contact_subject').val();
		data[3] = $('textarea#contact_message').val();
		
		return data;
	}
