/** 
 * Javascript Document
 * stoneykun.com
 * Adam Russell Stone
 */
 
 $(document).ready(function() {
	// Stop caching! Slap random number on the query string
	var num = 0;
	// Do when form is submitted
	$("#contact form").submit(function() {
		num ++;
		// Serialize form names and values
		var str = $(this).serialize();
		// AJAX object handles key/value pairs
		$.ajax({
   			type: "POST",
			url: "contact.php?rand=" + num,
			data: str,
			// Do if AJAX is successful
			success: function(msg) {
				if(msg == "BLANK") {
					alert("One or more fields were left blank!");
				}
				else if(msg == "EMAIL") {
					alert("The email address was invalid!");
				}
				else if(msg == "CAPTCHA") {
					alert("Don't forget the captcha field!");
				}
				else if(msg == "PHONE") {
					alert("The phone number was invalid!");
				}
				else if(msg == "OK") {
					$("#contact p").fadeIn('fast').delay(2000).fadeOut('fast');
					$(".field").val("");
				}
				else {
					alert("Something has gone horribly wrong!");
				}
			}
		});
		// Deactivate form
		return false;
	});
});