$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#e2e2e2"});
  });
  $('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#poc-name").val();
		if (name == "") {
			$("label#name_error").show();
			$("input#name").focus();
		return false;
		}
		
	var name = $("input#your-name").val();
		if (name == "") {
			$("label#name_error").show();
			$("input#name").focus();
		return false;
		}
	
	var address = $("input#address").val();
		if (address == "") {
      $("label#address_error").show();
      $("input#address").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 dataString = 'name='+ name + '&address=' + address + '&email=' + email + '&phone=' + phone +  '&story=' + story;
		 //alert (dataString);return false;
		
		$.ajax({
      	type: "POST",
      	url: "bin/process-form-v2.php",
      	data: dataString,
      	success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Contact Form Submitted!</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
  
  function reset_form() {
	change("poc-name","normal");
	change("poc-emplid","normal");
	change("poc-email","normal");
	change("your-name","normal");			
	change("title","normal");
	change("phone","normal");
	change("emai1","normal");
	change("date-of-incident","normal");	
	change("time-of-incident","normal");	
	change("location-of-incident","normal");			
}
});
