/* Js for , Version=1777538660 */
 if(typeof(v) != "object") v = {};v.lang = {"confirmDelete":"\u60a8\u78ba\u5b9a\u8981\u57f7\u884c\u522a\u9664\u64cd\u4f5c\u55ce\uff1f","deleteing":"\u522a\u9664\u4e2d","doing":"\u8655\u7406\u4e2d","loading":"\u52a0\u8f09\u4e2d","updating":"\u66f4\u65b0\u4e2d...","timeout":"\u7db2\u7d61\u8d85\u6642,\u8acb\u91cd\u8a66","errorThrown":"<h4>\u57f7\u884c\u51fa\u932f\uff1a<\/h4>","continueShopping":"\u7e7c\u7e8c\u8cfc\u7269","required":"\u5fc5\u586b","back":"\u8fd4\u56de","continue":"\u7e7c\u7e8c","bindWechatTip":"\u767c\u5e16\u529f\u80fd\u8a2d\u7f6e\u4e86\u7d81\u5b9a\u5fae\u4fe1\u7684\u9650\u5236\uff0c\u8acb\u5148\u7d81\u5b9a\u5fae\u4fe1\u6703\u54e1\u3002","importTip":"\u53ea\u5c0e\u5165\u4e3b\u984c\u7684\u98a8\u683c\u548c\u6a23\u5f0f","fullImportTip":"\u5c07\u6703\u5c0e\u5165\u6e2c\u8a66\u6578\u64da\u4ee5\u53ca\u66ff\u63db\u7ad9\u9ede\u6587\u7ae0\u3001\u7522\u54c1\u7b49\u6578\u64da"};;v.theme = {"template":"mobile","theme":"default","device":"mobile"};;v.path = ["74","99","","89","106"];;v.categoryID = 99;;v.categoryPath = ["74","99"];;v.addToCartSuccess = "\u6210\u529f\u52a0\u5165\u8cfc\u7269\u8eca\u3002";;v.gotoCart = "\u53bb\u8cfc\u7269\u8eca\u7d50\u7b97";;v.goback = "\u8fd4\u56de";;
;v.price = 0;;v.currencySymbol = "\uffe5";;
$(function()
{
    var userLink = createLink('user', 'login');
    extra = {};

    $('.price-label').click(function()
    {
        hideAttrForm();
        $(this).parent().find('.active').removeClass('active');
        $(this).addClass('active');
        code = $(this).data('attribute');
        extra[code] = $(this).data('value');
        $(this).find('[type=hidden]').val($(this).data('value'));

        computedPrice();
    });

    $('.attr-selector').click(function()
    {
        code = $(this).data('attribute');
        $('.' + code + '-inputer').val($(this).data('value'));
    })

   $('#count').change(function()
   {
       $('.count-input').val($(this).val())
   });

    $('.btncart').click(function()
    {
        if(!checkAttr()) 
        {
            alertAttrForm();
            return false;
        }

        cartLink = $(this).data('url').replace('countParam', $('#count').val())
        $.post(cartLink, {extra: extra},
            function(response)
            {
                if(response.result == 'success')
                {
                    setCartCount();
                    $.messager.success(window.v.addToCartSuccess);
                }
                else
                {
                    location.href = response.locate;           
                }
            },
            'json'
        )
    });
    
    $('.btnbuy').click(function()
    {
        if(!checkAttr()) 
        {
            alertAttrForm();
            return false;
        }

        $('#buyForm').submit();
     });

    function alertAttrForm()
    {
        window.scrollTo(0,$('#attribute').offset().top-200)
        $('.attr-selector').parents('tr').css('border', '1px solid red');
    }
    function hideAttrForm() 
    {
        window.scrollTo(0,$('#attribute').offset().top-200)
        $('.attr-selector').parents('tr').css('border', 'none');
    }

    function computedPrice()
    {
        if(!checkAttr()) return false;
        price = v.price;

        $('.attr-selector.active').each(function()
        {
            if($(this).data('price') != 0)
            {
                value = $(this).data('price');
                price = parseFloat(price) + parseFloat(value);
            }
            price = price.toFixed(2);
        });
        if(v.hasDiscount)
        {
            price = price * v.discount;
            price = price.toFixed(2);
        }

        $('#priceBox .text-danger').html(v.currencySymbol + price);
        $('#price').val(price);
    }

    function checkAttr()
    {
        attrSelected = true;
        $('.attr-selector').each(function()
        {
            if($(this).parents('td').find('.attr-selector.active').size() == 0) attrSelected = false;
        });
        return attrSelected;
    }
    
});
;$(function()
{
    /* Set current active topNav. */
    var hasActive = false;
    if(v.categoryID > 0 && $('.nav-product-' + v.categoryID).length >= 1)
    {
        hasActive = true;
        $('.nav-product-' + v.categoryID).addClass('active');
    }

    if(v.categoryPath && v.categoryPath.length)
    {
        $.each(v.categoryPath, function(index, category)
        {
            if(!hasActive)
            {
                if($('.nav-product-' + category).length >= 1) hasActive = true;
                $('.nav-product-' + category).addClass('active');
            }
        });
    }
    else if(v.path && v.path.length)
    {
        $.each(v.path, function(index, category)
        {
            if(!hasActive)
            {
                if($('.nav-product-' + category).length >= 1) hasActive = true;
                $('.nav-product-' + category).addClass('active');
            }
        });
        if(!hasActive) $('.nav-product-0').addClass('active');
    }
    
    if(v.categoryID !== 0) $('#category' + v.categoryID).parent().addClass('active');
})
+(function($){
    'use strict';

    var minDelta = 20;

    $.fn.numberInput = function(){
        return $(this).each(function(){
            var $input = $(this);
            $input.on('click', '.btn-minus, .btn-plus', function(){
                var $val = $input.find('.btn-number, [type="number"]');
                var val = parseInt($val.val());
                val = Math.max(1, $(this).hasClass('btn-minus') ? (val - 1) : (val + 1));
                $val.val(val).trigger('change');
            });
        });
    };

    $(function(){$('.input-number').numberInput();});
}(Zepto));

function setCartCount()
{
    $.getJSON(createLink('cart', 'count'), function(data)
    {
        $('.label.badge.red.circle').text(data.count);
    })
}
function hideMessage()
{
    $('div .comment-post.vertical-center').hide();
}
setCartCount();
hideMessage();
$(function()
{
    $(document).on('click', '#message', function()
    {
        if($('div .comment-post.vertical-center').css('display') != 'none')
        {
            $('div .comment-post.vertical-center').hide(); 
        }
        else
        {
            $('div .comment-post.vertical-center').show(); 
        }
    })

    $(document).on('click', '#submitComment', function()
    {
        $('div .comment-post.vertical-center').hide();    
    })
    $(document).on('click', '.btn-buy', function()
    {
        window.location.href = $(this).data('url').replace('productcount', $('#count').val());
    }).on('click', '.btn-cart', function()
    {
        var $btn = $(this);
        if($btn.hasClass('disabled')) return;

        $btn.addClass('disabled')
        $.getJSON($btn.data('url').replace('productcount', $('#count').val()), function(data, status)
        {
            if(status === 'success')
            {
                if($.isPlainObject(data) && data.result === 'success')
                {
                    if($.isFunction($.refreshCart))
                    {
                        $.refreshCart(true);
                    }
                    else if(window.v && window.v.addToCartSuccess)
                    {
                        setCartCount();
                        $.messager.success(window.v.addToCartSuccess);
                    }
                }
                else if(data && data.locate)
                {
                    window.location.href = data.locate;
                }
                else
                {
                    $.messager.danger($.param(data));
                }
            }
            else
            {
                if(window.v && window.v.lang.timeout)
                {
                    $.messager.danger(window.v.lang.timeout);
                }
            }
            $btn.removeClass('disabled');
        });
    });

    if(v.stockOpened) 
    {
       $('#count').change(function()
       {
          if($('#count').val() > v.stock) $(this).val(v.stock);
       })
    }
});

;v.exchangeURL = "\/index.php\/tw\/gift-exchange.mhtml";;
  $(document).ready(function()
  {
      $('#buyForm').attr('id', 'exchangeForm');
      $('#exchangeForm').attr('action', v.exchangeURL);
      $('#exchangeForm').append($('#productID'));
      $('#exchangeForm table tbody').prepend($('#scoreItem'));
      $('.footer-right').html($('#btnBox'));
      $('#priceBox').remove();
      $('input').filter(function(){return this.id.match(/[price|count|product]\[.*\]/);}).remove();

      var checkAttr = function ()
      {
          attrSelected = true;
          $('.attr-selector').each(function()
          {
              if($(this).parents('td').find('.attr-selector.active').size() == 0) attrSelected = false;
          });
          return attrSelected;
      };

      var alertAttrForm = function ()
      {
          window.scrollTo(0,$('#attribute').offset().top-200)
          $('.attr-selector').parents('tr').css('border', '1px solid red');
      };

      var hideAttrForm = function ()
      {
          window.scrollTo(0,$('#attribute').offset().top-200)
          $('.attr-selector').parents('tr').css('border', 'none');
      };


      $('#exchangeBtn').click(function()
      {
          if(!checkAttr())
          {
              alertAttrForm();
              return false;
          }
          $('#exchangeForm').submit();
      });

      $('.price-label').click(function()
      {
          hideAttrForm();
          $(this).parent().find('.active').removeClass('active');
          $(this).addClass('active');
          code = $(this).data('attribute');
          extra[code] = $(this).data('value');
          $(this).find('[type=hidden]').val($(this).data('value'));
      });
  });
  