$(document).ready(function(){
	$('#first_name').bind({
		focus: function() {
			var val = $(this).val().toUpperCase();
			if(val == "FIRST NAME") {
				$(this).val("");
				$(this).removeClass("entryGray");
			}
		},
		blur: function() {
			var val = $(this).val().toUpperCase();
			if(val == "") {
				$(this).addClass("entryGray");
				$(this).val("First Name");
			}
		}
	});

	$('#last_name').bind({
		focus: function() {
			var val = $(this).val().toUpperCase();
			if(val == "LAST NAME") {
				$(this).val("");
				$(this).removeClass("entryGray");
			}
		},
		blur: function() {
			var val = $(this).val().toUpperCase();
			if(val == "") {
				$(this).addClass("entryGray");
				$(this).val("Last Name");
			}
		}
	});

	$('#email_address').bind({
		focus: function() {
			var val = $(this).val().toUpperCase();
			if(val == "EMAIL ADDRESS") {
				$(this).val("");
				$(this).removeClass("entryGray");
			}
		},
		blur: function() {
			var val = $(this).val().toUpperCase();
			if(val == "") {
				$(this).addClass("entryGray");
				$(this).val("Email Address");
			}
		}
	});

	$('#phone_no').bind({
		focus: function() {
			var val = $(this).val().toUpperCase();
			if(val == "PHONE #") {
				$(this).val("");
				$(this).removeClass("entryGray");
			}
		},
		blur: function() {
			var val = $(this).val().toUpperCase();
			if(val == "") {
				$(this).addClass("entryGray");
				$(this).val("Phone #");
			}
		}
	});

	$('#comments').bind({
		focus: function() {
			var val = $(this).val().toUpperCase();
			if(val == "COMMENTS") {
				$(this).val("");
				$(this).removeClass("entryGray");
			}
		},
		blur: function() {
			var val = $(this).val().toUpperCase();
			if(val == "") {
				$(this).addClass("entryGray");
				$(this).val("Comments");
			}
		}
	});

	$('#contact_email').bind({
		click: function(e) {
			
		}
	});

	$('#frm_contact').submit(function(e) {
		e.preventDefault();

		// Make sure required fields are filled
		if($('#first_name').val() == "" || $('#first_name').val().toUpperCase() == "FIRST NAME") {
			alert("First Name is a required field!");
			$('#first_name').focus();
			return false;
		}

		if($('#last_name').val() == "" || $('#last_name').val().toUpperCase() == "LAST NAME") {
			alert("Last Name is a required field!");
			$('#last_name').focus();
			return false;
		}

		if($('#email_address').val() == "" || $('#email_address').val().toUpperCase() == "EMAIL ADDRESS") {
			alert("Email Address is a required field!");
			$('#email_address').focus();
			return false;
		}
		
		// Make sure the email address is valid
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test($('#email_address').val())) {
			alert("Enter a valid Email Address!");
			$('#email_address').focus();
			return false;
		}

		$('#contact_frame').block({ 
			message: 'Sending...'
		}); 

		$.ajax({
			type: "POST",
			url: $(this).attr("action"),
			data: $(this).serializeArray(),
			success: function(data) {
				$.unblockUI();

				$('#contact_frame').block({
					message: '<h2>Thank you!</h2><br><br>Your request has been successfully submitted.  Thank you for your inquiry.  One of our staff members will be in contact with you within the next 48 hours.',
					overlayCSS: { backgroundColor: '#EEF1DE', opacity: 1, cursor: 'auto' },
					css: { cursor: 'auto', border: '0', width: '90%', backgroundColor: '#EEF1DE', left: '0', top: '0', textAlign: 'left', padding: '5px 5px 5px 5px' }
				});

				$('.blockElement').removeClass("blockElement");

				$('body').append('<img height=1 width=1 border=0 src="http://www.googleadservices.com/pagead/conversion/1021246545/?label=MuTzCP3KygEQ0fj75gM&guid=ON&script=0">');
			}
		});

		return false;
	});

	$('table#engines tr:even').addClass("cellGray");
});