﻿/* Js for , Version=1775112368 */
 if(typeof(v) != "object") v = {};v.path = ["26","22","20"];;v.objectType = "product";;v.productID = 4;;v.objectID = 4;;v.categoryID = 20;;v.categoryPath = ["26","22","20"];;v.addToCartSuccess = "\u6210\u529f\u52a0\u5165\u8d2d\u7269\u8f66\u3002";;v.gotoCart = "\u53bb\u8d2d\u7269\u8f66\u7ed3\u7b97";;v.goback = "\u8fd4\u56de";;v.stockOpened = false;;v.stock = 0;;
;v.pageLayout = "global";;
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?eb445dbf0c385ee3bd0dc397802528f5";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
;v.location = "L3Byb2R1Y3QvNC5odG1s";;v.attributeHtml = "";;v.price = 0;;
    $(document).ready(function()
    {
        $('#priceItem').replaceWith(v.attributeHtml);
        extra = {};
        $('#buyBtnBox').before($('#buyForm'));
        $('#buyBtnBox').replaceWith($('#btnBox'));

        $('#buyForm').after($('#countBox').parent());
        $('.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())
       });
    
        $('#cartBtn').click(function()
        {
            if(!checkAttr()) 
            {
                alertAttrForm();
                return false;
            }
    
            $.post(createLink('cart', 'add', "product=" + v.objectID + '&count=' + $('#count').val()),
                {extra: extra},
                function(response)
                {
                    if(response.result == 'success')
                    {
                        loadCartInfo(true);
                    }
                    else
                    {
                        location.href = response.locate;           
                    }
                },
                'json'
            )
        });
        
        $('#buyBtn.login').click(function(){location.href=createLink('user', 'login', "referer=" + v.location)});
        $('#buyBtn.buy').click(function()
        {
            if(!checkAttr()) 
            {
                alertAttrForm();
                return false;
            }
            $('#buyForm').submit();
         });
    
        function alertAttrForm() { $('#attributeBox').css('border', '1px solid red'); }
        function hideAttrForm() { $('#attributeBox').css('border', 'none'); }
    
        function computedPrice()
        {
            if(!checkAttr()) return false;
            price = v.price;
            $('.attr-selector.active').each(function()
            {
                if($(this).data('price') && $(this).data('price') != 0)
                {
                    value = $(this).data('price');
                    price = parseFloat(price) + parseFloat(value);
                }
                price = parseFloat(price);
                price = price.toFixed(2);
            });
            if(v.hasDiscount)
            {
                price = price * v.discount;
                price = price.toFixed(2);
            }
            $('.product-property .meta-list .meta-value strong.text-danger').html(price);
            $('.product-property .meta-list .meta-value strong.text-important').html(price);
            $('#price').val(price);
        }
    
        function checkAttr()
        {
            attrSelected = true;
            $('.attr-selector').each(function()
            {
                if($(this).parents('li').find('.attr-selector.active').size() == 0) attrSelected = false;
            });
            return attrSelected;
        }
    });
    