/**
 * Ce script javaScript rassemble les fonctions affichage des différents modules du site.  
 *
 */
 
    /* La variable contenu indique la page chargé dans le div contenu, 
    elle est surtout utile dans le cas d'une page se rafraichissant a un temps donné*/
    var contenu = "demarrage";
    var timerRafPlanning,timerRafCal,timerRafNbNote,timerRafInfoAppelant,timerRafInfoAppelantArch;
    var date_planning;  // timestamp de la date a afficher dans le planning
    var mois_planning;  // decomposition de la date planning
    var annee_planning; // decomposition de la date planning
    var date_planning_arch = new Date();;  // timestamp de la date a afficher dans le planning
    var mois_planning_arch = date_planning_arch.getMonth()+1;  // decomposition de la date planning
    var annee_planning_arch = date_planning_arch.getFullYear(); // decomposition de la date planning
    var Select = '';  // id du select choisi dans la liste des select du menu secretaire
    var X;            // position de la souris
    var Y;            // position de la souris
    var SupprProtect=0;
	var pause=0;
	var tabsAnnee;
	var comboValue;
	var periode='dates';
	var logo='medical';
	var server;
	var interv=0;
	var typeclient=1;
	var genfact=0;
			 function AffMasque()
			  {
			   if (interv==0)
			    {
				 interv=1;
				 document.getElementById("interval").style.display="";
				 return true;
				}
			   if (interv==1)
			    {
				 interv=0;
				 document.getElementById("interval").style.display="none";
				 return true;
				} 
			  }
			  
			  function typeClient(id)
			   {
			    typeclient=id;
			   }
			  function ValidFact()
			   {
			    var mois1=document.getElementById("mois1").value;
				var an1=document.getElementById("an1").value;
				
				
				var Intervaltemp=interv;
				var mois2=document.getElementById("mois2").value;
				var an2=document.getElementById("an2").value;
				
				if (typeclient==1)
				 var idclient=document.getElementById("client").value;
				if (typeclient==2)
				 var idclient=document.getElementById("categorie").value;
				
				var generation=document.getElementById("generation").value;
				 
				$('contenu').innerHTML="<center><br><img src='./extjs/resources/images/default/grid/loading.gif'> Calcul des factures</center>";
				ouvrir("IHM/IHM_Facturation.php?facturation=1&mois1="+mois1+"&an1="+an1+"&interval="+Intervaltemp+"&mois2="+mois2+"&an2="+an2+"&typeclient="+typeclient+"&idclient="+idclient+"&generation="+genfact,"contenu");
				
				
			   }
    /**    
     *Fonction d'affichage du calendrier
     *@param int mois a afficher dans le calendrier
     *@param int annee a afficher dans le calendrier
     **/
    function afficher_calendrier(mois,annee){
	   
	    var today = new Date();
	    var time = today.getTime();
	    mois_planning  = mois;
	    annee_planning = annee;
      	ouvrir("IHM/IHM_Calendrier.php?mois="+mois+"&annee="+annee+"&time="+time,"calendrier");
    }
    
    
    /**    
     *Fonction dre rafraichissement du calendrier
     **/
    function rafraichir_calendrier(){
	    clearTimeout(timerRafCal);
	    afficher_calendrier(mois_planning,annee_planning);
	    timerRafCal=setTimeout("rafraichir_calendrier()", 30000);
    }
    
                                                      
              
     /**    
     *Fonction d'affichage de l'agenda ( le planning )
     *@param int timestamp de la date a afficher  
     *ici on créé la structure de l'agenda et on fait afficher le planning dedans    
     **/
    function afficher_agenda(date){
	    ToolBar.menuAgenda();
	    var today = new Date();
		var time = today.getTime();
		if (date=="")
		 {
	      time="";
		 }
        
        
        //afficher_calendrier(today.getMonth()+1,today.getFullYear())
        afficher_calendrier(mois_planning,annee_planning);
        date_planning = date;
       
	        if(contenu!='agenda'){
		          contenu='agenda';
		          //$('agenda_planning').innerHTML="<center><br><img src='./extjs/resources/images/default/grid/loading.gif'> Chargement des données</center>";
		          ouvrir("IHM/IHM_Agenda.php?time="+time,"contenu");
		          setTimeout('rafraichir_planning()', 1000); // amorcage de l'affichage et rafraichissement du planning dans la fenetre agenda
	        }                                                  //  > pourra sans doute être supprimé apres quelques tests plus poussés
	        else {
		        $('agenda_planning').innerHTML="<center><br><img src='./extjs/resources/images/default/grid/loading.gif'> Chargement des données</center>";
	          ouvrir("IHM/IHM_Planning.php?date="+date+"&time="+time,"agenda_planning");
	         
	        } 
        
    }  
    
    function agenda_setDisplayMode( date, viewMode, archiveMode ) {
	    var today = new Date();
		var time = today.getTime();
		var baseURL = "IHM/IHM_Planning";
		
		if ( archiveMode ) {
			baseURL = baseURL + "_sauv";
		}
		
		baseURL = baseURL + ".php";
        ouvrir( baseURL + "?date="+date+"&viewMode="+viewMode+"&time="+time,"agenda_planning");
	}
    
    
    
      /**    
      *Fonction d'affichage du planning dans l'agenda
      *@param int timestamp de la date a afficher
      *
      **/
      function rafraichir_planning(){
	      clearTimeout(timerRafPlanning);
	    var today = new Date();
	    var time = today.getTime();
        // on vérifie bien que la page de l'agenda (et donc celle du planning) est toujours visible
      
         ouvrir("IHM/IHM_Planning.php?date="+date_planning+"&time="+time,"agenda_planning");  
         // préparation du rafraichissement de la vitesse de rafraichissement (ici 10s)
         timerRafPlanning = setTimeout("rafraichir_planning()", 75000);
         
      }

    
      
    
    /**    
     *Fonction d'affichage du menu
     *@param int timestamp de la date a afficher     
     **/
    function afficher_menu(date, affich){
	    var today = new Date();
	    var time = today.getTime();
     
    }
    
     
    /**    
     *Fonction d'affichage du menu
     *@param int timestamp de la date a afficher     
     **/
    function change_menu(date){
	      var today = new Date();
	      var time = today.getTime();
    
	      if (document.getElementById('RadioMenu').affichage[0].checked)
	      {
	        ouvrir("IHM/IHM_Menu.php?date="+date+"&affichage=activite&time="+time,"menuCC");
	      }
	      else
	      {
	        ouvrir("IHM/IHM_Menu.php?date="+date+"&affichage=nom&time="+time,"menuCC");
	      }
    }
    
    


    /**
     * Fonction d'encryptage des mots de passe
     **/ 
    function crypte()
    {
		    id1 = 'password';
		    id2 = 'MD5pass';
      		document.getElementById(id2).value = document.getElementById(id1).value;
    } 
    
	function generation()
	 {
	  genfact=genfact+1;
	  if (genfact==2)
	   genfact=0;

	 }
    
    /**
     * Fonction d'affichage de l'entete
     **/ 
    function afficher_header()
    { 
		    var today = new Date();
		    var time = today.getTime();
	      	ouvrir("IHM/IHM_Header.php?time="+time,"header");
    }
    
    /**
     * Fonction d'affichage du panneau de prise de rendez-vous
     * avec pour date celle envoyé en parametre     
     **/ 
    function afficher_rendezvous(date)
    { 
		    var today = new Date();
		    var time = today.getTime();
	     	ouvrir("IHM/IHM_RendezVous.php?date="+date+"&time="+time,"agenda_rdv");
    }
  
    /**
     * Fonction d'affichage de la tranche horaire
     * avec pour date de base la date du planning affiché     
     **/ 
    function afficher_trancheshoraires(date) { 
	    DialogBox.showDialog();
	    DialogBox.resize(720,300);
	    DialogBox.setTitre('Ajout de Tranches horaires');
	    var today = new Date();
	    var time = today.getTime();
       	ouvrir("IHM/IHM_TranchesHoraires.php?date="+date+"&action=affich&time="+time,"agenda_rdv");
    }  
    
    
    
    /**
     * Fonction d'affichage de l'ajout de la tranche horaire
     * avec pour date de base la date du planning affiché     
     **/ 
    function copier_tranches_horaires( date )
    { 
    var today = new Date();
    var time = today.getTime();
    var msg = '';
    
    // tests de conformité des données entrées :
    // conformité de la saisie de
        // date de début et de fin
        var reg_date=new RegExp("^[0-3][0-9][/][0-1][0-9][/][1-2][0-9][0-9][0-9]$");
        if(!reg_date.test(document.getElementById('CopieDebut').value)||!reg_date.test(document.getElementById("CopieFin").value)) 
          {
          msg = msg+"Veuillez entrer des dates valides\n \r";
          }
    
    // si pas d'erreurs
    if(msg=="")
      { 
          ouvrir("IHM/IHM_TranchesHoraires.php?action=copier&date="+date+"&dateDebut=" + document.getElementById("CopieDebut").value +"&dateFin=" + document.getElementById('CopieFin').value +"&time="+time,"agenda_rdv");
      }
      else
      {
       Ext.MessageBox.alert('Erreur', msg);
      }
    ouvrir("IHM/AppelVidePlage.php?type=2","ok");
    }
    
    
    /**
     * Fonction d'affichage de l'ajout de la tranche horaire
     * avec pour date de base la date du planning affiché     
     **/ 
    function ajouter_tranches_horaires( date )
    { 
    var today = new Date();
    var time = today.getTime();
    var msg = '';
    
    
    // tests de conformité des données entrées :
    // conformité de la saisie de
        // date de début
       
        var reg_date=new RegExp("^[0-3][0-9][/][0-1][0-9][/][1-2][0-9][0-9][0-9]$");
        if(!reg_date.test(document.getElementById("date_debut").value)||!reg_date.test(document.getElementById("date_fin").value)) 
          {
          msg = msg+"Veuillez entrer des dates valides\n \r";
          }
       
       
    //on récupere les jours cochées
    var jours = document.forms['form-ajout-th'].jours;
    var tab = new Array();
    var indice = 0;
    var act = 0;
    
    var heureDeb=document.getElementById("aj_heure_deb").value+':'+document.getElementById("aj_mn_deb").value
    var heureFin=document.getElementById("aj_heure_fin").value+':'+document.getElementById("aj_mn_fin").value
    
    try{
    	act = document.getElementById("activite").value;
	}catch(ex){
		act=0;	
	}
   
     
    for( i=0; i<jours.length;i++)
       {
         if (jours[i].checked==true)
         {
           tab[indice]=jours[i].value;
           indice++;
         }
       }
           
    if (indice==0)  // tous les jours ont été decochés, on n'aura donc rien a ajouter
      {
      msg = msg+"Veuillez cocher au moins un jour\n \r";
      }  
   
    // si pas d'erreurs
    if(msg=='')
      {   
        ouvrir("IHM/IHM_TranchesHoraires.php?date="+date+"&action=ajout&datedebut="+document.getElementById("date_debut").value+"&datefin="+document.getElementById("date_fin").value+"&heuredebut="+heureDeb+"&heurefin="+heureFin+"&tab="+tab+"&activite="+act+"&etat="+document.getElementById("etat").value+"&time="+time,"agenda_rdv");
        
        setTimeout('afficher_agenda(date_planning)',2000);  // afficher le planning
        
        setTimeout('afficher_calendrier(mois_planning,annee_planning)',2000);  // afficher le calendrier
        
      }else
      {
       Ext.MessageBox.alert('Erreur', msg);
      }
    
    ouvrir("IHM/AppelVidePlage.php?type=2","ok");
      
    }
    
    /**
     * Fonction de "fermeture" du div agenda_rdv (tranches horaires/rdv/...)
     **/ 
    function fermer_div_rdv()
      {
	      DialogBox.hideDialog();
      	  document.getElementById('agenda_rdv').innerHTML='';
      }
      

    /**
     * Fonction d'affichage des rendez-vous de la tranche horaire
     **/ 
    function rdv(rdv_date,IdRDV,activite_id,activite_nom,etat_id,note)
    { 
	    DialogBox.showDialog();
	    DialogBox.resize(375,250);
	    
	  	$('agenda_rdv').innerHTML="<center><br><img src='./extjs/resources/images/default/grid/loading.gif'> Chargement des données</center>";   
	    var today = new Date();
	    var time = today.getTime();
	    clearTimeout(timerRafInfoAppelant);
	    ouvrir('IHM/IHM_RendezVous.php?rdvDate='+rdv_date+'&IdRDV='+IdRDV+'&activiteID='+activite_id+'&activiteNom='+activite_nom+'&etatId='+etat_id+'&time='+time,'agenda_rdv');
        
    }
    
    
     /**
     * Fonction d'affichage d'un nouvel appelant lors de la prise de rendez vous
     * @param id du rendez vous     
     **/ 
    function ajouter_rdv( IdRDV, idAppelant ) { 
		var today = new Date();
		var time = today.getTime();
    
/*		if( idAppelant == -1 ) {
			ouvrir('IHM/IHM_Appelant.php?action=ajouterRDV&IdRDV='+IdRDV+'&time='+time,'gestion');
		} else {
		ouvrir('IHM/IHM_Appelant.php?action=afficherAppelantRDV&IdRDV='+IdRDV+'&id='+idAppelant+' &time='+time,'gestion');
		}*/
		
	// si l'on demande un nouvel appelant
    if(document.getElementById('appelant').value==-1)     
      {
      // ihm appelant
      ouvrir('IHM/IHM_Appelant.php?action=ajouterRDV&IdRDV='+IdRDV+'&time='+time,'gestion');
     
      }
      else if(document.getElementById('appelant').value!='rien') // un appelant deja list‚
      {
        ouvrir('IHM/IHM_Appelant.php?action=afficherAppelantRDV&IdRDV='+IdRDV+'&id='+document.getElementById('appelant').value+'&time='+time,'gestion');
      }
      else
      {
        document.getElementById('gestion').innerHTML = "<a onClick='fermer_div_rdv()'> Annuler</a>";
      }
		
    }
    
    /**
     * Fonction d'affichage d'un nouvel appelant lors de la prise de rendez vous
     * @param id du rendez vous     
     **/ 
    function modifier_rdv(IdAppelant, date, activite_id, activite_nom, etat_id) { 
	  DialogBox.resize(535,680);
      var today = new Date();
      var time = today.getTime();
      
      ouvrir('IHM/IHM_Appelant.php?action=ModifierRDV&id='+IdAppelant+'&rdvDate='+date+'&activiteID='+activite_id+'&activiteNom='+activite_nom+'&etatId='+etat_id+'&time='+time,'gestion');
    }
    
   
      /**
     * Fonction d'affichage d'un nouvel appelant lors de la prise de rendez vous
     * @param id du rendez vous     
     **/ 
    function modifier_Appelant_RDV(date, IdAppelant, activite_id, activite_nom, etat_id) { 
      var today = new Date();
      var time = today.getTime();
      
      var note = Format_Texte(document.getElementById("note").value);
      
      ouvrir("IHM/IHM_RendezVous.php?action=modifRDV&IdAppelant=" + IdAppelant + "&rdvDate="+date+"&activiteID="+activite_id+"&activiteNom="+activite_nom+"&etatId="+etat_id
		+"&civilite=" + document.getElementById("civilite").value + "&nom=" +document.getElementById("nom").value + "&prenom=" + document.getElementById("prenom").value + "&adresse=" 
		+ document.getElementById("adresse").value + "&dateNaissance=" + document.getElementById("dateNaissance").value + "&secu=" + document.getElementById("secu").value + "&codePostal=" 
		+ document.getElementById("codePostal").value + "&ville=" + document.getElementById("ville").value + "&telDomicile=" + document.getElementById("telDomicile").value + "&telPortable=" 
		+ document.getElementById("telPortable").value + "&mail=" + document.getElementById("mail").value + "&note=" + note + "&time="+time + "&note_rdv=" 
		+ document.getElementById("note_rdv").value + "&id_statut=" + Ext.get( "id_statut" ).getValue(),"agenda_rdv");
        
    }
    
    
    /**
     * Fonction d'affichage de la zone de choix de traitement (edition, suppression) sur les tranches horaires affectées
     **/ 

    function afficher_traitement(mod)
    { 
	    DialogBox.showDialog();
		    
	    if(mod=='etat'){
		    DialogBox.setTitre('Modification de l\'etat');
	    }else if(mod=='act'){
		    DialogBox.setTitre('Modification de l\'activité');
		}else if(mod=='suppr'){
	    	DialogBox.setTitre('Suppression de Tranche Horaire');
    	}
	    clearTimeout(timerRafPlanning);
    	var today = new Date();
    	var time = today.getTime();
      	ouvrir('IHM/IHM_Traitement.php?date='+date_planning+'&time='+time+'&mod='+mod,'agenda_rdv');

    }
    
     /**
     * Fonction de suppression d'une ou plusieurs tranches horaires
     **/ 
    function supprimer_tranches_horaires()
    { 
    var today = new Date();
    var time = today.getTime();    
      //on récupere les tranches horaires cochées
    var rdv_chgt = document.form_planning.rdv_chgt;
    var tab = new Array();
    var indice = 0;
     //si il y a plusieurs cases a cocher, rdv_chgt[0] existe
     try{
	      if (typeof(rdv_chgt[0])=="object")
	      {
	      
	        for( i=0; i<rdv_chgt.length;i++)
	           {
	             if (rdv_chgt[i].checked==true)
	             {
	               tab[indice]=rdv_chgt[i].value;
	               indice++;
	             }
	           }
	       }else{
	       if (rdv_chgt.checked==true)
	        {
	          tab[0]=rdv_chgt.value;
	        }
	       
	       }
	       
	       
	    if (indice==0)  // toutes les tranches horaires ont été decochées, on n'aura donc rien a supprimer
	    {
	      	Ext.MessageBox.alert('Erreur', 'Veuillez selectionner les tranches horaires à supprimer.');
	    }else{
			
        	Ext.MessageBox.confirm('Confirmation', 'Etes-vous sûr de vouloir supprimer les tranches horaires sélectionnées?', function(btn){if(btn=='yes'){
	        	
	        	ouvrir('IHM/IHM_Planning.php?action=suppTranchesHoraires&tadbIdRDV='+tab+'&date='+date_planning+'&time='+time,'agenda_planning'); 
		      	fermer_div_rdv();
		    	setTimeout('afficher_calendrier(mois_planning,annee_planning)', 1000);
		        contenu='agenda';
		        rafraichir_planning();
	        	
	        	}});
	      
	      	
	     }
	}catch(ex){
	    
     }
    }
    
     /**
     * Fonction de suppression d'une ou plusieurs tranches horaires
     **/ 
    function supprimer_tranches_horaires_arch()
    { 
    var today = new Date();
    var time = today.getTime();    
      //on récupere les tranches horaires cochées
    var rdv_chgt = document.form_planning.rdv_chgt;
    var tab = new Array();
    var indice = 0;
     //si il y a plusieurs cases a cocher, rdv_chgt[0] existe
     try{
	      if (typeof(rdv_chgt[0])=="object")
	      {
	      
	        for( i=0; i<rdv_chgt.length;i++)
	           {
	             if (rdv_chgt[i].checked==true)
	             {
	               tab[indice]=rdv_chgt[i].value;
	               indice++;
	             }
	           }
	       }else{
	       if (rdv_chgt.checked==true)
	        {
	          tab[0]=rdv_chgt.value;
	        }
	       
	       }
	       
	       
	    if (indice==0)  // toutes les tranches horaires ont été decochées, on n'aura donc rien a supprimer
	    {
	      	Ext.MessageBox.alert('Erreur', 'Veuillez selectionner les tranches horaires à supprimer.');
	    }else{
			
        	Ext.MessageBox.confirm('Confirmation', 'Etes-vous sûr de vouloir supprimer les tranches horaires sélectionnées?', function(btn){if(btn=='yes'){
	        	
	        	ouvrir('IHM/IHM_Planning.php?action=suppTranchesHorairesArch&tadbIdRDV='+tab+'&date='+date_planning+'&time='+time,'agenda_planning'); 

		       
	        	
	        	}});
	      
	      	
	     }
	}catch(ex){
	     //Ext.MessageBox.alert('Erreur', 'Veuillez d\'abord créer des tranches horaires.'); 
     }
    }
    
    
     /**
     * Fonction de modification d'etat d'une ou plusieurs tranches horaires
     **/ 
    function modifie_etat_tranches_horaires( etat ) { 
	    etat=document.getElementById('etat').value;
	   
    var today = new Date();
    var time = today.getTime();    
      //on récupere les tranches horaires cochées
    var rdv_chgt = document.form_planning.rdv_chgt;
    var tab = new Array();
    var indice = 0;
    var msg;
     //si il y a plusieurs cases a cocher, rdv_chgt[0] existe
     	try{
	     	 if(typeof(rdv_chgt[0])=="object"){
		     	 erreur=0;
     	 	}
     }catch(ex){
	     erreur=1;
	     Ext.MessageBox.alert('Erreur', 'Veuillez d\'abord créer des tranches horaires.'); 
     }
     if(erreur==0){
	      if (typeof(rdv_chgt[0])=="object")
	      {
	      
	        for( i=0; i<rdv_chgt.length;i++)
	           {
	             if (rdv_chgt[i].checked==true)
	             {
	               tab[indice]=rdv_chgt[i].value;
	               indice++;
	             }
	           }
	       }else{
	       if (rdv_chgt.checked==true)
	        {
	          tab[0]=rdv_chgt.value;
	        }
	       
	       }
	       
	       DialogBox.hideDialog();
	    if (indice==0)  // toutes les tranches horaires ont été decochées, on n'aura donc rien a supprimer
	      {
	    		Ext.MessageBox.alert('Erreur', 'Veuillez selectionner les tranches horaires à supprimer.');
	      }  else{
		      	
		      	  Ext.MessageBox.confirm('Confirmation', 'Etes-vous sûr de vouloir modifier l\'état des tranches horaires sélectionnées?', function(btn){if(btn=='yes'){
			      ouvrir('IHM/IHM_Planning.php?action=modifieEtatTranchesHoraires&etat='+etat+'&tadbIdRDV='+tab+'&date='+date_planning+'&time='+time,'agenda_planning'); 
			      fermer_div_rdv();
		          setTimeout('afficher_calendrier(mois_planning,annee_planning)', 1000);
		          contenu='agenda';
		          rafraichir_planning();
	       	}});   
	     }
     }

 	  
	 
 	  
    }
    

    
     /**
     * Fonction de suppression de rendez vous
     * @param id du rendez vous   
     * @param id de l'appelant     
     **/ 
    function supprimer_rdv(IdRDV, idAppelant)
    { 
	   var today = new Date();
	   var time = today.getTime();
    
                
       ouvrir("IHM/IHM_Planning.php?action=suppRdv&IdRDV="+IdRDV+"&idAppelant="+idAppelant+"&date="+date_planning+"&time="+time,"agenda_planning"); 
       
       fermer_div_rdv();
       setTimeout("afficher_calendrier(mois_planning,annee_planning)", 1000);1

    }



    
/**
 *cette fonction transforme les retour chariot en balise html <br/> pour garder la mise en forme dans les textarea. En effet, lors de l"envoie d"un textarea par POST, on peut récupérer la mise en forme a l"aide de la foncrion nl2br(), mais lors d"un passage en GET, on ne peut plus. Or dans notre application, on utilise pas le POST pour ne pas avoir a recharger toute la page, mais on utilise l"ajax pour ne changer que le contenu qui nous interesse.
 *
 *@param string message a renvoyer dont on veut garder la mis en forme  
 */
function Format_Texte(text)
{
  if (navigator.appName =="Explorer")
    text = text.replace(/\r\n/g,"<br>");
  else
    text = text.replace(/\n/g,"<br/>");
  
  return text;
}

    function deconnexion()
    {
	     clearTimeout(timerRafPlanning);
      var today = new Date();
      var time = today.getTime();
          contenu = "deconnexion";
          ouvrir("IHM/IHM_deconnexion.php?time="+time,"contenant");
      
    }
    
    /**    
     *Fonction d"affichage des notes
     *@param int 0 ou 1 0 pour afficher les notes non archivées, 1 pour les archivées    
     */
    function afficher_notes(arch){
	    clearTimeout(timerRafPlanning);
	    ToolBar.menuNotes();
		var today = new Date();
		var time = today.getTime();
        contenu = "notes";
        $('contenu').innerHTML="<center><br><img src='./extjs/resources/images/default/grid/loading.gif'> Chargement des données</center>";
        ouvrir("IHM/IHM_Notes.php?arch="+arch +"&time="+time,"contenu");
    }

    /**    
     * Affichage des consignes (qui sont des notes particulières).
     * @param arch int 0 ou 1 0 pour afficher les notes non archivées, 1 pour les archivées    
     */
    function afficher_consignes() {
	    clearTimeout( timerRafPlanning );
		ToolBar.init();
		var today = new Date();
		var time = today.getTime();
        contenu = "notes";
        $('contenu').innerHTML="<center><br /><img src='./extjs/resources/images/default/grid/loading.gif'>Chargement des données</center>";
        ouvrir("IHM/IHM_Notes.php?consignes=1&time="+time,"contenu");
    }

    
    
     /**    
     *Fonction d"affichage des notes
     *@param integer id de la note a rafrachir    
     */
    function afficher_note_seule(idnote){
    var today = new Date();
    var time = today.getTime();
      ouvrir("IHM/IHM_Note_Seule.php?action=affiche&id="+idnote +"&time="+time,"postIt"+idnote);
    } 
    
    
    /**    
     *Fonction d"affichage d"une note à éditer
     *@param integer id de la note a éditée    
     */
    function afficher_note_editer(idnote){
    var today = new Date();
    var time = today.getTime();
      ouvrir("IHM/IHM_Note_Seule.php?action=affiche&edit=1&id="+idnote +"&time="+time,"postIt"+idnote);
    } 


    /**    
     *Fonction d"affichage d"une note qui change d"etat
     *@param integer id de la note a éditée    
     */
    function afficher_note_change_etat(idnote)
    {
    var today = new Date();
    var time = today.getTime();
      ouvrir("IHM/IHM_Note_Seule.php?action=etat&id="+idnote +"&time="+time,"postIt"+idnote);
    }
    
    /**    
     *Fonction d"affichage d"une note qui change le message de la note
     *@param integer id de la note a éditée    
     */
    function afficher_note_change_message(idnote)
    {
    var today = new Date();
    var time = today.getTime();
    
    
    mess = Format_Texte(document.getElementById("message"+idnote).value);
  	// POUR IE  mess = document.getElementById("message"+idnote).value.replace(/\r\n/g,"<br>");
      ouvrir("IHM/IHM_Note_Seule.php?action=message&id="+idnote +"&message="+mess +"&time="+time,"postIt"+idnote);
    }
    
    /**    
     * Transmission de note par e-mail
     * @param integer id de la note a éditée    
     */
    function note_sendByEmail( idNote ) {
		var today = new Date();
		var time = today.getTime();
		ouvrir("IHM/IHM_Note_Seule.php?action=sendbyemail&id="+idNote +"&time="+time,"postIt"+idNote);
    }

    
    
    /**    
     *Fonction d"affichage de la saisie d"une nouvelle note
     *Comme on ne peut ajouter qu"une seule note en mˆme temps, on cache le bouton nouvelle note     
     *     
     */
    function afficher_note_nouvelle() {
	   
	    DialogBox.showDialog(); 
	    DialogBox.setTitre('Nouvelle Note'); 
	    DialogBox.resize( 300, 240 );
		ouvrir("IHM/IHM_Note_Seule.php?action=newNote",'agenda_rdv');	

    }
    
    
    
    
    
    /**    
     *Fonction d"affichage ... de d‚saffichage de la saisie d"une nouvelle note
     *on rends le bouton nouvelle note a nouveau visible 
     */
    function afficher_note_nouvelle_cahee()
    {
      document.getElementById("postItNouveau").style.display="none";
      document.getElementById("btnnouv").style.visibility="visible";
    }



    



    /**    
     *Fonction qui envoie les id des notes … archiver et rafraichie la page pour ne plus afficher ces notes
     *@param int 0 si onveut afficher les notes non archiv‚es, 1 si on veut afficher les notes deja archiv‚es
     */
    function archiver_note(archiv)
    {
	 
      var today = new Date();
      var time = today.getTime();
      //on r‚cupŠre les id des notes coch‚es
      var arch = document.formulaire.archivebox;
      var tab = new Array();
      var indice = 0;
     
      
      //si il y a plusieurs cases a cocher, arch[0] existe
      if (typeof(arch[0])=="object")
      {
         for( i=0; i<arch.length;i++)
        {
          if (arch[i].checked==true)
          {
            tab[indice]=arch[i].value;
            indice++;
          }
        }
      }
      //sinon, arch[0] n"exite pas et donc il n"y a qu"une seule case a cocher
      else
      {
        if (arch.checked==true)
        {
          tab[0]=arch.value;
        }
      }
      
      ouvrir("IHM/IHM_Notes.php?archive=" + tab + "&arch=" + archiv + "&time=" + time,"contenu");
    }
  

/*--------------------------------------------------------------------------------------*/

/**
 *  Affiche la liste de tous les clients
 */
  function affiche_gestionClient()
  {
	   clearTimeout(timerRafPlanning);
	  $('contenu').innerHTML="<center><br><img src='./extjs/resources/images/default/grid/loading.gif'> Chargement des données</center>";
	  ToolBar.menuGestionClient();
    var today = new Date();
    var time = today.getTime();
    contenu = "gestionClient";
    ouvrir("IHM/IHM_Gestion_Clients.php?action=afficher&time=" + time,"contenu");
    afficher_header();
  }

/**
 *  Affiche les details d"un seul client
 *  @param integer id de client dont on veut afficher les details
 */
  function affiche_Client(id)
  {
	  
    var today = new Date();
    var time = today.getTime();
    contenu = "gestion";
    ouvrir("IHM/IHM_Client.php?action=afficher&id="+id +"&time=" + time,"contenu");
   
  }

/**
 *  Affiche les details d"un seul client
 *  @param integer id de client dont on veut afficher les details
 */
  function affiche_MonCompte()
  {
	   clearTimeout(timerRafPlanning);
	 ToolBar.menuMonCompte();
	  
    var today = new Date();
    var time = today.getTime();
    contenu = "gestion";
    ouvrir("IHM/IHM_Client.php?action=afficher&time=" + time,"contenu");
  }

/**
 *  Affiche la liste de tous les clients, ais en ayant sauvegarder les info du client
 *  @param int identifient du client … modifier 
 */
  function modifie_gestionClient(id)
  {
    var today = new Date();
    var time = today.getTime();
    
    var etat;
    //si on bloque le compte
    if(document.getElementById("etat").checked == true){ etat = "BL"; }else{ etat=""}
    if(document.getElementById("tva").checked == true){ tva = "1"; }else{ tva="0"}
	if(document.getElementById("in_dynamique").checked == true){ in_dynamique = "1"; }else{ in_dynamique="0"}
    if(document.getElementById("medecin").checked == true){ medecin = "1"; }else{ medecin="0"}
    if(document.getElementById("typeClient").checked == true){ typeClient = "1"; }else{ typeClient="0"}
    if(document.getElementById("rdv2005").checked == true){ rdv2005 = "1"; }else{ rdv2005="0"}
    
	var spec = document.getElementById("spec").value;
	
    var note = Format_Texte(document.getElementById("note").value);

   ouvrir("IHM/IHM_Gestion_Clients.php?action=modifier&id="+id + "&spec="+spec+"&debcontrat="+document.getElementById("debcontrat").value+"&refcontrat="+document.getElementById("refcontrat").value+"&civilite=" + document.getElementById("civilite").value + "&zone=" + document.getElementById("zone").value + "&nom=" +document.getElementById("nom").value + "&prenom=" + document.getElementById("prenom").value + "&societe=" + document.getElementById("societe").value + "&adresse=" + document.getElementById("adresse").value + "&codePostal=" + document.getElementById("codePostal").value + "&ville=" + document.getElementById("ville").value + "&telBureau=" + document.getElementById("telBureau").value + "&telPortable=" + document.getElementById("telPortable").value + "&telSda=" + document.getElementById("telSda").value + "&fax=" + document.getElementById("fax").value + "&mail=" + document.getElementById("mail").value + "&denom=" + document.getElementById("denom").value +"&prixrdv2005=" + document.getElementById("prixRdv2005").value + "&prixBureau=" + document.getElementById("prixBureau").value + "&prixClient=" + document.getElementById("prixClient").value +"&numClient=" + document.getElementById("numClient").value +"&numTVA=" + document.getElementById("numTVA").value +"&prixNote=" + document.getElementById("prixNote").value +"&rmqClient=" + document.getElementById("rmqClient").value + "&etat=" + etat +"&tva=" + tva +"&typeClient=" + typeClient + "&rdv2005=" + rdv2005 + "&medecin=" + medecin + "&note=" + note + "&time=" + time+"&dynamique="+in_dynamique,"gestion");
   
       
    setTimeout('afficher_header()',1000);
  }
/**
 *  Affiche la liste de tous les clients, ais en ayant sauvegarder les info du client
 *  @param int identifient du client … modifier 
 */
  function modifie_gestionClientClient(id)
  {
    var today = new Date();
    var time = today.getTime();
   
    var note = Format_Texte(document.getElementById("note").value);

   ouvrir("IHM/IHM_Gestion_Clients.php?action=modifierClient&id="+id + "&civilite=" + document.getElementById("civilite").value + "&zone=" + document.getElementById("zone").value + "&nom=" +document.getElementById("nom").value + "&prenom=" + document.getElementById("prenom").value + "&societe=" + document.getElementById("societe").value + "&adresse=" + document.getElementById("adresse").value + "&codePostal=" + document.getElementById("codePostal").value + "&ville=" + document.getElementById("ville").value + "&telBureau=" + document.getElementById("telBureau").value + "&telPortable=" + document.getElementById("telPortable").value + "&telSda=" + document.getElementById("telSda").value + "&fax=" + document.getElementById("fax").value + "&mail=" + document.getElementById("mail").value + "&denom=" + document.getElementById("denom").value + "&note=" + note + "&time=" + time,"gestion");
   
       
    setTimeout('afficher_header()',1000);
  }



/**
 *  demande une confiramtion de suppression et supprime en cas de reponse positive
 *  @param int identifient du client … supprimer
 *  @param int timestamp actuel (necessaire pour differencier les adrese sous Internet Explorer pour ‚viter des probŠme de cache)  
 */
  function supprime_Client(id)
  {
    var today = new Date();
    var time = today.getTime();
    
    
    
    //on supprime uniquement si la reponse est affirmative
    Ext.MessageBox.confirm('Confirmation', 'Etes-vous sûr de vouloir supprimer le client sélectionné?', function(btn){if(btn=='yes'){
		ouvrir("IHM/IHM_Gestion_Clients.php?action=supprimer&id="+id + "&time=" + time,"gestion");
	}});
   
  }
  
  
  
 /**
 *  ouvre le div contenant le formulaire necessaire a la cr‚ation d"un nouveau client
 */
  function nouveau_client()
  {
    var today = new Date();
    var time = today.getTime();
      document.getElementById("ajout_client").style.display="block";
      
    setTimeout('document.getElementById(\"nom\").focus()', 500);
  }
  
 /**
 *  ferme le div contenant le formulaire necessaire a la cr‚ation d"un nouveau client
 */
  function nouveau_client_ferme()
  {
      document.getElementById("ajout_client").style.display="none";
  }


 /**
 *  ferme le div contenant le formulaire necessaire a la cr‚ation d"un nouveau client
 */
  function creerClient()
  {    
    var today = new Date();
    var time = today.getTime();
    ouvrir("IHM/IHM_Client.php?action=ajouter&nom=" + document.getElementById("nom").value + "&mdp=" + MD5(document.getElementById("mdp").value) + "&time=" + time,"contenu");
    setTimeout('document.getElementById(\"civilite\").focus()', 1000);
	}
/**
 *  ouvre le div contenant le formulaire necessaire a la modification du mot de passe d"un client
 */
  function affichemodif(id_client)
  {
	Ext.MessageBox.prompt('Nouveau Mot de Passe', 'Entrez le nouveau mot de passe:', function(btn,text){
		if(btn=='ok'){
			var today = new Date();
	     	var time = today.getTime();     
    		ouvrir("IHM/IHM_Client_Modif_Password.php?id=" + id_client + "&mdp=" + text + "&time=" + time, "reponse");
     	}
     });

  }
  
  /**
 *  ferme le div contenant le formulaire necessaire a la modification du mot de passe d"un client
 */
  function cachemodif()
  {

      document.getElementById("modif_password").style.display="none";
      document.getElementById("affiche_modif").style.visibility="visible";
  }


/**
 *  ferme le div contenant le formulaire necessaire a la modification du mot de passe d"un client
 *  @param integer identifiant du client aui doit changer de mot de passe 
 */
  function nouveauPassword(id)
  {

    
    
    document.getElementById("modif_password").style.display="none";
    document.getElementById("affiche_modif").style.visibility="visible";
    
    document.getElementById("txt_newMdp").value="";
  }
  

  

/*--------------------------------------------------------------------------------------*/
/* chrystel ajout sms */

  /**
   *  affiche la page de selection des sms
   */
  function afficher_sms()
  {
   clearTimeout(timerRafPlanning);
    var today = new Date();
    var time = today.getTime();
    ToolBar.init();
    contenu = "sms";
    ouvrir("IHM/IHM_Sms.php?time=" + time, "contenu");
  }

  /**
   *  affiche le suivi des sms
   */
  function afficher_histoSms(client)
  {
   clearTimeout(timerRafPlanning);
    var today = new Date();
    var time = today.getTime();
    ToolBar.init();
    contenu = "histoSms";
    ouvrir("IHM/IHM_SmsHisto.php?time=" + time + "&client=" + client, "contenu");
  }

/* fin chrystel */

/*--------------------------------------------------------------------------------------*/

  /**
   *  affiche la page de selection d'affichage du compte rendu
   */
  function afficher_compte_rendu()
  {
	   clearTimeout(timerRafPlanning);
    var today = new Date();
    var time = today.getTime();
    ToolBar.init();
    contenu = "gestionClient";
    ouvrir("IHM/IHM_Compte_Rendu.php?time=" + time, "contenu");
  }
  
  
  /**
   *  affiche le compte rendu imprimable
   */
  function afficher_compte_rendu_imprimable()
  {
    var today = new Date();
    var time = today.getTime();

      
    window.open("IHM/IHM_Compte_Rendu_Imprimable.php?periode="+periode+"&semaine="+comboValue+"&debut="+document.getElementById('debut').value+"&fin="+document.getElementById('fin').value+"&logo="+logo+"&time=" + time);
  }

afficher_compte_rendu_mail
  /**
   *  affiche le compte rendu imprimable
   */
  function afficher_compte_rendu_mail()
  {
    var today = new Date();
    var time = today.getTime();

      
    ouvrir("IHM/IHM_Compte_Rendu_Mail.php?periode="+periode+"&semaine="+comboValue+"&debut="+document.getElementById('debut').value+"&fin="+document.getElementById('fin').value+"&logo="+logo+"&time=" + time, "contenu");
  }


 

/*--------------------------------------------------------------------------------------*/
/**
 *  Affiche la liste de tous les appelants
 */
  function affiche_gestionAppelant(action, indiceId, id)
  {
	   clearTimeout(timerRafPlanning);
	  ToolBar.menuGestionAppelant();
    var today = new Date();
    var time = today.getTime();
    contenu = "gestionAppelant";
    if (action == 'afficher')
    {
      ouvrir("IHM/IHM_Gestion_Appelants.php?action=afficher&indiceId=" + indiceId + "&time=" + time,"contenu");
    }
    else
    {
      ouvrir("IHM/IHM_Gestion_Appelants.php?action=annulerAjout&id=" + id + "&indiceId=" + indiceId + "&time=" + time,"contenu");
    }
    
  }
  
   function affiche_gestionAppelant2(action, lettre, id)
  {
	   clearTimeout(timerRafPlanning);
	  ToolBar.menuGestionAppelant();
    var today = new Date();
    var time = today.getTime();
    contenu = "gestionAppelant2";
    if (action == 'afficher')
    {
      ouvrir("IHM/IHM_Gestion_Appelants2.php?action=afficher&lettre=" + lettre + "&time=" + time,"contenu");
    }
    else
    {
      ouvrir("IHM/IHM_Gestion_Appelants2.php?action=annulerAjout&id=" + id + "&lettre=" + lettre + "&time=" + time,"contenu");
    }
    
  } 
  
 
/**
 *  Affiche les details d"un seul client
 *  @param integer id de client dont on veut afficher les details
 */
  function affiche_Appelant(id)
  {
    var today = new Date();
    var time = today.getTime();
    contenu = "gestion";
    ouvrir("IHM/IHM_Appelant.php?action=afficher&id="+id +"&time=" + time,"contenu");
  }

 
  

/**
 *  Affiche la liste de tous les appelants, mais en ayant sauvegarder les info de l'appelant
 *  @param int identifient du client … modifier 
 */
  function modifie_gestionAppelant(id) {
    var today = new Date();
    var time = today.getTime();
    
    var note = Format_Texte(document.getElementById("note").value);
  
	ouvrir("IHM/IHM_Gestion_Appelants.php?action=modifier&id="+id +"&civilite=" + document.getElementById("civilite").value + "&nom=" +document.getElementById("nom").value 
	+ "&prenom=" + document.getElementById("prenom").value + "&adresse=" + document.getElementById("adresse").value + "&dateNaissance=" + document.getElementById("dateNaissance").value 
	+ "&secu=" + document.getElementById("secu").value + "&codePostal=" + document.getElementById("codePostal").value + "&ville=" + document.getElementById("ville").value + "&telDomicile=" 
	+ document.getElementById("telDomicile").value + "&telPortable=" + document.getElementById("telPortable").value + "&mail=" + document.getElementById("mail").value 
	+ "&note=" + note + "&time=" + time + "&id_statut=" + Ext.get("id_statut").getValue(), "contenu"); //document.getElementById("id_statut").value

  }

/**
 *  demande une confiramtion de suppression et supprime en cas de reponse positive
 *  @param int identifient de l'supprime_Appelant … supprimer
 *  @param string nom de l'ppelant a supprimer 
 */
  function supprime_Appelant(id, nom)
  {
    var today = new Date();
    var time = today.getTime();
    
    
    //on supprime uniquement si la reponse est affirmative
	  Ext.MessageBox.confirm('Confirmation', 'Etes-vous sûr de vouloir supprimer ' + nom  + ' ?', function(btn){if(btn=='yes'){
      	ouvrir("IHM/IHM_Gestion_Appelants.php?action=supprimer&id="+id + "&time=" + time,"contenu");
      }});
  }
  
  
   
/**
 *  Affiche la fenetre de selection d'un nouvel applant
 */
  function nouvel_appelant()
  {
    var today = new Date();
    var time = today.getTime();
    contenu = "gestion";
    ouvrir("IHM/IHM_Appelant.php?action=ajouter&time=" + time,"contenu");
  }


   
/**
 *  Affiche la fenetre de selection d'un nouvel applant
 */
  function affiche_fusion()
  {
    var today = new Date();
    var time = today.getTime();
    ouvrir("IHM/IHM_Fusion.php?action=affichage&time=" + time,"fusion");
    
    setTimeout('document.getElementById(\"appelant1\").focus()', 5000);
  }

 
   
/**
 *  Affiche la fenetre de selection d'un nouvel applant
 */
  function fusion()
  {
    var today = new Date();
    var time = today.getTime();
    var appelant1 = document.getElementById('appelant1').value;
    var appelant2 = document.getElementById('appelant2').value;
    
    if (appelant1 == appelant2)
    {
      Ext.MessageBox.alert('Erreur', 'vous ne pouvez pas fusionner deux appelants identiques');
    }
    else
    {
      Ext.MessageBox.confirm('Confirmation', 'Etes-vous sûr de vouloir fusionner ces deux appelants ?', function(btn){if(btn=='yes'){
      	ouvrir("IHM/IHM_Fusion.php?action=fusion&appelant1=" + appelant1 + "&appelant2=" + appelant2 + "&time=" + time,"fusion");
      }});
      
    }
    
  }

 /**
 *  Affiche la fenetre de selection d'un nouvel applant
 */
  function annuler_fusion()
  {
    document.getElementById('fusion').innerHTML ="";
  }


	/**
	 *  Affiche le planning en ajoutant l'appelant et le rendez-vous
	 */
	function Ajouter_RDV_NvxAppelant(IdRDV, idAppelant) {
	  
    var today = new Date();
    var time = today.getTime();
    
    var note = Format_Texte(document.getElementById("note").value);
    
    ouvrir("IHM/IHM_Planning.php?action=ajoutAppelant&IdRDV=" + IdRDV + "&idAppelant=" 
			+ idAppelant + "&date="+date_planning + "&civilite=" + document.getElementById("civilite").value + "&nom=" +document.getElementById("nom").value 
			+ "&prenom=" + document.getElementById("prenom").value + "&adresse=" + document.getElementById("adresse").value + "&dateNaissance=" 
			+ document.getElementById("dateNaissance").value + "&secu=" + document.getElementById("secu").value + "&codePostal=" + document.getElementById("codePostal").value 
			+ "&ville=" + document.getElementById("ville").value + "&telDomicile=" + document.getElementById("telDomicile").value + "&telPortable=" 
			+ document.getElementById("telPortable").value + "&mail=" + document.getElementById("mail").value + "&note=" + note + "&time=" + time  + "&note_rdv=" 
			+ document.getElementById("note_rdv").value + "&id_statut=" + Ext.get("id_statut").getValue(), "agenda_planning");
			
    setTimeout('afficher_calendrier(mois_planning,annee_planning)', 1000);
    DialogBox.hideDialog();
  }

 /**
 *  supprime l'appelant qui a ete annuler et n'affiche rien
 */
  function Supprime_AppelantRDV(idAppelant)
  {
    var today = new Date();
    var time = today.getTime();
    ouvrir("IHM/IHM_supprimeAppelant.php?idAppelant=" + idAppelant + "&time=" + time,"gestion");
     fermer_div_rdv();
  }



/*----------------------------------------------------------------------------*/
/* Activités */  
/*----------------------------------------------------------------------------*/  
  
  /**
 *  Affiche la gestion des activit‚s
 *  @param integer id de client dont on veut afficher les activit‚s
 */
  function affiche_Activite() {
    var today = new Date();
    var time = today.getTime();
    contenu = "gestion";
    ouvrir("IHM/IHM_Gestion_Activites.php?action=afficher&time=" + time,"contenu");
  }
  
  
  



/**
 *  Affiche la fenetre d'ajout d'une nouvelle activité‚
 */
  function nouvelle_activite(idClient)
  {
    var today = new Date();
    var time = today.getTime();
    
      ouvrir("IHM/IHM_Activite.php?action=ajouter&id_client=" + idClient + "&time=" + time,"PropActivite");

    
  }

  
  
/**
 *  ferme la fenetre d'‚dition d'une nouvelle activit‚
 */
  function annulerNouvelleActivite(idAct, idClient)
  {
    var today = new Date();
    var time = today.getTime();
      ouvrir("IHM/IHM_Activite.php?action=annulerAjout&idActivite=" + idAct + "&id_client=" + idClient + "&time=" + time,"PropActivite");

    
  }
  
/**
 *  ferme la fenetre d'‚dition d'une activit‚
 */
  function annulerActivite()
  {
      document.getElementById('PropActivite').innerHTML ="";
  
  }

  
/**
 *  ferme la fenetre d'‚dition d'une nouvelle activit‚
 */
  function sauvegardeActivite(idClient, idActivite)
  {
    var today = new Date();
    var time = today.getTime();
    
    if (isFinite(document.getElementById("duree").value) && document.getElementById("duree").value!= '' && document.getElementById("duree").value >= 0)
    {
 		
      ouvrir("IHM/IHM_Gestion_Activites.php?action=sauvegarde&id_client=" + idClient + "&idActivite=" + idActivite + "&nom=" + document.getElementById("nom").value + "&duree=" + document.getElementById("duree").value + "&description=" + document.getElementById("description").value + "&couleur=" + document.getElementById("couleur").value + "&time=" + time,"contenu");
    }
    else
    {
      Ext.MessageBox.alert('Erreur', "la duree n'est pas valide");
    }
    
  }
  
  
  
  /**
 *  ferme la fenetre d'‚dition d'une nouvelle activit‚
 */
  function modifie_activite(idAct, idClient)
  {
    var today = new Date();
    var time = today.getTime();
      ouvrir("IHM/IHM_Activite.php?action=modifier&idActivite=" + idAct + "&id_client=" + idClient + "&time=" + time,"PropActivite");

  }
  
  
  /**
 *  ferme la fenetre d'‚dition d'une nouvelle activit‚
 */
  function supprime_activite(idAct, idClient)
  {
    var today = new Date();
    var time = today.getTime();
    
    //on supprime uniquement si la reponse est affirmative
    Ext.MessageBox.confirm('Confirmation', 'Etes-vous sûr de vouloir supprimer cette activité ?', function(btn){if(btn=='yes'){
      	ouvrir("IHM/IHM_Gestion_Activites.php?action=supprimer&idActivite=" + idAct + "&id_client=" + idClient + "&time=" + time,"contenu");
      }}); 

  }



  
  /**
 *  on change de client, on doit donc recharger (num = le numero du select dans le menu)
 *     -l'agenda
 *     -le calendrier (pour connaitres les jours ou il reste des rendez-vous)
 *     -le header  
 */
  function change_Client(num, date, mois, annee) {
	ouvrir("IHM/IHM_Infos.php","infos");
	ToolBar.menuAgenda();

	pause=0;
	var today = new Date();
	var time = today.getTime();
	mois_planning  = today.getMonth()+1;
	annee_planning = today.getFullYear();
	idSelect = 'client'+num;
	IdOk = 'ok'+num;
	if(document.getElementById(idSelect).value != -1 ) {
		//on change la couleur du div du select pour voir lequel est selectionné‚
		changeCouleur(num);

		//chargement de l'agenda
		date_planning = date;

		ouvrir('IHM/IHM_Agenda.php?session=' + document.getElementById(idSelect).value + '&time='+time,'contenu');
		document.getElementById(IdOk).focus()

		if(contenu!='agenda') 	{
			contenu='agenda';
			$('contenu').innerHTML="<center><br><img src='./extjs/resources/images/default/grid/loading.gif'> Chargement des données</center>";
			setTimeout('rafraichir_planning()', 500); // amorcage de l'affichage et rafraichissement du planning dans la fenetre agenda
													  // on décale de 1000ms afin d'être sur que les div soient créées et puissent se remplir
													  //  > pourra sans doute être supprimé apres quelques tests plus poussés
		} else {
		   Select = idSelect;
		   $('contenu').innerHTML="<center><br><img src='./extjs/resources/images/default/grid/loading.gif'> Chargement des données</center>";
		   setTimeout('afficher_planning_change_client()', 500);
		}

		//chargement du header
		ouvrir('IHM/IHM_Header.php?session=' + document.getElementById(idSelect).value + '&time='+time,'header');

		//affichage du calendrier
		ouvrir('IHM/IHM_Calendrier.php?mois='+mois+'&annee='+annee+'&session=' + document.getElementById(idSelect).value + '&time='+time,'calendrier');
	}
	refreshMenu();
  }


  
  
  
  
  
  
  
  function appelinfo(num)
  {
	   

    if(document.getElementById('client'+num).value != -1 )
    {
      ouvrir("IHM/AppelVidePlage.php?type=1&id="+ document.getElementById('client'+num).value,"ok");
      
    }
    
  }
  
  
  

/**
 *Cette fonction sert a afficher le planning avec en plus, un arguent session qui est l'id du client dont on veut afficher le planning. 
 *Cette fonction est utile car pour d‚caler l'execution d'une fonction, on utilise un setTimeOut, mais on ne peut pas passer des variables en parametre dans le setTimeout car ils seront consid‚r‚ comme des string et non comme des valeurs. 
 */ 
 function afficher_planning_change_client()
  {
    var today = new Date();
    //var time = today.getTime();
    date_planning="";
	
    //ouvrir('IHM/IHM_Planning.php?date='+date_planning+'&session=' + document.getElementById(Select).value + '&time='+time,'agenda_planning');
	ouvrir('IHM/IHM_Planning.php?session=' + document.getElementById(Select).value,'agenda_planning');
  }






/**
 *Cette fonction cach le div contenant le nom des appelant ayant rendez-vous une date donne
 * 
 */ 
 function cache_Appelant_RDV()
 
  {
	clearTimeout(timerRafInfoAppelant);
    document.getElementById('info').style.display='none';
    document.getElementById('info').innerHTML="";
  }



/**
 *Cette fonction affiche le nom des appelant ayant rendez-vous a la date DateRDV.
 *note est la note associer au rendez-vous qui sera affich‚e si elle n'est pas vide 
 * 
 */ 
 function affiche_Appelant_RDV(DateRDV,i)
 
  {
	  clearTimeout(timerRafInfoAppelant);
	  timerRafInfoAppelant=setTimeout("affiche_Info_Appelant_RDV("+DateRDV+","+i+")",500);
	  
  }
   function affiche_Appelant_RDV_arch(DateRDV,i)
 
  {
	  clearTimeout(timerRafInfoAppelantArch);
	  timerRafInfoAppelantArch=setTimeout("affiche_Info_Appelant_RDV_arch("+DateRDV+","+i+")",500);
	
  }

  function affiche_Info_Appelant_RDV(DateRDV,i)
  {
		    var today = new Date();
		    var time = today.getTime();

		  	if(i==1){
		    	ouvrir('IHM/IHM_RDVAppelant.php?DateRDV=' + DateRDV + '&time=' + time,'info');
	    	}else{
		    	setTimeout("setC()",10);
	    	}

  }
  function affiche_Info_Appelant_RDV_arch(DateRDV,i)
  {
	  
		    var today = new Date();
		    var time = today.getTime();

		  	if(i==1){
		    	ouvrir('IHM/IHM_RDVAppelant_sauv.php?DateRDV=' + DateRDV + '&time=' + time,'info');
	    	}

  }
  
  function setC(){
	  try{																		//utilisation d'un try catch au cas ou l'info bulle est déjà masqué
		$('msgp').innerHTML='Cliquez ici pour ajouter un rendez-vous';
	}catch(ex){
	}
  }









     /**
     * Fonction de modification d'etat d'un rendez-vous
     **/ 
    function modifie_etat_rendez_vous(IdRDV)
    { 
	    
    var today = new Date();
    var time = today.getTime();    
  
      
      	ouvrir('IHM/IHM_Planning.php?action=modifieEtatRendezVous&etat='+document.getElementById('etat').value+'&IdRDV='+IdRDV+'&date='+date_planning+'&time='+time,'agenda_planning'); 
      	fermer_div_rdv();
        setTimeout('afficher_calendrier(mois_planning,annee_planning)', 1000);
        contenu='agenda';
        rafraichir_planning();
        DialogBox.hideDialog();
    }
    

     /**
     * Fonction de modification d'etat d'une activité d'un rendez-vous
     **/ 
    function modifie_activite_rendez_vous(IdRDV)
    { 
	    
    var today = new Date();
    var time = today.getTime();    
  
      
      ouvrir('IHM/IHM_Planning.php?action=modifieActiviteRendezVous&activite='+document.getElementById('activite').value+'&IdRDV='+IdRDV+'&date='+date_planning+'&time='+time,'agenda_planning'); 
      fermer_div_rdv();
        setTimeout('afficher_calendrier(mois_planning,annee_planning)', 1000);
         contenu='agenda';
         rafraichir_planning();
         DialogBox.hideDialog();
    }
    

/**
 *cette fonction change la couleur de fond du div contenant le Select dont on vient de choisir le client dans le menu
 *
 */  
function changeCouleur( num ) {
	idDiv = 'divclient'+num;
	document.getElementById('divclient1').style.backgroundColor = "white";
	document.getElementById('divclient2').style.backgroundColor = "white";
	document.getElementById('divclient3').style.backgroundColor = "white";
	document.getElementById('divclient4').style.backgroundColor = "white";
	document.getElementById('divclient5').style.backgroundColor = "white";
	document.getElementById('divclient6').style.backgroundColor = "white";
	document.getElementById(idDiv).style.backgroundColor = "#3f6fff";
}



/**
 *cette fonction affiche la page de facturation
 */ 
function affiche_facturation()
{
	ToolBar.init();
    var today = new Date();
    var time = today.getTime(); 
	genfact=0;	
    clearTimeout(timerRafPlanning);
    contenu='facturation';   
    interv=0;
	typeclient=1;
    ouvrir('IHM/IHM_Facturation.php?time='+time,'contenu'); 
}

function affiche_statistiques()
{
	ToolBar.init();
    var today = new Date();
    var time = today.getTime(); 
    clearTimeout(timerRafPlanning);
    contenu='facturation';   
    interv=0;
	typeclient=0;
    ouvrir('IHM/IHM_Statistiques.php?time='+time,'contenu'); 
}


function affiche_tableaufacturation()
{
	ToolBar.init();
    var today = new Date();
    var time = today.getTime(); 
    clearTimeout(timerRafPlanning);
    contenu='facturation';   
    interv=0;
	typeclient=1;
	$('contenu').innerHTML="<center><br><img src='./extjs/resources/images/default/grid/loading.gif'> Chargement des données</center>";
    ouvrir('IHM/IHM_TableauFacturation.php','contenu'); 
}

/**
 *cette fonction affiche la page de facturation avec les dates selectionner par l'utilisateur
 */

function changer_Facturation(id_client)
{
    var today = new Date();
    var time = today.getTime();
    var year = today.getFullYear()+1;
    var month = today.getMonth()+2;
    var moisSelect=document.getElementById('SLCTmois').value;
    var moisNum;
		contenu='facturation';
		
		switch(moisSelect){
			case 'Janvier':
				moisNum = 1;
			break;
			case 'Février'	:
				moisNum = 2;
			break;
			case 'Mars'	:
				moisNum = 3;
			break;
			case 'Avril'	:
				moisNum = 4;
			break;
			case 'Mai'	:
				moisNum = 5;
			break;
			case 'Juin'	:
				moisNum = 6;
			break;
			case 'Juillet'	:
				moisNum = 7;
			break;
			case 'Août'	:
				moisNum = 8;
			break;
			case 'Septembre'	:
				moisNum = 9;
			break;
			case 'Octobre'	:
				moisNum = 10;
			break;
			case 'Novembre'	:
				moisNum = 11;
			break;
			case 'Décembre'	:
				moisNum = 12;
			break;
						
		}
		
		if((document.getElementById('TXTannee').value > 2002) && (document.getElementById('TXTannee').value < year))
		{
		 	if(moisNum < month)
			{	
				window.open('IHM/IHM_Facturation_print.php?mois=' + moisNum + '&annee=' + document.getElementById('TXTannee').value);
			}
			else
			{
				Ext.MessageBox.alert('Erreur', "La facture n'est pas encore disponible");
			}
		}
		else
		{
	     Ext.MessageBox.alert('Erreur', "Votre saisie de l'année n'est pas correct. Elle doit etre comprise entre 2003 et "+(year-1));
		}
}
function valider_Facturation(id_client)
{
    var today = new Date();
    var time = today.getTime();
    var year = today.getFullYear()+1;
    var month = today.getMonth();
		contenu='facturation';
		
		if((document.getElementById('TXTannee').value > 2002) && (document.getElementById('TXTannee').value < year))
		{
		 	if(document.getElementById('SLCTmois').value < month)
			{	
				window.open('IHM/IHM_Facturation_print.php?mod=export&mois=' + document.getElementById('SLCTmois').value + '&annee=' + document.getElementById('TXTannee').value);
			}
			else
			{
				Ext.MessageBox.alert('Erreur', "La facture n'est pas encore disponible");
			}
		}
		else
		{
	     Ext.MessageBox.alert('Erreur', "Votre saisie de l'annee n'est pas correct. Elle doit etre comprise entre 2003 et "+(year-1));
		}
}
function afficher_facturesClient(){
	ToolBar.init();
	 clearTimeout(timerRafPlanning);
	contenu="Factures";
	ouvrir("IHM/IHM_Facturation_Client.php","contenu");
}

function affiche_gestionSecretaires(){
	 clearTimeout(timerRafPlanning);
	$('contenu').innerHTML="<center><br><img src='./extjs/resources/images/default/grid/loading.gif'> Chargement des données</center>";
	ToolBar.menuGestionSecr();
	contenu = "gestionSec";
	 ouvrir('IHM/IHM_Gestion_secretaires.php?mod=afficher','contenu'); 
}

function affiche_add_secr(loading){
	contenu = "gestionSec";
	ouvrir('IHM/IHM_Gestion_secretaires.php?mod=add&loading='+loading,'contenu'); 
}

function mod_secr(id){
	contenu = "gestionSec";
	if($('check').checked==true){
		check="SAD";
	}else{
		check='';
	}
	ouvrir("IHM/IHM_Gestion_secretaires.php?mod=mod&id_admin="+id+"&nom="+$('nom').value+"&mdp="+$('mdp').value+"&droit="+check,'contenu'); 
}
function add_secr(){
	contenu = "gestionSec";
	if($('check').checked==true){
		check="SAD";
	}else{
		check='';
	}
	ouvrir("IHM/IHM_Gestion_secretaires.php?mod=add&nom="+$('nom').value+"&mdp="+$('mdp').value+"&droit="+check,'contenu'); 
}
function affiche_mod_secr(id){
	contenu = "gestionSec";
	ouvrir('IHM/IHM_Gestion_secretaires.php?mod=mod&id='+id,'contenu'); 
}

  
function del_secr(id){
	contenu = "gestionSec";
	Ext.MessageBox.confirm('Confirmation', 'Etes-vous sûr de vouloir supprimer le secrétaire sélectionné?', function(btn){if(btn=='yes'){
		ouvrir('IHM/IHM_Gestion_secretaires.php?mod=del&id='+id,'contenu'); 
	}});
}
/**
 *cette fonction affiche la page historique
 */ 
function affiche_historique(limit)
{
	 clearTimeout(timerRafPlanning);
	ToolBar.menuHistorique();	
   contenu = "historiques";
   ouvrir('IHM/IHM_Historique.php?limit='+limit,'contenu'); 
   setTimeout("afficheTextBtnProtect()",200);
}

function affiche_histo_recherche(){
	 contenu = "historiques";
   ouvrir('IHM/IHM_Historique.php?mode=search','contenu'); 
   setTimeout("afficheTextBtnProtect()",200);
}
function affiche_histo_prev(){
	 contenu = "historiques";
   ouvrir('IHM/IHM_Historique.php?mode=prev','contenu'); 
   setTimeout("afficheTextBtnProtect()",200);
}
function histo_restaurer(id){
   contenu = "historiques";
   ouvrir('IHM/IHM_Historique.php?mode=restor&id='+id,'contenu'); 	
   setTimeout("afficheTextBtnProtect()",200);
}
function histo_search(){
	contenu = "historiques";
   ouvrir('IHM/IHM_Historique.php?mode=search&id_client='+$('id_client').value+'&id_admin='+$('id_admin').value+'&date_deb='+$('date_deb').value+'&date_fin='+$('date_fin').value+'&mot='+$('mot').value+'&limit='+$('limit').value,'contenu'); 	
   setTimeout("afficheTextBtnProtect()",200);
}
function protectDel(){
	if(SupprProtect==1){
		SupprProtect=0;
		$('protectBtn').innerHTML='Desactiver la protection de la suppression';
	}else{
		SupprProtect=1;	
		$('protectBtn').innerHTML='Activer la protection de la suppression';
	}
}
function afficheTextBtnProtect(){
	if(SupprProtect==0){
		$('protectBtn').innerHTML='Desactiver la protection de la suppression';
	}else{
		$('protectBtn').innerHTML='Activer la protection de la suppression';
	}
}
function histo_delete(id,mod,limit){
	if(SupprProtect==1){
		 ouvrir('IHM/IHM_Historique.php?mode=del&id='+id,''); 	
		 if(mod=='search'){
			histo_search();
		 }else{
			affiche_historique(limit); 
		 }
	 }else{
		
			Ext.MessageBox.confirm('Confirmation', 'Etes-vous sûr de vouloir supprimer cette action?\n(Suppression irréversible)', function(btn){if(btn=='yes'){
				 ouvrir('IHM/IHM_Historique.php?mode=del&id='+id,''); 	
				 if(mod=='search'){
					histo_search();
				 }else{
					affiche_historique(limit); 
				 }
			}});
			
		
	 }
}
/**    
     *Fonction d'affichage du calendrier des vacances
     *@param int mois a afficher dans le calendrier
     *@param int annee a afficher dans le calendrier
     **/
function affiche_vacances(annee){
	 clearTimeout(timerRafPlanning);
	ToolBar.menuVacances();
	contenu = "vacances";
	  
	ouvrir("IHM/IHM_Vacances.php?annee="+annee,"contenu");
}
    
function affiche_mod_vac(id,annee){
	DialogBox.showDialog();
	DialogBox.resize(460,230);
	DialogBox.setTitre('Modification de Vacances');
	contenu = "vacances";
	ouvrir("IHM/IHM_Vacances.php?annee="+annee+"&mod=mod&id="+id,"agenda_rdv");	
}
function mod_vac(id){
	contenu = "vacances";
	ouvrir("IHM/IHM_Vacances.php?&mod=mod&id="+id+"&zone="+$('zone').value+"&nom="+$('nom').value+"&date_deb="+$('date_deb').value+"&date_fin="+$('date_fin').value+"&annee="+$('annee').value,"");	
	curTabAnnee = tabsAnnee.getActiveTab();
	tabsAnnee.activate('annee1');
	tabsAnnee.activate('annee2');
	tabsAnnee.activate(curTabAnnee.id);
}
function del_vac(id){
	contenu = "vacances";
	Ext.MessageBox.confirm('Confirmation', 'Etes-vous sûr de vouloir supprimer ?', function(btn){if(btn=='yes'){
			ouvrir("IHM/IHM_Vacances.php?&mod=del&id="+id,"");	
			curTabAnnee = tabsAnnee.getActiveTab();
			tabsAnnee.activate('annee1');
			tabsAnnee.activate('annee2');
			tabsAnnee.activate(curTabAnnee.id);
		}});
}
function add_vac(){
	contenu = "vacances";
	ouvrir("IHM/IHM_Vacances.php?&mod=add&nom="+$('nom').value+"&date_debA="+$('date_debA').value+"&date_finA="+$('date_finA').value+"&date_debB="+$('date_debB').value+"&date_finB="+$('date_finB').value+"&date_debC="+$('date_debC').value+"&date_finC="+$('date_finC').value+"&annee="+$('annee').value,"");	
	curTabAnnee = tabsAnnee.getActiveTab();
	tabsAnnee.activate('annee1');
	tabsAnnee.activate('annee2');
	tabsAnnee.activate(curTabAnnee.id);
	
}
function affiche_ajout_vac(){
	DialogBox.showDialog();
	DialogBox.resize(460,390);
	DialogBox.setTitre('Ajout de Vacances');
	contenu = "vacances";
	ouvrir("IHM/IHM_Vacances.php?mod=add","agenda_rdv");
}


 function infobulle_hide()
 
  {
    document.getElementById('info').style.display='none';
    document.getElementById('info').innerHTML="";
  }




 function infobulle_show()
 
  {
	  if(document.getElementById('info').style.display='none'){

		    document.getElementById('info').style.display='block';
		  	document.getElementById('info').style.top = Y+20;
		  	document.getElementById('info').style.left = X-90;
		  	document.getElementById('info').innerHTML="Annuler cette action";
		    
	   }
  }
  



  /************GRPAHIQUES*************/
  function affiche_stat(){
	   clearTimeout(timerRafPlanning);
	  ToolBar.init();
	  contenu = "stat";
	  ouvrir('IHM/IHM_Charts.php?graph=1','contenu'); 	
  }
 
  function graph2(){
	  contenu = "stat";
	  ouvrir('IHM/IHM_Charts.php?graph=2&id_client='+$('id_client').value+'&date_deb='+$('date_deb').value+'&date_fin='+$('date_fin').value,'contenu'); 	
  }
  

function afficher_agenda_arch(date){
	    ToolBar.menuAgendaArch();
	    var today = new Date();
        var time = today.getTime();
        
        
       afficher_calendrier_arch(mois_planning_arch,annee_planning_arch);
        
       clearTimeout(timerRafPlanning);
       clearTimeout(timerRafCal);
	        if(contenu!='agenda_arch'){
		          contenu='agenda_arch';
		          ouvrir("IHM/IHM_Agenda_sauv.php?time="+time,"contenu");
		          setTimeout("afficher_agenda_arch("+date+")",500);
		         
	        }                                                  //  > pourra sans doute être supprimé apres quelques tests plus poussés
	        else {
		        $('agenda_planning').innerHTML="<center><br><img src='./extjs/resources/images/default/grid/loading.gif'> Chargement des données</center>";
	          ouvrir("IHM/IHM_Planning_sauv.php?date="+date+"&time="+time,"agenda_planning");
	         
	        } 
        
    } 
    function afficher_agenda_arch_client(date){
	    ToolBar.menuAgendaArchClient();
	    var today = new Date();
        var time = today.getTime();
        
        
        afficher_calendrier_arch(mois_planning_arch,annee_planning_arch);
        
       clearTimeout(timerRafPlanning);
       clearTimeout(timerRafCal);
	        if(contenu!='agenda_arch'){
		          contenu='agenda_arch';
		          ouvrir("IHM/IHM_Agenda_sauv.php?time="+time,"contenu");
		          setTimeout("afficher_agenda_arch_client("+date+")",500);
		         
	        }                                                  //  > pourra sans doute être supprimé apres quelques tests plus poussés
	        else {
		        $('agenda_planning').innerHTML="<center><br><img src='./extjs/resources/images/default/grid/loading.gif'> Chargement des données</center>";
	          ouvrir("IHM/IHM_Planning_sauv.php?date="+date+"&time="+time,"agenda_planning");
	         
	        } 
        
    }  
    
    
function afficher_calendrier_arch(mois,annee){
	   
    var today = new Date();
    var time = today.getTime();
    mois_planning_arch  = mois;
    annee_planning_arch = annee;
    
    ouvrir("IHM/IHM_Calendrier_sauv.php?mois="+mois+"&annee="+annee+"&time="+time,"calendrier");
}
    
    








var tab_checked=new Array();

function affiche_archive(){
	 clearTimeout(timerRafPlanning);
	contenu='archive';
	ouvrir("IHM/IHM_Archivage.php?mod=afficher","agenda");
}
function cleanBdd(){
	tab_checked=new Array();
	 var choix = document.formulaire.cases;
	  for (i = 0; i < choix.length; i++){
          if(choix[i].checked == true){
           		tab_checked.push(choix[i].value);
           		
          }
      }
      ouvrir("IHM/IHM_Archivage.php?mod=clean&tab="+tab_checked,"agenda");
}

function checkAll(){
	var choix = document.formulaire.cases;
	  for (i = 0; i < choix.length; i++){
         choix[i].checked = true;
      }	
}

function uncheckAll(){
	var choix = document.formulaire.cases;
	  for (i = 0; i < choix.length; i++){
         choix[i].checked = false;
      }	
}

function reverseCheck(){
	var choix = document.formulaire.cases;
	  for (i = 0; i < choix.length; i++){
         if(choix[i].checked == true){
             choix[i].checked = false;
         }else{
             choix[i].checked = true;
         }
      }	
}

	/**
	 * refreshMenu
	 * Fonction dédiée au rafraîchissement de certains éléments du menu principal
	 * 
	 **/
	function refreshMenu() {
		refreshNbNotes();
		refreshNbConsignes();
		setTimeout( "refreshMenu()", 60000 );
	}

	function refreshNbNotes() {
		ouvrir("IHM/IHM_Note_Seule.php?action=refreshNbNotes","nbNote");	
	}
	
	function refreshNbConsignes() {
		ouvrir("IHM/IHM_Note_Seule.php?action=refreshNbConsignes","nbConsignes");	
	}
	

 /**    
     *Fonction d'affichage du menu
     *@param int timestamp de la date a afficher     
     **/
    function afficher_params(){
	     clearTimeout(timerRafPlanning);
	    contenu='param';
   		ouvrir("IHM/IHM_Params.php?&mod=afficher","contenu");
    }
    
    function affiche_params_factures(){
	     clearTimeout(timerRafPlanning);
	    contenu='param';
   		ouvrir("IHM/IHM_Params.php?&mod=afficher","contenu");
    }
    
    function params_modif(){
	    contenu='param';
	    ouvrir("IHM/IHM_Params.php?&mod=modifier&capital="+$('capital').value+"&rcs="+$('rcs').value+"&siren="+$('siren').value+"&numtva="+$('numtva').value+"&titre="+$('titre').value+"&adresse="+$('adresse').value+"&code="+$('code').value+"&ville="+$('ville').value+"&tel="+$('tel').value+"&rmq="+$('rmq').value+"&capitalLBM="+$('capitalLBM').value+"&rcsLBM="+$('rcsLBM').value+"&sirenLBM="+$('sirenLBM').value+"&numtvaLBM="+$('numtvaLBM').value+"&titreLBM="+$('titreLBM').value+"&adresseLBM="+$('adresseLBM').value+"&codeLBM="+$('codeLBM').value+"&villeLBM="+$('villeLBM').value+"&telLBM="+$('telLBM').value+"&rmqLBM="+$('rmqLBM').value,"contenu");
	    
    }
    
function affiche_chatHisto(){
	var id_admin=document.getElementById('admin').value;
	var id_client=document.getElementById('client').value;
	ouvrir("IHM_ChatHisto.php?id_admin="+id_admin+"&id_client="+id_client,"contenu");	
}

function listeTranchesLibres(id_act){
		DialogBox.showDialog();
	    DialogBox.resize(620,120);
	   
	    ouvrir("IHM/IHM_TranchesLibres.php?date="+date_planning+"&action=afficher&id_act="+id_act,"agenda_rdv");
}


function getMonthCombo(combo){
	 var moisSelect=document.getElementById(combo).value;
    	var moisNum;
		
		
		switch(moisSelect){
			case 'Janvier':
				moisNum = 1;
			break;
			case 'Fevrier'	:
				moisNum = 2;
			break;
			case 'Mars'	:
				moisNum = 3;
			break;
			case 'Avril'	:
				moisNum = 4;
			break;
			case 'Mai'	:
				moisNum = 5;
			break;
			case 'Juin'	:
				moisNum = 6;
			break;
			case 'Juillet'	:
				moisNum = 7;
			break;
			case 'Aout'	:
				moisNum = 8;
			break;
			case 'Septembre'	:
				moisNum = 9;
			break;
			case 'Octobre'	:
				moisNum = 10;
			break;
			case 'Novembre'	:
				moisNum = 11;
			break;
			case 'Decembre'	:
				moisNum = 12;
			break;
						
		}
		return moisNum;	
}

function checkNbArch(){
	var today = new Date();
    var month = today.getMonth();
    var year = today.getFullYear();
    if(year==$("TXTannee").value){
	    if(getMonthCombo("SLCTmois")<month){
		    ouvrir("IHM/IHM_Archivage.php?mod=NbRdv&mois="+getMonthCombo("SLCTmois")+"&annee="+$("TXTannee").value,"nbArch")	
		    
		}else{
			Ext.MessageBox.alert('Erreur', 'Vous ne pouvez pas archiver les rendez-vous qui n\'ont pas plus d\'un mois');			
		}
	}else{
		 ouvrir("IHM/IHM_Archivage.php?mod=NbRdv&mois="+getMonthCombo("SLCTmois")+"&annee="+$("TXTannee").value,"nbArch")		
	}
	
}


function archive(){
	var today = new Date();
    var month = today.getMonth();
    var year = today.getFullYear();
    if(year==$("TXTannee").value){
	    if(getMonthCombo("SLCTmois")<month){
		     
		   window.open("IHM/IHM_Archivage.php?mod=archiver&mois="+getMonthCombo("SLCTmois")+"&annee="+$("TXTannee").value);
		   	
		}else{
			Ext.MessageBox.alert('Erreur', 'Vous ne pouvez pas archiver les rendez-vous qui n\'ont pas plus d\'un mois');			
		}
	}else{
		  window.open("IHM/IHM_Archivage.php?mod=archiver&mois="+getMonthCombo("SLCTmois")+"&annee="+$("TXTannee").value);
	}

}





function modifier_etat(){
	
	DialogBox.showDialog();	
	DialogBox.resize(400,60);
	DialogBox.setTitre('Modification de l\'etat');

	$('agenda_rdv').innerHTML="<center><br /><img src='./extjs/resources/images/default/grid/loading.gif'> Chargement des données</center>";
	var today = new Date();
    var time = today.getTime();
	ouvrir('IHM/IHM_Traitement.php?date='+date_planning+'&time='+time+'&mod=etat','agenda_rdv');
}

function selectionner(jour){
	var rdv_chgt = document.form_planning.rdv_chgt;
	var begin=0,end=0;
	var val='check'+jour;
	for( i=0; i<rdv_chgt.length;i++)
	           {
		           
		           	if(rdv_chgt[i].id==val){
			           	if (rdv_chgt[i].checked==true)
 	             		{
	 	             		rdv_chgt[i].checked=false;
 	             		}else{
			           		rdv_chgt[i].checked=true;
		           		}
		           	}

	           }	
}

function changePause(){
	if (pause==0){
		$('pauseDiv').style.visibility='visible';
		clearTimeout(timerRafCal);		
		clearTimeout(timerRafPlanning);
		pause=1;
	}else if(pause==1){
		$('pauseDiv').style.visibility='hidden';
		rafraichir_planning();
		rafraichir_calendrier();
		pause=0;
	}
	
}



function setDate(champ,day,month,year){
	date=day+'/'+month+'/'+year;
	setTimeout("$('"+champ+"').value='"+date+"'",700);
}


function imprimer(){
	window.open('IHM/IHM_Impression.php?date='+date_planning+'&typeimp=sem');
}
function imprimerJ(date){
	window.open('IHM/IHM_Impression.php?date='+date);
}

String.prototype.trim = function(){
	return this.replace(/^\s+/, "").replace(/\s+$/, "");
}

function affiche_histoChat(){
	chatHisto.init();
}




function LesStats()
			   {
			    var mois1=document.getElementById("mois1").value;
				var an1=document.getElementById("an1").value;
				
				if (typeclient==0)
				 var idclient=document.getElementById("secretaire").value;
				if (typeclient==1)
				 var idclient=document.getElementById("client").value;
				if (typeclient==2)
				 var idclient=document.getElementById("categorie").value;
				 
				$('contenu').innerHTML="<center><br><img src='./extjs/resources/images/default/grid/loading.gif'> Calcul des Statistiques</center>";
				ouvrir("IHM/IHM_Statistiques.php?stats=1&mois1="+mois1+"&an1="+an1+"&typeclient="+typeclient+"&idclient="+idclient,"contenu");
				
				
			   }
			   
/*----------------------------------------------------------------------------*/
/* Statuts */  
/*----------------------------------------------------------------------------*/  
  
	function affiche_Statut() {
		var today = new Date();
		var time = today.getTime();
		contenu = "gestion";
		ouvrir("IHM/IHM_Gestion_Statuts.php?action=afficher&time=" + time,"contenu");
	}
  
	function nouveau_statut( idClient ) {
		var today = new Date();
		var time = today.getTime();
		ouvrir("IHM/IHM_Statut.php?action=ajouter&id_client=" + idClient + "&time=" + time,"PropStatut");
	}
  
	function annulerNouveauStatut( idStatut, idClient ) {
		var today = new Date();
		var time = today.getTime();
		ouvrir("IHM/IHM_Statut.php?action=annulerAjout&idStatut=" + idStatut + "&id_client=" + idClient + "&time=" + time,"PropStatut");
	}
  
	function annulerStatut() {
		document.getElementById('PropStatut').innerHTML ="";
	}

	function sauvegardeStatut( idClient, idStatut )  {
		var today = new Date();
		var time = today.getTime();
		ouvrir("IHM/IHM_Gestion_Statuts.php?action=sauvegarde&id_client=" + idClient + "&idStatut=" + idStatut + "&nom=" + document.getElementById("nom").value + "&description=" + document.getElementById("description").value + "&couleur=" + document.getElementById("couleur").value + "&time=" + time,"contenu");
	}
  
	function modifie_statut( idStatut, idClient ) {
		var today = new Date();
		var time = today.getTime();
		ouvrir("IHM/IHM_Statut.php?action=modifier&idStatut=" + idStatut + "&id_client=" + idClient + "&time=" + time,"PropStatut");
	}
  
	function supprime_statut( idStatut, idClient ) {
		var today = new Date();
		var time = today.getTime();
    
        Ext.MessageBox.confirm('Confirmation', 'Etes-vous sûr de vouloir supprimer ce statut  ?', function(btn){if(btn=='yes'){
			ouvrir("IHM/IHM_Gestion_Statuts.php?action=supprimer&idStatut=" + idStatut + "&id_client=" + idClient + "&time=" + time,"contenu");
		}}); 
	}
			  

