/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 *
 */

/*
 *
 * Classe di Gestione della procedura di login
 *
 */

function resetForm(id) {
$('#' + id + ' :input').each(function(){
$(this).val('');
});
}


$(document).ready(function(){

   $(".error").hide();

   $(".button").click(function() {

     // Valido Il form

     $('.error').hide();


      var nome = $("#nome").val();

         if (nome == "") {

                $("label#nome_error").show();
                $("input#nome").focus();
                return false;
         }

    var cognome = $("#cognome").val();

         if (cognome == "") {

                $("label#cognome_error").show();
                $("input#cognome").focus();
                return false;
         }

     var indirizzo = $("#indirizzo").val();

         if (indirizzo == "") {

                $("label#indirizzo_error").show();
                $("input#indirizzo").focus();
                return false;
         }




var ajaxCaptcha = $("#ajax-captchaHash").val();
var ajaxcaptcha2 = $("#ajax-captcha").val();
  var cap = $("input#cap").val();
  var citta = $("input#citta").val();
  var regione = $("#regione").val();
  var telefono = $("input#telefono").val();
  var fax = $("input#fax").val();
  var cellulare = $("input#cellulare").val();
  

  var email = $("input#email").val();
   if (email == "") {

              $("label#email_error").show();
                $("input#email").focus();
                return false;
                
         }

  var note = $("#note").val();

  var p      = $("input#p").val();
  var form      = $("input#form").val();

 var dataString = 'p='+p+'&nome='+ nome + '&cognome=' +cognome+'&cap=' +cap+'&citta=' +citta+'&regione=' +regione+
     '&ip=' +ip+'&telefono=' +telefono+'&fax=' +fax+'&cellulare=' +cellulare+'&indirizzo=' +indirizzo+
     '&note=' +note+'&email=' +email+'&form=' +form+'&ajaxCaptcha='+ajaxCaptcha+'&ajaxcaptcha2='+ajaxcaptcha2;

  $.ajax({
        type: "POST",
        url: "php/contattiNuovo.php",
        data: dataString,
            success: function(data) {

                if(data==0){




                    $('#form').html("<div id='message' class='testo2'></div>")
                    .hide()
                    .fadeIn(1500, function() {
                    $('#message').append("<p>Problema nella registrazione del contatto</p>");

                    });


                }else if(data==1){

                     $('#form').html("<div id='message' class='testo2'></div>")
                    .hide()
                    .fadeIn(1500, function() {
                    $('#message').append("<p>Grazie per averci contattato , sarai ricontattato al più presto</p>");

                    });


                }
            }

        });

        return false;

    });
});

