$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  
  $('textarea.text-input').css({backgroundColor:"#FFFFFF"});
  $('textarea.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('textarea.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 company_name = $("input#company_name").val();
		if (company_name == "") {
      $("label#company_name_error").show();
      $("input#company_name").focus();
      return false;
    }
		var c_email = $("input#c_email").val();
		if (c_email == "") {
      $("label#c_email_error").show();
      $("input#c_email").focus();
      return false;
    }
		var testvar = $("textarea#testvar").val();
		if (testvar == "") {
      $("label#testvar_error").show();
      $("textarea#testvar").focus();
      return false;
    }
	
		
		var dataString = 'name='+ name + '&company_name=' + company_name + '&c_email=' + c_email + '&testvar=' + testvar;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2><img id='checkmark' src='images/check2.png' /> Contact Form Submitted!</h2>")
        .append("<p>We will be in touch soon.</p><p>&nbsp;</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<!--<img id='checkmark' src='images/check2.png' />-->");
        });
      }
     });
    return false;
	});
});

