$(function() {
  $('.error').hide();
  $('#loading').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#9f9f9f"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
		var email = $("input#email").val();
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
	    return false;
	  } else if(!emailReg.test(email)) {
	  $("label#email_error").show();
      $("input#email").focus();
		return false;
    }
		var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
	
	var details = $("textarea#details").val();
		
	var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&details=' + details;
	//alert (dataString);return false;
	$('#loading').fadeIn(1500, function() { });
      
		
	$.ajax({
      type: "GET",
      url: "send.asp",
      data: dataString,
      success: function() {
        $('#loading').hide();
		$('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Contact Form Submitted!</h2><br />")
        .append("<p>We will be in touch soon.</p>")
        .hide()
		.fadeIn(1500, function() { });
		
       }
     });
    return false;
	});
});


