$(function() {
  $('.error').hide();
  $('input.text-input').css("background-image", "url(40w.png)");
  $('input.text-input').focus(function(){
    $(this).css("background-image", "url(60w.png)"); 
  });
  $('input.text-input').blur(function(){
    $(this).css("background-image", "url(40w.png)"); 
  });
  
  
  
    $('textarea.text-input').css("background-image", "url(40w.png)");
  $('textarea.text-input').focus(function(){
    $(this).css("background-image", "url(60w.png)"); 
  });
  $('testarea.text-input').blur(function(){
    $(this).css("background-image", "url(40w.png)"); 
  });





  $(".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 email = $("input#email").val();
		if (email == "") {
      $("label#email_label").css("Color", "red"); 
       $("input#email").focus();
      return false;
    }
		var comment = $("textarea#comment").val();
		if (comment == "") {
      $("label#comment_error").show();
      $("input#comment").focus();
      return false;
    }
    
     var title = $("input#title").val();
          var phone = $("input#phone").val();
     var company = $("input#company").val();
     var jobtitle = $("input#jobtitle").val();
     var address = $("textarea#address").val();

		
		var dataString = 'name='+ name + '&email=' + email + '&comment=' + comment + '&title=' + title + '&phone=' + phone + '&company='+company+'&jobtitle='+jobtitle+'&address='+address;
		//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 style='color:#d0db4c;'>Contact Form Submitted!</h2>")
        .append("<p style='color:#000;'>Thank you for you enquiry.<br/>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();
});

