// 主選單開關
;(function($) {
    $('body').on('click', '.menu-toggle', function(e) {
    	e.preventDefault()
    	$('body').toggleClass('menu-active');
    })
})($)

// 首次載入，重刷，滿額加購 加入購物車Icon
;(function($){
    updatePage();
})($)

// 滑動定位
;(function($) {
    $(window).on('scroll', function(e) {
    	e.preventDefault()

    	if($('body').scrollTop()) {
    		$('body').addClass('is-sticky')
    	} else {
    		$('body').removeClass('is-sticky')
    	}
    })
})($)

// 點擊滑動動畫
;(function($) {
    const slideTarget = $('body, html')
    const slideDuration = 750

    $('#gotop').on('click', function(e) {
    	e.preventDefault()
    	slideTarget.animate({
    		scrollTop: 0
    	}, slideDuration);
    })

    $('body').on('click', '.main-menu .link', function(e) {
    	e.preventDefault()

    	const slideOrigin = $(this).attr('href')
    	const slideOffset = (($(slideOrigin).length)? $(slideOrigin).offset().top: 0) - $('.header').height()
    	slideTarget.removeClass('menu-active').animate({
    		scrollTop: slideOffset
    	}, slideDuration);
    })
})($)

// 倒數計時
;(function($) {
	if($("#CountDown_Box").length) {
	    let num = parseInt($("#CountDown_Box").attr("second"),10);
	    const _this = $("#CountDown_Box");
	    if(num > 0) {
	        setInterval(function() {
	            num--;
	            if(num <= 0) {
	                $("#CountDown_Box").hide();
	            }

	            var day = Math.floor(num/(3600*24)),
	                hour = Math.floor((num - (day*3600*24) )/3600),
	                min = Math.floor((num - (day*3600*24) - (hour*3600) )/60 ),
	                second = num - (day*3600*24) - (hour*3600) - (min*60),
	                pad = '00';
	            if(day > 0) {
	                _this.find(".timer").eq(0).html(day);
	                _this.find(".timer").eq(1).html(pad.substring(hour.toString().length)+hour);
	                _this.find(".timer").eq(2).html(pad.substring(min.toString().length)+min);
	                _this.find(".timer").eq(3).html(pad.substring(second.toString().length)+second);
	            } else {
	                _this.find(".Date_Box").remove();
	                _this.find(".timerbox").html(_this.find(".timerbox").html().replace('天',''));

	                _this.find(".timer").eq(0).html(pad.substring(hour.toString().length)+hour);
	                _this.find(".timer").eq(1).html(pad.substring(min.toString().length)+min);
	                _this.find(".timer").eq(2).html(pad.substring(second.toString().length)+second);
	            }
	        },1000);
	    } else {
	    	_this.remove()
	    }
	}
})($)

// 商品資料頁籤切換
;(function($) {
    $('body').on('click', '.tag-box .title-h2', function(e) {
        e.preventDefault()

        const tagTarget = $(this).attr('for')
        $(this).addClass('in-active')
               .siblings('.title-h2').removeClass('in-active')
        $(this).parents('.tag-box')
               .find('.' + tagTarget).addClass('in-active')
               .siblings('.itembox').removeClass('in-active')
    })
})($)







// ==========================================================
//  通用跳窗功能
// ==========================================================
;(function($) {
    $('body').on('click', '.popupBox-wrapper', function(e) {
        if(e.currentTarget === e.target || $(e.target).hasClass('closer') || $(e.target).parent().hasClass('closer')) {
            e.preventDefault()
            $('body').removeClass('overflow-hidden')
            $(e.currentTarget).remove()
        }
    })
})($)


// ==========================================================
//  快速購物跳窗
// ==========================================================
;(function($) {
    let commonShopcartStep = false
    $('body').on('click', '.QuickShop', function(e) {
        e.preventDefault()
        if(!commonShopcartStep) {
            commonShopcartStep = true
            jQuery.ajax({
                url:  Project_Country + 'ajax/ajax_popup_shopbox.php',
                type: 'POST',
                dataType: 'html',
                data: {
                    SID: $(this).attr('sid'),
                    Serial: $(this).attr('serial'),
                    Page_Shop_ID:$('#Page_Shop_ID').val(),
                    Add_Type:$(this).attr('add_type')
                },
            }).done(function(res) {
                if(res.indexOf('window.location.href=') == 0)
                {
                    eval(res);
                }
                else
                {
                    $('body').addClass('overflow-hidden').append(res)
                    const slideTarget = $('.quickShop-box .preview-slide')
                    if(slideTarget.length && slideTarget.children('.slide-item').length > 1) {
                        slideTarget.addClass('with-dots').owlCarousel({
                            nav: true,
                            navText: ['<i class="icon icon-angle-left"></i>', '<i class="icon icon-angle-right"></i>'],
                            dots: false,
                            margin: 10,
                            items: 1,
                        })
                    }
                }
            }).fail(function(x, y, z) {
                console.log(x)
            }).always(function() {
                commonShopcartStep = false
            })
        }
    })
})($)


$(function() {
    $("#Member_Form").fromsAuth();
    $("#Main_Form").fromsAuth();

    $("#Main_Content").on('click', '#step2', function() {
        var pass = $(this).attr('Pass');
        if(pass==2){
            // alert("您尚未登入會員，請先登入會員。");
            // location.href='/member-login/';
        }
        var sh = $("#s2 .section-wrapper").height() + 100;
        $("html,body").animate({scrollTop: $('#s2').offset().top - sh}, 800);
    });

    $("#Main_Content").on('click', '#step3', function() {
        var sh2 = $("#s3").height();
         if($(window).width() <= 480){
            $("html,body").animate({scrollTop: $('#s3').offset().top - 70}, 800);
        } else {
            $("html,body").animate({scrollTop: $('#s3').offset().top}, 800);
        }
    });


    $("#Main_Content").on('click','#productlist .button-full',function(){
        if(!$(this).is('.button-cant')){
            var $class = $(this).attr("class"),
                type = '1';
            if($class == 'button-add')
            {
                type = '2';
            }
            $('.popupbg').addClass('is-show');
            $('.popupbg').attr("type",type);
            $('.popupbg').html($(this).parents(".productBox").find(".Box_Data").html());
        }

    });
    $("#Main_Content").on('click','.informButton',function(){
        $("#informID").val($(this).attr("sid"));
        $('.emailPopup').css('display','flex');
    });
    $("#Main_Content").on('click','.emailPopup .close',function(){
        $('.emailPopup').css('display','none');
    });

    $("#Main_Content").on('click','.loginButton',function(){
        $('body').addClass('memberOnPop')
        $('.memberPopup').css('display','flex');
    });
    $("#Main_Content").on('click','.memberPopup .close',function(){
        $('body').removeClass('memberOnPop')
        $('.memberPopup').css('display','none');
    });
    $("#Change_Pic").click(function(e){
        $("#Checkspan").load(Project_Country+'ajax/ajax_get_check_pic.php',{change:1});
    });
    /* 小圖hover效果及切換功能 */
    if($(".moreview .picitem ").length > 5){
        $(".productView .moreview").owlCarousel({
            loop:false,
            responsive:{
                0:{
                    items : 3,
                  },
                768:{
                    items : 5,
                }
            },
            nav : true,
            dots: false,
            navText: ['<i class="icon icon-angle-left"></i>', '<i class="icon icon-angle-right"></i>'],
        }).on('mouseleave','.owl-stage-outer', function() {
            var box = $(this).parents(".productBox");
            box.find(".productView .zoonbox").removeAttr('style');
        })
        .on('click','.owl-item', function() {
            var now = $(this).index(),
                box = $(this).parents(".productBox");
            box.find(".productView .owl-item").not(this).find('.picitem').removeClass('now');
            $(this).find('.picitem').addClass('now');
            box.find(".productView .zoonbox").removeClass('now').eq(now).addClass('now');
        })
        .on('mouseenter','.owl-item', function() {
            var now = $(this).index(),
                box = $(this).parents(".productBox");
            box.find(".productView .zoonbox").css('display','none').eq(now).css('display','flex');
        });
    }else{
        $(".productView .moreview")
        .on('mouseleave', function() {
            var box = $(this).parents(".productBox");
            box.find(".productView .zoonbox").removeAttr('style');
        })
        .on('click','.picitem', function() {
            var now = $(this).index(),
                box = $(this).parents(".productBox");

            box.find(".productView .picitem").removeClass('now');
            $(this).addClass('now');
            box.find(".productView .zoonbox").removeClass('now').eq(now).addClass('now');
        })
        .on('mouseenter','.picitem', function() {
            var now = $(this).index(),
                box = $(this).parents(".productBox");

            box.find(".productView .zoonbox").css('display','none').eq(now).css('display','block');
        });
    }

    $("#Main_Content").on('focusin','.input-text',function(){
        $(this).parents(".word-line").find('.text-title').addClass('now');
    });
    $("#Main_Content").on('focusout','.input-text',function(){
        if($(this).val()==''){
            $(this).parents(".word-line").find('.text-title').removeClass('now');
        }
    });

    $('.gotop').on('click',function(){
        $("html,body").animate({scrollTop: 0},800);
    });




});

//刪除購物車
$("#Main_Content").on('click','.product-del',function() {
    $.ajax({
        url:Project_Country+"quickshop/ajax/ajax_del_cart.php",
        type:"POST",
        cache:false,
        data:{ID:$(this).attr("sid"), Page_Shop_ID:$("#Page_Shop_ID").val()},
        dataType:'json',
        error:function(d){
            alert('網路連線過慢，網頁請重新整理');
        },
        success:function(d){
            if(d.Status == 'RET_SUCCESS')
            {
                alert(_jsLang.刪除成功);
                updatePage();
            }
            else
            {
                alert(_jsLang.資料庫忙線中);
            }
        }
    });

    setTimeout(function () {
        $('.emptyCartPrompt').fadeOut()
    }, 5000)
});

//修改數量
$("#Main_Content").on('click','.Prod_Plus',function(){
    var Amount = parseInt($(this).prev(".Prod_Amount").val())+1,
        Stock = parseInt($(this).attr("max"));
    if(Amount > 100 || Amount > Stock)
    {
        return false;
    }
    $(this).prev(".Prod_Amount").val(Amount).change();
});
$("#Main_Content").on('click','.Prod_Minus',function(){
    var Amount = parseInt($(this).next(".Prod_Amount").val())-1;
    if(Amount < 1)
    {
        return false;
    }
    $(this).next(".Prod_Amount").val(Amount).change();
});

$("#Main_Content").on('change','.Prod_Amount',function(){
    var ID = $(this).parents(".listbox-item").find(".product-del").attr("sid"),
        Amount = $(this).val(),
        Input = $(this);

    if(Amount > 100)
    {
        Amount = 100;
    }
    if(Amount < 1)
    {
        Amount = 1;
    }

    $.ajax({
        url:Project_Country+"quickshop/ajax/ajax_change_cart.php",
        type:"POST",
        cache:false,
        data:{ID:ID,Amount:Amount,Page_Shop_ID:$("#Page_Shop_ID").val()},
        error:function(d){
            alert('網路連線過慢，網頁請重新整理');
        },
        success:function(d){
            var d = d.trim();
            switch(d){
                case "RET_SUCCESS":
                    updatePage();
                    break;
                case "RET_NO_MEMBER_NO":
                    alert(_jsLang.欲購買紅利兌換商品請先登入會員並完成會員認證);
                    break;
                case "RET_RBONUS_OUT":
                    alert(_jsLang.紅利不足);
                    break;
                case "RET_ERROR":
                    alert(_jsLang.資料庫忙線中);
                    break;
                case "RET_PROD_ERROR":
                    alert(_jsLang商品已下架);
                    break;
                case "RET_NO_PROD":
                    alert(_jsLang.請選擇商品);
                    break;
                case "RET_STOCK_ERROR":
                    alert(_jsLang.商品庫存不足);
                    break;
                case "RET_LIMIT_ERROR":
                    alert(_jsLang.數量超過限購量);
                    break;
				case "RET_OVER_SIT_MAX":
					alert(_jsLang.數量超過定期購限購量);
					break;
                default:
                    alert(_jsLang.資料庫忙線中);
                    break;
            };
        }
    });
});

//活動字串
$("#Main_Content").on('click','#Act_Str_Button',function(){
    var str = $("#Act_Str_Input").val();
    if(str)
    {
        updatePage('&Act_Str='+str);
    }
});
$("#Main_Content").on('click','#Act_Str_Cancel',function(){
    updatePage('&Act_Str=Cancel_Act_Str');
});
//紅利
$("#Main_Content").on('click','#Red_Point_Button',function(){
    var str = $("#Red_Point_Input").val();
    if(str)
    {
        updatePage('&Red_Point='+str);
    }
});
$("#Main_Content").on('click','#Red_Point_Cancel',function(){
    updatePage('&Red_Point=0');
});

//抵用券
$("#Main_Content").on('click','#Coupon_Button',function(){
    var str = $("#Coupon_Input").val();
    if(str)
    {
        updatePage('&Coupon_Code='+str);
    }
});
$("#Main_Content").on('click','#Red_Point_Cancel',function(){
    updatePage('&Coupon_Code=Cancel');
});

$(document).on("change", "[name='usable_no']", function(){
    var str = $("[name='usable_no']:checked").val()
    $(".coupon-popup").addClass("hide")
    updatePage('&Coupon_Code=' + str);
})

$(document).on("click", ".coupon-popup-btn", function(){
    $(".coupon-popup").removeClass("hide")
})
$(document).on("click", ".coupon-popup .close", function(){
    $(".coupon-popup").addClass("hide")
})


//退貨保留款
$("#Main_Content").on('click','#MemberMoney_Use',function(){
    var str = $("#MemberMoney_Input").val();
    if(str)
    {
        updatePage('&MemberMoney='+str);
    }
});
$("#Main_Content").on('click','#MemberMoney_Cancel',function(){
    updatePage('&MemberMoney=MemberMoney_Cancel');
});
$("#Main_Content").on('click','#MemberMoney_Unuse',function(){
    updatePage('&MemberMoney=MemberMoney_Cancel');
});

//切換配送國家
$("#Main_Content").on('change','#Send_Country',function(){
    updatePage('&Country='+$(this).val());
});

//切換配送方式
$("#Main_Content").on('click','input[name="Ship_Type"]',function(){
    updatePage('&Ship_Type='+$(this).val());
});

//門市取貨
$("#Main_Content").on("change","#Store_Pick",function(){
    updatePage('&CVSStoreID='+$(this).val());
});

//切換付款方式
$("#Main_Content").on('click','input[name="Pay_Type"]',function(){
    updatePage('&Pay_Type='+$(this).val());
});

//切換配送城市
$("#Main_Content").on('change','#Send_City',function(){
    updatePage('&City='+$(this).val());
});

//切換配送地區
$("#Main_Content").on('change','#Send_Area',function(){
    updatePage('&Area='+$(this).val());
});

//樓層切換
$("#Main_Content").on('change',".Send_Floor",function(){
    updatePage('&Send_Floor='+$(this).val());
});

//是否有電梯
$("#Main_Content").on('change',".Send_Elevator",function(){
    updatePage('&Send_Elevator='+$(this).val());
});

//選擇門市
$("#Main_Content").on("click","#Choose_Store", function(){
    var $return = encodeURIComponent('quickshop/quickshop.php?ID='+$("#Page_Shop_ID").val()+'&Pass_Str='+$("#Pass_Str").val()+'#s2'),
        $type = $(this).attr("type"),
        $coll = $(this).attr("coll");
    updatePage('&save=1');

    setTimeout(function(){
        window.location.href = '/shopcart/e_returns/emap-p.php?url='+$return+'&type='+$type+'&coll='+$coll+'&shop_id='+$("#Page_Shop_ID").val();
    },500);
});

//送出訂單
$("#Main_Content").on('click','#Form_Submit',function(){
    var pattern_En = /^[A-Za-z]+$/;

    var check_Name = $("#Send_Name").val();
    var submit = false;
    //允許字元4-10,半形英4-10,中文2-5
    if(!hasSpecialStr(check_Name)) {
        //無特殊符號
        if(pattern_En.test(check_Name)) {
            //是英數
            if(check_Name.length >= 4 && check_Name.length <= 10){
                submit = true;
            }
        }else if(check_Name.length >= 2 && check_Name.length <= 5){
                        //其他語系
            submit = true;
        }
    }
    if(!submit) {
        alert(_jsLang.收件人姓名長度不合);
        $(".forms_show[for='Send_Name']").text("*").show().attr('error', 'true');
    } else {
        var gift = $("#Act13_Num").val() - $("#ChooseGift").val();
        if($("#CanGift").val() == 1 && (gift > 0 || gift < 0)){
            if(gift > 0) {
                alert(_jsLang.尚可挑選+gift+_jsLang.件贈品請挑選後再送出購物車);
            } else {
                alert(_jsLang.贈品+_jsLang.數量超過限購量);
            }
        /*}else if($("#CanAdd").val() == 1 && $("#ChooseAdd").val() == 0) {
            alert(_jsLang.至少加購一件加購品);*/
        }else{
            $("#Main_Form").submit();
        }
    }
});

//姓名、電話、Email、地址、備註
$("#Main_Content").on('change','#Send_Name,#Send_Cellphone,#Email,#Send_Address,#Send_Memo',function(){
    updatePage('&save=1');
});

//自動加入會員、收貨時間
$("#Main_Content").on('click',"#Auto_Add,input[name='Send_Time']",function(){
    updatePage('&save=1');
});

//切換載具類型
$("#Main_Content").on('change',"#CarrierType",function(){
    updatePage();
});
//切換發票類型
$("#Main_Content").on('click',"input[name='Invo_Mod']",function(){
    updatePage();
});

//同收件地址
$("#Main_Content").on('click','#Invo_Same_Button',function(){
    if($(this).prop("checked"))
    {
        var same = '1';
        $("#Invo_Address_Box").hide();
        $("#Invo_Address").attr("fun","");
    }
    else
    {
        var same = '2';
        $("#Invo_Address_Box").show();
        $("#Invo_Address").attr("fun","checkNull");
    }
    updatePage('&Invo_Same='+same+'&save=1');
    $("input[name='Invo_Same']").val(same);
});

$("#Main_Content").on('click','.title-big',function(){
    var num = $(this).parent('section').attr("num");
    if(num > '0')
    {
        $(this).parent('section').toggleClass("open",500);
    }
    else
    {
        $(".emptyCartPrompt").css("display","block");
        setTimeout(function () {
            $('.emptyCartPrompt').fadeOut()
        }, 5000)
    }
});

$("#Main_Content").on('click','.shopcart-link',function(){
    $('section').addClass("open",500);
});

$('body').on('click','.arrow .title-big', function(event) {
    // console.log($('.is-nowStep'));
    if(!$(this).is('.open')){
        $('.arrow').not(this).removeClass('open');
        $(this).parent('.arrow').addClass('open');
        updatePage('&Step='+$(this).parent('section').attr("id").substr(1,1)+'&save=1');
    }
});

$("#Main_Content").on('click','#step2',function(){
    $('#s2').addClass("open",500);
    $('#s2').addClass("arrow",500);
    // $(this).parents('.section-wrapper').parent('section').removeClass('open');
    updatePage('&Step=2&save=1&MoneyShow=1');
});
$("#Main_Content").on('click','#step3',function(){
    $('#s3').addClass("open",500);
    $('#s3').addClass("arrow",500);
    // $(this).parents('section').removeClass('open');
    updatePage('&Step=3&save=1');
});

// 按下我要結帳後出現底部浮動
$("#Main_Content").on('click', '#step2', function() {
     $('.moneyPrompt').css('display', 'block').hide().fadeIn()
});

//切換定期購期數
$("#Main_Content").on('change',"#SIT_Installment",function(){
    updatePage();
});

//收件人姓名
$("#Main_Content").on('change',"#Send_Name",function(){
    var pattern_En = /^[A-Za-z]+$/;

    var check_Name = $("#Send_Name").val();
    var submit = false;
    if(!hasSpecialStr(check_Name)) {
        //無特殊符號
        if(pattern_En.test(check_Name)) {
            //是英數
            if(check_Name.length >= 4 && check_Name.length <= 10){
                submit = true;
            }
        }else if(check_Name.length >= 2 && check_Name.length <= 5){
                        //其他語系
            submit = true;
        }
    }
    if(!submit) {
        $(".forms_show[for='Send_Name']").text("*").show().attr('error', 'true');
    }else {
        $(".forms_show[for='Send_Name']").text("").show();
    }
});

//結帳登入 手機驗證碼
$("#Main_Content").on('click','#VerifyCode_Button',function(e){
    var Button = $(this);
    var Email = $('#Email').val();
    var Buy_Cellphone = $('#Send_Cellphone').val();
    var Password = $('#Login_Password').val();
    var Country_Tel_Code = $('#Country_Tel_Code').val();
    var Country_ID = $('#Send_Country_ID').val();
    // if(Email == ""){alert('請輸入訂購人的E-mail');return false;}
    if(Buy_Cellphone == ""){alert('請輸入訂購人的行動電話');return false;}
    // if(Password == ""){alert('請輸入密碼');return false;}
    // if(Country_Tel_Code == ""){alert("請輸入國碼");return false;}
    $.ajax({
        url: Project_Country + "shopcart/ajax/ajax_verifycode.php",
        type:"POST",
        cache:false,
        data:{Email:Email,CellPhone:Buy_Cellphone,Password:Password,Country_Tel_Code:Country_Tel_Code,Country_ID:Country_ID},
        success:function(h){
            if(h=="ERROR1"){
                alert(Email +' - 此E-Mail已是網站會員，請直接登入。\n若忘記密碼，請按"忘記密碼?"進行索取。');
                $(".memberPopup").show();
                //window.location.href = '/' + $("#Website_Mall_ID").val() + '/member-login';
            }
            else if(h=="ERROR2"){
                alert(Buy_Cellphone +' - 此手機號碼已是網站會員，請直接登入。\n若忘記密碼，請按"忘記密碼?"進行索取。');
                $(".memberPopup").show();
                //window.location.href = '/' + $("#Website_Mall_ID").val() + '/member-login';
            }
            else if(h=='OK'){
                $('#VerifyCode_Tag').hide();
                $('#VerifyCode').attr("fun","");
                alert('您已是網站會員，請直接登入。');
                $(".memberPopup").show();
                //window.location.href = '/' + $("#Website_Mall_ID").val() + '/member-login';
            }
            else if(h == 'RET_REPLY'){
                alert('請勿重覆發送簡訊, 請等侯5分鐘');
            }
            else if(h == 'RET_OVER'){
                alert('手機簡訊發送已上限');
            }
            else if(h == 'RET_CELLPHONE_REPLY'){
                alert('您已經是會員，請登入會員，如忘記登入密碼，可至會員登入處點選「忘記密碼?」');
                $(".memberPopup").show();
                //window.location.href = '/' + $("#Website_Mall_ID").val() + '/member-login';
            }
            else if(h == 'RET_OK'){
                Button.attr('disabled','disabld').html('認證簡訊已發送');
                alert('認證簡訊已發送');
            }
            else if(h == 'RET_ERROR_CRM'){
                alert(_jsLang.會員中心呼叫異常);
            }
        }
    });
});

function updatePage(data) {
    //取得一般配送資料
    var send = '';
    var data = data || '';
    //寄送資料
    $("#Send_Name,#Send_Cellphone,#Email,#Send_Address,input[name='Send_Time']:checked,#Send_Memo,#Del_Type,#Auto_Add:checked,#SIT_Installment,#Code,#Login_Password,#Login_Password2").each(function(){
        send += '&'+$(this).attr("name")+'='+$(this).val();
    });
    //發票資料
    $("input[name='Invo_Mod']:checked,#CarrierType,#CarrierId1,#CarrierId2,#NPOBAN,#Invo_Title,#Invo_No,#Invo_Address").each(function(){
        send += '&'+$(this).attr("name")+'='+$(this).val();
    });
    var $data = 'type=update'+data+send+'&Page_Shop_ID='+$("#Page_Shop_ID").val();
    $.ajax({
        url:Project_Country+"quickshop/ajax/ajax_get_cart.php",
        type:"POST",
        async: true,
        data:$data,
        cache:false,
        error:function(d,e,f){
            alert('網路連線過慢，網頁請重新整理');
        },
        success:function(d){
            if(d)
            {
                $("#Ajax_Box").html(d);
                //活動字串訊息
                if($("#Coupon_Msg").val()){
                    alert($("#Coupon_Msg").val());
                }
                $("#Main_Form").fromsAuth();
                //加購按鈕
                var add = parseInt($("#CanAdd").val());
                if(add > 0)
                {
                    $(".Add_Button").removeClass('button-cant');
                    $(".Add_Button").html('<i class="icon icon-cart"></i>');
                }
                else
                {
                    $(".Add_Button").addClass('button-cant');
                    $(".Add_Button").html('');
                }
                //滿額按鈕
                var gift = parseInt($("#CanGift").val());
                if(gift > 0)
                {
                    $(".Gift_Button").removeClass('button-cant');
                    $(".Gift_Button").html('<i class="icon icon-cart"></i>');
                }
                else
                {
                    $(".Gift_Button").addClass('button-cant');
                    $(".Gift_Button").html('');
                }

                var amount = parseInt($("#ChooseGift").val());
                $("#Gift_Amount").html(amount);
            }
        }
    })
}
//檢查符號
function hasSpecialStr(str) {
	var specialChars = "^`'!@$%#&*+\\\"<>|_-[](){},.︿‵＇！＠＃％＆＊+，？（）｛｝［］?1234567890 ";
	for(var i=0;i<specialChars.length;i++) {
		if(str.indexOf(specialChars.substring(i,i+1)) != -1) {
			return true;
		}
	}
	return false;
}
//商品彈窗內商品說明頁簽
;(function($) {
    $(document).on('click', '.detail-tag', function(){
        let _this = $(this),
            target = _this.data('target')

        if(!_this.hasClass('in-active')){
            $('.detail-tag').removeClass('in-active')
            _this.addClass('in-active')

            $('.detail-content').removeClass('in-active')
            $('.detail-content[data-index=' + target + ']').addClass('in-active')
        }
    })
})($)


//  密碼顯示切換
;(function($) {
    $(document).on('click', '.password-toggle', function(e) {
        e.preventDefault()
        const target = $(this).parents('.password-group').find('.password')
        const targetType = target.attr('type')

        $(this).find('.icon').toggleClass('icon-eye').toggleClass('icon-eye-slash')
        if(targetType === 'password') {
            target.attr('type', 'text')
        } else if(targetType === 'text') {
            target.attr('type', 'password')
        }

    })
})($)

// window trigger
;(function($) {
    $(window).trigger('resize, scroll')
})($)

