$(function () {
   var elements_with_frequent_values = $('*[data-frequent-values]'); 
   elements_with_frequent_values.each(function (i, elt) {
      var e = $(elt).data('frequent-values'); 
      var intro = $("<span> <em>Codes liés au destinataire de ce document ou récemment utilisés: </em> </span>");
      var after = $(elt);
      after.after(intro); 
      after = intro;
      for (var i = 0; i < e.length; i++) { 
        var y=e[i]; 
        var a=$('<a>' + y[0] + '</a>'); 
        a.click(function () { 
          $(elt).val($(this).text());
        });
        if (i>0) {
            var comma = $('<span>, </span>')
            after.after(comma);
            after = comma;
        } 
        after.after(a);
        after = a;
      }
   });
});
