$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#EEEEEE"});
  });
  $('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();
	  
	  function removeSpaces(string){
	  	return string.split(' ').join('');
	  }
	  
	  name = removeSpaces(name);
	  
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
		if (name == "Name") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
	
	  var email = $("input#email").val();
	  
	  email = removeSpaces(email);
		  
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus(); 
	  return false; 
	}
	    if (email == "Email") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var name = $("input#name").val();
		var email = $("input#email").val();
		var phone = $("input#phone").val();
		var company = $("input#company").val();
		var textarea = $("textarea#textarea").val();
		
		
		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&company=' + company + '&textarea=' + textarea;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "Scripts/contact.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<p>We have recieved your message!</p>")
        .append("<p>Please look for an automatic confirmation message at the email address you provided.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append(" ");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});
