{{ header }}
<div id="container" class="container j-container">
  <ul class="breadcrumb">
    {% for breadcrumb in breadcrumbs %}
      <li itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="{{ breadcrumb.href }}" itemprop="url"><span itemprop="title">{{ breadcrumb.text }}</span></a></li>
    {% endfor %}
  </ul>
  <div class="row">{{ column_left }}{{ column_right }}
    {% if column_left and column_right %}
      {% set class = 'col-sm-6' %}
    {% elseif column_left or column_right %}
      {% set class = 'col-sm-9' %}
    {% else %}
      {% set class = 'col-sm-12' %}
    {% endif %}
    <div id="content" class="{{ class }} search-page">
      <h1 class="heading-title">{{ heading_title }}</h1>
      {{ content_top }}
      <h2>{{ entry_search }}</h2>
      <div class="row content">
        <div class="col-sm-4">
          <input type="text" name="search" value="{{ search }}" placeholder="{{ text_keyword }}" id="input-search" class="form-control"/>
        </div>
        <div class="col-sm-3 s-cat">
          <select name="category_id" class="form-control">
            <option value="0">{{ text_category }}</option>
            {% for category_1 in categories %}
              {% if category_1.category_id == category_id %}
                <option value="{{ category_1.category_id }}" selected="selected">{{ category_1.name }}</option>
              {% else %}
                <option value="{{ category_1.category_id }}">{{ category_1.name }}</option>
              {% endif %}
              {% for category_2 in category_1.children %}
                {% if category_2.category_id == category_id %}
                  <option value="{{ category_2.category_id }}" selected="selected">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_2.name }}</option>
                {% else %}
                  <option value="{{ category_2.category_id }}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_2.name }}</option>
                {% endif %}
                {% for category_3 in category_2.children %}
                  {% if category_3.category_id == category_id %}
                    <option value="{{ category_3.category_id }}" selected="selected">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_3.name }}</option>
                  {% else %}
                    <option value="{{ category_3.category_id }}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_3.name }}</option>
                  {% endif %}
                {% endfor %}
              {% endfor %}
            {% endfor %}
          </select>
        </div>
        <div class="col-sm-3 s-check">
          <label class="checkbox-inline">
            {% if sub_category %}
              <input type="checkbox" name="sub_category" value="1" checked="checked"/>
            {% else %}
              <input type="checkbox" name="sub_category" value="1"/>
            {% endif %}
            {{ text_sub_category }}</label>
        </div>
        <div class="col-sm-3 s-check">
          <label class="checkbox-inline">
            {% if description %}
              <input type="checkbox" name="description" value="1" id="description" checked="checked"/>
            {% else %}
              <input type="checkbox" name="description" value="1" id="description"/>
            {% endif %}
            {{ entry_description }}</label>
        </div>
      </div>
      <div class="buttons">
        <div class="right">
          <input type="button" value="{{ button_search }}" id="button-search" class="btn btn-primary button"/>
        </div>
      </div>
      <h2>{{ text_search }}</h2>
      {% if products %}
        <div class="product-filter">
          <div class="display">
            <a onclick="Journal.gridView()" class="grid-view">{{ journal2.settings.get('category_grid_view_icon', button_grid) }}</a>
            <a onclick="Journal.listView()" class="list-view">{{ journal2.settings.get('category_list_view_icon', button_list) }}</a>
          </div>
          <div class="product-compare"><a href="{{ compare }}" id="compare-total">{{ text_compare }}</a></div>
          <div class="limit"><b>{{ text_limit }}</b>
            <select onchange="location = this.value;">
              {% for limits in limits %}
                {% if limits.value == limit %}
                  <option value="{{ limits.href }}" selected="selected">{{ limits.text }}</option>
                {% else %}
                  <option value="{{ limits.href }}">{{ limits.text }}</option>
                {% endif %}
              {% endfor %}
            </select>
          </div>
          <div class="sort"><b>{{ text_sort }}</b>
            <select onchange="location = this.value;">
              {% for sorts in sorts %}
                {% if sorts.value == '%s-%s'|format(sort, order) %}
                  <option value="{{ sorts.href }}" selected="selected">{{ sorts.text }}</option>
                {% else %}
                  <option value="{{ sorts.href }}">{{ sorts.text }}</option>
                {% endif %}
              {% endfor %}
            </select>
          </div>
        </div>
        <div class="row main-products product-grid" data-grid-classes="{{ journal2.settings.get('product_grid_classes') }} display-{{ journal2.settings.get('product_grid_wishlist_icon_display') }} {{ journal2.settings.get('product_grid_button_block_button') }}">
          {% for product in products %}
            <div class="product-grid-item {{ journal2.settings.get('product_grid_classes') }}">
              <div class="product-thumb product-wrapper {% if product.labels and product.labels.outofstock %} outofstock {% endif %}">
                <div class="image {% if journal2.settings.get('show_countdown', 'never') != 'never' and product.date_end %} has-countdown {% endif %}">
                  <a href="{{ product.href }}" {% if product.thumb2 %} class="has-second-image" style="background: url('{{ product.thumb2 }}') no-repeat" {% endif %}>
                    <img class="lazy first-image" width="{{ journal2.settings.get('config_image_width') }}" height="{{ journal2.settings.get('config_image_height') }}" src="{{ journal2.settings.get('product_dummy_image') }}" data-src="{{ product.thumb }}" title="{{ product.name }}" alt="{{ product.name }}"/>
                  </a>
                  {% for label, name in product.labels %}
                    <span class="label-{{ label }}"><b>{{ name }}</b></span>
                  {% endfor %}
                  {% if journal2.settings.get('product_grid_wishlist_icon_position') == 'image' and journal2.settings.get('product_grid_wishlist_icon_display') == 'icon' %}
                    <div class="wishlist"><a onclick="addToWishList('{{ product.product_id }}');" class="hint--top" data-hint="{{ button_wishlist }}"><i class="wishlist-icon"></i><span class="button-wishlist-text">{{ button_wishlist }}</span></a></div>
                    <div class="compare"><a onclick="addToCompare('{{ product.product_id }}');" class="hint--top" data-hint="{{ button_compare }}"><i class="compare-icon"></i><span class="button-compare-text">{{ button_compare }}</span></a></div>
                  {% endif %}
                </div>
                <div class="product-details">
                  <div class="caption">
                    <h4 class="name"><a href="{{ product.href }}">{{ product.name }}</a></h4>
                    <p class="description">{{ product.description }}</p>
                    {% if product.price %}
                      <div class="price">
                        {% if not product.special %}
                          {{ product.price }}
                        {% else %}
                          <span class="price-old">{{ product.price }}</span> <span class="price-new" {% if product.date_end %}data-end-date="{{ product.date_end }}"{% endif %}>{{ product.special }}</span>
                        {% endif %}
                        {% if product.tax %}
                          <span class="price-tax">{{ text_tax }} {{ product.tax }}</span>
                        {% endif %}
                      </div>
                    {% endif %}
                    {% if product.rating %}
                      <div class="rating">
                        {% for i in 1..5 %}
                          {% if product.rating < i %}
                            <span class="fa fa-stack"><i class="fa fa-star-o fa-stack-2x"></i></span>
                          {% else %}
                            <span class="fa fa-stack"><i class="fa fa-star fa-stack-2x"></i><i class="fa fa-star-o fa-stack-2x"></i></span>
                          {% endif %}
                        {% endfor %}
                      </div>
                    {% endif %}
                  </div>
                  <div class="button-group">
                    {% if staticCall('Journal2Utils', 'isEnquiryProduct', [null, product]) %}
                      <div class="cart enquiry-button">
                        <a href="javascript:Journal.openPopup('{{ journal2.settings.get('enquiry_popup_code') }}', '{{ product.product_id }}');" data-clk="addToCart('{{ product.product_id }}');" class="button hint--top" data-hint="{{ journal2.settings.get('enquiry_button_text') }}">{{ journal2.settings.get('enquiry_button_icon') }}<span class="button-cart-text">{{ journal2.settings.get('enquiry_button_text') }}</span></a>
                      </div>
                    {% else %}
                      <div class="cart {% if product.labels and product.labels.outofstock %} outofstock {% endif %}">
                        <a onclick="addToCart('{{ product.product_id }}', '{{ product.minimum }}');" class="button hint--top" data-hint="{{ button_cart }}"><i class="button-left-icon"></i><span class="button-cart-text">{{ button_cart }}</span><i class="button-right-icon"></i></a>
                      </div>
                    {% endif %}
                    <div class="wishlist"><a onclick="addToWishList('{{ product.product_id }}');" class="hint--top" data-hint="{{ button_wishlist }}"><i class="wishlist-icon"></i><span class="button-wishlist-text">{{ button_wishlist }}</span></a></div>
                    <div class="compare"><a onclick="addToCompare('{{ product.product_id }}');" class="hint--top" data-hint="{{ button_compare }}"><i class="compare-icon"></i><span class="button-compare-text">{{ button_compare }}</span></a></div>
                  </div>
                </div>
              </div>
            </div>
          {% endfor %}
        </div>
        <div class="row pagination">
          <div class="col-sm-6 text-left links">{{ pagination }}</div>
          <div class="col-sm-6 text-right results">{{ results }}</div>
        </div>
      {% else %}
        <p>{{ text_empty }}</p>
      {% endif %}
      {{ content_bottom }}</div>
  </div>
  <script>Journal.applyView('{{ journal2.settings.get('product_view', 'grid') }}');</script>
  {% if journal2.settings.get('show_countdown', 'never') != 'never' %}
    <script>Journal.enableCountdown();</script>
  {% endif %}
</div>
<script type="text/javascript"><!--
  $('#button-search').bind('click', function () {
    url = 'index.php?route=product/search';

    var search = $('#content input[name=\'search\']').prop('value');

    if (search) {
      url += '&search=' + encodeURIComponent(search);
    }

    var category_id = $('#content select[name=\'category_id\']').prop('value');

    if (category_id > 0) {
      url += '&category_id=' + encodeURIComponent(category_id);
    }

    var sub_category = $('#content input[name=\'sub_category\']:checked').prop('value');

    if (sub_category) {
      url += '&sub_category=true';
    }

    var filter_description = $('#content input[name=\'description\']:checked').prop('value');

    if (filter_description) {
      url += '&description=true';
    }

    location = url;
  });

  $('#content input[name=\'search\']').bind('keydown', function (e) {
    if (e.keyCode == 13) {
      $('#button-search').trigger('click');
    }
  });

  $('select[name=\'category_id\']').on('change', function () {
    if (this.value == '0') {
      $('input[name=\'sub_category\']').prop('disabled', true);
    } else {
      $('input[name=\'sub_category\']').prop('disabled', false);
    }
  });

  $('select[name=\'category_id\']').trigger('change');
  --></script>
{{ footer }}
