$(function () {

    "use strict";

    // Main navigation & mega menu
    // ----------------------------------------------------------------

    // Global menu variables

    var objSearch = $('.search-wrapper'),
        objLogin = $('.login-wrapper'),
        objCart = $('.cart-wrapper'),
        objMenu = $('.floating-menu'),
        objMenuLink = $('.floating-menu a'),
        $search = $('.open-search'),
        $login = $('.open-login'),
        $cart = $('.open-cart'),
        $menu = $('.open-menu'),
        $openDropdown = $('.open-dropdown'),
        $settingsItem = $('.nav-settings .nav-settings-list li'),
        $close = $('.close-menu');

    // Open/close login

    $login.on('click', function () {
        toggleOpen($(this));
        objLogin.toggleClass('open');
        closeSearch();
        closeCart();
    });

    // Open/close search bar

    $search.on('click', function () {
        toggleOpen($(this));
        objSearch.toggleClass('open');
        objSearch.find('input').focus();
        closeLogin();
        closeCart();
    });

    setTimeout(function () {
        if(jQuery('.search-wrapper').hasClass('open')){
            jQuery('nav .navigation-top ul li a.open-search').addClass('open');
        }
        else {
            jQuery('nav .navigation-top ul li a.open-search').removeClass('open');
        }
    }, 500);

    // Open/close cart

    // $cart.on('click', function () {
    //     toggleOpen($(this));
    //     objCart.toggleClass('open');
    //     closeLogin();
    //     closeSearch();
    // });

    // Mobile menu open/close

    $menu.on('click', function () {
        objMenu.addClass('expanded');
        closeSearch();
        closeLogin();
        closeCart();
    });

    // Settings language & currency dropdown

    $settingsItem.on('click', function () {
        var $value = $(this).closest('.nav-settings').find('.nav-settings-value');
        $value.text($(this).text());
    });

    // Floating menu hyperlink
    if ($('nav').hasClass('navbar-single-page')) {
        objMenuLink.on('click', function () {
            objMenu.removeClass('expanded');
        });
    }

    // Open dropdown/megamenu

    $openDropdown.on('click', function (e) {

        e.preventDefault();

        var liParent = $(this).parent().parent(),
            liDropdown = liParent.find('.navbar-dropdown');

        liParent.toggleClass('expanded');

        if (liParent.hasClass('expanded')) {
            liDropdown.slideDown();
        }
        else {
            liDropdown.slideUp();
        }
    });

    // Close menu (mobile)

    $close.on('click', function () {
        $('nav').find('.expanded').removeClass('expanded');
        $('nav').find('.navbar-dropdown').slideUp();
    });

    // Global functions

    function toggleOpen(el) {
        $(el).toggleClass('open');
    }

    function closeSearch() {
        objSearch.removeClass('open');
        $search.removeClass('open');
    }
    function closeLogin() {
        objLogin.removeClass('open');
        $login.removeClass('open');
    }
    function closeCart() {
        objCart.removeClass('open');
        $cart.removeClass('open');
    }

    // Sticky header
    // ----------------------------------------------------------------

    var navbarFixed = $('nav.navbar-fixed');

    // When reload page - check if page has offset
    if ($(document).scrollTop() > 94) {
        navbarFixed.addClass('navbar-sticked');
    }
    // Add sticky menu on scroll
    $(document).on('bind ready scroll', function () {
        var docScroll = $(document).scrollTop();
        if (docScroll >= 10) {
            navbarFixed.addClass('navbar-sticked');
        } else {
            navbarFixed.removeClass('navbar-sticked');
        }
    });

    // Tooltip
    // ----------------------------------------------------------------

    $('[data-toggle="tooltip"]').tooltip()

    // Main popup
    // ----------------------------------------------------------------

    $('.mfp-open').magnificPopup({
        type: 'inline',
        fixedContentPos: false,
        fixedBgPos: true,
        overflowY: 'auto',
        closeBtnInside: true,
        preloader: false,
        midClick: true,
        removalDelay: 300,
        mainClass: 'my-mfp-zoom-in',
        callbacks: {
            open: function () {
                // wait on popup initalization
                // then load owl-carousel
                $('.popup-main .owl-carousel').hide();
                setTimeout(function () {
                    $('.popup-main .owl-carousel').slideDown();
                }, 500);
            }
        }
    });

    // Main popup gallery
    // ----------------------------------------------------------------

    $('.open-popup-gallery').magnificPopup({
        delegate: 'a',
        type: 'image',
        tLoading: 'Loading image #%curr%...',
        gallery: {
            enabled: true,
            navigateByImgClick: true,
            preload: [0, 1] // Will preload 0 - before current, and 1 after the current image
        },
        fixedContentPos: false,
        fixedBgPos: true,
        overflowY: 'auto',
        closeBtnInside: true,
        preloader: false,
        midClick: true,
        removalDelay: 300,
        mainClass: 'my-mfp-zoom-in'
    });


    // Frontpage slider
    // ----------------------------------------------------------------

    var arrowIcons = [
        '<span class="icon icon-chevron-left"></span>',
        '<span class="icon icon-chevron-right"></span>'
    ];

    $.each($(".owl-slider"), function (i, n) {

        $(n).owlCarousel({
            autoHeight: false,
            navigation: true,
            navigationText: arrowIcons,
            items: 1,
            singleItem: true,
            addClassActive: true,
            transitionStyle: "fadeUp",
            afterMove: animatetCaptions,
            autoPlay: 8000,
            stopOnHover: false
        });

        animatetCaptions(); 

        function animatetCaptions(event) {
            "use strict";
            var activeItem = $(n).find('.owl-item.active'),
            timeDelay = 100;
            $.each(activeItem.find('.animated'), function (j, m) {
                var item = $(m);
                item.css('animation-delay', timeDelay + 'ms');
                timeDelay = timeDelay + 180;
                item.addClass(item.data('animation'));
                setTimeout(function () {
                    item.removeClass(item.data('animation'));
                }, 2000);
            });
        }

        if ($(n).hasClass('owl-slider-fullscreen')) {
            $('.header-content .item').height($(window).height());
        }
    });

    // Quote carousel
    // ----------------------------------------------------------------

    $.each($(".quote-carousel"), function (i, n) {
        $(n).owlCarousel({
            navigation: true, // Show next and prev buttons
            slideSpeed: 300,
            items: 3,
            paginationSpeed: 400,
            singleItem: false,
            navigationText: arrowIcons,
            itemsDesktop: [1199, 3],
            itemsDesktopSmall: [979, 3],
            itemsTablet: [768, 1],
            itemsTabletSmall: false,
            itemsMobile: [479, 1],
            autoPlay: 3000,
            stopOnHover: true
        });
    });

    // Icon slider
    // ----------------------------------------------------------------


    $.each($(".owl-icons"), function (i, n) {
        $(n).owlCarousel({
            autoHeight: false,
            pagination: false,
            navigation: true,
            navigationText: arrowIcons,
            items: 6,
            itemsDesktop: [1199, 5],
            itemsDesktopSmall: [979, 5],
            itemsTablet: [768, 4],
            itemsTabletSmall: false,
            itemsMobile: [479, 3],
            addClassActive: true,
            autoPlay: 5500,
            stopOnHover: true
        });
    });

    //Product slider
    $.each($(".owl-product-gallery"), function (i, n) {
        $(n).owlCarousel({
            //transitionStyle: "fadeUp",
            autoHeight: true,
            slideSpeed: 800,
            navigation: true,
            navigationText: arrowIcons,
            pagination: true,
            items: 1,
            singleItem: true
        });
    });


    // Scroll to top
    // ----------------------------------------------------------------

    var $wrapper = $('.wrapper');
    $wrapper.append($("<div class='scroll-top'><i class='icon icon-chevron-up'></i></div>"));

    var $scrollbtn = $('.scroll-top');

    $(document).on('ready scroll', function () {
        var docScrollTop = $(document).scrollTop(),
            docScrollBottom = $(window).scrollTop() + $(window).height() == $(document).height();

        if (docScrollTop >= 150) {
            $scrollbtn.addClass('visible');
        } else {
            $scrollbtn.removeClass('visible');
        }
        if (docScrollBottom) {
            $scrollbtn.addClass('active');
        }
        else {
            $scrollbtn.removeClass('active');
        }
    });

    $scrollbtn.on('click', function () {
        $('html,body').animate({
            scrollTop: $('body').offset().top
        }, 1000);
        return false;
    });

    // Product color var
    // ----------------------------------------------------------------

    $.each($('.product-colors'), function (i, n) {
        var $btn = $('.color-btn');
        $btn.on('click', function () {
            $(this).parent().find($btn).removeClass('checked');
            $(this).addClass('checked');
        });
    });

    // Tabsy images
    // ----------------------------------------------------------------

    var tabsyImg = $('.tabsy .tabsy-images > div'),
        tabsyLink = $('.tabsy .tabsy-links figure');

    // apply images to parent background
    tabsyImg.each(function (i, n) {
        $(n).css('background-image', 'url(' + $(n).find('img').attr('src') + ')');
    });

    tabsyLink.bind('mouseenter mouseleave', function () {
        var self = $(this),
            tabID = self.attr('data-image');
        tabsyLink.removeClass('current');
        tabsyImg.removeClass('current');
        self.addClass('current');
        self.closest('.tabsy').find("#" + tabID).addClass('current');
    });


    // Add to favorites list / product list
    // ----------------------------------------------------------------

    $('.add-favorite').on('click', function () {
        $(this).toggleClass("added");
    });

    $('.info-box-addto').on('click', function () {
        $(this).toggleClass('added');
    });

    // Filters toggle functions
    // ----------------------------------------------------------------

    // Check if some filter boxes has class active
    // then show hidden filters
    $('.filters .filter-box').each(function () {
        if ($(this).hasClass('active')) {
            $(this).find('.filter-content').show();
        }
    });

    var $filtersTitle = $('.filters .title');

    // Add emtpy span on title
    $filtersTitle.append('<span>' + '</span>');

    // Toggle filter function
    $filtersTitle.on('click', function (e) {
        var $this = $(this),
            $parent = $this.parent();
        $parent.toggleClass('active');

        if ($parent.hasClass('active')) {
            $parent.find('.filter-content').slideDown(300);
        }
        else {
            $parent.find('.filter-content').slideUp(200);
        }
    });

    // Update filter results - close dropdown filters
    // ----------------------------------------------------------------

    $('.filters .filter-update').on('click', function (e) {
        $(this).closest('.filter-box')
            .removeClass('active')
            .find('.filter-content').slideUp(200);
    });

    // Only for filters topbar
    // ----------------------------------------------------------------

    $('.filters input').on('change', function () {
        if ($(this).is(':checked')) {
            var $labelText = $(this).parent().find('label').text(),
                $title = $(this).closest('.filter-box').find('.title');
            
            $title.find('span').text($labelText);
        }
    });

    // Show hide filters (only for mobile)
    // ----------------------------------------------------------------

    $('.toggle-filters-mobile').on('click', function () {
        $('.filters').addClass('active');
    });
    $('.toggle-filters-close').on('click', function () {
        $('.filters').removeClass('active');
        $('html,body').animate({
            scrollTop: $('body').offset().top
        }, 800);
        return false;
    });

$('.toggle-filters-mobile-account').on('click', function () {
        $('.filters_account').addClass('active');
    });
    $('.toggle-filters-close').on('click', function () {
        $('.filters_account').removeClass('active');
        $('html,body').animate({
            scrollTop: $('body').offset().top
        }, 800);
        return false;
    });
    // Strecher accordion
    // ----------------------------------------------------------------

    var $strecherItem = $('.stretcher-item');
    $strecherItem.bind({
        mouseenter: function (e) {
            $(this).addClass('active');
            $(this).siblings().addClass('inactive');
        },
        mouseleave: function (e) {
            $(this).removeClass('active');
            $(this).siblings().removeClass('inactive');
        }
    });

    // Blog image caption
    // ----------------------------------------------------------------

    var $blogImage = $('.blog-post-text img');
    $blogImage.each(function () {
        var $this = $(this);
        $this.wrap('<span class="blog-image"></span>');
        if ($this.attr("alt")) {
            var caption = this.alt;
            var link = $this.attr('data');
            $this.after('<span class="caption">' + caption + '</span>');
        }
    });

    // Coupon code 
    // ----------------------------------------------------------------
/*
    $(".form-coupon").hide();
    $("#couponCodeID").on('click', function () {
        if ($(this).is(":checked")) {
            $(".form-coupon").fadeIn();
        } else {
            $(".form-coupon").fadeOut();
        }
    });
*/
    // Checkout login / register
    // ----------------------------------------------------------------

    var loginWrapper = $('.login-wrapper'),
        loginBtn = loginWrapper.find('.btn-login'),
        regBtn = loginWrapper.find('.btn-register'),
        signUp = loginWrapper.find('.login-block-signup'),
        signIn = loginWrapper.find('.login-block-signin');

    loginBtn.on('click', function () {
        signIn.slideDown();
        signUp.slideUp();
    });

    regBtn.on('click', function () {
        signIn.slideUp();
        signUp.slideDown();
    });

    // Isotope filter
    // ----------------------------------------------------------------

    $(function () {
        var price = 0;
        var $products = $("#products");
        var $checkboxes = $("#filters input");
        var $sortPrice = $("#sort-price");
        var filters = [];

        $(".item").addClass("show-me");
        filters.push(".show-me");

        // Sort products
        // --------------------------------------

        $products.isotope({
            itemSelector: '.item',
            getSortData: {
                number: '.price parseInt'
            },
            sortBy: 'number'
        });

        // Checkboxes & radiobuttons
        // --------------------------------------

        $sortPrice.on('change', function () {
            var order = $('option:selected', this).attr('data-option-value');
            var valAscending = (order == "asc");

            $products.isotope({
                itemSelector: '.item',
                getSortData: {
                    number: '.price parseInt'
                },
                sortBy: 'number',
                sortAscending: valAscending,
                filter: filters
            });

        });

        // Checkboxes & radiobuttons
        // --------------------------------------

        $checkboxes.on('change', function () {
            filters = [];
            filters.push(".show-me");
            $checkboxes.filter(':checked').each(function () {
                filters.push(this.value);
            });

            filters = filters.join('');
            $products.isotope({
                filter: filters
            });

        });

        // Range slider
        // --------------------------------------

        $("#range-price-slider").ionRangeSlider({

            type: "double",
            min: $('#min').val(),
            max: $('#max').val(),
            from: $('#startprice').val(),
            to: $('#endprice').val(),
            step: 1,
            prefix: $('#currency').val(),
            onChange: function (data) {
                $('#min').val(data.from);
                $('#max').val(data.to);

                $(".item").each(function () {


                    price = parseInt($(this).find(".price").text(), 1);

                    if (data.from <= price && data.to >= price) {
                        $(this).addClass('show-me');
                    }
                    else {
                        $(this).removeClass('show-me');
                    }
                });

                $products.isotope({
                    itemSelector: '.item',
                    filter: filters
                });
            }
        });
        
        $("#range-price-slider-mobile").ionRangeSlider({

            type: "double",
            min: $('#min').val(),
            max: $('#max').val(),
            from: $('#startprice').val(),
            to: $('#endprice').val(),
            step: 1,
            prefix: $('#currency').val(),
            onChange: function (data) {
                $('#min').val(data.from);
                $('#max').val(data.to);

                $(".item").each(function () {


                    price = parseInt($(this).find(".price").text(), 1);

                    if (data.from <= price && data.to >= price) {
                        $(this).addClass('show-me');
                    }
                    else {
                        $(this).removeClass('show-me');
                    }
                });

                $products.isotope({
                    itemSelector: '.item',
                    filter: filters
                });
            }
        });

    });

    // Single page - box filters
    // ----------------------------------------------------------------
    $(function () {

        // Filter buttons - toggle click event

        var $boxFilter = $('.box-filters figure');

        // init Isotope
        var $grid = $('#box-filters-results').isotope({
            itemSelector: '.item'
        });

        $boxFilter.on('click', function () {
            var $this = $(this);
            // Filter buttons - toggle click event
            if ($this.hasClass('active')) {
                $this.removeClass('active');

                $grid.isotope({ filter: "" });
            }
            else {
                $boxFilter.removeClass('active');
                $this.addClass('active');

                // Filter results
                var filterValue = $this.attr('data-filter');
                $grid.isotope({ filter: filterValue });
            }



        });


    });



    // Team members hover effect
    // ----------------------------------------------------------------

    var $member = $('.team article');
    $member.bind({
        mouseenter: function (e) {
            $member.addClass('inactive');
            $(this).addClass('active');
        },
        mouseleave: function (e) {
            $member.removeClass('inactive');
            $(this).removeClass('active');
        }
    });

    // Toggle contact form
    // ----------------------------------------------------------------

    $('.open-form').on('click', function () {
        var $this = $(this),
            parent = $this.parent();
        parent.toggleClass('active');
        if (parent.hasClass('active')) {
            $this.text($this.data('text-close'));
            $('.contact-form').slideDown();
        }
        else {
            $this.text($this.data('text-open'));
            $('.contact-form').slideUp();
        }

    });

    // Single page navigation (scroll to)
    // ----------------------------------------------------------------


    if ($('nav').hasClass('navbar-single-page')) {

        var $singleHyperlink = $('.navigation-main a');

        $singleHyperlink.on('click', function () {

            $singleHyperlink.removeClass('current');

            $(this).addClass('current');

            $('html, body').animate({
                scrollTop: $($(this).attr('href')).offset().top - $('.navigation-main').height()
            }, 500);
            return false;
        });

        // Magnific popup scroll to content
        // ----------------------------------------------------------------

        $('.mfp-open-scrollto').on('click', function () {
            $('html,body').animate({
                scrollTop: $('.mfp-content').offset().top - 200
            }, 300);
            return false;
        });
    }

});

$(window).bind('load', function () {
    setTimeout(function () {
        $('.page-loader').addClass('loaded');
    }, 1000);
});

/*Product Details Blouse*/
function calculatePrice()
{
    var blouseType = jQuery("input[name='blouse-option']:checked").val();
    if(blouseType == 'unstitched'){
        jQuery("#select-design-standard").hide();
        jQuery("#select-design-designer").hide();
    }
    else if(blouseType == 'standard'){
        jQuery("#select-design-standard").show();
        jQuery("#select-design-designer").hide();
    }
    else if(blouseType == 'designer'){
        jQuery("#select-design-standard").hide();
        jQuery("#select-design-designer").show();
    }
    
    var val = jQuery('input[name=blouse-option]:checked').val();
	var valFall = jQuery('input[name=fall_service]:checked').val();
}
function resetSelection(){
	jQuery('input[name="frontdesign"]').prop('checked', false);
	jQuery('input[name="backdesign"]').prop('checked', false);
	//jQuery('input[name="embroidery"]').prop('checked', false);
	jQuery('.measure-block-input').val('');
}
function measureImagePreview(imgPreview,obj){
    if(obj !== null){
        jQuery(obj).find('input:text').focus();
    }
    jQuery("#img_measurePreview").attr("src",imgPreview);
}
jQuery('.front-design').click(function() {		
    if(jQuery(".blouse-front-design-outer").hasClass('open')) {
		jQuery(".blouse-front-design-outer").removeClass("open");
		jQuery(".blouse-front-design-outer").addClass("close");
		jQuery(".front-design i").removeClass("fa fa-caret-up");
		jQuery(".front-design i").addClass("fa fa-caret-down");
	}
	else
	{
		jQuery(".blouse-front-design-outer").removeClass("close");
		jQuery(".blouse-front-design-outer").addClass("open");
		jQuery(".front-design i").removeClass("fa fa-caret-down");
		jQuery(".front-design i").addClass("fa fa-caret-up");
	}
});
jQuery('.back-design').click(function() {		
    if(jQuery(".blouse-back-design-outer").hasClass('open')) {
		jQuery(".blouse-back-design-outer").removeClass("open");
		jQuery(".blouse-back-design-outer").addClass("close");
		jQuery(".back-design i").removeClass("fa fa-caret-up");
		jQuery(".back-design i").addClass("fa fa-caret-down");
	}
	else
	{
		jQuery(".blouse-back-design-outer").removeClass("close");
		jQuery(".blouse-back-design-outer").addClass("open");
		jQuery(".back-design i").removeClass("fa fa-caret-down");
		jQuery(".back-design i").addClass("fa fa-caret-up");
		jQuery(".blouse-back-design-inner-block").show();
	}
});
jQuery('.blouse-embroidery-design').click(function() {		
    if(jQuery(".blouse-embroidery-design-outer").hasClass('open')) {
		jQuery(".blouse-embroidery-design-outer").removeClass("open");
		jQuery(".blouse-embroidery-design-outer").addClass("close");
		jQuery(".blouse-embroidery-design i").removeClass("fa fa-caret-up");
		jQuery(".blouse-embroidery-design i").addClass("fa fa-caret-down");
	}
	else
	{
		jQuery(".blouse-embroidery-design-outer").removeClass("close");
		jQuery(".blouse-embroidery-design-outer").addClass("open");
		jQuery(".blouse-embroidery-design i").removeClass("fa fa-caret-down");
		jQuery(".blouse-embroidery-design i").addClass("fa fa-caret-up");
	}
});
jQuery('.blouse-measurement').click(function() {		
    if(jQuery(".blouse-measurements-outer").hasClass('open')) {
		jQuery(".blouse-measurements-outer").removeClass("open");
		jQuery(".blouse-measurements-outer").addClass("close");
		jQuery(".blouse-measurement i").removeClass("fa fa-caret-up");
		jQuery(".blouse-measurement i").addClass("fa fa-caret-down");
	}
	else
	{
		jQuery(".blouse-measurements-outer").removeClass("close");
		jQuery(".blouse-measurements-outer").addClass("open");
		jQuery(".blouse-measurement i").removeClass("fa fa-caret-down");
		jQuery(".blouse-measurement i").addClass("fa fa-caret-up");
	}
});
function openbackdesign()
{
	if(jQuery(".blouse-back-design-outer").hasClass('close')) {
		jQuery(".blouse-back-design-outer").removeClass("close");
		jQuery(".blouse-back-design-outer").addClass("open");
	}
}
function backids(item, index){
	if (item !== ''){
		jQuery('#back-design-'+item).show();
	}
	else {
		jQuery('.blouse-back-design-block').css("display","inline-block");
	}
}
function enableSaveButton()
{
    jQuery("#popmeasuresave").removeClass("disabled");
    document.getElementById('popmeasuresave').setAttribute("onclick", "javascript:SaveMeasurements();");
}
function SaveMeasurements()
{
    
}
jQuery('#values_tab').click(function(e) {  
    var i, tabcontent, tablinks;
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablinks");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active", "");
    }
    document.getElementById('values').style.display = "block";
    jQuery("button").removeClass("active");
    jQuery("#values_tab").addClass("active");
    //evt.currentTarget.className += " active";
});
jQuery('#about_tab').click(function(e) {  
    var i, tabcontent, tablinks;
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablinks");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active", "");
    }
    document.getElementById('about').style.display = "block";
    jQuery("button").removeClass("active");
    jQuery("#about_tab").addClass("active");
    //evt.currentTarget.className += " active";
});
jQuery('#purpose_tab').click(function(e) {  
    var i, tabcontent, tablinks;
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablinks");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active", "");
    }
    document.getElementById('purpose').style.display = "block";
    jQuery("button").removeClass("active");
    jQuery("#purpose_tab").addClass("active");
    //evt.currentTarget.className += " active";
});
jQuery('#history_tab').click(function(e) {  
    var i, tabcontent, tablinks;
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablinks");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active", "");
    }
    document.getElementById('history').style.display = "block";
    jQuery("button").removeClass("active");
    jQuery("#history_tab").addClass("active");
    //evt.currentTarget.className += " active";
});
jQuery('#stories_tab').click(function(e) {  
    var i, tabcontent, tablinks;
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablinks");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active", "");
    }
    document.getElementById('stories').style.display = "block";
    jQuery("button").removeClass("active");
    jQuery("#stories_tab").addClass("active");
    //evt.currentTarget.className += " active";
});
jQuery('#select-design-standard').click(function(){
    jQuery(".blouse-module").show();
    jQuery(".blouse-embroidery-design").hide();
    jQuery(".blouse-embroidery-design-outer").hide();
    enableSaveButton();
});
jQuery('#select-design-designer').click(function(){
    jQuery(".blouse-module").show();
    jQuery(".blouse-embroidery-design").show();
    jQuery(".blouse-embroidery-design-outer").show();
    enableSaveButton();
});
jQuery('.close-blouse-module').click(function(){
    jQuery(".blouse-module").hide();
});

jQuery( document ).ready(function() {
    var front = jQuery("input[name='blouse-option']:checked").val();
    var back = jQuery("input[name='blouse-option']:checked").val();
    var design = jQuery("input[name='blouse-option']:checked").val();
    
    //faq accordion
    var acc = document.getElementsByClassName("pfaq accordion");
    var i;
    for (i = 0; i < acc.length; i++) {
        acc[i].addEventListener("click", function () {
            this.classList.toggle("active");
            var panel = this.nextElementSibling;
            if (panel.style.display === "block") {
                panel.style.display = "none";
            } else {
                panel.style.display = "block";
            }
        });
    }
    
});

$(".chkpartner").click(function () {

    $(".chkpartner").attr("checked", false); //uncheck all checkboxes

    $(this).attr("checked", true);  //check the clicked one

    var selected_partner = $('.chkpartner:checked').val();



    var path = window.location.href.split('?')[0];
    var searchParams = new URLSearchParams(window.location.search);

    var url = new window.URL(document.location);
    url.searchParams.set("pid", selected_partner);
    if (document.location.search.length) {
        window.location.href = url.toString();
    } else {
        window.location.href = path + '?pid=' + selected_partner;
    }

});


$(".chksubcat").click(function () {

    $(".chksubcat").attr("checked", false); //uncheck all checkboxes

    $(this).attr("checked", true);  //check the clicked one

    var selected_val = $('.chksubcat:checked').val();

    var path = window.location.href.split('?')[0];
    var searchParams = new URLSearchParams(window.location.search);

    var url = new window.URL(document.location);
    url.searchParams.set("subid", selected_val);
    if (document.location.search.length) {
        window.location.href = url.toString();
    } else {
        window.location.href = path + '?subid=' + selected_val;
    }

});


$(".chkdiscount").click(function () {

    $(".chkdiscount").attr("checked", false); //uncheck all checkboxes

    $(this).attr("checked", true);  //check the clicked one

    var selected_val = $('.chkdiscount:checked').val();

    

    var path = window.location.href.split('?')[0];
    var searchParams = new URLSearchParams(window.location.search);

    var url = new window.URL(document.location);
    url.searchParams.set("discount", selected_val);
    if (document.location.search.length) {
        window.location.href = url.toString();
    } else {
        window.location.href = path + '?discount=' + selected_val;
    }

});


/*
jQuery('#partners-filter').change(function() {
    var item=jQuery(this);
	var selected_partner = item.val();
	var path = window.location.href.split('?')[0];
	var searchParams = new URLSearchParams(window.location.search);

	var url = new window.URL(document.location);
    url.searchParams.set("pid", selected_partner);
	if(document.location.search.length) {
		window.location.href = url.toString();
	} else {
		window.location.href = path+'?pid='+selected_partner;
	}
});

jQuery('#subcat-filter').change(function() {    
    var item=jQuery(this);
	var selected_partner = item.val();
	var path = window.location.href.split('?')[0];
	var searchParams = new URLSearchParams(window.location.search);
	var url = new window.URL(document.location); 
    url.searchParams.set("subid", selected_partner);

	if(document.location.search.length) {
		window.location.href = url.toString();
	} else {
		window.location.href = path+'?subid='+selected_partner;
	}
});
jQuery('#discount-filter').change(function() {    
    var item=jQuery(this);
	var selected_disc = item.val();
	var path = window.location.href.split('?')[0];
	var searchParams = new URLSearchParams(window.location.search);
	var url = new window.URL(document.location); 
    url.searchParams.set("discount", selected_disc);

	if(document.location.search.length) {
		window.location.href = url.toString();
	} else {
		window.location.href = path+'?discount='+selected_disc;
	}
});
*/
// Product Image Zoom plugin - product pages by Obaid
    if ( $.fn.elevateZoom ) {
        $('#product-zoom').elevateZoom({
            gallery:'product-zoom-gallery',
            galleryActiveClass: 'active',
            zoomType: "none",
            cursor: "crosshair",
            zoomWindowFadeIn: 400,
            zoomWindowFadeOut: 400,
            responsive: true
        });

        // On click change thumbs active item
        $('.product-gallery-item').on('click', function (e) {
            $('#product-zoom-gallery').find('a').removeClass('active');
            $(this).addClass('active');

            e.preventDefault();
        });

        var ez = $('#product-zoom').data('elevateZoom');

        // Open popup - product images
        $('#btn-product-gallery').on('click', function (e) {
            if ( $.fn.magnificPopup ) {
                $.magnificPopup.open({
                    items: ez.getGalleryList(),
                    type: 'image',
                    gallery:{
                        enabled:true
                    },
                    fixedContentPos: false,
                    removalDelay: 600,
                    closeBtnInside: false
                }, 0);

                e.preventDefault();
            }
        });
    }

jQuery("#manufactured_name").click(function(){
	jQuery("#productinfo_tabs li").removeClass("active");
	jQuery("#product-tab-content .tab-pane").removeClass("active");
	jQuery("#productinfo_tabs li#partner_block").addClass("active");
	jQuery("#product-tab-content .tab-pane#partner_details").addClass("active");
});

//tryme js START  

jQuery('#tryme-btn').click(function() { 
    jQuery('.tryme-block-bg').show();
    jQuery('#tryme-block-main').show();
    jQuery('.product .info-box.cart-btns').hide();
    jQuery('#tryme-block-main .tryme_inner_popup').hide();
    jQuery('#resizable').attr("src","");
    jQuery('#renderImg').attr("src","");
    jQuery('#tryme_save').hide();
    jQuery('#canvas_container').hide();
    jQuery('#uploadTryMeImg').show();
});
jQuery('#tryme-close-btn').click(function() { 
    jQuery('.tryme-block-bg').hide();
    jQuery('#tryme-block-main').hide();
    jQuery('.product .info-box.cart-btns').show();
});
jQuery('#watch').click(function() {
    jQuery("#tryme-block").css("z-index", "9998"); 
    jQuery('.tryme_inner_popup').hide();
    jQuery('#watch_block').show();
});
jQuery('#learn').click(function() { 
    jQuery("#tryme-block").css("z-index", "9998");
    jQuery('.tryme_inner_popup').hide();
    jQuery('#learn_block').show();
});
jQuery('#choose').click(function() { 
    jQuery('#tryme-block-main .tryme_models_outer_block').show();  
});
jQuery('#upload').click(function() {
    jQuery("#tryme-block").css("z-index", "9998");
    jQuery('.tryme_inner_popup').hide();
    jQuery('#upload_block').show();
    jQuery('#resizable').attr("src","");
    jQuery('#renderImg').attr("src","");
});
jQuery('.tryme-close-inner-btn').click(function() { 
    jQuery("#tryme-block").css("z-index", "9999");
    jQuery('.tryme_inner_popup').hide();

    jQuery('#tryme_video_iframe').each(function(index) {
        jQuery(this).attr('src', jQuery(this).attr('src'));
        return false;
    });
});
jQuery('#trymeshare').click(function() {
    jQuery('.share_popup').show();
});
jQuery('.share_popup').click(function() { 
    setTimeout(function () {
        jQuery('.share_popup').hide();
    }, 1500);
});
jQuery('#trymeshare-thumbnail').click(function() {
    jQuery('.share_popup_thumb').show();
});
jQuery('.share_popup_thumb').click(function() { 
    setTimeout(function () {
        jQuery('.share_popup_thumb').hide();
    }, 1500);
});
jQuery('#trymeshare-btn-1').click(function() {		
    jQuery('#trymeshare-btn').click();
});
jQuery('#tryme-thumbnail-btn').click(function() {		
    jQuery('#tryme-btn').click();
});

 $(document).on('click', "#trymeshare-btn", function () {
//jQuery('#trymeshare-btn').click(function() { 
    //debugger;
    var base_url = window.location.origin;
    var userid = jQuery("body").attr("userid");
    var prod_id = jQuery('#productid').text();
    var prod_img_url = jQuery('#product-zoom').attr('src');
    var prod_url = window.location.href;
    //var prod_title = jQuery('.product .title').text();
    var prod_title = jQuery('.product-single__title').text();
    var is_tryme = localStorage.getItem("tryme_outputid");
   // userid = '149848';
    if (userid == ''){
        window.location.href = base_url +"/account/";
    }
    localStorage.setItem("redirect_to", "https://yespoho.community/");
    //localStorage.setItem("redirect_to", "https://yespoho.com/mycommunity/");
    localStorage.setItem("prod_id", prod_id);
    localStorage.setItem("prod_img_url", prod_img_url);
    localStorage.setItem("prod_title", prod_title);

    $.ajax({
        url: base_url +"/catalog/sharetocommunity/",
        type: "POST",
        data: { 
            mode: 'sharetryme', encoded_userid:userid, product_id:prod_id, prod_img_url:prod_img_url,prod_title:prod_title, is_tryme:is_tryme, prod_url:prod_url
        },
        cache: false,
        success: function(dataResult){
           // debugger;
            var dataResult = JSON.parse(dataResult);
            if(dataResult.statusCode==200){
              //  window.open('https://www.yespoho.com/mycommunity/login/?id='+userid, '_blank');
                window.open('https://yespoho.community/comapi/yespohoautologin.php?em='+dataResult.em, '_blank');
            }    
            else{
               
            }
        },
    });
});

$(document).on('click', "#trymeshare-btn-cmd", function () {
//jQuery('#trymeshare-btn').click(function() { 
   // debugger;
    var base_url = window.location.origin;
    var userid = jQuery("body").attr("userid");
    var prod_id = jQuery('#productid').text();
    var prod_img_url = jQuery('#cmd_output').attr('src');
    var prod_url = window.location.href;
    //var prod_title = jQuery('.product .title').text();
    var prod_title = jQuery('.product-single__title').text();
    var is_tryme = localStorage.getItem("tryme_outputid");
    //userid = '149848';
    if (userid == ''){
        window.location.href = base_url +"/account/";
    }
    localStorage.setItem("redirect_to", "https://yespoho.community/");
    //localStorage.setItem("redirect_to", "https://yespoho.com/mycommunity/");
    localStorage.setItem("prod_id", prod_id);
    localStorage.setItem("prod_img_url", prod_img_url);
    localStorage.setItem("prod_title", prod_title);

    $.ajax({
        url: base_url +"/catalog/sharetocommunity/",
        type: "POST",
        data: { 
            mode: 'sharetryme', encoded_userid:userid, product_id:prod_id, prod_img_url:prod_img_url,prod_title:prod_title, is_tryme:is_tryme, prod_url:prod_url
        },
        cache: false,
        success: function(dataResult){
           // debugger;
            var dataResult = JSON.parse(dataResult);
            if(dataResult.statusCode==200){
              //  window.open('https://www.yespoho.com/mycommunity/login/?id='+userid, '_blank');
                window.open('https://yespoho.community/');
            }    
            else{
               
            }
        },
    });
});


function update(activeAnchor) {
    var group = activeAnchor.getParent();

    var topLeft = group.findOne('.topLeft');
    var topRight = group.findOne('.topRight');
    var bottomRight = group.findOne('.bottomRight');
    var bottomLeft = group.findOne('.bottomLeft');
    var image = group.findOne('Image');

    var anchorX = activeAnchor.x();
    var anchorY = activeAnchor.y();

    // update anchor positions
    switch (activeAnchor.getName()) {
    case 'topLeft':
        topRight.y(anchorY);
        bottomLeft.x(anchorX);
        break;
    case 'topRight':
        topLeft.y(anchorY);
        bottomRight.x(anchorX);
        break;
    case 'bottomRight':
        bottomLeft.y(anchorY);
        topRight.x(anchorX);
        break;
    case 'bottomLeft':
        bottomRight.y(anchorY);
        topLeft.x(anchorX);
        break;
    }
    
    image.position(topLeft.position());

    var width = topRight.x() - topLeft.x();
    var height = bottomLeft.y() - topLeft.y();
    if (width && height) {
        image.width(width);
        image.height(height);
    }
   
}

function addAnchor(group, x, y, name, radius) {
    var base_url = window.location.origin;
    var stage = group.getStage();
    var layer = group.getLayer();

    var anchor = new Konva.Circle({
        x: x,
        y: y,
        stroke: '#F26D78',
        fill: '#F26D78',
        strokeWidth: 5,
        radius: 8,
        name: name,
        draggable: true,
        dragOnTop: false,
    });

    anchor.on('dragmove', function () {
        update(this);
    });
    anchor.on('mousedown touchstart', function () {
        group.draggable(false);
        this.moveToTop();
    });
    anchor.on('dragend', function () {
        group.draggable(true);
    });
    // add hover styling
    anchor.on('mouseover', function () {
        var layer = this.getLayer();
        document.body.style.cursor = 'pointer';
        this.strokeWidth(4);
    });
    anchor.on('mouseout', function () {
        var layer = this.getLayer();
        document.body.style.cursor = 'default';
        this.strokeWidth(2);
    });

    group.add(anchor);
    anchor.show();
     
    jQuery("#tryme_save").click(function(){
        anchor.hide();
    });
    jQuery("#tryme_save_model").click(function(){
        anchor.hide();
    });
}

if (jQuery("section.product").hasClass("hasTryMe")) {
    var base_url = window.location.origin;

    var width = 348;
    var height = 522;

    var imageObj1 = new Image(); 
    var imageObj2 = new Image();

    var stage = new Konva.Stage({
        container: 'canvas_container',
        width: width,
        height: height,
    });

    var layer = new Konva.Layer();
    stage.add(layer);

    // darth vader - Image 1
    var darthVaderImg = new Konva.Image({
        width: 350,
        height: 520,
    });

    // yoda - Image 2
    var yodaImg = new Konva.Image({
        width: 260,
        height: 350,
    });

    var darthVaderGroup = new Konva.Group({
        x: 0,
        y: 0,
        draggable: false,
    });
    layer.add(darthVaderGroup);
    darthVaderGroup.add(darthVaderImg);

    var yodaGroup = new Konva.Group({
        x: 10,
        y: 20,
        draggable: true,
    });
    layer.add(yodaGroup);
    yodaGroup.add(yodaImg);
    addAnchor(yodaGroup, 0, 0, 'topLeft');
    addAnchor(yodaGroup, 260, 0, 'topRight');
    addAnchor(yodaGroup, 260, 350, 'bottomRight');
    addAnchor(yodaGroup, 0, 350, 'bottomLeft');

    imageObj1.onload = function () {
        darthVaderImg.image(imageObj1);
    };
    
    imageObj2.onload = function () {
        yodaImg.image(imageObj2);
    };

    imageObj1.setAttribute("crossorigin", "anonymous");
    imageObj2.setAttribute("crossorigin", "anonymous");

    imageObj1.src = document.getElementById("resizable").src;
    imageObj2.src = document.getElementById("renderImg").src;

    imgInp.onchange = evt => {
        //debugger;
        var img = "<img id='resizable' src=''><img id='renderImg' src=''>";
        jQuery("#fileList").append(img);
        var product_id = jQuery('#productid').text();
        //var renderImg = "https://newyespoho.yespoho.com/public/img/try_me_image.png";
        var renderImg = base_url+"/public/img/trymeimg/tinified/"+product_id+"/31_23-5_32-5.png";

        setTimeout(function () {
            jQuery('#renderImg').attr("src",renderImg)
        }, 1000);
              
        setTimeout(function () {
            imageObj1.src = document.getElementById("resizable").src;
            imageObj2.src = document.getElementById("renderImg").src;            
        }, 1100);
      
      
        const [file] = imgInp.files
        if (file) {
            resizable.src = URL.createObjectURL(file)
        }

        localStorage.setItem("tryme_user_img", document.getElementById("resizable").src);
        jQuery("#resizable").hide();
        jQuery("#renderImg").hide();
        jQuery("#uploadTryMeImg").hide();
        jQuery("#canvas_container").show();
        jQuery("#tryme_save").show();
    }

    document.getElementById('tryme_save').addEventListener(
        'click',
        function () {
            var dataURL = stage.toDataURL({ pixelRatio: 3 });
            downloadURI(dataURL, 'stage.jpg');
        },
        false
    );
}

function downloadURI(uri, name) {
     //debugger;
    var base_url = window.location.origin;
   
    var prod_id = jQuery('#productid').text();
    var userid = jQuery("body").attr("userid");
    localStorage.setItem("tryme_outputid", "tryme_"+prod_id);
    $.ajax({
        url: base_url+"/savetry.php",
        type: "POST",
        data: { 
            mode:'tryme', tryimage: uri, product_id: prod_id, encoded_userid:userid
        },
        cache: false,
        success: function(dataResult){
		console.log(dataResult);
            var dataResult = JSON.parse(dataResult);
	    
            if(dataResult.statusCode==200){
                jQuery('.tryme-output-item').show();
                //jQuery("#tryme-output-img").attr("src","/"+dataResult.image_url);
                jQuery("#product-zoom").attr("src","/"+dataResult.image_url);
                jQuery('#tryme_span').show();
                jQuery("#tryme_span").append('<a style="display:block;" class="tryme-output-item" href="#" data-image="" data-zoom-image=""> <img id="tryme-output-img" src="'+base_url+'/'+dataResult.image_url+'"> </a>');
                jQuery(".tryme-output-item").attr("data-image","/"+dataResult.image_url);
                jQuery(".tryme-output-item").attr("data-zoom-image","/"+dataResult.image_url);
                jQuery('.tryme-output-item').click();
            }    
            else{
               //alert(dataResult.image_url);
            }
        },
    });
    jQuery('.tryme-block-bg').hide();
    jQuery('#tryme-block-main').hide();
    jQuery('#tryme-block-main .tryme_inner_popup#upload_block').hide();
    jQuery('.product .info-box.cart-btns').show();
    jQuery("#tryme-block").css("z-index", "9999");
    jQuery('#resizable').attr("src","");
    jQuery('#renderImg').attr("src","");
    
}

function showListingTryMe(product_id){
    var base_url = window.location.origin;
   // debugger;
    if(localStorage.getItem("tryme_user_img") == null){
        var prod_link = $('#prod_'+product_id).prop('href');
        window.location.href = prod_link+'?action=opentryme';
    }
    else{    
        /*var width = 263;
        var height = 280;*/
        var width = 287;
        var height = 431;

        var imageObj1 = new Image(); 
        var imageObj2 = new Image();
    
        var img = "<img id='userImage' src=''><img id='renderImg' src=''>";
        var renderImg = base_url+"/public/img/trymeimg/tinified/"+product_id+"/31_23-5_32-5.png";
        //var renderImg = "https://newyespoho.yespoho.com/public/img/try_me_image.png";

        jQuery(".figure_"+product_id+" #prod_"+product_id).hide();
        jQuery(".figure_"+product_id).append(img);
        
        setTimeout(function () {
            jQuery('#renderImg').attr("src",renderImg);
            jQuery('#userImage').attr("src",localStorage.getItem("tryme_user_img"))
        }, 1000);
        
        setTimeout(function () {
            imageObj1.src = document.getElementById("userImage").src;
            imageObj2.src = document.getElementById("renderImg").src;

            jQuery("#userImage").hide();
            jQuery("#renderImg").hide();

            
        }, 1100);

        var stage = new Konva.Stage({
            container: 'canvas_container_listing_'+product_id,
            width: width,
            height: height,
            centeredScaling: true,
            draggable: false,
        });
        
        var layer = new Konva.Layer();
        stage.add(layer);
        
        // darth vader - Image 1
        var darthVaderImg = new Konva.Image({
            width: 287,
            height: 431,
            draggable: false,
        });
        
        // yoda - Image 2
        var yodaImg = new Konva.Image({
            width: 202,
            height: 390,
            draggable: false,
            centeredScaling: true,
        });
        
        var darthVaderGroup = new Konva.Group({
            x: 0,
            y: 0,
            draggable: false,
            centeredScaling: true,
        });
        layer.add(darthVaderGroup);
        darthVaderGroup.add(darthVaderImg);
        
        var yodaGroup = new Konva.Group({
            x: 75,
            y: 55,
            draggable: false,
            centeredScaling: true,
            draggable: false,
        });
        layer.add(yodaGroup);
        yodaGroup.add(yodaImg);
    
        imageObj1.onload = function () {
            darthVaderImg.image(imageObj1);
        };
        
        imageObj2.onload = function () {
            yodaImg.image(imageObj2);
        };
        
        imageObj1.setAttribute("crossorigin", "anonymous");
        imageObj2.setAttribute("crossorigin", "anonymous");
    }
}

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
jQuery( document ).ready(function() {
    var tryme_action = getUrlVars()["action"];
    if(tryme_action == 'opentryme'){
        jQuery('#tryme-btn').click();
    }
});

if (jQuery("section.product").hasClass("hasTryMe")) {
    var stage1 = new Konva.Stage({
        container: 'canvas_container_model',
        width: width,
        height: height,
    });
}

jQuery("#tryme_model_img1").click(function() {
    jQuery(this).prev().prop("checked", true);
    chooseModel();
});
jQuery("#tryme_model_img2").click(function() {
    jQuery(this).prev().prop("checked", true);
    chooseModel();
});
jQuery("#tryme_model_img3").click(function() {
   jQuery(this).prev().prop("checked", true);
   chooseModel();
});

function chooseModel() {
    var base_url = window.location.origin;
    //debugger;
    var model = jQuery('input[name="tryme_model"]:checked').val();
    
    jQuery("#tryme-block").css("z-index", "9998");
    jQuery('.tryme_inner_popup').hide();
    jQuery('#choose_block').show();

    var img = "<img id='resizable' src=''><img id='renderImg' src=''>";
    jQuery("#canvas_container_model").append(img);

    var url = base_url+'/thumb/tryme_models/'+model;

    var product_id = jQuery('#productid').text();
    //var renderImg = "https://newyespoho.yespoho.com/public/img/try_me_image.png";
    var renderImg = base_url+"/public/img/trymeimg/tinified/"+product_id+"/31_23-5_32-5.png";

    jQuery('#resizable').attr("src",url);
    jQuery('#renderImg').attr("src",renderImg);

    var width = 348;
    var height = 522;

    var imageObj1 = new Image(); 
    var imageObj2 = new Image();

    imageObj1.src = document.getElementById("resizable").src;
    imageObj2.src = document.getElementById("renderImg").src;

    var layer = new Konva.Layer();
    stage1.add(layer);

    // darth vader - Image 1
    var darthVaderImg = new Konva.Image({
        width: 350,
        height: 520,
    });

    // yoda - Image 2
    var yodaImg = new Konva.Image({
        width: 260,
        height: 450,
    });

    var darthVaderGroup = new Konva.Group({
        x: 0,
        y: 0,
        draggable: false,
    });
    layer.add(darthVaderGroup);
    darthVaderGroup.add(darthVaderImg);

    var yodaGroup = new Konva.Group({
        x: 80,
        y: 85,
        draggable: true,
    });
    layer.add(yodaGroup);
    yodaGroup.add(yodaImg);
    addAnchor(yodaGroup, 0, 0, 'topLeft');
    addAnchor(yodaGroup, 260, 0, 'topRight');
    addAnchor(yodaGroup, 260, 350, 'bottomRight');
    addAnchor(yodaGroup, 0, 350, 'bottomLeft');

    imageObj1.onload = function () {
        darthVaderImg.image(imageObj1);
    };
    
    imageObj2.onload = function () {
        yodaImg.image(imageObj2);
    };

    imageObj1.setAttribute("crossorigin", "anonymous");
    imageObj2.setAttribute("crossorigin", "anonymous");

    localStorage.setItem("tryme_user_img", document.getElementById("resizable").src);
    jQuery('input[name="tryme_model').prop('checked', false);
}

if (jQuery("section.product").hasClass("hasTryMe")) {
    document.getElementById('tryme_save_model').addEventListener(
        'click',
        function () {
            var dataURL = stage1.toDataURL({ pixelRatio: 3 });
            downloadURI(dataURL, 'stage.jpg');
        },
        false
    );
}


//try me END

//Product Video Display START
jQuery('#video-btn').click(function() { 
    jQuery('.tryme-block-bg').show();
    jQuery('.product-video-block').show();
    jQuery('.product .info-box.cart-btns').hide();
});

jQuery('#product-video-close-btn').click(function() { 
    //debugger;
    jQuery('.tryme-block-bg').hide();
    jQuery('.product-video-block').hide();
    jQuery('.product .info-box.cart-btns').show();

    if($('#product_video').length){
        jQuery('#product_video').get(0).pause();
    }

    if($('#product_video_iframe').length){
        jQuery('#product_video_iframe').each(function(index) {
            jQuery(this).attr('src', jQuery(this).attr('src'));
            return false;
        });
    }   
});

jQuery('.listing-product-video-block').click(function() { 
    //debugger;
    jQuery('.tryme-block-bg').hide();
    jQuery('.listing-product-video-block').hide();
    // jQuery('#product_video').get(0).pause();

    jQuery('#product_video_iframe').attr('src','');
});

function showVideoPopup(url){
    //debugger;
    jQuery('#product_video_iframe').attr('src',url);
    jQuery('.tryme-block-bg').show();
    jQuery('.listing-product-video-block').show();
}
//Product Video Display END

setTimeout(function () {
    jQuery('#product-zoom').removeData('elevateZoom');
    jQuery('.zoomWrapper img.zoomed').unwrap();
    jQuery('.zoomContainer').remove();
    jQuery("#product-zoom").unbind("touchmove");
}, 1000);

//CMD Start

jQuery('#cmd_next').click(function() { 
    jQuery(".cmd_inner_blocks").removeClass("active");
    jQuery("#cmd2").addClass("active");
});
jQuery('#cmd_mob_next1').click(function() { 
    jQuery(".cmd_inner_blocks").removeClass("active");
    jQuery("#cmd2").addClass("active");
});
jQuery('#cmd_back1').click(function() { 
    jQuery(".cmd_inner_blocks").removeClass("active");
    jQuery("#cmd1").addClass("active");
});
jQuery('#cmd_mob_back1').click(function() { 
    jQuery(".cmd_inner_blocks").removeClass("active");
    jQuery("#cmd1").addClass("active");
});

jQuery('.cmd-share-block img').click(function() { 
    jQuery(".cmd_share_popup").show();
    
    var img = document.getElementById("cmd_output").src;
    // jQuery("meta[property='og:url']").attr("content", document.location.origin+"/cmd");
    // jQuery("meta[property='og:image']").attr("content", img);

    // jQuery("meta[property='og:url']").remove();
    // jQuery("meta[property='og:image']").remove();
    // jQuery("head").append('<meta property="og:url" content="https://newyespoho.yespoho.com/cmd">');
    // jQuery("head").append('<meta property="og:image" content="'+img+'">');
});

jQuery('#cmd_back2').click(function() { 
    jQuery(".cmd_inner_blocks").removeClass("active");
    jQuery("#cmd2").addClass("active");

    jQuery("#patternPopup").addClass("disabled");
    jQuery("#colorPopup").addClass("disabled");

    jQuery('#fabric').prop('selectedIndex',0);
    jQuery(".cmd-block .addtocart").hide();
    jQuery(".cmd-block .buynow").hide();
    jQuery(".cmd-block .cmdshare").hide();
    jQuery(".cmd-block .cmd_cart_block").hide();
    jQuery("#cmd_product_price").hide();
    jQuery(".cmd-block .cmd-share-block").hide();

});
jQuery('#cmd_mob_back2').click(function() { 
    jQuery(".cmd_inner_blocks").removeClass("active");
    jQuery("#cmd2").addClass("active");

    jQuery("#patternPopup").addClass("disabled");
    jQuery("#colorPopup").addClass("disabled");

    jQuery('#fabric').prop('selectedIndex',0);
    jQuery(".cmd-block .addtocart").hide();
    jQuery(".cmd-block .buynow").hide();
    jQuery(".cmd-block .cmdshare").hide();
    jQuery(".cmd-block .cmd_cart_block").hide();
    jQuery("#cmd_product_price").hide();
    jQuery(".cmd-block .cmd-share-block").hide();
});
jQuery("#cmd_model_img1").click(function() {
    jQuery(this).prev().prop("checked", true);
    jQuery(".cmd_inner_blocks").removeClass("active");
    jQuery("#cmd3").addClass("active");
    var url = document.getElementById("cmd_model_img1").src;
    jQuery('#cmd_output').attr("src",url);
    localStorage.setItem("cmdimg", 'm1');
    localStorage.setItem("cmdimg_modelurl", url);
    jQuery('input[name="cmd_model').prop('checked', false);
});
jQuery("#cmd_model_img2").click(function() {
    jQuery(this).prev().prop("checked", true);
    jQuery(".cmd_inner_blocks").removeClass("active");
    jQuery("#cmd3").addClass("active");
    var url = document.getElementById("cmd_model_img2").src;
    jQuery('#cmd_output').attr("src",url);
    localStorage.setItem("cmdimg", 'm2');
    localStorage.setItem("cmdimg_modelurl", url);
    jQuery('input[name="cmd_model').prop('checked', false);
});
jQuery("#fabricPopup").click(function() {
    jQuery(".cmd_popup_bg").show();
    jQuery(".fabric_select_block").show();
});
jQuery("#patternPopup").click(function() {
    jQuery(".cmd_popup_bg").show();
    jQuery(".design_select_block").show();
});
jQuery("#colorPopup").click(function() {
    jQuery(".cmd_popup_bg").show();
    jQuery(".color_select_block").show();
});
jQuery(".cmd-block .cmd-close-btn").click(function() {
    jQuery(".cmd_popup_bg").hide();
    jQuery(".cmd_popup").hide();
});
jQuery('.cmd_share_popup').click(function() { 
    setTimeout(function () {
        jQuery('.cmd_share_popup').hide();
    }, 1500);
});

jQuery('#fabric').change(function () {
    var base_url = window.location.origin;

    var item = jQuery(this);
    var selectedfabric = item.val();
    var model = localStorage.getItem('cmdimg');
    var path = window.location.href.split('?')[0];
    var selected = jQuery('#fabric').find(":selected").text();
    var searchParams = new URLSearchParams(window.location.search);
    var url = new window.URL(document.location); 
    url.searchParams.set("fid", selectedfabric);

    var link = window.location.href;
    
    jQuery(".cmd_popup_bg").hide();
    jQuery(".cmd_popup").hide();
 
    $.ajax({
        url: base_url+"/cmd/pattern/",
        type: "POST",
        data: {
            fid: selectedfabric, mid: model
        },
        cache: false,
        success: function (response) {
            var response = JSON.parse(response); 
            jQuery("#patternPopup").removeClass('disabled');
            jQuery("#appendPattern").empty();
            jQuery(".prod_info").attr("fid",selectedfabric);
            response.forEach(element => {
                jQuery('#appendPattern').append('<div class="col-md-2 col-xs-2 cmd_design_blocks"> <input name="cmd_design" type="radio" id="cmd_design_'+element['cmd_pattern_id']+'" value="'+element['cmd_pattern_id']+'"><img onclick="selectDesign('+element['cmd_pattern_id']+');" id="cmd_design_img'+element['cmd_pattern_id']+'" src="https://d1hv57p0mfzhgm.cloudfront.net/thumb/'+element['pattern_image']+'"><p>'+element['pattern_name']+'</p></div>');
            });
        },
    });
});

function selectDesign(i) {
   // debugger;
    var base_url = window.location.origin;
    jQuery('#cmd_design_img' + i).prev().prop("checked", true);
    var selectedfabric = jQuery("#fabric").val();
    var selectedpattern = jQuery("input[name='cmd_design']:checked").val();
    var model = localStorage.getItem('cmdimg');
    var path = window.location.href;
    var searchParams = new URLSearchParams(window.location.search);
    var url = new window.URL(document.location);
    url.searchParams.set("pid", selectedpattern);
    url.searchParams.set("mid", model);

    var link = window.location.href;

    jQuery(".cmd_popup_bg").hide();
    jQuery(".cmd_popup").hide();

    $.ajax({
        url: base_url+"/cmd/color/",
        type: "POST",
        data: {
            fid: selectedfabric, pid: selectedpattern, mid: model
        },
        cache: false,
        success: function (response) {
//alert(response);
            jQuery(".prod_info").attr("pid",selectedpattern);

            var response = JSON.parse(response);
            var colorData = response.color_data;
			var productData = response.product_detail;
			var additional_info = response.additional_info;
			var currency = response.currency_sym;
            jQuery("#cmd_output").attr("src",response.trymeimg);
            jQuery("#colorPopup").removeClass('disabled');

            jQuery("#cmd_product_price").empty();
            if(response.final_price != '' && response.final_price > 0){  
				populateproductdata(productData,currency,additional_info);
                /*jQuery("#cmd_product_price").append("Product Price: <b>"+response.final_currency+response.final_price+"</b>");
                jQuery("#cmd_product_price").show();
                jQuery("#cmd_product_price_mob").empty();
                jQuery("#cmd_product_price_mob").append("Product Price: <b>"+response.final_currency+response.final_price+"</b>");
                jQuery("#cmd_product_price_mob").show();*/
                jQuery(".cmd-block .addtocart").removeClass("disabled");
                jQuery(".cmd-block .buynow").removeClass("disabled");
                
                jQuery(".cmd-block .cmd-share-block").removeClass("disabled");

                jQuery(".cmd_cart_block .addtocart").attr("data-product-id",response.product_id);
                jQuery(".cmd_cart_block .buynow").attr("data-product-id",response.product_id);
                jQuery(".cmd_cart_block .addtocart").attr("product-price",response.final_price);
                jQuery(".cmd_cart_block .buynow").attr("product-price",response.final_price);
            }
            if(response.final_price == '' || response.final_price == 0){
                jQuery(".cmd-block .addtocart").addClass("disabled");
                jQuery(".cmd-block .buynow").addClass("disabled");
                
                jQuery(".cmd-block .cmd-share-block").addClass("disabled");
            }
        
            jQuery(".cmd-block .addtocart").show();
            jQuery(".cmd-block .buynow").show();
            jQuery(".cmd-block .cmd-share-block").show();
            jQuery(".cmd-block .cmd_cart_block").show();

            jQuery("#color").empty();
            colorData.forEach(element => {
                jQuery('#color').append('<div class="col-md-1 col-xs-2"><input name="color" type="radio" id="cmd_color_'+element['cmd_color_id']+'" value="'+element['cmd_color_id']+'"><span onclick="selectColor('+element['cmd_color_id']+');" id="cmd_color_span_'+element['cmd_color_id']+'" class="color_span" style="background-color: '+element['color_code']+'; color: '+element['color_code']+';">.</span></div>');
            });
        },
    });
}

function populateproductdata(product_data,currency,additional_info)
{
	var domain=window.location.hostname;
	//alert (domain);
var strike_price =0;
var discount_percentage =0;
var discount_percentage_new=0;

if (product_data.markup>0)
{
strike_price = (parseInt(product_data.final_price) * parseInt(product_data.markup)/100) ;
discount_percentage = (1-product_data.final_price/(parseInt(strike_price)+parseInt(product_data.final_price))) * 100;
discount_percentage_new =product_data.markup;
}
var regularprice=   parseFloat(parseInt(strike_price)+parseInt(product_data.final_price)).toFixed(2);
var saveprice = parseFloat(parseInt(strike_price)+parseInt(product_data.final_price)-parseInt(product_data.final_price)).toFixed(2);
	
	//alert(currency);
	var html ='<div bis_skin_checked="1"><section class="product" productid="'+product_data.id+'"><div class="" bis_skin_checked="1">';
    html=html+'<div class="product-block product-block--header" bis_skin_checked="1">';
    html=html+'<div class="product-single__vendor" bis_skin_checked="1">'+product_data.brand_name+'</div>';
    html=html+'<h1 class="h2 product-single__title">'+product_data.product_name+'</h1><h5>SKU:<span id="productid">'+product_data.id+'</span><img id="trymeshare-btn-cmd" width="30px" style="cursor: pointer;max-width:30px;margin:0 0px 0px 0px;" src="/public/img/Share-icon.png"></h5></div>';
    html=html+'<div data-product-blocks="" bis_skin_checked="1">';
    html=html+'<div class="product-block product-block--price" bis_skin_checked="1">';
    html=html+'<span data-a11y-price="" class="visually-hidden" aria-hidden="false">Regular price</span>';
    html=html+'<span data-product-price-wrap="" class="">';
    html=html+'<span data-compare-price="" class="product__price product__price--compare">'+currency+''+regularprice+'</span></span>'+currency+product_data.final_price+' ';
	html=html+'<span data-save-price="" class="product__price-savings">Save '+currency+''+saveprice+'</span>';
    html=html+'<div data-unit-price-wrapper="" class="product__unit-price product__unit-price--spacing  hide" bis_skin_checked="1">';
    html=html+'<span data-unit-price=""></span>/<span data-unit-base=""></span></div>';
    html=html+'<div class="product__policies rte small--text-center" bis_skin_checked="1">Trusted by 10,00,000+ women 😃</div></div>';
    html=html+'<div id="shopify-block-28fc29c5-160c-4bda-8f24-fa0c5ee50cba" class="shopify-block shopify-app-block" data-block-handle="star_rating" bis_skin_checked="1">';
	html=html+'<div style="justify-content: flex-start;" class="spr-starrating spr-summary-starrating" data-product-id="'+product_data.id+'" bis_skin_checked="1">';
    html=html+'<div class="spr-stars" bis_skin_checked="1">';
    html=html+'<span role="img" aria-label="0 out of 5 stars">';
    html=html+'<svg aria-hidden="true" focusable="false" role="presentation" class="spr-star" style="width: 15px; height: 15px;" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 512 512" xml:space="preserve">';
    html=html+'<path fill="#8b2e32" d="M512,197.816L325.961 185.585 255.898 9.569 185.835 185.585 0 197.816 142.534 318.842 95.762 502.431 255.898 401.21 416.035 502.431 369.263 318.842z"></path>';
    html=html+'</svg>';
    html=html+'<svg aria-hidden="true" focusable="false" role="presentation" class="spr-star" style="width: 15px; height: 15px;" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 512 512" xml:space="preserve">';
    html=html+'<path fill="#8b2e32" d="M512,197.816L325.961 185.585 255.898 9.569 185.835 185.585 0 197.816 142.534 318.842 95.762 502.431 255.898 401.21 416.035 502.431 369.263 318.842z"></path>';
    html=html+'</svg>';
    html=html+'<svg aria-hidden="true" focusable="false" role="presentation" class="spr-star" style="width: 15px; height: 15px;" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 512 512" xml:space="preserve">';
    html=html+'<path fill="#8b2e32" d="M512,197.816L325.961 185.585 255.898 9.569 185.835 185.585 0 197.816 142.534 318.842 95.762 502.431 255.898 401.21 416.035 502.431 369.263 318.842z"></path>';
    html=html+'</svg>';
    html=html+'<svg aria-hidden="true" focusable="false" role="presentation" class="spr-star" style="width: 15px; height: 15px;" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 512 512" xml:space="preserve">';
    html=html+'<path fill="#8b2e32" d="M512,197.816L325.961 185.585 255.898 9.569 185.835 185.585 0 197.816 142.534 318.842 95.762 502.431 255.898 401.21 416.035 502.431 369.263 318.842z"></path>';
    html=html+'</svg>';
    html=html+'<svg aria-hidden="true" focusable="false" role="presentation" class="spr-star" style="width: 15px; height: 15px;" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 512 512" xml:space="preserve">';
    html=html+'<path fill="#8b2e32" d="M512,197.816L325.961 185.585 255.898 9.569 185.835 185.585 0 197.816 142.534 318.842 95.762 502.431 255.898 401.21 416.035 502.431 369.263 318.842z"></path>';
    html=html+'</svg>';
    html=html+'</span>';
    html=html+'</div></div></div>';
	html=html+'<div class="product-block" bis_skin_checked="1"><hr></div><div class="product-block" bis_skin_checked="1">';
    html=html+'<input type="hidden" id="variation" value="No"><input type="hidden" id="variation_value"></div>';
    html=html+'<div class="product-block product-block--sales-point" bis_skin_checked="1">';
    html=html+'<ul class="sales-points"><li class="sales-point"><span class="icon-and-text">';
    html=html+'<svg aria-hidden="true" focusable="false" role="presentation" class="icon icon-truck" viewBox="0 0 64 64">';
	html=html+'<defs><style>.cls-1 {fill: none;stroke: #000;stroke-miterlimit: 10;stroke-width: 2px}</style></defs>';
    html=html+'<path class="cls-1" d="M17 47.72H7.38V21h33.14v26.72H24.44M45.92 47.72h-5.4V34.9h17.1v12.82h-4.23M57.62 34.9l-6.41-8.56H40.52"></path>';
    html=html+'<circle class="cls-1" cx="20.74" cy="48.26" r="3.74"></circle><path class="cls-1" d="M45.92 47.73a3.82 3.82 0 1 1 0 .37v-.37"></path>';                                         
    html=html+'</svg><span>Free shipping on membership orders.</span></span>';                                         
    html=html+'</li> </ul></div><div class="product-block product-block--sales-point" bis_skin_checked="1">';                                         
    html=html+'<ul class="sales-points"><li class="sales-point"><span class="icon-and-text inventory"> ';                                         
    html=html+'<span class="icon icon--inventory"></span>Stock - '+product_data.instock_quantity+' items left</span></li></ul></div>';                                         
    html=html+'<div class="product-block" bis_skin_checked="1"><div class="product-block" bis_skin_checked="1">';                                         
    html=html+'<input type="hidden" name="product_id" id="product_id" value="'+product_data.id+'">';                                      
    html=html+'<input type="hidden" name="product_price" id="product_price" value="'+product_data.final_price+'">';                                   
    html=html+'<input type="hidden" id="variation" value="No">';                                   
    html=html+'<input type="hidden" id="variation_value">';  
    html=html+'<div class="cbb-frequently-bought-form col-md-6" style="display: inline-block; margin-bottom: 12px;" bis_skin_checked="1">';                                   
    html=html+'<button class="cbb-frequently-bought-add-button btn--full add-to-cart blouse-fall-block" style="font-family: &quot;Twentieth Century&quot;, sans-serif; font-size: 14px; font-weight: 700; text-transform: uppercase; text-decoration: none solid rgb(139, 46, 50); text-align: center; vertical-align: middle; max-height: 70px; letter-spacing: 4.2px; white-space: normal; line-height: normal; color: rgb(139, 46, 50); background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); box-shadow: none; border-width: 1px; border-radius: 3px; border-color: rgb(139, 46, 50); padding: 13px 20px; position: relative; display: inline-block; width: auto; margin-top: 0px; margin-left: 0px; cursor: pointer; border-style: solid;">';                                   
    html=html+'<span id="add_fall">Click to Add Fall Stitching ('+currency+''+product_data.fall_charge+')</span></button>'                                
	html=html+'<div class="note" style="display:none;" bis_skin_checked="1">Extra 7 days for delivery</div>';																	 
	html=html+'<input type="hidden" name="fall_service" id="fall_service" value="No"></div>';								                                                    
    html=html+'<div class="payment-buttons" bis_skin_checked="1">';     

if (product_data.instock_quantity>0)
{
    html=html+'<button type="button" product-price="'+product_data.final_price+'" data-product-id="'+product_data.id+'" class="btn btn--full add-to-cart btn--secondary addtocart" >';
    html=html+'<span data-add-to-cart-text="" data-default-text="Add to cart">Add to cart</span></button>';
    html=html+'<a href="javascript:void(0);" type="button" class="buynow btn btn--full btn-primary text-center w-100 mt-3 py-2-5" data-testid="Checkout-button" data-id="buy">Buy now</a>';    
}
else
{
	
	html=html+'<ul class="sales-points"><li class="sales-point"><span class="icon-and-text inventory--low"> <span class="icon icon--inventory"></span>Out of stock</span></li></ul>';
	
}
    html=html+'</div><div class="product-block" style="width: 100%; height: 100%; clear: both; text-align: left; margin: 20px auto; max-width: 1420px;" bis_skin_checked="1">';                             
    html=html+'<div class="info-box info-box-addto added text-link" bis_skin_checked="1">';                             
    html=html+'<span><input type="hidden" name="wish_id" id="wish_id" value=""><i class="add addtowish" id="addtowish" data-id="'+product_data.id+'"><i class="fas fa-heart" style="font-weight:400"></i> Add to wishlist</i></span></div>';                             
    html=html+'<ul id="exchange-info">';     
	if (product_data.sub_category_id==205 )
	{
    html=html+'<li>Any additional service such as blouse/fall stitching that alters the original condition of the product is not eligible for return or exchange</li>';                          
    }
	
	if (product_data.made_in_days==0)
	{
	html=html+'<li>Exchange this product for all non-members within <span id="exchange-value">7 Days</span></li>';                           
    html=html+'<li>Members have up to 365 days.</li></ul>';    
	}
	else{
	html=html+'<li>Made for order (<span id="exchange-value">'+product_data.made_in_days+' Days</span>)</li>';
	html=html+'<li>Kindly note this product will not be eligible for exchange.</li>';

    }
	if (product_data.codavailable=="yes")
	{
		html=html+'<li>COD might be available</li>';
	}
	
    html=html+'<div class="membership-block" bis_skin_checked="1">'                                
    html=html+'<p id="membership-info">To get more <span id="membership-value">Benefits</span> apply for our Membership.</p>';                                
    html=html+'<a href="https://'+domain+'/page/membership" class="btn btn--small btn-secondary text-center btn-membership">Get Membership</a>';                                
	html=html+'</div></div></div></div>';
    html=html+'<div class="product-block product-block--tab" bis_skin_checked="1">';
    html=html+'<div class="accordion" id="accordionFilter" bis_skin_checked="1">';
    html=html+'<div class="accordion-item" bis_skin_checked="1">';
    html=html+'<h2 class="accordion-header" id="headingFilterOne">';
    html=html+'<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne">';
    html=html+'Description</button></h2>'                            
    html=html+'<div id="collapseOne" class="accordion-collapse collapse" aria-labelledby="headingFilterOne" data-bs-parent="#accordionFilter" bis_skin_checked="1">';
    html=html+'<div class="accordion-body" bis_skin_checked="1">';
    html=html+'<p>'+product_data.product_description+'</p><p></p>';
    html=html+'</div> </div> </div>'                                      
    html=html+'<div class="accordion-item" bis_skin_checked="1"><h2 class="accordion-header" id="headingFilterTwo">'                                                           
    html=html+'<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">';                                   
    html=html+'Additional information</button></h2>';
    html=html+'<div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingFilterTwo" data-bs-parent="#accordionFilter" bis_skin_checked="1">';                                                             
    html=html+'<div class="accordion-body" bis_skin_checked="1">';
		for (let additional in additional_info) {
			//console.log(additional_info[additional]);
		if (additional_info[additional]){
         html=html+'<p><strong>'+additional+'</strong> :'+ additional_info[additional]+'</p>';	
			}
		}                                    
    html=html+'</div> </div> </div>';                                  
    html=html+'<div class="accordion-item" bis_skin_checked="1"><h2 class="accordion-header" id="headingFilterThree">';                                   
    html=html+'<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">';                                      
    html=html+'Partner Details</button></h2>'                                   
    html=html+'<div id="collapseThree" class="accordion-collapse collapse" aria-labelledby="headingFilterThree" data-bs-parent="#accordionFilter" bis_skin_checked="1">';                                   
    html=html+'<div class="accordion-body" bis_skin_checked="1">';
    html=html+'<div class="col-md-12" bis_skin_checked="1">';
    html=html+'<div class="col-md-12 col-sm-12 partner_details_blocks" bis_skin_checked="1">';
    html=html+'<div class="col-md-8 col-sm-6" style="margin-bottom: 20px;" bis_skin_checked="1">';
    html=html+'<h5>RR Handloom</h5>';
    html=html+'<a href="/rr-handloom" class="btn--secondary btn">View Shop</a>';
    html=html+'</div>';
    html=html+'</div></div> </div></div></div> </div></div></div> </div></section></div>';
	   jQuery("#cmd_product_price").empty();
	   jQuery("#cmd_product_price").append(html);
                jQuery("#cmd_product_price").show();
                jQuery("#cmd_product_price_mob").empty();
                jQuery("#cmd_product_price_mob").append(html);
                jQuery("#cmd_product_price_mob").show();
}
function selectColor(color_id) {
	//debugger;
	
    var base_url = window.location.origin;
    jQuery('#cmd_color_span_' + color_id).prev().prop("checked", true);

    var path = window.location.href;
    var model = localStorage.getItem('cmdimg');
 
    var selectedfabric = jQuery("#fabric").val();
    var selectedpattern = jQuery("input[name='cmd_design']:checked").val();
    var selectedcolor = jQuery("input[name='color']:checked").val();

    var link = window.location.href;
     
    jQuery(".cmd_popup_bg").hide();
    jQuery(".cmd_popup").hide();

    $.ajax({
        url: base_url+"/cmd/lookup/",
        type: "POST",
        data: {
            fid: selectedfabric, pid: selectedpattern, cid: selectedcolor, mid: model
        },
        cache: false,
        success: function (response) {
            jQuery(".prod_info").attr("cid",selectedcolor);
			//debugger;
            var response = JSON.parse(response);
			var productData = response.product_detail;
			var currency = response.currency_sym;
			var additional_info = response.additional_info;
            jQuery("#cmd_output").attr("src",response.trymeimg);
            jQuery(".cmd_cart_block .addtocart").attr("data-product-id",response.product_id);
            jQuery(".cmd_cart_block .buynow").attr("data-product-id",response.product_id);
            jQuery(".cmd_cart_block .addtocart").attr("product-price",response.final_price);
            jQuery(".cmd_cart_block .buynow").attr("product-price",response.final_price);

            jQuery(".cmd-block .addtocart").removeClass("disabled");
            jQuery(".cmd-block .buynow").removeClass("disabled");
            jQuery(".cmd-block .cmd-share-block").removeClass("disabled");

            if(response.final_price == '' || response.final_price == 0){
				
                jQuery(".cmd-block .addtocart").addClass("disabled");
                jQuery(".cmd-block .buynow").addClass("disabled");
                jQuery(".cmd-block .cmd-share-block").addClass("disabled");
            }
			else
			{
				populateproductdata(productData,currency,additional_info);
			}

            jQuery(".cmd-block .addtocart").show();
            jQuery(".cmd-block .buynow").show();
            jQuery(".cmd-block .cmd-share-block").show();
            jQuery(".cmd-block .cmd_cart_block").show();           
        },
    }); 
}

jQuery('.cmd-block .cmdshare img').click(function() { 
    var base_url = window.location.origin;
    //debugger;
    var cmd_output = document.getElementById("cmd_output").src;
    var userid = jQuery("body").attr("userid");

    localStorage.setItem("cmdshare", "yes");

    if (userid == ''){
        window.location.href = base_url+"/account/";
    }
    $.ajax({
        url: base_url+"/share_cmd.php",
        type: "POST",
        data: { 
            mode: 'sharecmd', cmd_url: cmd_output, userid: userid
        },
        cache: false,
        success: function(dataResult){
            var dataResult = JSON.parse(dataResult);
            window.open('https://www.yespoho.com/mycommunity/login/?id='+userid, '_blank');
            if(dataResult.statusCode==200){
                window.open('https://www.yespoho.com/mycommunity/login/?id='+userid, '_blank');
            }    
            else{
               //failed
            }
        },
    });
});
//CMD End

//Abandoned Cart Start
jQuery('.cart-popup-close-btn span').click(function() { 

    jQuery('.cart_popup_bg').hide();
    jQuery('.cart_popup').hide();
});
jQuery('#cart_contactme').click(function() { 

    var base_url = window.location.origin;
    jQuery('.cart_contact_block').show();
    jQuery('.cart_popup').css("opacity", "0");
    var cartidle_form = localStorage.getItem("cart_idle_popup_form");
    var cartidle_form_uname = localStorage.getItem("cart_idle_popup_form_uname");
    if(cartidle_form == 'submitted'){
        jQuery('form#cart_idle_popup .input_details').hide();
        jQuery('#cart_greeting').remove();
        jQuery('form#cart_idle_popup').append('<p id="cart_greeting" style="font-weight: 800;">Hello ' + cartidle_form_uname + '!<br>We already have your details saved with us. How about you place order now and Earn instant 25% off + Choose a <a href="'+base_url+'/free-gifts">Free Gift</a> of Your Choice?</p>');      
    }
    else{
        jQuery('form#cart_idle_popup .input_details').show();
    }
});
jQuery('.cart-contact-close-btn span').click(function() { 
    jQuery('.cart_contact_block').hide();
    jQuery('.cart_popup').show();
    jQuery('.cart_popup').css("opacity", "1");
    jQuery('.cart_contact_block #response_msg').hide();
    jQuery('.cart_contact_block .input_details').show();
});
jQuery('#cart_contact_email').change(function(){
    var email = jQuery('#cart_contact_email').val();
    if(IsEmail(email)==false){
        jQuery("#email_error_msg").text("");
        jQuery("#email_error_msg").append('Please enter valid email id!');
        jQuery( "#cart_contact_submit" ).prop( "disabled", true );
        jQuery("#cart_contact_submit").css({ "pointer-events": "none" });
    }
    else{
        jQuery("#email_error_msg").text("");
        jQuery( "#cart_contact_submit" ).prop( "disabled", false );
        jQuery("#cart_contact_submit").css({ "pointer-events": "inherit" });
    }
});
jQuery('#cart_proceedcheckout').click(function() {
    var base_url = window.location.origin;
    debugger;
    $.ajax({
        url: base_url+"/cart/proceedToCheckout/",
        type: "POST",
        data: {
            mode: 'proceed_checkout'
        },
        cache: false,
        success: function (response) {
            var del_url = base_url + "/cart/delivery/";
            window.location.replace(del_url);          
        },
    });
});


//jQuery('#cart_contact_submit').click(function() { 

jQuery('.product-cart-popup-close-btn span').click(function() { 
    jQuery('.product_cart_popup_bg').hide();
    jQuery('.product_cart_popup').hide();
	localStorage.setItem("product_cart_popup", "no");
});
jQuery('#product_cart_idle_popup').submit(function(e){
	debugger;
    var base_url = window.location.origin;
    e.preventDefault();
    var name = jQuery("#cart_contact_name").val();
    var email = jQuery("#cart_contact_email").val();
    var mobile = jQuery("#cart_contact_phone").val();
	var buy_now = $(this).attr("data-id");

    $.ajax({
        url: base_url+"/cart/getAbandonedCartUserInfo/",
        type: "POST",
        data: {
            name: name, email: email, mobile: mobile
        },
        cache: false,
        success: function (response) {
            //if (response == 'success'){
              /*  jQuery(".cart_contact_block .input_details").hide();
                jQuery(".cart_contact_block #response_msg").empty();
            jQuery(".cart_contact_block #response_msg").append('Congratulations! Place order now and Earn instant 25% off + Choose a <a href="'+base_url+'"/free-gifts">Free Gift</a> of Your Choice');
                jQuery(".cart_contact_block #response_msg").show();*/
                localStorage.setItem("product_cart_popup", "no");
				var ls_buynow = localStorage.getItem('ls_buynow');
				 if(ls_buynow=="yes")
				 {
					 $('.buynow').click() ;
				 }
				 else
				 {
                  $('.addtocart').click() ;
				 }
            
        },
    });
});

//jQuery('#cart_contact_submit').click(function() { 
jQuery('#cart_idle_popup').submit(function(e){
	//debugger;
    var base_url = window.location.origin;
    e.preventDefault();
    var name = jQuery("#cart_contact_name").val();
    var email = jQuery("#cart_contact_email").val();
    var mobile = jQuery("#cart_contact_phone").val();

    $.ajax({
        url: base_url+"/cart/getAbandonedCartUserInfo/",
        type: "POST",
        data: {
            name: name, email: email, mobile: mobile
        },
        cache: false,
        success: function (response) {
//debugger;

            //if (response == 'success'){
                jQuery(".cart_contact_block_js .input_details").hide();
                jQuery(".cart_contact_block_js #response_msg").empty();
            jQuery(".cart_contact_block_js #response_msg").append('Congratulations! Place order now and Earn instant 25% off + Choose a <a href="'+base_url+'"/free-gifts">Free Gift</a> of Your Choice');
                jQuery(".cart_contact_block_js #response_msg").show();
                localStorage.setItem("cart_idle_popup_form", "submitted");
                localStorage.setItem("cart_idle_popup_form_uname", name);
            // }
            // else if(response == 'exists'){
            //     jQuery(".cart_contact_block #response_msg").empty();
            //     jQuery(".cart_contact_block #response_msg").append('Hello '+ name +'! We already have your details saved with us.');
            //     jQuery(".cart_contact_block #response_msg").show();
            // }
            
        },
    });
});
function IsEmail(email) {
    var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if(!regex.test(email)) {
        return false;
    }else{
        return true;
    }
}

jQuery('#cart_contact_phone').keypress(function (e) {     
    var charCode = (e.which) ? e.which : event.keyCode    
    if (String.fromCharCode(charCode).match(/[^0-9]/g))    
        return false;                        
}); 
$('#cart_contact_phone').on('paste', function (e) {      
    var charCode = (e.which) ? e.which : event.keyCode    
    if (String.fromCharCode(charCode).match(/[^0-9]/g))    
        return false;                        
}); 

let timer, currSeconds = 0;
function startIdleTimer() { 
    clearInterval(timer);          
    currSeconds++;
    timer = setInterval(startIdleTimer, 450);
    if(currSeconds == '150'){
        jQuery(".cart_popup_bg").show();
        jQuery(".cart_popup").show();
    }
}
function resetTimer() {
    /* Clear the previous interval */
    clearInterval(timer);

    /* Reset the seconds of the timer */
    currSeconds = 0;

    /* Set a new interval */
    timer = setInterval(startIdleTimer, 450);
}
jQuery(document).ready(function(){
    startIdleTimer();
    window.onload = resetTimer;
    window.onmousemove = resetTimer;
    window.onmousedown = resetTimer;
    window.ontouchstart = resetTimer;
    window.onclick = resetTimer;
    window.onkeypress = resetTimer;
});
//Abandoned Cart End

//Free Gifts Start

function open_giftBox(){
    var base_url = window.location.origin;
    //debugger;
    var boxURL = jQuery('#cartgifts_box').attr('src');
    var openBoxURL = base_url+"/public/img/open_giftbox.gif";
    jQuery('#cartgifts_box').attr("src", openBoxURL);
    // setTimeout(function () {
    //     window.location.href=base_url+"/free-gifts";
    // }, 20000);
    jQuery('#cartgifts_box').on('click', function () {
        window.location.href = base_url+"/free-gifts";
    });
}
function claimFreeGifts(){
    jQuery('.freeGifts_checkout_popup').show();
    jQuery('.freeGifts_checkout_popup_bg').show();
}

//Free Gifts End


//Open search box if user has done text search 
$(function () {
if (window.location.href.indexOf("catalog/search") > -1) {
        var objSearch = $('.search-wrapper');
        objSearch.addClass('open');
    }
});

//Size Chart info START
jQuery('#sizechart_info').click(function() { 
    jQuery('.sizechart_info_block_bg').show();
    jQuery('#sizechart_info_block').show();
    jQuery('.product .info-box.cart-btns').hide();
});
jQuery('#sizechart-close-btn span').click(function() { 
    jQuery('.sizechart_info_block_bg').hide();
    jQuery('#sizechart_info_block').hide();
    jQuery('.product .info-box.cart-btns').show();
});
//Size Chart info END

//Track Order Number START
function copyTrackid(itemid){
    var copyText = document.getElementById("copy_"+itemid);
    var textArea = document.createElement("textarea");
    textArea.value = copyText.textContent;
    document.body.appendChild(textArea);
    textArea.select();
    document.execCommand("Copy");
    textArea.remove();
}
function openBludartTrack(itemid){
    jQuery('#bg_trackingblock').show();
    jQuery('#block_'+itemid).show();
}
function closeBludartTrack(itemid){
    jQuery('#bg_trackingblock').hide();
    jQuery('#block_'+itemid).hide();
}
//Track Order Number END

