function detailsRDV(id_rdv) {
  var param = "id="+id_rdv ;
  // alert($("#cf_url").val()+"/rdv/details_rdv?"+param) ;
  $.ajax({
    type:"POST",
    url:$("#cf_url").val()+"/rdv/details_rdv",
    data:param,
    success:function(msg){
      $("#div_dialog").html(msg) ;
      $('#dialog-deatils_rdv').modal('show') ;
      $('#dialog-deatils_rdv').on('shown.bs.modal', function () {

      }) ;
      $('#dialog-deatils_rdv').on('hide.bs.modal', function () {
        grille() ;
      }) ;
    }
  }) ;
}
function initScan(id_patient_scan) {
  var streaming = false,
      video        = document.querySelector('#video'),
      cover        = document.querySelector('#cover'),
      canvas       = document.querySelector('#canvas'),
      photo        = document.querySelector('#photo'),
      startbutton  = document.querySelector('#startbutton'),
      width = 640,
      height = 0;

      // const constraints = {
      //   video: {
      //     width: { min: 640, ideal: 1920, max: 1920 },
      //     height: { min: 400, ideal: 1080 },
      //     // aspectRatio: 1.777777778,
      //     // frameRate: { max: 30 },
      //     facingMode: "environment"
      //   }
      // };

  navigator.getMedia = ( navigator.getUserMedia ||
                         navigator.webkitGetUserMedia ||
                         navigator.mozGetUserMedia ||
                         navigator.msGetUserMedia);

  navigator.getMedia(
    {
      video: true,
      audio: false
    },
    function(stream) {
      if (navigator.mozGetUserMedia) {
        video.mozSrcObject = stream;
        video.srcObject = stream;
      } else {
        video.srcObject = stream;
        // var vendorURL = window.URL || window.webkitURL;
        // video.src = vendorURL.createObjectURL(stream);
      }
      video.play();
    },
    function(err) {
      alert("VERIFIEZ QUE VOTRE WEBCAM N'EST PAS UTILISEE PAR UNE AUTRE APPLICATION") ;
      console.log("An error occured! " + err);
    }
  );

  video.addEventListener('canplay', function(ev){
    if (!streaming) {
      width = video.videoWidth ;
      height = video.videoHeight / (video.videoWidth/width);
      var btnWidth = parseInt($("#startbutton").width()) ;
      var btnHeight = parseInt($("#startbutton").height()) ;
      // alert(btnWidth) ;
      // alert(btnHeight) ;
      $("#startbutton").css("top",(height-(btnHeight+20))+"px") ;
      $("#startbutton").css("left",(width/2)+"px") ;
      $("#startbutton").css("visibility","visible") ;
      video.setAttribute('width', width);
      video.setAttribute('height', height);
      canvas.setAttribute('width', width);
      canvas.setAttribute('height', height);
      streaming = true;
    }
  }, false);

  function takepicture() {
    canvas.width = width;
    canvas.height = height;
    canvas.getContext('2d').drawImage(video, 0, 0, width, height);
    // var data = canvas.toDataURL('image/png');
    // alert(canvas.toDataURL('image/base64')) ;
    var param = "id_patient_scan="+id_patient_scan+"&base64="+encodeURIComponent(canvas.toDataURL('image/base64')) ;
    // alert($("#cf_url").val()+"/scan/scan_document?"+param) ;
    $.ajax({
      type: "POST",
      url: $("#cf_url").val()+"/scan/scan_document",
      data: param,
      success: function(msg){
        $('#scanModal').modal('hide') ;
      }
    });
    // photo.setAttribute('src', data);
  }

  startbutton.addEventListener('click', function(ev){
      takepicture();
    ev.preventDefault();
  }, false);
}
function scanDoc() {

  var id_rdv = $("#id_rdv_scan").val() ;
  var id_patient_scan = $("#id_patient_scan").val() ;
  var param = "id_patient_scan="+$("#id_patient_scan").val()+"&id_rdv="+id_rdv ;

  $('#dialog-deatils_rdv').modal('hide') ;
  $("#div_dialog").html("") ;
  $('#dialog-deatils_rdv').modal('dispose') ;
  // alert($("#cf_url").val()+"/scan/simple?"+param) ;
  $.ajax({
    type:"POST",
    url:$("#cf_url").val()+"/scan/simple",
    data:param,
    success:function(msg){
      $("#div_dialog").html(msg) ;
      $('#scanModal').modal('show') ;
      $('#scanModal').on('shown.bs.modal', function () {

        initScan(id_patient_scan) ;
        /*
        // alert("ici") ;
        feather.replace();

        const controls = document.querySelector('.controls');
        const cameraOptions = document.querySelector('.video-options>select');
        // const facingOptions = document.querySelector('.facing-options>select');
        const video = document.querySelector('video');
        const canvas = document.querySelector('canvas');
        const screenshotImage = document.querySelector('img');
        const buttons = [...controls.querySelectorAll('button')];
        let streamStarted = false;

        const [play, pause, screenshot] = buttons;
        // alert($("#facingMode").val()) ;
        const constraints = {
          video: {
            width: {
              min: 1280,
              ideal: 1920,
              max: 2560,
            },
            height: {
              min: 720,
              ideal: 1080,
              max: 1440
            },
            facingMode: "environment"
          }
        };

        play.onclick = () => {
          if (streamStarted) {
            video.play();
            play.classList.add('d-none');
            // pause.classList.remove('d-none');
            return;
          }
          if ('mediaDevices' in navigator && navigator.mediaDevices.getUserMedia) {
            const updatedConstraints = {
              ...constraints,
              deviceId: {
                exact: cameraOptions.value
              }
            };
            startStream(updatedConstraints);
          }
        };

        cameraOptions.onchange = () => {
          const updatedConstraints = {
            ...constraints,
            deviceId: {
              exact: cameraOptions.value
            }
          };

          startStream(updatedConstraints);
        };

        const pauseStream = () => {
          video.pause();
          play.classList.remove('d-none');
          pause.classList.add('d-none');
        };

        const doScreenshot = () => {
          canvas.width = video.videoWidth;
          canvas.height = video.videoHeight;
          canvas.getContext('2d').drawImage(video, 0, 0);
          screenshotImage.src = canvas.toDataURL('image/webp');
          screenshotImage.classList.remove('d-none');
          var param = "id_patient_scan="+id_patient_scan+"&base64="+encodeURIComponent(canvas.toDataURL('image/base64')) ;
          // alert($("#cf_url").val()+"/scan/scan_document?"+param) ;
          $.ajax({
            type: "POST",
            url: $("#cf_url").val()+"/scan/scan_document",
            data: param,
            success: function(msg){
              $('#scanModal').modal('hide') ;
            }
          });
          // alert(canvas.toDataURL('image/base64')) ;
        };

        const doChange = () => {

        };

        pause.onclick = pauseStream;
        screenshot.onclick = doScreenshot;
        // change.onclick = doChange;

        const startStream = async (constraints) => {
          const stream = await navigator.mediaDevices.getUserMedia(constraints);
          handleStream(stream);
        };


        const handleStream = (stream) => {
          video.srcObject = stream;
          play.classList.add('d-none');
          // pause.classList.remove('d-none');
          screenshot.classList.remove('d-none');
          change.classList.remove('d-none');

        };


        const getCameraSelection = async () => {
          const devices = await navigator.mediaDevices.enumerateDevices();
          const videoDevices = devices.filter(device => device.kind === 'videoinput');
          const options = videoDevices.map(videoDevice => {
            return `<option value="${videoDevice.deviceId}">${videoDevice.label}</option>`;
          });
          cameraOptions.innerHTML = options.join('');
        };

        getCameraSelection();


          if (streamStarted) {
            video.play();
            play.classList.add('d-none');
            pause.classList.remove('d-none');
            return;
          }
          if ('mediaDevices' in navigator && navigator.mediaDevices.getUserMedia) {
            const updatedConstraints = {
              ...constraints,
              deviceId: {
                exact: cameraOptions.value
              }
            };
            startStream(updatedConstraints);
          }

          */

      }) ;
      $('#scanModal').on('hide.bs.modal', function () {
        detailsRDV(id_rdv) ;
      }) ;
    }
  }) ;

}

function jourDate(date) {
  $("#date").val(date) ;
  $("#affJ").prop('checked',true)
  grille() ;
}

function grilleRestant() {
  var aff = $('input[type=radio][name=aff]:checked').attr('value');
  var param = "aff="+aff+"&date="+$("#date").val() ;
  param+="&rech_voir="+$("#rech_voir").val() ;
  // alert($("#cf_url").val()+"/agenda/grille_restant?"+param) ;
  $.ajax({
    type:"POST",
    url:$("#cf_url").val()+"/agenda/grille_restant",
    data:param,
    success:function(msg){
      $("#restant").html(msg) ;
    }
  }) ;
}
function grilleEffectuee() {
  var aff = $('input[type=radio][name=aff]:checked').attr('value');
  var param = "aff="+aff+"&date="+$("#date").val() ;
  param+="&rech_voir="+$("#rech_voir").val() ;

  // alert($("#cf_url").val()+"/agenda/grille_effectuee?"+param) ;
  $.ajax({
    type:"POST",
    url:$("#cf_url").val()+"/agenda/grille_effectuee",
    data:param,
    success:function(msg){
      $("#effectuee").html(msg) ;
    }
  }) ;
}
function grille() {
  var aff = $('input[type=radio][name=aff]:checked').attr('value');
  var param = "aff="+aff+"&date="+$("#date").val() ;
  param+="&rech_voir="+$("#rech_voir").val() ;
  // alert($("#cf_url").val()+"/agenda/grille?"+param) ;
  $.ajax({
    type:"POST",
    url:$("#cf_url").val()+"/agenda/grille",
    data:param,
    success:function(msg){
      $("#div_grille").html(msg) ;
      grilleRestant() ;
      grilleEffectuee() ;
    }
  }) ;
}

function grilleToDate(date) {
  // alert(date) ;
  $("#date").val(date) ;
  grille() ;
}

function affAlertErr(txt) {
  $("#div_alert_err").html("<div class=\"alert alert-warning alert-dismissible fade show\" role=\"alert\">"+txt+"<button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"alert\" aria-label=\"Close\"></button></div>") ;
}


function traitNewRdv() {
  var type_new = $('input[type=radio][name=type_new]:checked').attr('value') ;
  var frequence_new = $('input[type=radio][name=frequence_new]:checked').attr('value') ;
  $("#div_alert_err").html("") ;
  // var petit_matin = 0 ;
  // if($("#new_petit_matin").is(":checked")) petit_matin = 1 ;
  // var mms = 0 ;
  // if($("#new_mms").is(":checked")) mms = 1 ;
  var type_acte = $('input[type=radio][name=new_type_acte]:checked').attr('value') ; // unique ou multiple
  var type_repete = $("#new_acte_type_repete").val() ; // j,s,m,a
  var fin_actes = $('input[type=radio][name=fin_actes]:checked').attr('value'); // d ou o (date ou occurence)
  var liste_semaine = "" ;
  var cpt=0;
  $("a.case_jour_sel").each(function(){
    if(cpt>0) liste_semaine+="," ;
    liste_semaine+=$(this).attr('rel') ;
    cpt++;
  }) ;
  if($("#new_id_patient").val()=="0"){
    affAlertErr("Vous devez séléctionner un patient pour continuer") ;
    $("#new_id_patient").focus() ;
  }
  else if($("#new_id_acte").val()=="0"){
    affAlertErr("Vous devez séléctionner un acte pour continuer") ;
    $("#new_id_acte").focus() ;
  }
  else if(type_acte=="multiple" && (isNaN($("#new_acte_diff_repete").val()) || $("#new_acte_diff_repete").val()=="" ) ){
    affAlertErr("La valeur n'est pas correct...") ;
    $("#new_acte_diff_repete").focus() ;
  }
  else if(type_acte=="multiple" && type_repete=="s" && liste_semaine==""){ // SI ON A AUCUN JOUR COCHE ALORS QU'ON A CHOISI LA REPETITION PAR SEMAINE
    affAlertErr("Veuillez choisir au moins un jour de la semaine...") ;
  }
  else if(type_acte=="multiple" && fin_actes=="d" && !isDateValide($("#new_acte_date_fin").val())){
    affAlertErr("Date de fin non valide. Format requis dd/mm/YYYY") ;
    $("#new_acte_date_fin").focus() ;
  }
  else if(type_acte=="multiple" && fin_actes=="o" && (isNaN($("#new_acte_nb_o").val()) || $("#new_acte_nb_o").val()=="") ){
    affAlertErr("Nombre d'occurences requises incorrect.") ;
    $("#new_acte_nb_o").focus() ;
  }
  else{
    // alert("OK TOUT BON") ;

    var renouvelable = 0 ;
    if($("#new_acte_renouvelable").is(":checked")) renouvelable = 1 ;
    var param = "id_bo_user="+$("#new_id_bo_user").val() ;
    param+="&new_date="+$("#new_date").val() ;
    param+="&id_patient="+$("#new_id_patient").val() ;
    param+="&id_acte="+$("#new_id_acte").val() ;
    param+="&type_acte="+type_acte ;
    param+="&diff_repete="+$("#new_acte_diff_repete").val() ;
    param+="&type_repete="+type_repete ;
    param+="&liste_semaine="+liste_semaine ;
    param+="&choix_repete_mois="+$("#choix_repete_mois").val() ;
    param+="&fin_actes="+fin_actes ;
    param+="&date_fin="+$("#new_acte_date_fin").val() ;
    param+="&nb_o="+$("#new_acte_nb_o").val() ;
    param+="&renouvelable="+renouvelable ;
    param+="&type_new="+type_new ;
    param+="&frequence_new="+frequence_new ;
    param+="&horaire_souhaite="+encodeURIComponent($("#horaire_souhaite").val()) ;
    // param+="&petit_matin="+petit_matin ;
    // param+="&mms="+mms ;
    // alert(type_new) ;
    // alert($("#cf_url").val()+"/rdv/trait_new_rdv?"+param) ;
    $.ajax({
      type:"POST",
      url:$("#cf_url").val()+"/rdv/trait_new_rdv",
      data:param,
      success:function(msg){
        // if(msg!="") alert(msg) ;
        $('#dialog-rdv').modal('hide') ;
      }
    }) ;

  }

}

function radioFinActes() {
  $("#div_alert_err").html("") ;
  var fin_actes = $('input[type=radio][name=fin_actes]:checked').attr('value');
  if(fin_actes=="d"){
    $( "#new_acte_date_fin" ).prop( "disabled", false );
    $( "#new_acte_nb_o" ).prop( "disabled", true );
  }
  else {
    $( "#new_acte_date_fin" ).prop( "disabled", true );
    $( "#new_acte_nb_o" ).prop( "disabled", false );
  }
}

function newRdvDetailsRepete() {
  $("#div_alert_err").html("") ;
  var type_acte = $('input[type=radio][name=new_type_acte]:checked').attr('value');
  var param = "id_bo_user="+$("#new_id_bo_user").val() ;
  param+="&new_date="+$("#new_date").val() ;
  param+="&id_patient="+$("#new_id_patient").val() ;
  param+="&id_acte="+$("#new_id_acte").val() ;
  param+="&type_acte="+type_acte ;
  param+="&diff_repete="+$("#new_acte_diff_repete").val() ;
  param+="&type_repete="+$("#new_acte_type_repete").val() ;
  // alert($("#cf_url").val()+"/rdv/details_repete?"+param) ;
  $.ajax({
    type:"POST",
    url:$("#cf_url").val()+"/rdv/details_repete",
    data:param,
    success:function(msg){
      $("#div_new_details_repete").html(msg) ;

      $("a.case_jour").click(function(){
        if( $(this).hasClass("case_jour_sel") ) $(this).removeClass("case_jour_sel") ;
        else $(this).addClass("case_jour_sel") ;
        // alert($(this).attr("rel")) ;
      }) ;

    }
  }) ;
}

function newRdvCheckTypeActe() {
  $("#div_alert_err").html("") ;
  var type_acte = $('input[type=radio][name=new_type_acte]:checked').attr('value');
  var param = "id_bo_user="+$("#new_id_bo_user").val() ;
  param+="&new_date="+$("#new_date").val() ;
  param+="&id_patient="+$("#new_id_patient").val() ;
  param+="&id_acte="+$("#new_id_acte").val() ;
  param+="&type_acte="+type_acte ;
  // alert($("#cf_url").val()+"/rdv/acte_details_multiple?"+param) ;
  $.ajax({
    type:"POST",
    url:$("#cf_url").val()+"/rdv/acte_details_multiple",
    data:param,
    success:function(msg){
      $("#div_details_multiple").html(msg) ;
      newRdvDetailsRepete() ;
    }
  }) ;
}

function divNewActeDetails() {
  $("#div_alert_err").html("") ;
  var param = "id_bo_user="+$("#new_id_bo_user").val() ;
  param+="&new_date="+$("#new_date").val() ;
  param+="&id_patient="+$("#new_id_patient").val() ;
  param+="&id_acte="+$("#new_id_acte").val() ;
  $.ajax({
    type:"POST",
    url:$("#cf_url").val()+"/rdv/acte_details",
    data:param,
    success:function(msg){
      $("#div_new_acte_details").html(msg) ;
      newRdvCheckTypeActe() ;
    }
  }) ;
}

function newPatient() {
  $("#div_alert_err").html("") ;
  var param = "" ;
  // alert($("#cf_url").val()+"/patient/form_new?"+param) ;
  $.ajax({
    type:"POST",
    url:$("#cf_url").val()+"/patient/form_new",
    data:param,
    success:function(msg){
      $("#div_form_new_patient").html(msg) ;
      listeVille() ;
    }
  }) ;
}

function traitDetailsRDV() {
  if(!isDateValide($("#rdv_date").val())){
    alert("Date non valide, format attendu : jj/mm/aaaa ") ;
  }
  else{
    var type = $('input[type=radio][name=type_rdv]:checked').attr('value') ;
    var frequence = $('input[type=radio][name=frequence]:checked').attr('value') ;
    // var petit_matin = 0 ;
    // if($("#rdv_petit_matin").is(":checked")) petit_matin = 1 ;
    // var matin = 0 ;
    // if($("#rdv_matin").is(":checked")) matin = 1 ;
    // var midi = 0 ;
    // if($("#rdv_midi").is(":checked")) midi = 1 ;
    // var soir = 0 ;
    // if($("#rdv_soir").is(":checked")) soir = 1 ;
    // var mms = 0 ;
    // if($("#rdv_mms").is(":checked")) mms = 1 ;
    var param = "id="+$("#rdv_id").val()+"&type="+type+"&frequence="+frequence ; //+"&petit_matin="+petit_matin+"&mms="+mms+"&matin="+matin+"&midi="+midi+"&soir="+soir ;
    param+="&date="+$("#rdv_date").val() ;
    param+="&id_acte="+$("#rdv_id_acte").val() ;

    // alert($("#cf_url").val()+"/rdv/trait_details_rdv?"+param) ;
    $.ajax({
      type:"POST",
      url:$("#cf_url").val()+"/rdv/trait_details_rdv",
      data:param,
      success:function(msg){
        $('#dialog-deatils_rdv').modal('hide') ;
      }
    }) ;
  }
}

function ouvrir(hauteur,largeur,left,top,chemin,scr){
  var scrol ;
  if(scr==1) scrol = "scrollbars=yes" ;
  else scrol = "scrollbars=no" ;
  window.open(chemin,'_blank','top='+top+',left='+left+',width='+largeur+',height='+hauteur+','+scrol);
}

function traitNewPatient() {
  if($("#new_nom").val()==""){
    affAlertErr("Le nom est obligatoire") ;
    $("#new_nom").focus() ;
  }
  else if($("#new_prenom").val()==""){
    affAlertErr("Le prénom est obligatoire") ;
    $("#new_prenom").focus() ;
  }
  else if($("#new_adresse").val()==""){
    affAlertErr("L'adresse est obligatoire") ;
    $("#new_adresse").focus() ;
  }
  else if($("#new_cp").val()==""){
    affAlertErr("Le code postal est obligatoire") ;
    $("#new_cp").focus() ;
  }
  else if($("#id_ville").val()=="0"){
    affAlertErr("La ville est obligatoire") ;
    $("#id_ville").focus() ;
  }
  else if($("#new_tel").val()==""){
    affAlertErr("Le téléphone est obligatoire") ;
    $("#new_tel").focus() ;
  }
  else{
    var param = "nom="+encodeURIComponent($("#new_nom").val()) ;
    param+="&prenom="+encodeURIComponent($("#new_prenom").val()) ;
    param+="&adresse="+encodeURIComponent($("#new_adresse").val()) ;
    param+="&cp="+encodeURIComponent($("#new_cp").val()) ;
    param+="&id_ville="+$("#id_ville").val() ;
    param+="&tel="+encodeURIComponent($("#new_tel").val()) ;
    // alert($("#cf_url").val()+"/patient/trait_form_new?"+param) ;
    $.ajax({
      type:"POST",
      url:$("#cf_url").val()+"/patient/trait_form_new",
      data:param,
      success:function(msg){
        divNewPatient() ;
      }
    }) ;
  }
}

function listeVille() {
  var param = "cp="+encodeURIComponent($("#new_cp").val())+"&id_ville="+$("#id_ville").val() ;
  // alert($("#cf_url").val()+"/ville/liste?"+param) ;
  $.ajax({
    type:"POST",
    url:$("#cf_url").val()+"/ville/form_inc_liste",
    data:param,
    success:function(msg){
      $("#div_ville").html(msg) ;
    }
  }) ;
}

function divNewActe() {
  $("#div_alert_err").html("") ;
  if($("#new_id_patient").val()=="new"){ // selection de la creation nouveau patient
    $("#div_new_acte").html("") ;
    newPatient() ;
  }
  else{ // selection normale
    $("#div_form_new_patient").html("") ;
    var param = "id_bo_user="+$("#new_id_bo_user").val() ;
    param+="&new_date="+$("#new_date").val() ;
    param+="&id_patient="+$("#new_id_patient").val() ;
    $.ajax({
      type:"POST",
      url:$("#cf_url").val()+"/rdv/liste_acte",
      data:param,
      success:function(msg){
        $("#div_new_acte").html(msg) ;
        divNewActeDetails() ;
      }
    }) ;
  }
}

function divNewPatient() {
  $("#div_alert_err").html("") ;
  var param = "id_bo_user="+$("#new_id_bo_user").val() ;
  param+="&new_date="+$("#new_date").val() ;
  // alert($("#cf_url").val()+"/rdv/liste_patient?"+param) ;
  $.ajax({
    type:"POST",
    url:$("#cf_url").val()+"/rdv/liste_patient",
    data:param,
    success:function(msg){
      $("#div_new_patient").html(msg) ;
      divNewActe() ;
    }
  }) ;
}


function supRDV(id) {
  if(confirm("SUPPRIMER CE RENDEZ VOUS ?")){
    var param = "id="+id ;
    // alert($("#cf_url").val()+"/visite/trait_new?"+param) ;
    $.ajax({
      type:"POST",
      url:$("#cf_url").val()+"/rdv/supprime",
      data:param,
      success:function(msg){
        $('#dialog-deatils_rdv').modal('hide') ;
      }
    }) ;
  }
}

function selPatientVisite(val) {
  if(val=="new"){
    if(confirm('CREER NOUVEAU PATIENT ?')){
      window.location.href = $("#cf_url").val()+"/patient?action=new" ;
    }
  }
}

function traitNewVisite() {
  if($("#nv_id_patient").val()=="0"){
    alert("Veuillez choisir un patient...") ;
    $("#nv_id_patient").focus() ;
  }
  else{
    var param = "date="+$("#nv_date").val() ;
    param+="&id_bo_user="+$("#nv_id_bo_user").val() ;
    param+="&id_patient="+$("#nv_id_patient").val() ;
    // alert($("#cf_url").val()+"/visite/trait_new?"+param) ;
    $.ajax({
      type:"POST",
      url:$("#cf_url").val()+"/visite/trait_new",
      data:param,
      success:function(msg){
        $('#dialog-visite').modal('hide') ;
      }
    }) ;
  }
}

function traitMakeEffectue(id) {
  var param = "id="+id ;
  param+="&com_effectue="+encodeURIComponent($("#com_effectue").val()) ;
  // alert($("#cf_url").val()+"/visite/make_termine?"+param) ;
  $.ajax({
    type:"POST",
    url:$("#cf_url").val()+"/rdv/make_effectuee",
    data:param,
    success:function(msg){
      $('#dialog-make_effectue').modal('hide') ;
      grilleRestant() ;
      grilleEffectuee() ;
    }
  }) ;
}

function makeEffectuee(id) {

  var param = "id="+id ;
  // alert($("#cf_url").val()+"/rdv/modal_make_effectue?"+param) ;
  // alert(id) ;
  $.ajax({
    type:"POST",
    url:$("#cf_url").val()+"/rdv/modal_make_effectue",
    data:param,
    success:function(msg){
      $("#div_dialog").html(msg) ;
      $('#dialog-make_effectue').modal('show') ;
      $('#dialog-make_effectue').on('shown.bs.modal', function () { }) ;
      $('#dialog-make_effectue').on('hide.bs.modal', function () { }) ;
    }
  }) ;



}

function makeNotEffectuee(id) {
  var param = "id="+id ;
  // alert($("#cf_url").val()+"/visite/make_termine?"+param) ;
  $.ajax({
    type:"POST",
    url:$("#cf_url").val()+"/rdv/make_not_effectuee",
    data:param,
    success:function(msg){
      grilleRestant() ;
      grilleEffectuee() ;
    }
  }) ;
}



function newRDV(date) {
  var param = "date="+date ;
  // alert($("#cf_url").val()+"/visite/new?"+param) ;
  // alert($("#cf_url").val()+"/rdv/new?"+param) ;
  $.ajax({
    type:"POST",
    url:$("#cf_url").val()+"/rdv/new",
    data:param,
    success:function(msg){
      $("#div_dialog").html(msg) ;
      $('#dialog-rdv').modal('show') ;
      $('#dialog-rdv').on('shown.bs.modal', function () {
        divNewPatient() ;
      }) ;
      $('#dialog-rdv').on('hide.bs.modal', function () {
        grille() ;
      }) ;
    }
  }) ;
}
function newVisite(date) {
  var param = "date="+date ;
  // alert($("#cf_url").val()+"/visite/new?"+param) ;
  $.ajax({
    type:"POST",
    url:$("#cf_url").val()+"/visite/new",
    data:param,
    success:function(msg){
      $("#div_dialog").html(msg) ;
      $('#dialog-visite').modal('show') ;
      $('#dialog-visite').on('shown.bs.modal', function () {

      }) ;
      $('#dialog-visite').on('hide.bs.modal', function () {
        grille() ;
      }) ;
    }
  }) ;
}

$(document).ready(function(){
  grille() ;
}) ;
