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

  $(".submit").click(function() {
		// validate and process form
		// first hide any error messages
		//alert('here');
    $('.error').hide();

	  var name = $("input#name").val();
		if (name == "") {
      $("p#name_error").show();
      $("input#name").focus();
      return false;
    }

	  var company = $("input#company-name").val();
		if (company == "") {
      $("p#company-name_error").show();
      $("input#company-name").focus();
      return false;
    }
		
		var email = $("input#email").val();
		if (email == "") {
      $("p#email_error").show();
      $("input#email").focus();
      return false;
    }
		var phone = $("input#phone").val();
		if (phone == "") {
      $("p#phone_error").show();
      $("input#phone").focus();
      return false;
    }
		
		var message = $("textarea#message").val();

		var dataString = 'name='+ name + '&company-name=' + company + '&email=' + email + '&phone=' + phone + '&message=' + message ;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
       // $('form-contact').html("<div id='message'></div>");
        $('#popup_div').html("<b>Thank You. We will respond shortly.")
        .append("")
        .hide()
        .fadeIn(3000, function() {
          $('#popup_div');
        })
		.fadeOut(3000);
		$("input#name").val("");
		$("input#company-name").val("");
		$("input#email").val("");
		$("input#phone").val("");
		$("textarea#message").val("");
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();

});

