{% if dependent_options %}
{% if view_type == 'header' %}
<style type="text/css" id="dependent-options-style">
#product .form-group:not(:last-child), .has-parent-option option + option {display: none;}
#product [type="checkbox"][style*="block"], #product [type="radio"][style*="block"] {display: inline-block !important;}
{% if css %}{{ css }}{% endif %}
</style>
{% elseif view_type == 'footer' %}
<script type="text/javascript" id="dependent-options-script"><!--
{% for dependent_option in dependent_options %}
  $('#input-option{{ dependent_option.product_option_id }}').attr({
    'data-option-id': '{{ dependent_option.option_id }}',
    'data-parent-id': '{{ dependent_option.parent_id }}'
  });
  {% if dependent_option.product_option_value %}
    {% for product_option_value in dependent_option.product_option_value %}
        $('#product [value="{{ product_option_value.product_option_value_id }}"]').attr({
          'data-option-value-id': '{{ product_option_value.option_value_id }}'
        });
        {% if product_option_value.parent_option_values %}
          $('#product [value="{{ product_option_value.product_option_value_id }}"]').attr({
            'data-values': '[{{ product_option_value.parent_option_values }}]'
          });
        {% endif %}
    {% endfor %}
  {% endif %}
  {% if dependent_option.parent_values %}
    $('#input-option{{ dependent_option.product_option_id }}').attr({
      'data-values': '[{{ dependent_option.parent_values }}]'
    });
  {% endif %}
{% endfor %}
$('#product [data-parent-id="0"]').parents('.form-group').fadeIn('fast');
$('#product [data-parent-id]').each(function() {
  if ($(this).data('parent-id')) {
    $(this).addClass('has-parent-option');
  }
});
$('#product [type="radio"], #product [type="checkbox"], #product select').on('change', function() {
  $('.has-parent-option').each(function() {
    var element = $(this);
    var parentId = element.data('parent-id');
    var values = element.data('values');
    var show = false;
    if ($('#product [data-option-id="' + parentId + '"]').length) {
      for (i in values) {
        if ($('#product [data-option-id="' + parentId + '"] [data-option-value-id="' + values[i] + '"]:checked').length || $('#product [data-option-id="' + parentId + '"] [data-option-value-id="' + values[i] + '"]:selected').length) {
          show = true;
        }
      }
      if (element.find('[data-values]').length) {
        element.find('[data-values]').each(function() {
          var element2 = $(this);
          var values2 = element2.data('values');
          var show2 = false;
            for (i in values2) {
              if ($('#product [data-option-id="' + parentId + '"] [data-option-value-id="' + values2[i] + '"]:checked').length || $('#product [data-option-id="' + parentId + '"] [data-option-value-id="' + values2[i] + '"]:selected').length) {
                show = true;
                show2 = true;
              }
            }
          if (show2) {
            element2.fadeIn('fast').attr({'name': element2.data('name'), 'hidden': false, 'disabled': false}).parents('.checkbox, .radio').fadeIn('fast');
          } else {
            element2.hide().attr({'data-name': element2.attr('name'), 'hidden': true, 'disabled': true}).removeAttr('name').parents('.checkbox, .radio').hide();
          }
        });
      }
    } else {
      show = false;
    }
    if (show) {
      element.fadeIn('fast').attr({'name': element.data('name'), 'hidden': false, 'disabled': false}).parents('.form-group').fadeIn('fast');
    } else {
      element.hide().attr({'data-name': element.attr('name'), 'hidden': true, 'disabled': true}).removeAttr('name').parents('.form-group').hide();
    }
  });
  if ($('#product select option:selected[disabled]').length) {
    $('#product select option:selected[disabled]').parent('select').val('').trigger('change');
  }
});
//--></script>
{% endif %}
{% endif %}