$(function () {

    $.validator.setDefaults({

      submitHandler: function () {

        $('#telephone').val(iti.getNumber())

        $.ajax({

            url:'engine/index.php?_c=form&_a=insert',

            data:$('#form').serialize(),

            success:function(e){//alert(e)

              if(e!=''){

                document.location='response?id='+e

              }

              else{

                alert("Delai depassé ! Veuillez resaisir"); //window.location.reload()

              }

            }

        })

      }

    });

    $('#form').validate({

      rules: {

        email: {required: true,email: true},

        nom: {required: true},

        prenom: {required: true},

        sexe: {required: true},

        jour_nais: {required: true},

        annee_nais: {required: true},

        mois_nais: {required: true},

        nationalite: {required: true},

        pays_origine: {required: true},

        jour_arrivee: {required: true},

        annee_arrivee: {required: true},

        mois_arrivee: {required: true},

        num_passeport: {required: true},

        tel: {required: true},

        compagnie: {required: true},

        assurance_maladie: {required: true},

        num_vol: {required: true},

        num_siege: {required: true},

        fievre: {required: true},

        sensation_fievre: {required: true},

        test_covid: {required: true},

        frisson: {required: true},

        toux: {required: true},

        province: {required: true},

        voie_transport: {required: true},

        difficulte_respiratoire: {required: true},

        adresse: {required: true},

      },

      messages: err_msg,

      errorElement: 'span',

      errorPlacement: function (error, element) {

        error.addClass('invalid-feedback');

        element.closest('.form-group').append(error);

      },

      highlight: function (element, errorClass, validClass) {

        $(element).addClass('is-invalid');

      },

      unhighlight: function (element, errorClass, validClass) {

        $(element).removeClass('is-invalid');

      }

    });

    var input = document.querySelector("#tel");

    var iti=window.intlTelInput(input, {

      // allowDropdown: false,

      // autoHideDialCode: false,

      // autoPlaceholder: "off",

      // dropdownContainer: document.body,

      // excludeCountries: ["us"],

      // formatOnDisplay: false,

      // geoIpLookup: function(callback) {

      //   $.get("http://ipinfo.io", function() {}, "jsonp").always(function(resp) {

      //     var countryCode = (resp && resp.country) ? resp.country : "";

      //     callback(countryCode);

      //   });

      // },

       hiddenInput: "full_number",

       initialCountry: "cd",

      // localizedCountries: { 'de': 'Deutschland' },

      // nationalMode: false,

      // onlyCountries: ['us', 'gb', 'ch', 'ca', 'do'],

      // placeholderNumberType: "MOBILE",

      preferredCountries: ['cd','us','fr','uk','et'],

      separateDialCode: true,

      utilsScript: "build/js/utils.js",

    });



    $('#voie_transport').change(function(){

      if($(this).val()=='Voie aérienne'){

        $('#comp').removeClass('d-none')

        $('#comp_').addClass('d-none')

        $('#comp_').val('')

        

      }

      else{

        $('#comp').addClass('d-none')

        $('#comp').val('-1')

        $('#comp_').removeClass('d-none')

      }

      

    })

  });

  