$(document).ready(function(){

	$('form').submit(function(e){
		e.preventDefault();
		
		//Reset
		$('div#form_alert').hide();
		$('div#contact_first_name_error').hide();
		$('div#contact_last_name_error').hide();
		$('div#contact_telephone_error').hide();
		$('div#contact_email_error').hide();
		$('input#contact_first_name').css('border','1px solid silver');
		$('input#contact_last_name').css('border','1px solid silver');
		$('input#contact_telephone').css('border','1px solid silver');
		$('input#contact_email').css('border','1px solid silver');
		
		//First Name
		if ( $('#contact_first_name').val().length < 2 )
		{
			$('div#form_alert').show();
			$('div#contact_first_name_error').show();
			$('input#contact_first_name').css('border','1px solid #CD0A0A');
		}

		//Last Name
		if ( $('#contact_last_name').val().length < 2 )
		{
			$('div#form_alert').show();
			$('div#contact_last_name_error').show();
			$('input#contact_last_name').css('border','1px solid #CD0A0A');
		}
		
		//Last Name
		if ( $('#contact_telephone').val().length < 2 )
		{
			$('div#form_alert').show();
			$('div#contact_telephone_error').show();
			$('input#contact_telephone').css('border','1px solid #CD0A0A');
		}		
		
		//Email
		if ( $('#contact_email').val().length == 0 || validateEmail($('#contact_email').val()) == false )
		{
			$('div#form_alert').show();
			$('div#contact_email_error').show();
			$('input#contact_email').css('border','1px solid #CD0A0A');
		}	
	
		//Form Submission
		if ( $('div#form_alert').css('display') == 'none' )
		{
			var contactInfo = $('form').serialize();
			$.ajax({
				type: "POST",
				url: "/contact/thankyou",
				data: $('form').serialize(),
				success: function(msg){}
				error: function(msg){}
			});
			alert('done');
		}
	});
	
});

// Email Validation
function validateEmail(email)
{
	var pattern = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (pattern.test(email))
		return true;
	else
		return false;
}