// When the document is ready.
$(document).ready(function() {

	// Whenever the submit button is clicked run this function.
	$('#submit').click(function() {

		// Perform an AJAX call.
		$.ajax({
			// This options function is run before the AJAX call is made. It blanks any error messages from previous attempts.
			beforeSend: function() {
				$('#originalMessage').css("display", "none");
				$('#emptyField').css("display", "none");
				$('#invalidEmail').css("display", "none");
				$('#serverFailed').css("display", "none");
				$('#success').css("display", "none");
			},
			type: "POST",
			url: "/includes/inc_receiveinfo.php",
			// This sends the data as a post variable called email, that has a value of whatever was in the textbox.
			data: "email=" + $('#email').val(),
			// If the operation is successful, run this function.
			success: function(data, textStatus) {
				// alert("Data: " + data + "\n\n" + "Status: " + textStatus);

				// The response number for if the field was left empty.
				if (data == 0)
				{
					$('#emptyField').fadeIn("slow");
				}

				// The response number for if the string was not a valid email.
				if (data == 1)
				{
					$('#invalidEmail').fadeIn("slow");
				}

				// The response number for if the email was sent successfully.
				if (data == 2)
				{
					$('#success').fadeIn("slow");
				}

				// The response number for if the email was sent successfully.
				if (data == 3)
				{
					$('#serverFailed').fadeIn("slow");
				}

			}
		});

	});

});