jQuery(document).ready(function($) {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FF0000"});

	  $(".btn").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
		var email = $("input#email").val();
		var filter = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
		//if it’s valid email
		if(!filter(email)){
		$("label#email_error").show();
		$("input#email").focus();
		return false;
    }
	  var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
	  var street = $("input#street").val();
		if (street == "") {
      $("label#street_error").show();
      $("input#street").focus();
      return false;
    }
	  var city = $("input#city").val();
		if (city == "") {
      $("label#city_error").show();
      $("input#city").focus();
      return false;
    }
	  var state = $("input#state").val();
		if (state == "") {
      $("label#state_error").show();
      $("input#state").focus();
      return false;
    }
	  var zip = $("input#zip").val();
		if (zip == "") {
      $("label#zip_error").show();
      $("input#zip").focus();
      return false;
    }
	  var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
		
		var dataString = 'email='+ encodeURIComponent(email) + '&name=' + name + '&street=' + street + '&city=' + city + '&state=' + state + '&zip=' + zip + '&phone=' + phone;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "contact.php",
      data: dataString,
      success: function() {
        $('#success').html("<div id='message'></div>");
        $('#message').html("<p style='float:left;'>Contact Form Submitted!</p>")
				.append("<img id='checkmark' width='20px' height='20px' src='check.png' />")
        .hide()
        .fadeIn(1500, function() {
          $('#message')
		.delay(1000).fadeOut(1500);
		$(':input','#subscribe')
		 .not(':button, :submit, :reset, :hidden')
		 .val('');
        });
      }
     });
    return false;
	});
});

