function updateTablesAttributes() {
    $("table").each(function(index, tableID) {
        //cas th en haut
        if ($(tableID).find("thead tr th").length > 0) {
            $(tableID).find("thead tr th").each(function(index) {
                index += 1;
                $(tableID).find("tbody tr td:nth-child(" + index + ")").attr("data-title", $(this).text());
            });
        } else {
            $(tableID).find("tr td").each(function(index, td) {
                var $td = $(td);
                var titleTh = $("th", $td.parents("tr")[0])[0];
                $td.attr("data-title", $(titleTh).text());
            });
        }
    });
}

function validmail(emailDom,isValue=false) {
    var regexMail = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if(isValue)
        return regexMail.test(emailDom);
    return regexMail.test(emailDom.value);
}
function validTelephone(telephone){
    telephone = telephone.replace(/[^0-9]/g, '');

    if ( telephone == "" ){ //ce n'est pas vide
        return false;
    }
    if (telephone.length!=10){ //ça contient 10 chiffres
        return false;
    }
    if(telephone[0]!=0) //ça commence par 0 normalement
        return false;
    return true;
}
function verif_date(input) {
    var regex = new RegExp("[/-]");
    var date = input.split(regex);
    var nbJours = new Array('', 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    var result = true;
    if (date['2'] % 4 == 0 && date['2'] % 100 > 0 || date['2'] % 400 == 0) nbJours['2'] = 29;
    if (isNaN(date['2'])) result = false;
    if (isNaN(date['1']) || date['1'] > 12 || date['1'] < 1) result = false;
    if (isNaN(date['0']) || date['0'] > nbJours[Math.round(date['1'])] || date['0'] < 1) result = false;
    return result;
}

module.exports = {
    validmail,
    validTelephone,
    verif_date,
    updateTablesAttributes
}