 /* 
 * 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 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 ip      = $("input#ip").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;

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

                if(data==0){


                    

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

                    });


                    

                }else if(data==1){

                     $('#generale_div').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;

    });
});

