(function() {
   'use strict';

   var $wrapper = $('.catalog-wrapper-top10');

   $wrapper.on('submit', '.buy-form', function() {
      var $form = $(this);
      wpj.domUtils.reloadPartsFromUrl($form.attr('action'), $('[data-reload="cart-info"]'), $form.serialize());
      return false;
   });

   $wrapper.on('click', '.buy_count button', function() {
      var $button = $(this);
      var $input = $button.closest('.submit-block').find('input[name="No"]');
      var oldValue = $input.val();
      var newVal;

      if ($button.hasClass('plus_unit')) {
         newVal = parseFloat(oldValue) + 1;
      } else {
         // Don't allow decrementing below zero
         if (oldValue > 1) {
            newVal = parseFloat(oldValue) - 1;
         } else {
            newVal = 1;
         }
      }

      $input.val(newVal);
   });
})();
