$(document).ready(function() {
	$('a.show-popup').click(function() {
		$('#popup_form').fadeIn('slow');
		return false;
	});

	$('a.close-popup').click(function() {
		$('#popup_form').fadeOut('slow');
		return false;
	});
	
	$('#popup_form form label').each(
		function()
		{
			var required = '<small style="padding-left:8px; color:red;">Required</small>';
			
			if( 'Full Name' == $(this).text() )
			{
				$(this).html( 'Full Name ' + required );
			}
			
			if( 'Email' == $(this).text() )
			{
				$(this).html( 'Email ' + required );
			}
		}
	);

	$('#popup_form form').submit(function() {

		var full_name = $('#full_name').attr('value');
		var phone_number = $('#phone_number').attr('value');
		var email = $('#email').attr('value');
		var comments = $('#comments').attr('value');
		
		if( '' == full_name || '' == email )
		{
			alert( 'Please make sure to include your full name and email address' );
		}
		else
		{
			$.ajax({
				type: "POST",
				url: '/Ajax.sendEmail.php',
				data: "full_name=" + full_name + "&phone_number=" + phone_number + "&email=" + email + "&comments=" + comments,
				success: function( msg )
				{
					if( 'Mail Sent Successfully!' == msg )
					{
						$('#popup_form form').hide();
						$('#popup_form .message').fadeIn('slow');
					}
					else
					{
						alert( msg )
					}
				}
			});
		}
		
		return false;
	});
});
