/* Minification failed. Returning unminified contents.
(541,36-37): run-time error JS1014: Invalid character: `
(541,37-38): run-time error JS1195: Expected expression: <
(542,17-18): run-time error JS1195: Expected expression: <
(542,17-18): run-time error JS1195: Expected expression: <
(543,19-20): run-time error JS1014: Invalid character: `
(548,9-13): run-time error JS1197: Too many errors. The file might not be a JavaScript file: self
 */

var homeEventWap = {
    init: function () {
        const self = this;

        self.initSlide();
        self.ShowTabNews();
        self.ShowHideNewsPaper();
        self.showTabCarBrands();

        if ($('#tabSearch').length === 1) {
            $('#tabSearch').attr('data-id', '0');
        }

        //Lowest Monthly Payment
        if (typeof dealerPromosV2 != 'undefined')
            dealerPromosV2.initFeaturedPromo();

    },
    initSlide: function () {
        let box = '';

        //Box New Cars For Sale
        //let box = '#boxHomeNewCarsForSale';
        //if ($(box + ' .swiper-container').length > 0 && $(box + ' .swiper-slide').length > 1) {
        //    new Swiper(box + ' .swiper-container', {
        //        slidesPerView: 'auto',
        //        spaceBetween: 10
        //    });
        //}

        //Box Used Cars For Sale
        box = '#boxHomeUsedCarsForSale';
        if ($(box + ' .swiper-container').length > 0 && $(box + ' .swiper-slide').length > 1) {
            new Swiper(box + ' .swiper-container', {
                slidesPerView: 'auto',
                spaceBetween: 10
            });
        }

        //New Cars Guide
        box = '#boxNewCarsGuide';
        if ($(box + ' .swiper-container').length > 0 && $(box + ' .swiper-slide').length > 1) {
            new Swiper(box + ' .swiper-container', {
                slidesPerView: 'auto',
                spaceBetween: 10
            });
        }

        //Box Featured cars
        box = '#boxHomeFeaturedCar';
        if ($(box + ' .swiper-container').length > 0 && $(box + ' .swiper-slide').length > 1) {
            new Swiper(box + ' .swiper-container', {
                slidesPerView: 'auto',
                spaceBetween: 10
            });
        }

        //Box Find Car Dealerships
        box = '#boxDealershipRegions';
        if ($(box + ' .swiper-container').length > 0 && $(box + ' .swiper-slide').length > 1) {
            new Swiper(box + ' .swiper-container', {
                slidesPerView: 'auto',
                spaceBetween: 10,
                loop: true,
                centeredSlides: true,
                // Navigation
                navigation: {
                    nextEl: box + ' .next',
                    prevEl: box + ' .prev',
                }
            });
        } else
            $(box + ' .btn-slide').remove();

        //Box Featured promos 
        box = '#box-list-promos-home';
        if ($(box + ' .swiper-container').length > 0 && $(box + ' .swiper-slide').length > 1) {
            new Swiper(box + ' .swiper-container', {
                slidesPerView: 'auto',
                loop: true,
                // Navigation
                navigation: {
                    nextEl: box + ' .next',
                    prevEl: box + ' .prev',
                }
            });
        } else
            $('#boxHighlightReviewHome .btn-slide').remove();

        //Box Featured Videos 
        box = '.box-list-video';
        if ($(box + ' .swiper-container').length > 0 && $(box + ' .swiper-slide').length > 1) {
            new Swiper(box + ' .swiper-container', {
                slidesPerView: 'auto',
                spaceBetween: 10
            });
        }

        //Box Our Partners
        box = '#box-our-partners';
        if ($(box + ' .swiper-container').length > 0 && $(box + ' .swiper-slide').length > 1) {
            new Swiper(box + ' .swiper-container', {
                slidesPerView: 'auto',
                spaceBetween: 10
            });
        }

    },
    Slider: function () {
        //Box New Cars For Sale
        let box = '#boxHomeNewCarsForSale';
        if ($(box + ' .swiper-container').length > 0 && $(box + ' .swiper-slide').length > 1) {
            new Swiper(box + ' .swiper-container', {
                // Default parameters
                slidesPerView: 'auto',
                spaceBetween: 10,
                autoplay: 10000,
                speed: 400
            });
        }

        //Box Used Cars For Sale
        box = '#boxHomeUsedCarsForSale';
        if ($(box + ' .swiper-container').length > 0 && $(box + ' .swiper-slide').length > 1) {
            new Swiper(box + ' .swiper-container', {
                // Default parameters
                slidesPerView: 'auto',
                spaceBetween: 10,
                autoplay: 10000,
                speed: 400
            });
        }

        //Box Find car dealerships 
        box = '#boxDealershipRegions';
        if ($(box + ' .swiper-container').length > 0 && $(box + ' .swiper-slide').length > 1) {
            new Swiper(box + ' .swiper-container', {
                slidesPerView: 'auto',
                centeredSlides: true,
                spaceBetween: 10,
                loop: true,
                autoplay: 10000,
                speed: 400,
                paginationClickable: true,
                pagination: {
                    el: '.pagination',
                    clickable: true,
                },
            });
        }

        //Box Featured videos 
        if ($('#box-small-video').length > 0) {
            new Swiper('#box-small-video',
                {
                    slidesPerView: 'auto',
                    spaceBetween: 10,
                    loop: true,
                    autoplay: 10000,
                    speed: 400,
                });
        }

        if ($('#box-list-promos-home .swiper-container').length > 0) {
            new Swiper('#box-list-promos-home .swiper-container',
                {
                    slidesPerView: 1,
                    spaceBetween: 10,
                    calculateHeight: true,
                    loop: false,
                    paginationClickable: false,
                    navigation: {
                        nextEl: '#box-list-promos-home .next',
                        prevEl: '#box-list-promos-home .prev',
                    },
                });

        }

        if ($('#box-our-partners').length > 0) {
            new Swiper('#box-our-partners .list-our',
                {
                    slidesPerView: 2.2,
                    slidesPerGroup: 1,
                    calculateHeight: true,
                    loop: true,
                    breakpoints: {
                        '@0.00': {
                            slidesPerView: 2.2,
                            spaceBetween: 10,
                        },
                        '@0.5': {
                            slidesPerView: 2.5,
                            spaceBetween: 10,
                        },
                        '@0.75': {
                            slidesPerView: 3,
                            spaceBetween: 10,
                        },
                        '@1.0': {
                            slidesPerView: 4,
                            spaceBetween: 10,
                        },
                    }
                });
        }
    },
    ShowTabNews: function () {
        if ($('#boxHomeNewsByCategory').length > 0) {
            var labels = $('#boxHomeNewsByCategory .menu-tab > li').map(function () { return $(this).text().trim(); });

            var tabCount = $('#boxHomeNewsByCategory .menu-tab > li').length;

            $('#boxHomeNewsByCategory .menu-tab > li').click(function () {
                var aTag = $(this).find('a');
                if (!aTag.hasClass('active')) {
                    var targetTabId = aTag.attr('data-tab-ref');
                    $('#boxHomeNewsByCategory .menu-tab > li > a.active').removeClass('active');
                    aTag.addClass('active');


                    $('#boxHomeNewsByCategory .content-tab').addClass('hidden');
                    //$('#boxHomeNewsByCategory [data-tab-id]').removeClass('hidden');

                    var dataTab = $(this).find('a').attr('data-tab-ref');
                    $('#boxHomeNewsByCategory .content-tab-' + dataTab).removeClass('hidden');

                    var tabMenuWidths = [];

                    $('#boxHomeNewsByCategory .menu-tab > li').each(function (key) {
                        tabMenuWidths.push($(this).outerWidth());
                    });

                    var activeTabLabel = $('#boxHomeNewsByCategory .menu-tab > li a.active').closest('li');
                    var activeElmIndex = activeTabLabel.index();

                    var targetScrollLeft = 0;
                    for (var i = 0; i < activeElmIndex; i++) {
                        targetScrollLeft += tabMenuWidths[i];
                    }

                    if (activeElmIndex != 0 && activeElmIndex != tabCount - 1) {
                        targetScrollLeft += (activeTabLabel.outerWidth() - $('#boxHomeNewsByCategory .scroll-menu-tab').outerWidth()) / 2;
                    }

                    $('#boxHomeNewsByCategory .scroll-menu-tab').animate({ scrollLeft: targetScrollLeft }, 200);
                }
            });
        }
    },
    ShowHideNewsPaper: function () {
        $('#showHideNewsPaper').on('click', function () {
            if ($('#news-paper-article-box .box-view-all').hasClass('hidden')) {
                $('#news-paper-article-box .box-view-all').removeClass('hidden').show();
            }
            else {
                $('#news-paper-article-box .box-view-all').addClass('hidden').hide();
            }

        });
    },
    showTabCarBrands: function () {
        if ($('#boxCarBrands').length > 0) {
            $('#boxCarBrands .tab-categories > li').click(function () {
                if (!$(this).find('a').hasClass('active')) {
                    var targetTabId = $(this).attr('data-tab-ref');
                    $('#boxCarBrands .tab-categories li a').removeClass('active');
                    $(this).find('a').addClass('active');
                    $('#boxCarBrands .tab').addClass('hidden');
                    $('#boxCarBrands .tab[data-tab-id="' + targetTabId + '"]').removeClass('hidden');
                    $('#boxCarBrands [data-href]').addClass('hidden');
                    $('#boxCarBrands [data-href="' + targetTabId + '"]').removeClass('hidden');
                }
            });
        }
    }
};

var searchProductHomeWap = {
    init: function () {
        this.initBoxSearch();
    },
    initBoxSearch: function () {
        const self = this;
        const box = '#boxSearchHome';

         // init box search when load page
        if (typeof $.fn.CustomDropdown != 'undefined') {
            //Brand
            $('#cboBrandSearch', box).CustomDropdown({
                targetInputId: 'cboSearchBrandId',
                targetTextId: 'cboBrandText',
                boxId: 'cstBrandDropdown',
                boxTitle: 'Select a brand',
                optionsFetchUrl: '/Common/GetListBrand',
                optionsFetchMethod: 'get',
                optionValueProperty: 'Id',
                optionTextProperty: 'Name',
                defaultValue: 0,
                //defaultOptionAppend: false,
                defaultText: 'All brands',
                defaultOptionPosition: 'top',
                onShow: CommonsEvent.AddNoScroll,
                onHide: CommonsEvent.RemoveNoScroll,
                onSelected: function () {
                    CommonsEvent.RemoveNoScroll();
                    var brandId = parseInt($('#cboSearchBrandId').val());
                    if (brandId > 0) {
                        modelCustomDropdown.changeStatus(true);
                        modelCustomDropdown.changeOptionsFetchUrl('/Model/GetListAllByBrandId?brandId=' + brandId);
                    }
                    else {
                        modelCustomDropdown.changeStatus(false);
                    }
                }
            });

            //Model
            let brandId = parseInt($('#cboSearchBrandId', box).val());
            let modelCustomDropdown = $('#cboModelSearch', box).CustomDropdown({
                targetInputId: 'cboSearchModelId',
                targetTextId: 'cboModelText',
                boxId: 'cstModelDropdown',
                boxTitle: 'Select a model',
                disabled: brandId > 0 || parseInt($('#cboSearchModelId').val()) > 0 ? false : true,
                optionsFetchUrl: brandId > 0 ? '/Model/GetListAllByBrandId?brandId=' + brandId : undefined,
                optionsFetchMethod: 'post',
                optionValueProperty: 'Id',
                optionTextProperty: 'Name',
                defaultValue: 0,
                defaultText: 'Model',
                onShow: CommonsEvent.AddNoScroll,
                onHide: CommonsEvent.RemoveNoScroll,
                onSelected: function () {
                    CommonsEvent.RemoveNoScroll();
                }
            });

            //BodyType
            $('#cboBodyTypeSearch', box).CustomDropdown({
                targetInputId: 'cboSearchBodyTypeId',
                targetTextId: 'cboBodyTypeText',
                boxId: 'cstBodyTypeDropdown',
                boxTitle: 'Select a Body Type',
                optionsFetchUrl: '/Common/GetListBodyType',
                optionsFetchMethod: 'get',
                optionValueProperty: 'AutoTypeId',
                optionTextProperty: 'AutoTypeName',
                defaultValue: 0,
                //defaultOptionAppend: false,
                defaultText: 'All Body Type',
                defaultOptionPosition: 'top',
                onShow: CommonsEvent.AddNoScroll,
                onHide: CommonsEvent.RemoveNoScroll,
                onSelected: function () {
                    CommonsEvent.RemoveNoScroll();
                }
            });

            //City
            $('#cboCitySearch', box).CustomDropdown({
                targetInputId: 'cboSearchCityId',
                targetTextId: 'cboCityText',
                boxId: 'cstCityDropdown',
                boxTitle: 'Select a City/Region',
                optionValueProperty: 'Id',  // can skip - default is Id
                optionTextProperty: 'Name', // can skip - default is Name
                defaultText: 'City/Region',
                //defaultOptionPosition: '',
                grouped: true,
                groupFetchType: 'merged',
                groupsFetchUrl: '/Common/GetListRegionCity',
                groupValueProperty: 'GroupId',  // can skip - default is GroupId
                groupTextProperty: 'GroupName', // can skip - default is GroupName
                optionsInGroupProperty: 'ListItem'
            });

            //Price
            $('#cboSearchPrice', box).CustomDropdown({
                targetInputId: 'cboSearchPriceId',
                targetTextId: 'cboPriceText',
                boxId: 'cstPriceDropdown',
                boxTitle: 'Select a Price',
                optionsFetchUrl: '/Common/GetListPrice',
                optionsFetchMethod: 'get',
                optionValueProperty: 'PriceCode',
                optionTextProperty: 'PriceName',
                defaultValue: 0,
                defaultText: 'Price',
                onShow: CommonsEvent.AddNoScroll,
                onHide: CommonsEvent.RemoveNoScroll,
                onSelected: function () {
                    CommonsEvent.RemoveNoScroll();
                }
            });

        }

         // init box search when click tab
        $('input[name="SecondHandId"]', box).on('click', function () {
            if ($(this).val() == carCondition.NewCar) {
                //show/hide combobox
                $('#cboCitySearch', box).addClass('hidden');
                $('#cboBodyTypeSearch', box).removeClass('hidden');

                //show/hide link advance search
                $('#advSearchCarGuide', box).removeClass('hidden');
                $('#advSearchCarForSale', box).addClass('hidden');

            } else if ($(this).val() == carCondition.UsedCar) {
                 //show/hide combobox
                $('#cboCitySearch', box).removeClass('hidden');
                $('#cboBodyTypeSearch', box).addClass('hidden');

                //show/hide link advance search
                $('#advSearchCarGuide', box).addClass('hidden');
                $('#advSearchCarForSale', box).removeClass('hidden');

            }
        });

         // search button
        $('#btnSearchHome', box).on('click', function () {
            self.search();
        });

    },
    search: function () {
        const box = '#boxSearchHome';
        //let regex = /\d+/g;
        //let minPrice = '';
        //let maxPrice = '';
        //let priceValue = $('#cboSearchPriceId', box).val();
        //if (priceValue !== undefined && priceValue != '0') {
        //    if (priceValue.indexOf('mlt') > -1) {
        //        maxPrice = priceValue.match(regex).join([]);
        //    }
        //    else if (priceValue.indexOf('mgt') > -1) {
        //        minPrice = priceValue.match(regex).join([]);
        //    }
        //    else {
        //        let arr = priceValue.split("-");
        //        minPrice = arr[0].match(regex).join([]);
        //        maxPrice = arr[1].match(regex).join([]);
        //    }
        //}

        let data = {};
        let rdoCarCondition = $('input[name="SecondHandId"]:checked', box).val();
        let priceObj = parseFromPriceCode($(box + ' #cboSearchPriceId').val());
        if (rdoCarCondition == carCondition.NewCar) {
            data = {
                BodyTypeId: $("#cboSearchBodyTypeId", box).val(),
                BrandId: $("#cboSearchBrandId", box).val(),
                ModelId: $("#cboSearchModelId", box).val(),
                MinPrice: priceObj.minprice,
                MaxPrice: priceObj.maxprice,
            }

            $.ajax({
                type: 'POST',
                cache: false,
                url: '/CarGuide/GetSearchLink',
                data: data,
                beforeSend: function () {
                    CommonsEvent.Loading();
                },
                success: function (searchUrl) {
                    location.href = searchUrl;
                },
                error: function () {
                    CommonsEvent.Loaded();
                },
                complete: function () {
                }
            });

        } else if (rdoCarCondition == carCondition.UsedCar) {
            data = {
                CityId: $("#cboSearchCityId", box).val(),
                //CityAlias: $("#cboHomeSearchCity option:selected", box).data("alias"),
                BrandId: $("#cboSearchBrandId", box).val(),
                //BrandAlias: $("#cboHomeSearchBrand option:selected", box).data("alias"),
                ModelId: $("#cboSearchModelId", box).val(),
                //ModelAlias: $("#cboHomeSearchModel option:selected", box).data("alias"),
                SecondHandId: $('input[name="SecondHandId"]:checked', box).val(),
                MinPrice: priceObj.minprice,
                MaxPrice: priceObj.maxprice,
            }

            $.ajax({
                type: "POST",
                cache: false,
                url: "/Auto/GetLinkSearch/",
                data: data,
                beforeSend: function () {
                    CommonsEvent.Loading();
                },
                success: function (link) {
                    location.href = link;
                },
                complete: function () {
                    CommonsEvent.Loaded();
                    return false;
                }
            });
        }


    }
};

$(document).ready(function () {
    homeEventWap.init();
    searchProductHomeWap.init();

    //if ($('.car-promo-grid').length > 0) {
    //    if (typeof DealerShips !== 'undefined') {
    //        DealerShips.init();
    //    }
    //}

    //Gắn survey trang homepage
    //if (typeof popupSurveyWap != 'undefined') {
    //    popupSurveyWap.init(40000, '0567b6e', 'https://khaosat.me/embed/survey/philkotse-survey-0567b6e');
    //}

});
;
var dealerPromosV2 = {
    lowestMonthlyPayment: {},
    lowestMonthlyPaymentSwiper: {},
    init: function () {
        const self = this;
        self.initBanner();

        let totalRecord = parseInt($('#totalRecord').val());
        if (totalRecord > 10) {
            /*$('#box-carpromo-list').append('<div class="button-loadmore" id="load-more"><span class= "btn-load-more" onclick = "dealerPromosV2.paging()">Load More</span ></div>');*/
            $('#boxResult').append(`<div class="box-load-more" id="load-more" data-redirect="false">
                <a href="javascript:void(0)" class="btn-load" onclick="dealerPromosV2.paging()">Load More</a>
            </div>`);
        }

        self.activeTagPayment();
        self.buildTitle();
        self.changeTags();
        if (totalRecord > 0) {
            $('#total-promos').text(totalRecord);
            if (totalRecord == 1)
                $('#txt-result').text("result");
            else
                $('#txt-result').text("results");
        }     
        else
            $('#total-promos').text(0);
        self.initFeaturedPromo();
        self.initBoxSlideBrandPromos();
        self.initBrandPriceList();
        self.initManyBoxHotPromoHomePage();
    },
    initBanner: function () {
        return;

        //const box = '.carpromo-banner';
        //if (box.length == 0)
        //    return;

        //if ($(box + ' .swiper-container').length > 0 && $(box + ' .swiper-slide').length > 1) {
        //    new Swiper(box + ' .swiper-container', {
        //        slidesPerView: 1,
        //        loop: true,
        //        autoplay: {
        //            delay: 3000,
        //        }
        //    });
        //}

        const box = '#banner_home_promo_top_1';
        if (box.length == 0)
            return;

        $.ajax({
            type: "GET",
            cache: false,
            url: "/Banner/CheckDisplayBannerPromo",
            success: function (dataJson) {
                if (!!dataJson) {
                    let html = '<img width="640" height="904" src="/ContentV2/Banner/BannerPromo/wap-car-promos-top-1-640x904_20220511.jpg" alt="Discover The Extraordinary" style="width:100%;height:auto;" />';
                    $(box).empty().html(html);
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                console.log(thrownError);
            }
        });

    },

    initFeaturedPromo: function () {
        const self = this;
        //first tab Lowest Monthly Payment
        let tabBrandId = $('.tab-lowest-promo').eq(0).attr('data-id');
        self.lowestMonthlyPayment[tabBrandId] = true;

        let boxLowestPromos = '#box-lowest .content-lowest-promo:not(.hidden)';
        if ($(boxLowestPromos + ' .swiper-container').length > 0 && $(boxLowestPromos + ' .swiper-slide').length > 1) {
            let boxLowestPromosSwiper = new Swiper(boxLowestPromos + ' .swiper-container', {
                // Default parameters
                slidesPerView: 'auto',
                spaceBetween: 10,
            });

            self.lowestMonthlyPaymentSwiper[tabBrandId] = boxLowestPromosSwiper;
        }

    },
    initBoxSlideBrandPromos: function () {
        let box = '#box-slide-brand-promos';
        if ($(box).length > 0) {
            new Swiper(box + ' .swiper-container', {
                slidesPerView: 1,
                spaceBetween: 10,
                loop: true,
                pagination: {
                    el: box + ' .swiper-pagination',
                    type: 'bullets',
                    clickable: 'true',
                    nextEl: box + ' .btn-next',
                    prevEl: box + ' .btn-prev',
                },
            });
        }

    },

    initManyBoxHotPromoHomePage: function () {
        //Box HotPromo By Brand
        let boxBrand = '#hot-promo-by-brand';
        if ($(boxBrand + ' .swiper-container').length > 0 && $(boxBrand + ' .swiper-slide').length > 1) {
            new Swiper(boxBrand + ' .swiper-container', {
                // Default parameters
                slidesPerView: 'auto',
                spaceBetween: 10,
                loop: false,
                // Navigation
                navigation: {
                    nextEl: boxBrand + ' .btn-next',
                    prevEl: boxBrand + ' .btn-prev',
                }
            });
        }

        //Box HotPromo By Location
        let boxLocation = '#hot-promo-by-location';
        if ($(boxLocation + ' .swiper-container').length > 0 && $(boxLocation + ' .swiper-slide').length > 1) {
            new Swiper(boxLocation + ' .swiper-container', {
                // Default parameters
                slidesPerView: 'auto',
                spaceBetween: 10,
                loop: false,
                // Navigation
                navigation: {
                    nextEl: boxLocation + ' .btn-next',
                    prevEl: boxLocation + ' .btn-prev',
                }
            });
        }

        //Box HotPromo By Promotion
        let boxPromotion = '#hot-promo-by-promotion';
        if ($(boxPromotion + ' .swiper-container').length > 0 && $(boxPromotion + ' .swiper-slide').length > 1) {
            new Swiper(boxPromotion + ' .swiper-container', {
                // Default parameters
                slidesPerView: 'auto',
                spaceBetween: 10,
                loop: false,
                // Navigation
                navigation: {
                    nextEl: boxPromotion + ' .btn-next',
                    prevEl: boxPromotion + ' .btn-prev',
                }
            });
        }

    },

    initBrandPriceList: function () {
        let boxBrandPrice = '#box-brand-price-list';
        if ($(boxBrandPrice + ' .swiper-container').length > 0 && $(boxBrandPrice + ' .swiper-slide').length > 1) {
            new Swiper(boxBrandPrice + ' .swiper-container', {
                // Default parameters
                slidesPerView: 'auto',
                spaceBetween: 10,
                loop: true,
                // Navigation
                navigation: {
                    nextEl: boxBrandPrice + ' .btn-slide.next',
                    prevEl: boxBrandPrice + ' .btn-slide.prev',
                },
            });
        }

    },
    getFeaturedPromo: function (elm) {
        const self = this;
        const boxLowestPromos = '#box-lowest';
        let tabBrandId = $(elm).attr('data-id');
        let tabElement = $('.content-lowest-promo[content-brand-id="' + tabBrandId + '"]', boxLowestPromos);
        $("#tabs li").removeClass("active");
        $(elm).parent().addClass("active");
        $('.content-lowest-promo', boxLowestPromos).addClass('hidden');
        tabElement.removeClass('hidden');

        if (!dealerPromosV2.lowestMonthlyPayment[tabBrandId]) {
            $.ajax({
                type: "POST",
                cache: false,
                url: "/DealerPromos/FillterPromoByCondition",
                data: {
                    regionId: 0,
                    cityId: 0,
                    brandId: tabBrandId,
                    modelId: 0,
                    dealerId: 0,
                    boxType: 1,
                    dealerPromosPage: DealerPromosPage.List
                },
                success: function (dataHtml) {
                    if (!dataHtml.Error && !!dataHtml && dataHtml.indexOf('<head>') == -1) {
                        tabElement.html(dataHtml).append(function () {
                            dealerPromosV2.lowestMonthlyPayment[tabBrandId] = true;

                            let contentLowestPromos = '#box-lowest .content-lowest-promo:not(.hidden)';
                            self.lowestMonthlyPaymentSwiper[tabBrandId] = dataHtml;

                            if ($(contentLowestPromos + ' .swiper-container').length > 0 && $(contentLowestPromos + ' .swiper-slide').length > 1) {
                                let boxLowestPromosSwiper = new Swiper(contentLowestPromos + ' .swiper-container', {
                                    // Default parameters
                                    slidesPerView: 'auto',
                                    spaceBetween: 10,
                                });

                                self.lowestMonthlyPaymentSwiper[tabBrandId] = boxLowestPromosSwiper;
                            }
                        });
                    }
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    console.log(thrownError);
                }
            });
        }

    },

    searchPromos: function (pageIndex, paymentType, sortType, dealerPromosPage, isRedirect) {
        const self = this;
        let regionId = $('#hddRegionFilter').val();
        let brandId = $('#hddBrandFilter').val();
        let modelId = $('#hddModelFilter').val();
        let dealershipId = $('#hddDealershipFilter').val();

        if (typeof dealerPromosPage == 'undefined')
            dealerPromosPage = $('#hddDealerPromosPage').val();

        if (paymentType == 0 || typeof paymentType == 'undefined')
            paymentType = $('#tagspaymenttype .active').attr('data-paymentid');

        if (sortType == 0 || typeof sortType == 'undefined')
            sortType = $('.dropdown-menu .active').attr('data-sort');

        if (typeof isRedirect == 'undefined')
            isRedirect = "true";

        if (dealerPromosPage == 1) {
            regionId = $('#cboSearchRegionId').val();
            brandId = $('#cboSearchBrandId').val();
            modelId = $('#cboSearchModelId').val();
            paymentType = $('#cboSearchPromotionId').val();
            dealershipId = $('#cboSearchDealershipId').val();
        }

        let data = {
            regionId: !!regionId ? regionId : 0,
            cityId: 0,
            brandId: !!brandId ? brandId : 0,
            modelId: !!modelId ? modelId : 0,
            pageIndex: pageIndex,
            dealerId: !!dealershipId ? dealershipId : 0,
            boxType: 0,
            paymentType: paymentType,
            sortType: sortType,
            dealerPromosPage: dealerPromosPage,
            isRedirect: isRedirect
        };
        $.ajax({
            type: "POST",
            cache: false,
            url: "/DealerPromos/FillterPromoByCondition",
            data: data,
            success: function (data) {

                self.loadingInline();

                let loadmore = $('#load-more').length
                if (loadmore > 0) {
                    $('#load-more').remove();
                }

                if ($('#totalRecord').length > 0) {
                    $('#totalRecord').first().remove();
                }
                if (data != '') {
                    $('.box-you-might-want-search-promo').addClass('hidden');

                    if (dealerPromosPage != DealerPromosPage.List && isRedirect == 'true') {
                        window.location.href = data;
                    }
                    else {
                        if (pageIndex > 1)
                            $('#boxResult').append(data);
                        else
                            $('#boxResult').empty().html(data);

                        let totalRecord = parseInt($('#totalRecord').val());
                        if (totalRecord > 0) {
                            $('#total-promos').text(totalRecord);
                            if (totalRecord == 1)
                                $('#txt-result').text("result");
                            else
                                $('#txt-result').text("results");
                        }                            
                        else
                            $('#total-promos').text(0);

                        let countItem = $('#boxResult .item').length;
                        if (countItem < totalRecord) {
                            /*$('#boxResult').append('<div class="button-loadmore" id="load-more"><span class= "btn-load-more" onclick = "dealerPromosV2.paging()">Load More</span ></div>');*/
                            $('#boxResult').append(`<div class="box-load-more" id="load-more" data-redirect="false">
                                <a href="javascript:void(0)" class="btn-load" onclick="dealerPromosV2.paging()">Load More</a>
                            </div>`);
                        }

                        if (typeof CommonsEvent != 'undefined')
                            CommonsEvent.InitLozadLoadImg('#boxResult');

                    }
                }
                else {
                    $('#boxResult').empty().html('<div class="data-fillter box-no-data"><img class="img-notfound" src="/ContentV2/Web/img/notfound.png" /><span class="text-notfound">Sorry, no results match your search</span></div>');
                    $('.box-you-might-want-search-promo').removeClass('hidden');
                    $('#total-promos').text('0');
                }
                self.afterLoadingInline();

            },
            error: function (xhr, ajaxOptions, thrownError) {
                console.log(thrownError);
            },
            complete: function () {
                self.initBoxSearch();
            }
        });

        if (brandId > 0 && modelId > 0) {
            dealerPromosV2.refreshBoxBrandModelGuide(brandId, modelId);
            dealerPromosV2.refreshBoxBrandPriceList(brandId, modelId);
        }

        if (brandId > 0 && modelId == 0) {
            dealerPromosV2.refreshBoxLink(2, brandId);
            dealerPromosV2.refreshBoxFeaturedCarGuide(brandId, modelId);
        }

        if (brandId == 0 && modelId == 0) {
            dealerPromosV2.refreshBoxBrandPriceList(brandId, modelId);
            dealerPromosV2.refreshBoxUpcomingCar();
            dealerPromosV2.refreshBoxLinkHottest();
        }

        if (dealerPromosPage == DealerPromosPage.List) {
            self.getLinkRedirect(data);
            //link change => reload boxtextseo header
            self.getBoxtextSEOHeader(data)
        }
    },
    getBoxtextSEOHeader(searchParam) {
        $.ajax({
            type: "POST",
            cache: false,
            url: "/DealerPromos/BoxtextSEOHeader",
            data: searchParam,
            success: function (data) {
                $('#ctnBoxtextSEO').html(data);
                if ($(".box-text-promo").length > 0 && dealerPromosJS != null) {
                    dealerPromosJS.initBoxtextSEOHeader();
                }
            }
        });
    },
    refreshBoxBrandModelGuide: function (brandId, modelId) {
        if ($('#box-featured-car-guide').length > 0) {
            $('#box-featured-car-guide').empty();
            $('#box-upcoming-car').empty();
            $('#box-link-bottom').empty();
            $('#box-link-hottest').empty();
        }

        let data = {
            brandId: !!brandId ? brandId : 0,
            modelId: !!modelId ? modelId : 0,
        }
        $.ajax({
            type: "POST",
            cache: false,
            url: "/CarGuide/BrandModelGuide",
            data: data,
            success: function (dataHtml) {
                if (dataHtml != null && $('#box-brand-model-guide').length > 0) {
                    $('#box-brand-model-guide').empty().html(dataHtml);
                    CommonsEvent.InitLozadLoadImg('#box-brand-model-guide');
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                console.log(thrownError);
            }
        });
    },

    refreshBoxBrandPriceList: function () {
        $.ajax({
            type: "GET",
            cache: false,
            url: "/CarPrice/BrandPriceList",
            success: function (dataHtml) {
                if (dataHtml != null && $('#box-brand-price').length > 0) {
                    $('#box-brand-price').empty().html(dataHtml);
                    CommonsEvent.InitLozadLoadImg('#box-brand-price');
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                console.log(thrownError);
            }
        });
    },

    refreshBoxFeaturedCarGuide: function (brandId, modelId) {
        if ($('#box-brand-model-guide').length > 0 && $('#box-brand-price').length > 0) {
            $('#box-brand-model-guide').empty();
            $('#box-brand-price').empty();
            $('#box-upcoming-car').empty();
            $('#box-link-hottest').empty();
        }
        let data = {
            brandId: !!brandId ? brandId : 0,
            modelId: !!modelId ? modelId : 0,
            top: 4
        }
        $.ajax({
            type: "POST",
            cache: false,
            url: "/CarGuide/FeaturedCarGuide",
            data: data,
            success: function (dataHtml) {
                if (dataHtml != null && $('#box-featured-car-guide').length > 0) {
                    $('#box-featured-car-guide').empty().html(dataHtml);
                    CommonsEvent.InitLozadLoadImg('#box-featured-car-guide');
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                console.log(thrownError);
            }
        });
    },

    refreshBoxUpcomingCar: function () {
        if ($('#box-featured-car-guide').length > 0) {
            $('#box-featured-car-guide').empty();
            $('#box-brand-model-guide').empty();
            $('#box-link-bottom').empty();
        }
        let data = {
            top: 4
        }
        $.ajax({
            type: "POST",
            cache: false,
            url: "/CarGuide/UpcomingCarGuide",
            data: data,
            success: function (dataHtml) {
                if (dataHtml != null && $('#box-upcoming-car').length > 0) {
                    $('#box-upcoming-car').empty().html(dataHtml);
                    CommonsEvent.InitLozadLoadImg('#box-upcoming-car');
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                console.log(thrownError);
            }
        });
    },

    refreshBoxLink: function (pageType, brandId) {
        let data = {
            pageType: !!pageType ? pageType : 2,
            brandId: !!brandId ? brandId : 0,
        }
        $.ajax({
            type: "POST",
            cache: false,
            url: "/BoxLink/BoxLinkByBrand",
            data: data,
            success: function (dataHtml) {
                if (dataHtml != null && $('#box-link-bottom').length > 0) {
                    $('#box-link-bottom').empty().html(dataHtml);
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                console.log(thrownError);
            }
        });
    },

    refreshBoxLinkHottest: function () {
        let data = {
            pageType: 2,
            takeItem: 3
        }
        $.ajax({
            type: "POST",
            cache: false,
            url: "/BoxLink/BoxLinkHottestModel",
            data: data,
            success: function (dataHtml) {
                if (dataHtml != null && $('#box-link-hottest').length > 0) {
                    $('#box-link-hottest').empty().html(dataHtml);
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                console.log(thrownError);
            }
        });
    },

    loadingInline: function () {
        $('#loading-inline').addClass('loaders');
    },

    afterLoadingInline: function () {
        const self = this;
        self.changeTags();

        $('#menu-sort').removeClass('hidden');
        $('#menu-sort').addClass('hidden');
        $('#box-carpromo-list').addClass('hidden');
        $('#load-more').addClass('hidden');

        setTimeout(function () {
            $('#loading-inline').removeClass('loaders');
            $('#box-carpromo-list').removeClass('hidden');
            $('#load-more').removeClass('hidden');
        }, 300);
    },

    removeTags: function (elm) {
        $(elm).remove();
        let dataName = $(elm).attr('data-name');
        $('input[name="' + dataName + '"]').val('');
        if (dataName == 'RegionId') {
            $('#hddRegionFilter').val(0);
            $('#hddRegionFilter').attr('data-title', 'Select a region');
        }
        if (dataName == 'BrandId') {
            $('#hddBrandFilter').val(0);
            $('#hddBrandFilter').attr('data-title', 'Select a brand');
            $('#tagmodel').click();
        }
        if (dataName == 'ModelId') {
            $('#hddModelFilter').val(0);
            $('#hddModelFilter').attr('data-title', 'Select a model');
        }

        if (dataName == 'DealershipId') {
            $('#hddDealershipFilter').val(0);
            $('#hddDealershipFilter').attr('data-title', 'Select a dealership');
        }
        dealerPromosV2.searchPromos(1, 0, 0);
    },

    changeTags: function () {
        const self = this;
        let regionId = $('#hddRegionFilter').val();
        let regionName = $('#hddRegionFilter').attr('data-title');
        let brandId = $('#hddBrandFilter').val();
        let brandName = $('#hddBrandFilter').attr('data-title');
        let modelId = $('#hddModelFilter').val();
        let modelName = $('#hddModelFilter').attr('data-title');
        let dealershipId = $('#hddDealershipFilter').val();
        let dealershipName = $('#hddDealershipFilter').attr('data-title');
        let paymentType = $('#tagspaymenttype .tag-name.active').attr('data-paymentid');
        /*let paymentType = $("#cboPromoType", box).val();*/
        let paymentType2 = $("#cboSearchPromotionId").val();
        console.log(paymentType2);

        if (regionId == "") {
            $('#tagregion').remove();
        }
        if (brandId == "") {
            $('#tagbrand').remove();
        }
        if (modelId == "") {
            $('#tagmodel').remove();
        }
        if (dealershipId == 0) {
            $('#tagdealership').remove();
        }
        if (regionId > 0) {
            $('#tagregion').remove();
            $('#tags').append('<a href="javascript:void(0);" data-name="RegionId" id="tagregion" onclick="dealerPromosV2.removeTags(this)" class="tag-name">' + regionName + '</a>');
        }
        if (brandId > 0) {
            $('#tagbrand').remove();
            $('#tags').append('<a href="javascript:void(0);" data-name="BrandId" id="tagbrand" onclick="dealerPromosV2.removeTags(this)" class="tag-name">' + brandName + '</a>');
        }
        if (modelId > 0) {
            $('#tagmodel').remove();
            $('#tags').append('<a href="javascript:void(0);" data-name="ModelId" id="tagmodel" onclick="dealerPromosV2.removeTags(this)" class="tag-name">' + modelName + '</a>');
        }
        if (dealershipId > 0) {
            $('#tagdealership').remove();
            $('#tags').append('<a href="javascript:void(0);" data-name="DealershipId" id="tagdealership" onclick="dealerPromosV2.removeTags(this)" class="tag-name">' + dealershipName + '</a>');
        }
        if (paymentType2)
            self.buildTitle(brandId, modelId, regionId, dealershipName, paymentType2);
        else
            self.buildTitle(brandId, modelId, regionId, dealershipName, paymentType);
        self.buildBreadCrumb(brandId, modelId);
    },

    changeTagsPayment: function (elm) {
        const self = this;
        let paymentType = $(elm).attr('data-paymentid');
        if (typeof paymentType == 'undefined')
            return;
        if (self.tabPaymentTypePrevSelected == paymentType)
            return;

        self.tabPaymentTypePrevSelected = paymentType;

        let dealerPromosPage = $('#hddDealerPromosPage').val();
        let isRedirect = $(elm).attr('data-redirect');

        $('#cboPromoType').val(paymentType).trigger("chosen:updated");

        $('#tagspaymenttype a').removeClass('active');
        $(elm).addClass('active');
        $('#currentPage').val(1);
        let sortId = $('.top-filter .btn-select .item-sort.active').attr('data-sort');
        if (typeof sortId == 'undefined' || sortId == '')
            sortId = 0;

        self.searchPromos(0, paymentType, sortId, dealerPromosPage, isRedirect);
    },

    sortByCondition: function (elm) {
        const self = this;
        let sortType = $(elm).find('option:selected').attr('data-sort');
        $('.dropdown-menu li').removeClass('selected-color');
        $('.dropdown-menu li').removeClass('active');
        $(elm).addClass('active');
        $(elm).addClass('selected-color');
        $('#defaut-sort').text($(elm).text());
        let dealerPromosPage = $('#hddDealerPromosPage').val();
        let isRedirect = $(elm).attr('data-redirect');
        self.searchPromos(0, 0, sortType, dealerPromosPage, isRedirect);
    },

    onSort: function () {
        $('#menu-sort').toggleClass('hidden');
    },

    paging: function () {
        const self = this;
        let page = parseInt($('#currentPage').val());
        if (page == 0) {
            page = 1;
        }
        if (page > 0)
            page += 1;
        $('#currentPage').val(page);
        let dealerPromosPage = $('#hddDealerPromosPage').val();
        let isRedirect = $('#load-more').attr('data-redirect');

        let sortId = $('.top-filter .btn-select .item-sort.active').attr('data-sort');
        if (typeof sortId == 'undefined' || sortId == '')
            sortId = 0;

        let paymentType = $('#tagspaymenttype .tag-name.active').attr('data-paymentid');
        if (typeof paymentType == 'undefined' || paymentType == '')
            paymentType = 0;

        self.searchPromos(page, paymentType, sortId, dealerPromosPage, isRedirect);
    },

    initBoxSearch: function () {
        if ($('.fins-promo').length > 0) {
            let brandCustomDropdown = $('#cboBrandSearch').CustomDropdown({
                targetInputId: 'cboSearchBrandId',
                targetTextId: 'cboBrandText',
                boxId: 'cstBrandDropdown',
                boxTitle: 'Select a brand',
                optionsFetchUrl: '/Common/GetListBrandHasModelActive',
                optionsFetchMethod: 'get',
                optionValueProperty: 'Id',
                optionTextProperty: 'Name',
                defaultValue: 0,
                //defaultOptionAppend: false,
                defaultText: 'Brand',
                defaultOptionPosition: 'top',
                onShow: CommonsEvent.AddNoScroll,
                onHide: CommonsEvent.RemoveNoScroll,
                onSelected: function () {
                    CommonsEvent.RemoveNoScroll();
                    var brandId = parseInt($('#cboSearchBrandId').val());
                    if (brandId > 0) {
                        modelCustomDropdown.changeStatus(true);
                        modelCustomDropdown.changeOptionsFetchUrl('/Model/GetListActiveByBrandId?brandId=' + brandId);
                    }
                    else {
                        modelCustomDropdown.changeStatus(false);
                    }
                }
            });

            let brandId = parseInt($('#cboSearchBrandId').val());
            let modelCustomDropdown = $('#cboModelSearch').CustomDropdown({
                targetInputId: 'cboSearchModelId',
                targetTextId: 'cboModelText',
                boxId: 'cstModelDropdown',
                boxTitle: 'Select a model',
                disabled: brandId > 0 || parseInt($('#cboSearchModelId').val()) > 0 ? false : true,
                optionsFetchUrl: brandId > 0 ? '/Model/GetListActiveByBrandId?brandId=' + brandId : undefined,
                optionsFetchMethod: 'post',
                optionValueProperty: 'Id',
                optionTextProperty: 'Name',
                defaultValue: 0,
                defaultText: 'Model',
                onShow: CommonsEvent.AddNoScroll,
                onHide: CommonsEvent.RemoveNoScroll,
                onSelected: function () {
                    CommonsEvent.RemoveNoScroll();
                }
            });

            if (brandId > 0) {
                let modelName = $('#cboModelText').text();
                modelCustomDropdown.changeStatus(true);
                modelCustomDropdown.changeOptionsFetchUrl('/Model/GetListActiveByBrandId?brandId=' + brandId);
                $('#cboModelText').text(modelName);
            }

            let regionCustomDropdown = $('#cboRegionSearch').CustomDropdown({
                targetInputId: 'cboSearchRegionId',
                targetTextId: 'cboRegionText',
                boxId: 'cstRegionDropdown',
                boxTitle: 'Select a region',
                optionsFetchUrl: '/Common/GetListRegion',
                optionsFetchMethod: 'get',
                optionValueProperty: 'Id',
                optionTextProperty: 'Name',
                defaultValue: 0,
                //defaultOptionAppend: false,
                defaultText: 'Region',
                defaultOptionPosition: 'top',
                onShow: CommonsEvent.AddNoScroll,
                onHide: CommonsEvent.RemoveNoScroll,
                onSelected: function () {
                    CommonsEvent.RemoveNoScroll();
                }
            });

            let paymentCustomDropdown = $('#cboPromotionSearch').CustomDropdown({
                targetInputId: 'cboSearchPromotionId',
                targetTextId: 'cboPromotionText',
                boxId: 'cstPromotionDropdown',
                boxTitle: 'Select a promo type',
                optionsFetchUrl: '/DealerPromos/GetListPaymentType',
                optionsFetchMethod: 'get',
                optionValueProperty: 'Id',
                optionTextProperty: 'PromoType',
                defaultValue: 0,
                defaultText: 'All promotion type',
                defaultOptionPosition: 'top',
                onShow: CommonsEvent.AddNoScroll,
                onHide: CommonsEvent.RemoveNoScroll,
                onSelected: function () {
                    CommonsEvent.RemoveNoScroll();
                }
            });

            let dealershipCustomDropdown = $('#cboDealershipSearch').CustomDropdown({
                targetInputId: 'cboSearchDealershipId',
                targetTextId: 'cboDealershipText',
                boxId: 'cstDealershipDropdown',
                boxTitle: 'Dealership',
                optionsFetchUrl: '/DealerShips/GetListDealershipJson',
                optionsFetchMethod: 'get',
                optionValueProperty: 'Id',
                optionTextProperty: 'Name',
                defaultValue: 0,
                //defaultOptionAppend: false,
                defaultText: 'All Dealerships',
                defaultOptionPosition: 'top',
                appendValueAfterText: true,
                onShow: CommonsEvent.AddNoScroll,
                onHide: CommonsEvent.RemoveNoScroll,
                onSelected: function () {
                    CommonsEvent.RemoveNoScroll();
                }
            });

            window.cboDealershipSearch = dealershipCustomDropdown;
            window.cboBrandSearch = brandCustomDropdown;
            window.cboModelSearch = modelCustomDropdown;
            window.cboRegionSearch = regionCustomDropdown;
            window.cboPromotionSearch = paymentCustomDropdown;
        }
    },

    activeTagPayment: function () {
        let typeOfPromo = $('#hddPromoType').val();
        if (!!typeOfPromo) {
            $('#tagspaymenttype .tag-name.active').removeClass('active');
            let tagPromotion = $('#tagspaymenttype').find("[data-paymentid='" + typeOfPromo + "']");
            tagPromotion.addClass('active');
            $('#tagspaymenttype').val(typeOfPromo);
        }

        // Update value for fillter
        if (!!typeOfPromo)
            $('#hddPaymentTypeFilter').val(typeOfPromo);

        let selectedOptionText = $('#tagspaymenttype').find('option:selected').text();
        if (!!selectedOptionText)
            $('#hddPaymentTypeFilter').attr('data-title', '' + selectedOptionText + '');
    },

    buildTitle: function () {
        if (location.pathname.indexOf('-promotions-in-the-philippines') < 0 && location.pathname.indexOf('search-car-promos') < 0)
            return;

        let brandName = $('#cboBrandText').text();
        let modelName = $('#cboModelText').text();
        let title = 'All Promos';
        if (!!brandName) {
            if (!!modelName) {
                title = brandName + " " + modelName + " Promos";
            }
            else {
                title = brandName + " Promos";
            }
        }
        $('#title-heading').text(title);
    },

    getLinkRedirect: function (requestData) {
        let data = {
            BrandId: requestData.brandId,
            ModelId: requestData.modelId,
            RegionId: requestData.regionId,
            CityId: 0,
            DealershipId: requestData.dealerId,
            PaymentType: requestData.paymentType
        };

        $.ajax({
            type: "POST",
            cache: false,
            url: "/DealerPromos/GetSearchLinkJson",
            data: data,
            success: function (data) {
                $('#boxResult').append('<input type="hidden" id="hddUrlRedirect" value="' + data + '" />');
                window.history.replaceState(null, null, data);
            }
        })
    },

    showFillterPromos: function () {
        if ($('#popup .model-popup').length == 0) {
            var tabNumber = $('#tabFilter').data('id').toString();
            searchAdvance.activeTab(tabNumber);
            return;
        }
        else {
            $('#popup').show(10);
        }
    },

    buildTitle: function (brandId, modelId, regionId, dealerName, paymentType) {
        if (location.pathname.indexOf('-promotions-in-the-philippines') < 0 && location.pathname.indexOf('search-car-promos') < 0)
            return;

        $.ajax({
            type: "POST",
            cache: false,
            url: "/DealerPromos/BuildTitleJson",
            data: {
                BrandId: brandId,
                ModelId: modelId,
                RegionId: regionId,
                dealershipName: dealerName,
                paymentType: paymentType
            },
            success: function (dataJson) {
                if (dataJson != null && dataJson.Heading != null && dataJson.Heading != '') {
                    //$('#titleListPromo').text(dataJson.Heading);

                    if (dataJson.TitlePage != null && document.title != dataJson.TitlePage) {
                        document.title = dataJson.TitlePage;
                    }
                    if (dataJson.Metadescription != null && document.description != dataJson.Metadescription) {
                        document.querySelector('meta[name="description"]').setAttribute("content", dataJson.Metadescription);
                    }
                }
            }
        });
    },

    buildBreadCrumb: function (brandId, modelId) {
        $.ajax({
            type: "POST",
            cache: false,
            url: "/DealerPromos/BuildBreadCrumbJson",
            data: {
                BrandId: brandId,
                ModelId: modelId
            },
            success: function (dataJson) {
                if (!dataJson.Error && !!dataJson && dataJson.indexOf('<head>') == -1) {
                    if ($('#breadcrumbContainer').length > 0)
                        $('#breadcrumbContainer').html(dataJson);
                }
            }
        });
    }
}
var HomepagePromos = {
    boxHotPromosByBrand: function (brandid, top, elm) {
        let data = {
            brandId: brandid,
            top: top
        };
        $.ajax({
            type: "POST",
            cache: false,
            url: "/DealerPromos/GetListItemHotPromosByBrand",
            data: data,
            success: function (dataHtml) {
                if (dataHtml != null) {
                    $('#tab-promo-by-brand a.active').removeClass('active');
                    $(elm).addClass('active');
                    $('#hot-promo-by-brand').empty().html(dataHtml);
                    dealerPromosV2.initManyBoxHotPromoHomePage();

                    if (typeof CommonsEvent != 'undefined')
                        CommonsEvent.InitLozadLoadImg('#hot-promo-by-brand');
                }
            }
        });
    },

    boxHotPromosByLocation: function (regionid, top, elm) {
        let data = {
            regionId: regionid,
            top: top
        };
        $.ajax({
            type: "POST",
            cache: false,
            url: "/DealerPromos/GetListItemHotPromosByLocation",
            data: data,
            success: function (dataHtml) {
                if (dataHtml != null) {
                    $('#tab-promo-by-location a.active').removeClass('active');
                    $(elm).addClass('active');
                    $('#hot-promo-by-location').empty().html(dataHtml);
                    dealerPromosV2.initManyBoxHotPromoHomePage();

                    if (typeof CommonsEvent != 'undefined')
                        CommonsEvent.InitLozadLoadImg('#hot-promo-by-location');
                }
            }
        });
    },

    boxHotPromosByPromotion: function (promoType, top, elm) {
        let data = {
            promoType: promoType,
            top: top
        };
        $.ajax({
            type: "POST",
            cache: false,
            url: "/DealerPromos/GetListItemHotPromosByPromotionType",
            data: data,
            success: function (dataHtml) {
                if (dataHtml != null) {
                    if (promoType == 1) {
                        $('#box-hot-promo-by-promotion .note-promo').text('Check all hottest low downpayment car promos, monthly car payment from every dealers collected by Philkotse!');
                    }
                    if (promoType == 2) {
                        $('#box-hot-promo-by-promotion .note-promo').text('Monthly payment cars are always a smart option. Pick the best deal for yourself and reaching closer to your future car!');
                    }
                    if (promoType == 3) {
                        $('#box-hot-promo-by-promotion .note-promo').text('Searching for some cash discount for your upcoming car purchase?  Look no further, here we have the best car cash discount Philippines for you to chooe!');
                    }

                    $('#tab-promo-by-promotion a.active').removeClass('active');
                    $(elm).addClass('active');
                    $('#hot-promo-by-promotion').empty().html(dataHtml);
                    dealerPromosV2.initManyBoxHotPromoHomePage();

                    if (typeof CommonsEvent != 'undefined')
                        CommonsEvent.InitLozadLoadImg('#hot-promo-by-promotion');
                }
            }
        });
    },

    setCookieHomeCarPromo: function () {
        let lstIdPromoBoxHot = $('#list-id-promo-box-hot').val();
        let lstIdPromoByBrand = $('#list-id-promo-by-brand').val();
        let lstIdPromoByLocation = $('#list-id-promo-by-brand').val();
        let lstIdPromoByPromotion = $('#list-id-promo-by-promotion').val();

        if (lstIdPromoBoxHot != null) {
            Utility.SetCookie('lstIdPromoBoxHot', lstIdPromoBoxHot, 1);
        }
        if (lstIdPromoByBrand != null) {
            Utility.SetCookie('lstIdPromoByBrand', lstIdPromoByBrand, 1);
        }
        if (lstIdPromoByLocation != null) {
            Utility.SetCookie('lstIdPromoByLocation', lstIdPromoByLocation, 1);
        }
        if (lstIdPromoByPromotion != null) {
            Utility.SetCookie('lstIdPromoByPromotion', lstIdPromoByPromotion, 1);
        }
    },

    searchPromosHome: function () {
        let promotionType = $('#cboSearchPromotionId').val();

        dealerPromosV2.searchPromos(0, promotionType, 0, 1);
    }
}

$(document).ready(function () {
    dealerPromosV2.init();
    dealerPromosV2.initBoxSearch();
    HomepagePromos.setCookieHomeCarPromo();
});;
