// source --> https://fepp.aero/wp-content/themes/Avada-Child-Theme/js/jquery-ui.datepicker-fr.min.js?ver=7.0 
!function(e){"function"==typeof define&&define.amd?define(["../jquery.ui.datepicker"],e):e(jQuery.datepicker)}(function(e){return e.regional.fr={closeText:"Fermer",prevText:"Précédent",nextText:"Suivant",currentText:"Aujourd'hui",monthNames:["janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre"],monthNamesShort:["janv.","févr.","mars","avril","mai","juin","juil.","août","sept.","oct.","nov.","déc."],dayNames:["dimanche","lundi","mardi","mercredi","jeudi","vendredi","samedi"],dayNamesShort:["dim.","lun.","mar.","mer.","jeu.","ven.","sam."],dayNamesMin:["D","L","M","M","J","V","S"],weekHeader:"Sem.",dateFormat:"dd-mm-yy",firstDay:1,isRTL:!1,showMonthAfterYear:!1,yearSuffix:""},e.setDefaults(e.regional.fr),e.regional.fr});
// source --> https://fepp.aero/wp-content/themes/Avada-Child-Theme/js/deaz-script.js?ver=7.0 
/* 
 * @date 2016-03-09
 * @author Deazweb.com
 */

jQuery(document).ready(function () {
    jQuery(function ($) {

        if ($("#accident-formulaire").length) {
            $('#accident-formulaire').formcache({
                // A special identification for the form cache
// Must be different to other forms in the same page.
//key: "",

// Store cache in localStorage
                local: false,
// Store cache in sessionStorage
                session: true,
// Up<a href="http://www.jqueryscript.net/time-clock/">date</a> and store the cache automatically 
// when a form control changed or before page unload.
                autoStore: true,
// set the stored time (in seconds) of the caches, 
// just like the max-age for cookie.
//maxAge: undefined,

// The form controls which need to be cached.
                controls: [
                    "select",
                    "textarea",
                    "input"
                            // "input[type='text']",
                            // "input[type='password']",
                            // "input[type='datetime']",
                            // "input[type='checkbox']",
                            // "input[type='radio']",
                            // "input[type='datetime-local']",
                            // "input[type='date']",
                            // "input[type='month']",
                            // "input[type='time']",
                            // "input[type='week']",
                            // "input[type='number']",
                            // "input[type='email']",
                            // "input[type='url']",
                            // "input[type='search']",
                            // "input[type='tel']",
                            // "input[type='color']"
                ]});
        }
//        $('[data-toggle="tooltip"]').tooltip();

        $('.input-datepicker').datepicker({dateFormat: 'dd-mm-yy'});

        $('#myTabs a').click(function (e) {
            e.preventDefault();
            if ($(this).parent('li').hasClass('disabled')) {
                e.preventDefault();
                e.stopImmediatePropagation();
                return false;
            } else {
                $(this).tab('show');
            }
        });


        // ###################### CLONE FIELD FOR PERSONNEL IF NECESSARY
        var regex = /^(.+?)(\d+)$/i;
        var cloneIndex = $(".clonedInput").length;

        function cloneFields() {
            cloneIndex++;
            $(this).parents(".clonedInput").clone()
                    .appendTo(".fieldset-employee")
                    .attr("id", "clonedInput" + cloneIndex)
                    .find("*")
                    .each(function () {
                        var forLabel = $(this).attr('for');
                        var id = this.id || "";
                        var match = id.match(regex) || [];
                        if (match.length == 3) {
                            this.id = match[1] + (cloneIndex);
                            // update as well for value in the label
                            $('#clonedInput' + cloneIndex + ' label[for="' + id + '"]').attr('for', this.id);
                        }
                    })
                    .on('click', 'input.add-employee', cloneFields)
                    .on('click', 'input.remove-employee', removeFields);

        }
        function removeFields() {
            if ($("input.remove-employee").length > 1) {
                $(this).parents(".clonedInput").remove();
            }
        }
        $("input.add-employee").on("click", cloneFields);
        $("input.remove-employee").on("click", removeFields);
    });
});