/* JS - AUTEUR: tapaj.net (c) 2007
fonctions standard pour maj ou pour tout (agenda, catalog, ...), selon ! */               

var maj ;
var chemin_ima ;
var curFile ;
var month_names = new Array("janv","fevr","mars","avr","mai","juin","juil","aout","sept","oct","nov","dec");
var day_names = new Array("dim","lun","mar","mer","jeu","ven","sam");

//////////////////////////
function affPlan(plan,i) {
if (i>0) {
   document.getElementById(plan).style.visibility='visible';
   if (plan=="planPup") document.forms['modif'].focus() ;
   }
else { document.getElementById(plan).style.visibility='hidden'; }
} 

//////////////////////////////////////////
function bouge (nomObj,xDest,yDest,pas) {
    var x = parseInt(document.getElementById(nomObj).style.left) ;
    var y = parseInt(document.getElementById(nomObj).style.top) ; 
    var xPas = xDest - x ;
    var yPas = yDest - y ;
    if ((Math.abs(xPas))>(Math.abs(yPas))) {
         if (xPas>0) yPas=(yPas*pas/(Math.abs(xPas))) ;
         if (xPas>0) xPas=(xPas*pas/(Math.abs(xPas))) ;
         }
    else {                                
          if (yPas>0) xPas=(xPas*pas/(Math.abs(yPas))) ;
          if (yPas>0) yPas=(yPas*pas/(Math.abs(yPas))) ;
         }
    bg(x,y,xDest,yDest,xPas,yPas,nomObj) ;
}  

//////////////////////////////////////////////////
function bg(x,y,xDest,yDest,xPas,yPas,nomObj) {  // recursivité de la fonction bouge
    if ((Math.abs(x-xDest)>(Math.abs(xPas))) || (Math.abs(y-yDest)>(Math.abs(yPas)))) {
    x+=xPas;
    y+=yPas;
    document.getElementById(nomObj).style.left = x+"px" ;
    document.getElementById(nomObj).style.top = y+"px" ;
    var str = "bg("+x+","+y+","+xDest+","+yDest+","+xPas+","+yPas+",'"+nomObj+"')" ;
    setTimeout(str,15000) ;
    }    
    else {
    document.getElementById(nomObj).style.left = xDest+"px" ;
    document.getElementById(nomObj).style.top = yDest+"px" ;
    }
}


//****************************************************************************************************
function br2rn(txt) {
       arrT=txt.split('<BR>') ;
       txt=arrT.join('<br>') ;
       arrT=txt.split('<br>') ;

       txt=arrT.join(retLine) ;    // \r ou \n ;
       return txt ;
}      
 
//****************************************************************************************************
function rn2br(txt) {
       arrT=txt.split(retLine) ;  //retLine \r ou \n ou '\r\n' ;
       txt=arrT.join('<br>') ;
       arrT=txt.split('<br><br>') ;
       txt=arrT.join('<br>') ;
       return txt ;
}     
 
//****************************************************************************************************
function formDate (laDate) {  // inverse date XXXX-XX-XX en XX-XX-XXXX
         D = laDate.split("-");
         d = D[2] ;
         m = D[1] ;
         y = D[0] ;
         laDate = d+"-"+m+"-"+y ;
         if (!d)  laDate="" ; // que d soit le jour ou l'année !!
         return laDate ;
}               
 
//****************************************************************************************************
function affDateComplete(laDate) {  // au format XX-XX-XXXX
         var D = laDate.split("-");
         var d = parseInt(D[0],10);
         var m = parseInt(D[1],10);
         var y = parseInt(D[2],10);
         var dt = new Date(y,m-1,d) ;
         var jour = day_names[dt.getDay()] ;
         var mois = month_names[dt.getMonth()] ;
         laDate="" + jour +" "+ d +" "+ mois +" "+ y ;

         //laDate = d+"-"+m+"-"+y ;
         //if (d==0)  laDate="" ; // que d soit le jour ou l'année !!
         return laDate ;
}                                
 
//****************************************************************************************************
function curDateComplete() {  // au format jjj XX mmmmm XXXX

         var dt = new Date() ;
         var jour = day_names[dt.getDay()] ;    
         var numJour = dt.getDate() ;
         var mois = month_names[dt.getMonth()] ;
         var an = dt.getYear() ;
         if (an<1900) an+=1900 ;
         var laDate="" + jour +" "+ numJour +" "+ mois +" "+ an ;
         return laDate ;
}
           
//****************************************************************************************************
function curDate() {  // au format XX-XX-XXXX

         var dt = new Date() ;
         dt.getDate()<10 ? numJour = "0"+dt.getDate() : numJour = dt.getDate() ;
         (dt.getMonth()+1)<10 ? mois = "0"+(dt.getMonth()+1) : mois = (dt.getMonth()+1) ;
         dt.getYear()<1900 ? an = dt.getYear()+1900 : an = dt.getYear() ;
         var laDate=""+ numJour +"-"+ mois +"-"+ an ;
         return laDate ;
}     
 
//****************************************************************************************************
function stripSl(txt) {
         var param = "\\" ;
         var arr = txt.split(param) ;
         txt = arr.join('') ;
         return txt ;
}                  
 
//****************************************************************************************************
function videSpaces(txt) {
         var Ttxt = txt.split(' ') ;   
         txt = Ttxt.join('') ;
         return txt ;
}

//*********détermine si une chaîne est bien alphanumérique************************************************
function alphaNum(str,q,qq) {
    er = /\w*/g  ;
    var rep = str.match(er) ;
    // alert (rep[0]) ;
    var cond1=(rep[0]==str) ;
    if (!q) q=1 ;
    var cond2=(str.length>=q) ;     
    if (!qq) qq=30 ;
    var cond3=(str.length<=qq) ;
    return (cond1&&cond2&&cond3) ;
}

//*********appartenance à une liste (égal ou contient)******************************************************************
function appListe(txt,nomListe,type) {
var resultat = "" ;
var i = 0 ;
txt=txt.toLowerCase() ;
         switch(type) {
            case 0 : // égal
            while (i<nomListe.length) {
            if (txt==nomListe[i]) resultat = nomListe[i];
            i++ ;
            }
            break;
            case 1 : // contient
            while (i<nomListe.length) {
            if (txt.indexOf(nomListe[i])!=-1) resultat = nomListe[i];
            i++ ;
            }
            break;
         }
return resultat ;
}

/************************************************/
function envoiM(i) {   //compatibilité ascendante !
  txt="../pages/contact.php?env="+i ;
  document.location.href=txt ;
}

//*********fonction pause**************************************** // à finaliser
var cptPause=0 ;

function pause(iPause) {
   iPause-- ;
   cptPause++ ;
   if (iPause > 0) {setTimeout('pause('+iPause+')',1000) ; }
   else alert("cptPause = " + cptPause) ;
   return iPause ;
}   

//*********fonction Timer()**************************************** // exemple à finaliser
function Timer() {
       var dt=new Date()
       window.status=dt.getHours()+":"+dt.getMinutes()+":"+dt.getSeconds();
       setTimeout("Timer()",5000);
}

//*********fonction suppAttrib()****************************************

function suppUnAttrib (unAttrib,leTag) {
    leTag ? leTag=leTag : leTag='div' ;
    var divs = document.getElementsByTagName(leTag);
    var t= 0 ;
    var k= 0
    while (divs[t]) {
          if (divs[t].removeAttribute (unAttrib)) k++  ;
          t++ ;
          }
    alert (k+' '+unAttrib+' supprimés, '+t+' '+leTag+' examinés !!') ;
}


