//** Affiche ou masque la div qui permet de rendre le fond de l'écran inanctif.
// * @param boolean mode Mode d'appel : true = afficher ; false = masquer. */
function filigrane(mode) {
    if(mode) {
        var div = document.getElementById('filig');
        div.style.width = parseInt(document.body.clientWidth) + "px";
        div.style.height = parseInt(document.body.clientHeight) + "px";
        document.getElementById('filig').style.background = 'gray';				
        montrer('filig');
    } else {
        cacher('filig');
    }
}

function montrer(id){
    document.getElementById(id).style.display = "block";
}

function cacher(id){
    if(document.getElementById(id)) {
        document.getElementById(id).style.display = "none";
    }
}

//==============================================================================================================
// test de la pertinance d'une adresse mail
//==============================================================================================================

// Test de la validité d'une adresse e-mail
function checkemail(str){
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (filter.test(str))
        testresults=true
    else{
        testresults=false
    }
    if(str=='') testresults=true;
    return (testresults)
}



// Ouverture d'une fenêtre popup en 450 x 350
function openPopup(theURL) {
    var w = 450;
    var h = 350;
    var l = Math.ceil((screen.width / 2) - (w / 2));
    var t = Math.ceil((screen.height / 2) - (h / 2));
    popupW = window.open(theURL, "popupW", "resizable=1, scrollbars=1, width="+w+", height="+h+", left="+l+", top="+t);
    popupW.focus();
}

// Ouverture d'une fenêtre popup en 450 x 350
function openPub(theURL) {
    var w = 500;
    var h = 650;
    var l = Math.ceil((screen.width / 2) - (w / 2));
    var t = Math.ceil((screen.height / 2) - (h / 2));
    popupW = window.open(theURL, "pubW", "resizable=1, scrollbars=1, width="+w+", height="+h+", left="+l+", top="+t);
    popupW.focus();
}
// Ouverture d'une fenêtre popup en 800 x 500
function largePopup(theURL) {
    var w = 1024;
    var h = 700;
    var l = Math.ceil((screen.width / 2) - (w / 2));
    var t = Math.ceil((screen.height / 2) - (h / 2));
    popupLW = window.open(theURL, "popupLW", "resizable=1, scrollbars=1, width="+w+", height="+h+", left="+l+", top="+t);
    popupLW.focus();
}

// Affichage de la date du jour
function afficheDateJour() { 
    var datedujour, date, mois, mois1, jour, jour1, an; 
    datedujour = new Date();
    jour = datedujour.getDay()
    switch(jour){
        case 1 :
            jour1 ="Lundi" 
            break;
        case 2 :
            jour1 ="Mardi"
            break;
        case 3 :
            jour1 ="Mercredi"
            break;
        case 4 :
            jour1 ="Jeudi"
            break;
        case 5 :
            jour1 ="Vendredi"
            break;
        case 6 :
            jour1 ="Samedi" 
            break;
        case 0 :
            jour1 ="Dimanche"
            break;
    }
    date = datedujour.getDate()
    mois = datedujour.getMonth()
    switch(mois+1){
        case 1 :
            mois1 ="Janvier" 
            break;
        case 2 :
            mois1 ="Février"
            break;
        case 3 :
            mois1 ="Mars"
            break;
        case 4 :
            mois1 ="Avril"
            break;
        case 5 :
            mois1 ="Mai"
            break;
        case 6 :
            mois1 ="Juin" 
            break;
        case 7 :
            mois1 ="Juillet"
            break;
        case 8 :
            mois1 ="Août" 
            break;
        case 9 :
            mois1 ="Septembre"
            break;
        case 10 :
            mois1 ="Octobre"
            break;
        case 11 :
            mois1 ="Novembre"
            break;
        case 12 :
            mois1 ="Décembre"
            break;
    }
    an = datedujour.getFullYear()
    document.write(jour1, " ");
    document.write(date, " ");
    document.write(mois1 , " ");
    document.write(an, " ");
}

// Retaille dynamiquement une fenêtre
function resizeOuterTo(w,h) {
    if (parseInt(navigator.appVersion)>3) {
        if (navigator.appName=="Netscape") {
            top.outerWidth=w;
            top.outerHeight=h;
        }
        else top.resizeTo(w,h);
    }
}

// Redirige vers une URL
function redirige(lurl) {	
    self.location = lurl;  
}

// Mise à jour de la list-box en fonction du département cliqué
function majdep(obj)
{
    var depsel = obj;     
    var j
    for (j=0; j<document.chx.nodep.length; j++)
    {     
        if (document.chx.nodep.options[j].value == depsel)
        { 
            document.chx.nodep.options[j].selected=true; 
        }  
    }	 
    document.chx.submit(); 	  
}

// Fonction qui recopie le terme cliqué dans une popup 
// dans un champ de formulaire de la page parent
function recopieTerm(term, nomform, nomchamps) {
    window.opener.document.forms[nomform].elements[nomchamps].value = term;
    top.close();
}

// Confirmation de la suppression d'un enregistrement
function confirmSuppr(chemin, msg) {
    var confirmation = confirm(msg);
    if (confirmation) {
        document.location.href = chemin;
    }
}


function checkNumeric(objName,minval, maxval,comma,period,hyphen)
{
    var numberfield = objName;
    if (chkNumeric(objName,minval,maxval,comma,period,hyphen) == false)
    {
        numberfield.select();
        numberfield.focus();
        return false;
    }
    else
    {
        return true;
    }
}

function chkNumeric(objName,minval,maxval,comma,period,hyphen)
{
    // only allow 0-9 be entered, plus any values passed
    // (can be in any order, and don't have to be comma, period, or hyphen)
    // if all numbers allow commas, periods, hyphens or whatever,
    // just hard code it here and take out the passed parameters
    var checkOK = "0123456789" + comma + period + hyphen;
    var checkOK2 = "0 à 9 \"" ;
    if (comma!='') {
        checkOK2 = checkOK2 + " ou \"virgule : "+comma + "\"";
    }
    if (period!='') {
        checkOK2 = checkOK2 + " ou \"point : "+period + "\"";
    }
    if (hyphen!='') {
        checkOK2 = checkOK2 + " ou \"moins : "+hyphen + "\"";
    }
    var checkStr = objName;
    var allValid = true;
    var decPoints = 0;
    var allNum = "";

    for (i = 0;  i < checkStr.value.length;  i++)
    {
        ch = checkStr.value.charAt(i);
        for (j = 0;  j < checkOK.length;  j++)
            if (ch == checkOK.charAt(j))
                break;
        if (j == checkOK.length)
        {
            allValid = false;
            break;
        }
        if (ch != ",")
            allNum += ch;
    }
    if (!allValid)
    {	
        alertsay = "SVP, entrez uniquement ces valeurs \""
        alertsay = alertsay + checkOK2 + "\" dans ce champs  ."
        alert(alertsay);
        return (false);
    }

    // set the minimum and maximum
    var chkVal = allNum;
    var prsVal = parseInt(allNum);
    if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval))
    {
        alertsay = "SVP entrez une valeur numérique supérieure ou "
        alertsay = alertsay + "égale à \"" + minval + "\" et inférieure ou "
        alertsay = alertsay + "égale à \"" + maxval + "\" dans ce champs ."
        alert(alertsay);
        return (false);
    }
}
//  End -->
