var medical_coach_keyboard_navigation_loop = function (elem) {
  var medical_coach_tabbable = elem.find('select, input, textarea, button, a').filter(':visible');
  var medical_coach_firstTabbable = medical_coach_tabbable.first();
  var medical_coach_lastTabbable = medical_coach_tabbable.last();
  medical_coach_firstTabbable.focus();

  medical_coach_lastTabbable.on('keydown', function (e) {
    if ((e.which === 9 && !e.shiftKey)) {
      e.preventDefault();
      medical_coach_firstTabbable.focus();
    }
  });

  medical_coach_firstTabbable.on('keydown', function (e) {
    if ((e.which === 9 && e.shiftKey)) {
      e.preventDefault();
      medical_coach_lastTabbable.focus();
    }
  });

  elem.on('keyup', function (e) {
    if (e.keyCode === 27) {
      elem.hide();
    };
  });
};