$(document).ready(function() {
  $("#nouvelleCs").on("click","#id_atcdStrucCIM10_idAddOn", function() {
    $('#searchCIM10').modal('show');
  });

  $('#searchCIM10').on('shown.bs.modal', function() {
    $('#searchCIM10 #texteRechercheCIM10').focus();
  });

  $("#texteRechercheCIM10").typeWatch({
    wait: 1000,
    highlight: false,
    allowSubmit: false,
    captureLength: 3,
    callback: function(value) {
      $.ajax({
        url: urlBase+'/lap/ajax/cim10search/',
        type: 'post',
        data: {
          term: value
        },
        dataType: "html",
        beforeSend: function() {
          $('#codeCIM10trouves').html('<div class="col-md-12">Attente des résultats de la recherche ...</div>');
        },
        success: function(data) {
          $('#codeCIM10trouves').html(data);
        },
        error: function() {
          alert('Problème, rechargez la page !');
        }
      });
    }
  });

  $('#searchCIM10').on("click", "button.catchCIM10", function() {
    code = $(this).attr('data-code');
    label = $(this).attr('data-label');
    $("#id_atcdStrucCIM10_id").val(code);
    $("#id_atcdStrucCIM10Label_id").val(label);
    $('#searchCIM10').modal('toggle');
    $('#codeCIM10trouves').html('');
    $("#texteRechercheCIM10").val('');

  });
  
  //ajutement auto des textarea en hauteur
  autosize($('#id_atcdStrucNotes_id'));
  
});