/**
* Controla grupos de checkbox com dois níveis
*
* O id do controlador deve ser uma classe nos controlados
* O data-parent-id dos controlados deve ser igual ao id do controlador
*
* <label>
*   <input type="checkbox" name="213" id="213" class="js-check-control">
*   <span>ANEIS</span>
* </label>
* <div>
*   <label>
*     <input type="checkbox" name="225" id="225" data-parent-id="213" class="js-check-controlled 213">
*     <span>Solitario</span>
*   </label>
*   <label>
*     <input type="checkbox" name="214" id="214" data-parent-id="213" class="js-check-controlled 213">
*     <span>Zirconia</span>
*   </label>
* </div>
*/
$('.ftr-main').on('change', '.js-check-control', function(e) {
  $('.js-check-controlled.' + $(this).attr('id')).prop('checked', $(this).prop('checked'))
  if ($(this).prop('checked')) {
    $('.js-check-controlled.' + $(this).attr('id')).closest('.ftr-checkbox').addClass('is-checked');
  } else {
    $('.js-check-controlled.' + $(this).attr('id')).closest('.ftr-checkbox').removeClass('is-checked');
  }
});
$('.ftr-main').on('change', '.js-check-controlled', function(){
  if ($('.js-check-controlled.' + $(this).data('parent-id')).length  == $('.js-check-controlled.' + $(this).data('parent-id')).filter(':checked').length) {
    $('.js-check-control#' + $(this).data('parent-id')).prop('checked', true).closest('.ftr-checkbox').addClass('is-checked');
  } else {
    $('.js-check-control#' + $(this).data('parent-id')).prop('checked', false).closest('.ftr-checkbox').removeClass('is-checked');
  }
});
