$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#cfcfcf"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#cfcfcf"});
  });
  
  $('textarea.textbox').css({backgroundColor:"#cfcfcf"});
  $('textarea.textbox').focus(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  $('textarea.textbox').blur(function(){
    $(this).css({backgroundColor:"#cfcfcf"});
  });

  $(".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 firstname = $("input#firstname").val();
		if (firstname == "") {
      $("label#firstname_error").show();
      $("input#firstname").focus();
      return false;
    }
		var email = $("input#email").val();
		if (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 messagearea = $("textarea#messagearea").val();
		if (messagearea == "") {
      $("label#messagearea_error").show();
      $("textarea#messagearea").focus();
      return false;
    }
		
		var dataString = 'name='+ name + '&firstname=' + firstname + '&email=' + email + '&phone=' + phone + '&messagearea=' + messagearea;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h3 style='color:#4f4f4f;font-weight:bold;'>Contact Form Submitted!</h3>")
        .append("<p style='color:#4f4f4f;'>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
	});
	
	
	
	
  $(".button_footer").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name_footer = $("input#name_footer").val();
		if (name_footer == "") {
      $("label#name_footer_error").show();
      $("input#name_footer").focus();
      return false;
    }
		var email_footer = $("input#email_footer").val();
		if (email_footer == "") {
      $("label#email_footer_error").show();
      $("input#email_footer").focus();
      return false;
    }
		var phone_footer = $("input#phone_footer").val();
		if (phone_footer == "") {
      $("label#phone_footer_error").show();
      $("input#phone_footer").focus();
      return false;
    }
		var messagearea_footer = $("textarea#messagearea_footer").val();
		if (messagearea_footer == "") {
      $("label#messagearea_footer_error").show();
      $("textarea#messagearea_footer").focus();
      return false;
    }
		
		var dataString = 'name_footer='+ name_footer + '&email_footer=' + email_footer + '&phone_footer=' + phone_footer + '&messagearea_footer=' + messagearea_footer;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process_footer.php",
      data: dataString,
      success: function() {
        $('#contact_form_footer').html("<div id='message'></div>");
        $('#message').html("<h3 style='color:#4f4f4f;font-weight:bold;'>Contact Form Submitted!</h3>")
        .append("<p style='color:#4f4f4f;'>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
	});
});

