/******************
    User custom CSS
    ---------------

    In this file you can add your own custom CSS
    It will be loaded last, so you can override any other property.
    Also, it will never be updated. So if you inheritate a core template and just add here some CSS, you'll still benefit of all the updates
*/

  .table-bordered > thead > tr > th {
    border: 1px solid #dadada;
  }
  .table-bordered > thead > tr > td {
    border: 1px solid #dadada;
  }
  
  .asterisk {display: none;}

/* Hide the big title on the welcome page */
body .survey-header h1,
body .survey-header .survey-title {
  display: none ;
}


$(document).on('ready pjax:scriptcomplete', function () {
  var q = $('[id^="question"][id$="-B2"]'); // container for B2
  if (!q.length) return;

  function cleanup() {
    var ranked = q.find('.ls-rank .selected [data-code]');
    var hasNONE = ranked.filter('[data-code="NONE"]').length > 0;
    var hasPNS  = ranked.filter('[data-code="PNS"]').length > 0;
    if (hasNONE || hasPNS) {
      ranked.each(function () {
        var code = $(this).data('code');
        if ((hasNONE && code !== 'NONE') || (hasPNS && code !== 'PNS')) {
          $(this).find('.btn-remove, .move-back, a').first().trigger('click');
        }
      });
      // If both exclusives get dragged, keep the first one
      if (hasNONE && hasPNS) {
        ranked.filter('[data-code="PNS"]').first().find('.btn-remove, .move-back, a').first().trigger('click');
      }
    }
  }

  q.on('change', cleanup);
  setTimeout(cleanup, 200);
});
