$(function() {

	$(".button").click(function() {
	
		// ---- Check compulsory fields
	
		var firstname = $("input#firstname").val();
		if (firstname == "") {
			$("input#firstname").focus();
			$("input#firstname").css({'background-color' : '#ffe0e0'});
			return false;
		}
		
		var surname = $("input#surname").val();
		if (surname == "") {
			$("input#surname").focus();
			$("input#surname").css({'background-color' : '#ffe0e0'});
			return false;
		}
		
		var email = $("input#email").val();
		if (email == "") {
			$("input#email").focus();
			$("input#email").css({'background-color' : '#ffe0e0'});
			return false;
		}
		
		var telephone = $("input#telephone").val();
		if (telephone == "") {
			$("input#telephone").focus();
			$("input#telephone").css({'background-color' : '#ffe0e0'});
			return false;
		}
		
		// ---- Check non-compulsory fields
		
		var location = $("input#location").val();
		var comments = $("textarea#comments").val();
		var signup = $('input#signup').attr('checked'); 
	
		
		// ---- Create datastring
		
		var dataString = 'firstname=' + firstname + '&surname=' + surname + '&location=' + location + '&email=' + email + '&telephone=' + telephone + '&comments=' + comments + '&signup=' + signup;
		// alert (dataString);	return false;
			
		$.ajax({
			type: "POST",
			url: "process.php",
			data: dataString,
			success: function() {
				$('#formcontact').html("<div id='message'></div>");
				$('#message').html("<h2>Thank you...</h2>")
					.append("<p><strong>We will be in touch shortly to discuss your enquiry.<br />Thank you for visiting Jcraft Marine UK.</strong></p>")
					.hide()
					.fadeIn(500, function() {
				$('#message').append("&nbsp;");
			});
		}
	});
		
    return false;
	});
});

$("input#firstname").select().focus();
