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

  $(".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_error").show();
		$("input#email").focus();
		return false;
	}

	var phone = $("input#phone").val();
//	if (phone == "") {
//		$("label#phone_error").show();
//		$("input#phone").focus();
//		return false;
//	}

	var comment = $("textarea#comment").val();
	if (comment == "") {
		$("label#comment_error").show();
		$("textarea#comment").focus();
		return false;
	}

	var check = $("input#check").is(':checked');
	if (check == false) {
		$("label#check_error").show();
		$("input#check").focus();
		return false;
	}

//	var captcha = $("input#secure").val();
//	var security_number = $("input#security_number").val();
//	if (captcha != security_number) {
//      $("label#captcha_error").show();
//      $("input#secure").focus();
//      return false;
//    }

	var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&comment=' + comment + '&check=' + check ; //+ '&captcha=' + captcha;
//	alert (dataString);return false;

$.ajax({
      type: "POST",
      url: "/include/process.php",
      data: dataString,
	  error: function(){
		alert("Chiamata fallita!!!");
	  },
      success: function() {
        $('#box-form').html("<div id='message'></div>");
        $('#message').html("<h2>Mail inviata con successo!</h2>")
        .append("<p>Grazie per averci contattato</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='/imagepmw/check.png' />");
        });
      }
     });
    return false;
	});
});

runOnLoad(function(){
  $("input#name").select().focus();
});

