{{ header }}
<div id="product-product">
  <div id="breadcrumb" class="section">
      <!-- container -->
      <div class="container">
        <!-- row -->
        <div class="row">
          <div class="col-md-12">
            <ul class="breadcrumb-tree">
            {% for breadcrumb in breadcrumbs %}
            <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
             {% endfor %}
            </ul>
          </div>
        </div>
      </div>
    </div>
    <div class="section">
    <div class="container">
    <div class="row">
    <!-- Begin item -->
      <div id="content"></div>
      <!-- Product main img -->
        {% if thumb or images %}
        <div class="col-md-5 col-md-push-2">
            <div id="product-main-img">
              {% if thumb %}
              <div class="product-preview"><img src="{{ popup }}" alt="{{ heading_title }}" title="{{ heading_title }}"></div>
              {% endif %}
             {% if images %}
                {% for image in images %}
                <div class="product-preview">
                   <img src="{{ image.popup }}" alt="{{ heading_title }}" title="{{ heading_title }}" >
                </div>
                {% endfor %}
              {% endif %} 
            </div>
          </div>
          <div class="col-md-2  col-md-pull-5">
            <div id="product-imgs">
               {% if thumb %}
              <div class="product-preview"> <img src="{{ thumb }}" alt="{{ heading_title }}" title="{{ heading_title }}" class="center-block"></div>
              {% endif %}
              {% if images %}
                {% for image in images %}
              <div class="product-preview">
                 <img src="{{ image.thumb }}" alt="{{ heading_title }}" title="{{ heading_title }}" class="center-block">
              </div>
              {% endfor %}
              {% endif %}
            </div>
          </div>
        {% endif %}    
         <!-- Product details -->
          <div class="col-md-5">
            <div class="product-details">
              <h2 class="product-name">{{ heading_title }}</h2>
               <div>
              {% if review_status %}
                <div class="product-rating">
                  {% for i in 1..5 %}
                  {% if rating < i %} 
                    <span class="fa fa-stack"> <i class="fa fa-star-o fa-stack-1x"></i></span>
                    {% else %}
                    <span class="fa fa-stack"><i class="fa fa-star fa-stack-1x"></i><i class="fa fa-star-o fa-stack-1x"></i></span>
                    {% endif %}
                  {% endfor %} 
                  </div>
                    <a class="review-link">{{ reviews }} || {{ total_sales }} sales</a>
                  
              {% endif %}
              </div>
              <div>
                {% if price %}

			  {# start owc_core_productpageenhanced_hooks_twig.xml #}		
        {# HOOK_PRODUCTPAGEENHANCED_PRODUCT_BEFORE_PRICE #}

			  {# OWC start owc_productpageenhanced_short_description_twig.xml #}	
				{{ sd_html_product_position2 }}   
				{# OWC end owc_productpageenhanced_short_description_twig.xml #}
			
				{# end owc_core_productpageenhanced_hooks_twig.xml #}
			
                  {% if not special %}
                  <h3 class="product-price">{{ price }}</h3>
                  {% else %}
                   <h3 class="product-price">{{ special }} <del class="product-old-price">{{ price }}</del></h3>
                  {% endif %}
                {% endif %} 
                {% if price %}
                  <ul class="list-unstyled">
                  {% if tax %}
                   <li>{{ text_tax }} {{ tax }}</li>
                  {% endif %}

			  {# start owc_core_productpageenhanced_hooks_twig.xml #}		
        {# HOOK_PRODUCTPAGEENHANCED_PRODUCT_AFTER_PRICE #}

			  {# OWC start owc_productpageenhanced_short_description_twig.xml #}					
				{{ sd_html_product_position3 }}     
				{# OWC end owc_productpageenhanced_short_description_twig.xml #}
			
				{# end owc_core_productpageenhanced_hooks_twig.xml #}
			
                  {% if points %}
                   <li>{{ text_points }} {{ points }}</li>
                  {% endif %}
                  {% if discounts %}
                  {% for discount in discounts %}
                  <li>{{ discount.quantity }}{{ text_discount }}{{ discount.price }}</li>
                  {% endfor %}
                  {% endif %}
                  </ul>
                {% endif %} 
              </div>
               <hr>
               <ul class="list-unstyled">
                {% if manufacturer %}
                <li>{{ text_manufacturer }} <a href="{{ manufacturers }}">{{ manufacturer }}</a></li>
                {% endif %}

			  {# start owc_core_productpageenhanced_hooks_twig.xml #}		
        {# HOOK_PRODUCTPAGEENHANCED_PRODUCT_AFTER_MANUFACTURER #}
				{# end owc_core_productpageenhanced_hooks_twig.xml #}
			
                <li>{{ text_model }} {{ model }}</li>
			  	
        {# start owc_core_productpageenhanced_hooks_twig.xml #}		
        {# HOOK_PRODUCTPAGEENHANCED_PRODUCT_AFTER_PRODUCT_CODE #}
				{# end owc_core_productpageenhanced_hooks_twig.xml #}
			
			  	
        {# start owc_core_productpageenhanced_hooks_twig.xml #}		
        {# HOOK_PRODUCTPAGEENHANCED_PRODUCT_BEFORE_REWARD_POINTS #}
				{# end owc_core_productpageenhanced_hooks_twig.xml #}
			
                {% if reward %}
                <li>{{ text_reward }} {{ reward }}</li>
                {% endif %}
              </ul>
			  	
        {# start owc_core_productpageenhanced_hooks_twig.xml #}		
        {# HOOK_PRODUCTPAGEENHANCED_PRODUCT_AFTER_REWARD_POINTS #}
				{# end owc_core_productpageenhanced_hooks_twig.xml #}
			
              <div>
              </div>
             <div id="product">
              <div class="product-options">
               {% if options %}
                {% for option in options %}

                  {% if option.type == 'radio' %}
                  <div class="form-group{% if option.required %} required {% endif %}">
                    <label class="control-label">{{ option.name }}</label>
                    <div id="input-option{{ option.product_option_id }}"> 
                    {% for option_value in option.product_option_value %}
                      <div class="radio">
                        <label>
                          
				{# start owc_core_productpageenhanced_hooks_twig.xml #}	
				<input type="radio" {# HOOK_PRODUCTPAGEENHANCED_PRODUCT_OPTION_DISABLE #} name="option[{{ option.product_option_id }}]"
				{# end owc_core_productpageenhanced_hooks_twig.xml #}
				 value="{{ option_value.product_option_value_id }}" />
                          {% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" class="img-thumbnail" /> {% endif %}                  
                          {{ option_value.name }}
                          {% if option_value.price %}
                          ({{ option_value.price_prefix }}{{ option_value.price }})
                          {% endif %} </label>
                      </div>
                      {% endfor %} 
                      </div>
                  </div>

                  {% endif %}

                   {% if option.type == 'select' %}
                  <div class="form-group{% if option.required %} required {% endif %}">
                    <label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
                    <select name="option[{{ option.product_option_id }}]" id="input-option{{ option.product_option_id }}" class="form-control">
                      <option value="">{{ text_select }}</option>
                      {% for option_value in option.product_option_value %}
                      
				{# start owc_core_productpageenhanced_hooks_twig.xml #}	
				<option value="{{ option_value.product_option_value_id }}" {# HOOK_PRODUCTPAGEENHANCED_PRODUCT_OPTION_DISABLE #}>{{ option_value.name }}
				{# end owc_core_productpageenhanced_hooks_twig.xml #}
				
                      {% if option_value.price %}
                      ({{ option_value.price_prefix }}{{ option_value.price }})
                      {% endif %} </option>
                      {% endfor %}
                    </select>
                  </div>
                  {% endif %}
                  {% if option.type == 'checkbox' %}
                      <div class="form-group{% if option.required %} required {% endif %}">
                        <label class="control-label">{{ option.name }}</label>
                        <div id="input-option{{ option.product_option_id }}"> {% for option_value in option.product_option_value %}
                          <div class="checkbox">
                            <label>
                              
				{# start owc_core_productpageenhanced_hooks_twig.xml #}	
				<input type="checkbox" {# HOOK_PRODUCTPAGEENHANCED_PRODUCT_OPTION_DISABLE #}
				{# end owc_core_productpageenHanced_hooks_twig.xml #}
				 name="option[{{ option.product_option_id }}][]" value="{{ option_value.product_option_value_id }}" />
                              {% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" class="img-thumbnail" /> {% endif %}
                              {{ option_value.name }}
                              {% if option_value.price %}
                              ({{ option_value.price_prefix }}{{ option_value.price }})
                              {% endif %} </label>
                          </div>
                          {% endfor %} </div>
                      </div>
                  {% endif %}
                  {% if option.type == 'text' %}
                  <div class="form-group{% if option.required %} required {% endif %}">
                    <label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
                    <input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control" />
                  </div>
                  {% endif %}
                  {% if option.type == 'textarea' %}
                  <div class="form-group{% if option.required %} required {% endif %}">
                    <label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
                    <textarea name="option[{{ option.product_option_id }}]" rows="5" placeholder="{{ option.name }}" id="input-option{{ option.product_option_id }}" class="form-control">{{ option.value }}</textarea>
                  </div>
                  {% endif %}
                  {% if option.type == 'file' %}
                  <div class="form-group{% if option.required %} required {% endif %}">
                    <label class="control-label">{{ option.name }}</label>
                    <button type="button" id="button-upload{{ option.product_option_id }}" data-loading-text="{{ text_loading }}" class="btn btn-default btn-block"><i class="fa fa-upload"></i> {{ button_upload }}</button>
                    <input type="hidden" name="option[{{ option.product_option_id }}]" value="" id="input-option{{ option.product_option_id }}" />
                  </div>
                  {% endif %}
                  {% if option.type == 'date' %}
                  <div class="form-group{% if option.required %} required {% endif %}">
                    <label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
                    <div class="input-group date">
                      <input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD" id="input-option{{ option.product_option_id }}" class="form-control" />
                      <span class="input-group-btn">
                      <button class="btn btn-default" type="button"><i class="fa fa-calendar"></i></button>
                      </span></div>
                  </div>
                  {% endif %}
                  {% if option.type == 'datetime' %}
                  <div class="form-group{% if option.required %} required {% endif %}">
                    <label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
                    <div class="input-group datetime">
                      <input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="YYYY-MM-DD HH:mm" id="input-option{{ option.product_option_id }}" class="form-control" />
                      <span class="input-group-btn">
                      <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
                      </span></div>
                  </div>
                  {% endif %}
                  {% if option.type == 'time' %}
                  <div class="form-group{% if option.required %} required {% endif %}">
                    <label class="control-label" for="input-option{{ option.product_option_id }}">{{ option.name }}</label>
                    <div class="input-group time">
                      <input type="text" name="option[{{ option.product_option_id }}]" value="{{ option.value }}" data-date-format="HH:mm" id="input-option{{ option.product_option_id }}" class="form-control" />
                      <span class="input-group-btn">
                      <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
                      </span></div>
                  </div>
                  {% endif %}
                {% endfor %}  
                {% endif %}
                {% if recurrings %}
                <hr>
                <div class="form-group required">
                  <select name="recurring_id" class="form-control">
                    <option value="">{{ text_select }}</option>
                    {% for recurring in recurrings %}
                    <option value="{{ recurring.recurring_id }}">{{ recurring.name }}</option>
                    {% endfor %}
                  </select>
                  <div class="help-block" id="recurring-description"></div>
                </div>
               {% endif %}

              <div class="add-to-cart">
                {% if minimum > 1 %}
                <div class="alert alert-info"><i class="fa fa-info-circle"></i> {{ text_minimum }}</div>
                {% endif %}
                <div class="qty-label">
                  {{ entry_qty }}
                  <div class="input-number">
                    <input type="text" name="quantity" value="{{ minimum }}" size="2" id="input-quantity" class="form-control" >
                    <input type="hidden" name="product_id" value="{{ product_id }}" />
                  </div>
                </div>
                <button id="button-cart" class="add-to-cart-btn" data-loading-text="{{ text_loading }}"><i class="fa fa-shopping-cart"></i>{{ button_cart }}</button>
              </div>
              </div>
            </div>

              <ul class="product-btns">
                <button type="button" data-toggle="tooltip" class="btn btn-wishlist" title="{{ button_wishlist }}" onclick="wishlist.add('{{ product_id }}');"><i class="fa-icon fa fa-heart"></i>{{ button_wishlist }}</button>
                <button type="button" data-toggle="tooltip" class="btn btn-compare" title="{{ button_compare }}" onclick="compare.add('{{ product_id }}');"><i class="fa-icon fa fa-exchange"></i>{{ button_compare }}</button>
              </ul>
              {% if tags %}
              <ul class="product-links">  
              <li><i class="fa-icon fa fa-tags" aria-hidden="true"></i>{{ text_tags }}</li>
              {% for i in 0..tags|length - 1 %}
              {% if i < (tags|length - 1) %} 
               <li><a href="{{ tags[i].href }}">{{ tags[i].tag }}</a></li>,
              {% else %} 
               <li> <a href="{{ tags[i].href }}">{{ tags[i].tag }}</a> </li>
              {% endif %}
              {% endfor %}
              </ul>
              {% endif %}

              <ul class="product-links">
                <li><i class="fa-icon fa fa-folder-open" aria-hidden="true"></i>Category:</li>
                 {% for category in linked_categories %}
                      <li><a href="{{ category.href }}">  {{ category.name }} </a></li>
                  {% endfor %}

                </ul>
              <ul class="product-links">
                <li>Share:</li>
                <li><a href="#"><i class="fa fa-facebook"></i></a></li>
                <li><a href="#"><i class="fa fa-twitter"></i></a></li>
                <li><a href="#"><i class="fa fa-google-plus"></i></a></li>
                <li><a href="#"><i class="fa fa-envelope"></i></a></li>
              </ul>
            </div>
          </div>
          <!-- /Product details -->
          <!-- Product tab -->
          <div class="col-md-12">
            <div id="product-tab">
              <ul class="tab-nav">
                <li class="active"><a data-toggle="tab" href="#tab-description">{{ tab_description }}</a></li>
                {% if attribute_groups %}
                <li><a href="#tab-specification" data-toggle="tab">{{ tab_attribute }}</a></li>
                {% endif %}
                {% if review_status %}
                <li><a href="#tab-review" data-toggle="tab">{{ tab_review }}</a></li>
                {% endif %}
              </ul>
              <div class="tab-content">
                <div class="tab-pane active" id="tab-description">{{ description }}</div>
                {% if attribute_groups %}
                <div class="tab-pane" id="tab-specification">
                  <table class="table table-bordered">
                    {% for attribute_group in attribute_groups %}
                    <thead>
                      <tr>
                        <td colspan="2"><strong>{{ attribute_group.name }}</strong></td>
                      </tr>
                    </thead>
                    <tbody>
                    {% for attribute in attribute_group.attribute %}
                    <tr>
                      <td>{{ attribute.name }}</td>
                      <td>{{ attribute.text }}</td>
                    </tr>
                    {% endfor %}
                      </tbody>
                    {% endfor %}
                  </table>
                </div>
                {% endif %}
                {% if review_status %}
                <div class="tab-pane" id="tab-review">
                  <form class="form-horizontal" id="form-review">
                    <div id="review"></div>
                    <h4><i class="fa-icon fa fa-pencil-square-o" aria-hidden="true"></i>{{ text_write }}</h4>
                    {% if review_guest %}
                    <div class="form-group required">
                      <div class="col-sm-12">
                        <input type="text" name="name" value="{{ customer_name }}" id="input-name" class="form-control" placeholder="{{ entry_name }}" />
                      </div>
                    </div>
                    <div class="form-group required">
                      <div class="col-sm-12">
                        <textarea name="text" rows="5" id="input-review" class="form-control" placeholder="{{ entry_review }}"></textarea>
                        <div class="help-block">{{ text_note }}</div>
                      </div>
                    </div>
                    <div class="form-group required">
                      <div class="col-sm-12">
                        <label class="control-label">{{ entry_rating }}</label>
                        &nbsp;&nbsp;&nbsp; {{ entry_bad }}&nbsp;
                        <input type="radio" name="rating" value="1" />
                        &nbsp;
                        <input type="radio" name="rating" value="2" />
                        &nbsp;
                        <input type="radio" name="rating" value="3" />
                        &nbsp;
                        <input type="radio" name="rating" value="4" />
                        &nbsp;
                        <input type="radio" name="rating" value="5" />
                        &nbsp;{{ entry_good }}</div>
                    </div>
                    {{ captcha }}
                    <div class="buttons clearfix">
                      <div class="pull-right">
                        <button type="button" id="button-review" data-loading-text="{{ text_loading }}" class="primary-btn">{{ button_continue }}</button>
                      </div>
                    </div>
                    {% else %}
                    {{ text_login }}
                    {% endif %}
                  </form>
                </div>
            {% endif %}
            </div>
            </div>
          </div>
          
    <!-- /Section -->

    <!-- End item -->
    </div>
    </div>
  </div>
  {% if products %}
          <div class="section">
          <!-- container -->
          <div class="container">
            <!-- row -->
            <div class="row">
              <div class="col-md-12">
                <div class="section-title text-center">
                  <h3 class="title">{{ text_related }}</h3>
                </div>
              </div>
              {% for product in products %}
              <!-- product -->
              <div class="col-md-3 col-xs-6">
                <div class="product">
                  <div class="product-img">
                      <img src="{{ product.thumb }}" alt="{{ product.name }}" class="img-responsive center-block" >
                    <div class="product-label">

				{# start owc_core_productpageenhanced_hooks_twig.xml #}
				{# HOOK_PRODUCTPAGEENHANCED_LIST_BEFORE_PRICE #}
				{# end owc_core_productpageenhanced_hooks_twig.xml #}
				
                      {% if product.price %}
                          {% if product.special %}
                          <span class="sale">- {{ product.percent }}</span>
                          {% endif %}  
                      {% endif %}  
                    </div>
                  </div>
                  <div class="product-body">
                    <p class="product-category"><a href="{{ product.category_href }}">{{ product.category_title}}</a></p>
                    <h3 class="product-name"><a href="{{ product.href }}">{{ product.name }}</a></h3>

				{# start owc_core_productpageenhanced_hooks_twig.xml #}
				{# HOOK_PRODUCTPAGEENHANCED_LIST_BEFORE_PRICE #}
				{# end owc_core_productpageenhanced_hooks_twig.xml #}
				
                     {% if product.price %}
                        {% if not product.special %}
                         <h4 class="product-price"> {{ product.price }}</h4>
                        {% else %}
                        <h4 class="product-price">{{ product.special }} <del class="product-old-price">{{ product.price }}</del></h4> {% endif %} 
                      {% endif %} 
                     {% if product.rating %}
                          <div class="product-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>
                          {% else %} 
                            <div class="product-rating"></div>
                          {% endif %}
                      
                    <div class="product-btns">
                          <button type="button" data-toggle="tooltip" title="{{ button_wishlist }}" onclick="wishlist.add('{{ product.product_id }}');"><i class="fa fa-heart"></i></button>
                          <button type="button" data-toggle="tooltip" title="{{ button_compare }}" onclick="compare.add('{{ product.product_id }}');"><i class="fa fa-exchange"></i></button>
                           <a class="quick-view" data-toggle="tooltip" href="{{ product.href }}" title="View"><i class="fa fa-eye"></i></a>
                            <button class="add-to-cart-btn btn-cart-icon" onclick="cart.add('{{ product.product_id }}');"><i class="fa fa-shopping-basket"></i></button>
                        </div>
                  </div>
                   <div class="add-to-cart">
                        <button class="add-to-cart-btn" onclick="cart.add('{{ product.product_id }}');"> <span class="hidden-xs hidden-sm hidden-md">{{ button_cart }}</span></button>
                      </div>
                </div>
              </div>
              <!-- /product -->
              <div class="clearfix visible-sm visible-xs"></div>
              {% endfor %}
            </div>
            <!-- /row -->
          </div>
          <!-- /container -->
        </div>
         {% endif %}
         {% if content_bottom %}
         <div class="section">
          <!-- container -->
          <div class="container">
            <!-- row -->
            <div class="row">
                <div class="col-md-12">
                  {{ content_bottom }}
                </div>
              </div>
           </div>
          </div>
         {% endif %} 
</div>

<script type="text/javascript"><!--
$('select[name=\'recurring_id\'], input[name="quantity"]').change(function(){
  $.ajax({
    url: 'index.php?route=product/product/getRecurringDescription',
    type: 'post',
    data: $('input[name=\'product_id\'], input[name=\'quantity\'], select[name=\'recurring_id\']'),
    dataType: 'json',
    beforeSend: function() {
      $('#recurring-description').html('');
    },
    success: function(json) {
      $('.alert-dismissible, .text-danger').remove();

      if (json['success']) {
        $('#recurring-description').html(json['success']);
      }
    }
  });
});
//--></script> 
<script type="text/javascript"><!--
$('#button-cart').on('click', function() {
  $.ajax({
    url: 'index.php?route=checkout/cart/add',
    type: 'post',
    data: $('#product input[type=\'text\'], #product input[type=\'hidden\'], #product input[type=\'radio\']:checked, #product input[type=\'checkbox\']:checked, #product select, #product textarea'),
    dataType: 'json',
    beforeSend: function() {
      $('#button-cart').button('loading');
    },
    complete: function() {
      $('#button-cart').button('reset');
    },
    success: function(json) {
      $('.alert-dismissible, .text-danger').remove();
      $('.form-group').removeClass('has-error');

      if (json['error']) {
        if (json['error']['option']) {
          for (i in json['error']['option']) {
            var element = $('#input-option' + i.replace('_', '-'));

            if (element.parent().hasClass('input-group')) {
              element.parent().after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
            } else {
              element.after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
            }
          }
        }

        if (json['error']['recurring']) {
          $('select[name=\'recurring_id\']').after('<div class="text-danger">' + json['error']['recurring'] + '</div>');
        }

        // Highlight any found errors
        $('.text-danger').parent().addClass('has-error');
      }

      if (json['success']) {
        $('#breadcrumb').after('<div class="container alert alert-success alert-dismissible">' + json['success'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');

        $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');

        $('html, body').animate({ scrollTop: 0 }, 'slow');

        $('#cart > ul').load('index.php?route=common/cart/info ul li');
      }
    },
        error: function(xhr, ajaxOptions, thrownError) {
            alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
        }
  });
});
//--></script> 
<script type="text/javascript"><!--
$('.date').datetimepicker({
  language: '{{ datepicker }}',
  pickTime: false
});

$('.datetime').datetimepicker({
  language: '{{ datepicker }}',
  pickDate: true,
  pickTime: true
});

$('.time').datetimepicker({
  language: '{{ datepicker }}',
  pickDate: false
});

$('button[id^=\'button-upload\']').on('click', function() {
  var node = this;

  $('#form-upload').remove();

  $('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input type="file" name="file" /></form>');

  $('#form-upload input[name=\'file\']').trigger('click');

  if (typeof timer != 'undefined') {
      clearInterval(timer);
  }

  timer = setInterval(function() {
    if ($('#form-upload input[name=\'file\']').val() != '') {
      clearInterval(timer);

      $.ajax({
        url: 'index.php?route=tool/upload',
        type: 'post',
        dataType: 'json',
        data: new FormData($('#form-upload')[0]),
        cache: false,
        contentType: false,
        processData: false,
        beforeSend: function() {
          $(node).button('loading');
        },
        complete: function() {
          $(node).button('reset');
        },
        success: function(json) {
          $('.text-danger').remove();

          if (json['error']) {
            $(node).parent().find('input').after('<div class="text-danger">' + json['error'] + '</div>');
          }

          if (json['success']) {
            alert(json['success']);

            $(node).parent().find('input').val(json['code']);
          }
        },
        error: function(xhr, ajaxOptions, thrownError) {
          alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
        }
      });
    }
  }, 500);
});
//--></script> 
<script type="text/javascript"><!--
$('#review').delegate('.pagination a', 'click', function(e) {
    e.preventDefault();

    $('#review').fadeOut('slow');

    $('#review').load(this.href);

    $('#review').fadeIn('slow');
});

$('#review').load('index.php?route=product/product/review&product_id={{ product_id }}');

$('#button-review').on('click', function() {
  $.ajax({
    url: 'index.php?route=product/product/write&product_id={{ product_id }}',
    type: 'post',
    dataType: 'json',
    data: $("#form-review").serialize(),
    beforeSend: function() {
      $('#button-review').button('loading');
    },
    complete: function() {
      $('#button-review').button('reset');
    },
    success: function(json) {
      $('.alert-dismissible').remove();

      if (json['error']) {
        $('#review').after('<div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + '</div>');
      }

      if (json['success']) {
        $('#review').after('<div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> ' + json['success'] + '</div>');

        $('input[name=\'name\']').val('');
        $('textarea[name=\'text\']').val('');
        $('input[name=\'rating\']:checked').prop('checked', false);
      }
    }
  });
});

//--></script> 
{{ footer }} 