<!--
/**
 * @author philippe ripond
 * @copyright 2006
 */

/******************************************
*   Detection navigateur
******************************************/
function isIe() {
  var ms = navigator.appVersion.indexOf("MSIE");
  ie5 = (ms>0) && (parseInt(navigator.appVersion.substring(ms+5, ms+6)) >= 4);
  return ie5;
}
/******************************************
*   Affichage fenêtre popup
******************************************/
function popup(file,name,w,h,l,t,scroll,resize) {
    if ( scroll != 'no' ) { scroll = 'yes' ; }
    if ( resize != 'no' ) { resize = 'yes' ; }
    name = window.open(file,name,"width="+w+",height="+h+",left="+l+",top="+t+",scrollbars="+scroll+",resizable="+resize+",status=no,location=no") ;
    name.focus() ;
}

/******************************************
*   Affichage fenêtre de confirmation
******************************************/
function confirmation(mes) {
    if ( !confirm(mes) ) {
       return false ;
    }
    else {  return true ;  }
}

/******************************************
*   affichage date
******************************************/
function afficheDate() {
  today = new Date();
  var joursem=new Array('Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi');
  var mois=new Array('Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre');
  var annee=(isIE())?today.getYear():(today.getYear()+1900); //*** a rajouter pour annee netscape
  var date = joursem[today.getDay()] + ' ' + today.getDate() + ' ' + mois[today.getMonth()]+' '+annee ;
  document.write(date) ;
}
/******************************************
*   Affichage element si non non affiché
*   cache elemnt si visible
*   Utilisation de la propriété display
*     type : type d'affichage
******************************************/
function showHide(id,type) {
	var el=document.getElementById(id);
	if ( el.style.display=="none" ) {
       el.style.display=type ;
    }
    else {  
	   el.style.display='none' ;  
    }
}
/******************************************
*   Cache elemnt 
*   Utilisation de la propriété display
******************************************/
function hide(id) {
	var el=document.getElementById(id);
	if (el!=null) {
      el.style.display='none' ; 
   } 
}
/******************************************
*   Verification si date correcte
*   en fonction de jour,mois et année
* valable pour les annees > 2000
******************************************/
function isOkDate(j,m,a) {
    var ok = true ;
    if ( (m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12) && j > 31 ) {
      ok = false ;
    }
    if ( (m==2 && (a==5 || a==6 || a==7 || a==9 || a==10 || a==11)) && j > 28 ) {
      ok = false ;
    }
    if ( (m==2 && (a==4 || a==8 || a==12) ) && j > 29 ) {
      ok = false ;
    }
    if ( (m==4 || m==6 || m==9 || m==11 ) && j > 30 ) {
      ok = false ;
    }
    if ( a > 20 ) {    // attention si dates < 2000 (date naissance ....)
      ok = false ;
    }
    if ( m < 1 || m > 12 ) {
      ok = false ;
    }
    return ok ;
}
/******************************************
*   Verification d'1 date sous forme jj mm aa
*   et renvoi date formatté jj/mm/aa si correcte
******************************************/
function verifDate(d) {
  var j = d.substring(0,2) ;
  var m = d.substring(3,5) ;
  var a = d.substring(6,8) ;
  if ( isNaN(j) || isNaN(m) || isNaN(a) ) {
     return false ;
  }
  if ( d !="" && (d.length !=8 || !isOkDate(j,m,a)) ) {
    // alert ("Date invalide");
    return false ;
  }
  return true ;
}
/******************************************
*   Formattage d'1 date sous la forme jjmmaa
*   en jj/mm/aa
******************************************/
function formatDate(str) {
   string = str.substring(0,2)+"/"+str.substring(3,5)+"/"+str.substring(6,10);
   return string ;
}
/*************************************************
*    Retourne la chaine saisie en majuscule
*************************************************/
function majus(elem) {
   var str = document.getElementById(elem).value.toUpperCase();
   document.getElementById(elem).value = str;   
}

/*************************************************
*   Limite la longeur d'une saisie à la valeur 
*  passée en parametre
*************************************************/
function limite(elem,lg) {
   var str = document.getElementById(elem).value;
   if (str.length > lg) {
      document.getElementById(elem).value = str.substr(0,lg);   
   }
}
///////////////////////////////////////////////////////
//   A partir d'une chaine :
//   - affecte valeur vide si chaine non numérique  ou = 0
//   - rajoute le nombre de décimales demandées
//     http://www.aidejavascript.com/article63.html
///////////////////////////////////////////////////////
// Affichage avec un 0 avant le point decimal si nombre négatif
function formatNombre(nombre, decimales) {
// alert("Nombre : "+nombre) ;
  var n;
  var p10;
  if (isNaN(nombre) || nombre==0) return "";
  if (decimales == 0) {
     n = Math.round(nombre);
     return n.toString();
  }
  else if (decimales > 0) {
     if (document.all) var undefined; // Netscape 4 ne connaît pas la constante "undefined"
     p10 = Math.pow(10, decimales);
     n = Math.round(nombre * p10);
     var signe;
     n < 0 ? signe='-' : signe='';
     n = Math.abs(n);
     n = n.toString();
     var point = n.length - decimales;
     if (point > 0)   n = n.substring(0, point) + "." + n.substring(point);
     if (point == 0)  n = "0." + n;
     if (point < 0)   n = "0." + formater(n, decimales);
     n = signe + n;
  }
  else {
     p10 = Math.pow(10, -decimales);
     n = Math.round(nombre / p10) * p10;
     n = n.toString();
  }
  return n;
}

/******************************************
*   Compte le nombre d'éléments dans un tableau
*   de variables de formulaire
*    - id = id[] recherché
******************************************/
function compteElement(id)  {
     var i=0;
     while ( document.getElementById(id+'['+i+']')) {
        i++;
     }
     return i;
}

/******************************************
*   Recherche et remplace une chaine
******************************************/
function rechercheRemplace(cherche,remplace) {
  var exp=new RegExp("[, ;]+","g");
  chaine=chaine.replace(/[0]/g,remplace);
  return chaine
}
//-->