$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('textarea.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  $('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 == "" || name == "Name...") {
      $("label#name_error").show();
      $("input#Name").focus();
      $("input#Name").val("");
      return false;
    }
		var email = $("input#Tel").val();
		if (email == "" || email == "Telephone...") {
      $("label#tel_error").show();
      $("input#Tel").focus();
      $("input#Tel").val("");
      return false;
    }
		var mail = $("input#Email").val();
		if (mail == "" || mail == "Email...") {
      $("label#email_error").show();
      $("input#Email").focus();
      $("input#Email").val("");
      return false;
    }
		var phone = $("textarea#Address").val();
		if (phone == "" || phone == "Address...") {
      $("label#add_error").show();
      $("textarea#Address").focus();
      $("textarea#Address").val("");
      return false;
    }
	  $(".button").attr("disabled", "true"); 
      $(".button").val("Please wait...");
	  
	var packType = $("input#packType").val();
		
		var dataString = 'Name='+ name + '&Tel=' + email + '&Email=' + mail + '&Address=' + phone + '&packType=' + packType;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<p>Thank you for registering your details, you may now download the Customer Information Pack PDF by clicking the link below:</p>")
        .append("<p><a href='/pdfs/ApeFiorini pack.pdf' target='_blank'><img id='checkmark' src='/images/pdf.gif' />Download PDF</a></p>")
        .hide()
        .fadeIn(1500, function() {
          //$('#message').append("<img id='checkmark' src='/images/check.png' />");
        });
      }
     });
    return false;
	});
});
//runOnLoad(function(){
  //$("input#Name").select().focus();
//});

