
jQuery(document).ready(function() {
  var path = 'https://www.mummysmarket.com.sg/';


  var url_segment = window.location.href.split('/');
  var get_url = url_segment.pop();
   if (localStorage) {
        var url_count;
        if (!localStorage['url_count']) url_count = [];
        else url_count = JSON.parse(localStorage['url_count']);            
        if (!(url_count instanceof Array)) url_count = [];
        //console.log('-->',url_count);
        url_count.push(get_url);
        const url_unique = [...new Map(url_count.map((item, key) => [item[key], item])).values()]
        localStorage.setItem('url_count', JSON.stringify(url_unique));
    } 
    //console.log(JSON.parse(localStorage['url_count']));
    //console.log(JSON.parse(localStorage['url_count']).length);
    /*if(JSON.parse(localStorage['url_count']).length==2)
    {
      var randPopup = [];
      randPopup.push( "pgb-register" );
      var random_popup = randPopup[Math.floor(Math.random()*randPopup.length)];
      setTimeout(function() {
        var vend_off =  jQuery('[data-remodal-id='+random_popup+']').remodal();
        vend_off.open();
      }, 4500);
    }*/

  /* Open when someone clicks on the span element */
  function openNav() {
    document.getElementById("myNav").style.width = "80%";
  }

  /* Close when someone clicks on the "x" symbol inside the overlay */
  function closeNav() {
    document.getElementById("myNav").style.width = "0%";
  }

  jQuery("#divscroll").smoothDivScroll({
    autoScrollingMode: "always",
    autoScrollingDirection: "endlessLoopRight",
    autoScrollingStep: 2,
    autoScrollingInterval: 40
  });

var countdone = false;
  window.onscroll = function() { myFunction() };

  var header      = document.getElementById("myHeader");
  var sticky      = header.offsetTop;
  var mob_header  = document.getElementById("mobHeader");

  var page_option = jQuery('#page_option').val();
  var page_view   = jQuery('#page_view').val();
  var page_view_id = jQuery('#page_view_id').val();
  function myFunction() {
    if (window.pageYOffset > sticky) {
      header.classList.add("sticky");
      jQuery('#myHeader').addClass('shadow');
      mob_header.classList.add("mob_sticky");
      jQuery('.custom-header-mobile').css('padding', '10px 15px');
      jQuery('.custom-header-mobile').addClass('shadow');
      if(page_option=='com_luckydraw' && page_view=='220511')
      {
        jQuery('.dsk-container').css('display', 'none');
        jQuery('#myHeader').removeClass('shadow');
      }

      if(page_option=='com_sppagebuilder' && (page_view_id==99))
      {
        jQuery('.dsk-container').css('display', 'none');
        jQuery('#myHeader').removeClass('shadow');
      }

    } else {
      header.classList.remove("sticky");
      jQuery('#myHeader').removeClass('shadow');
      mob_header.classList.remove("mob_sticky");
      jQuery('.custom-header-mobile').css('padding', '10px 15px');
      jQuery('.custom-header-mobile').css('padding-bottom', '0px');
      jQuery('.custom-header-mobile').removeClass('shadow');
      if(page_option=='com_luckydraw' && page_view=='220511')
      {
        jQuery('.dsk-container').css('display', 'block');
      }
      if(page_option=='com_sppagebuilder' && (page_view_id==99))
      {
        jQuery('.dsk-container').css('display', 'block');
      }
    }


    if( jQuery("#count2").length == 0 ) {      
    }else{
        var hT = jQuery('#count2').offset().top,
        hH = jQuery('#count2').outerHeight(),
        wH = jQuery(window).height(),
        wS = jQuery(this).scrollTop();
        if (wS > (hT+hH-wH)){      
           
        if(!countdone){
          $('.count').each(function() {
            var $this = $(this),
                countTo = $this.attr('data-count');
            
            $({ countNum: 0}).animate({
              countNum: countTo
            },{
              duration: 4000,
              easing:'linear',
              step: function() {
                $this.text(Math.floor(this.countNum));
              },
              complete: function() {
                $this.text(this.countNum);
                countdone = true;
              }
            });
          });
        }
    }
  }

  }

  jQuery('.mobilemenu').on('click',function(){
    var dataval = $(this).attr('data-val');
    if(dataval=='brand')
    {
      jQuery('#mobi_freebies').css('display','none');
      jQuery('#mobi_category').css('display','none');
      jQuery('#mobi_baby_expo').css('display','none');
      jQuery('#mobi_shop_online').css('display','none');
      jQuery('#mobi_shop_retail').css('display','none');
      jQuery('#mobi_shop_retail_atrium').css('display','none');
      jQuery('#mobi_brands').css('display','block');
    }
    else if(dataval=='freebies')
    {
      jQuery('#mobi_brands').css('display','none');
      jQuery('#mobi_category').css('display','none');
      jQuery('#mobi_baby_expo').css('display','none');
      jQuery('#mobi_shop_online').css('display','none');
      jQuery('#mobi_shop_retail').css('display','none');
      jQuery('#mobi_shop_retail_atrium').css('display','none');
      jQuery('#mobi_freebies').css('display','block');
    } 
    else if(dataval=='baby_expo')
    {
      jQuery('#mobi_brands').css('display','none');
      jQuery('#mobi_category').css('display','none');
      jQuery('#mobi_freebies').css('display','none');
      jQuery('#mobi_shop_online').css('display','none');
      jQuery('#mobi_shop_retail').css('display','none');
      jQuery('#mobi_shop_retail_atrium').css('display','none');
      jQuery('#mobi_baby_expo').css('display','block');

    } 
    else if(dataval=='shop_online')
    {
      jQuery('#mobi_brands').css('display','none');
      jQuery('#mobi_category').css('display','none');
      jQuery('#mobi_freebies').css('display','none');
      jQuery('#mobi_baby_expo').css('display','none');
      jQuery('#mobi_shop_retail').css('display','none');
      jQuery('#mobi_shop_retail_atrium').css('display','none');
      jQuery('#mobi_shop_online').css('display','block');
    }
    else if(dataval=='shop_retail_atrium')
    {
      jQuery('#mobi_brands').css('display','none');
      jQuery('#mobi_category').css('display','none');
      jQuery('#mobi_freebies').css('display','none');
      jQuery('#mobi_baby_expo').css('display','none');
      jQuery('#mobi_shop_online').css('display','none');
      jQuery('#mobi_shop_retail').css('display','none');
      jQuery('#mobi_shop_retail_atrium').css('display','block');
    } 
    else if(dataval=='shop_retail')
    {
      jQuery('#mobi_brands').css('display','none');
      jQuery('#mobi_category').css('display','none');
      jQuery('#mobi_freebies').css('display','none');
      jQuery('#mobi_baby_expo').css('display','none');
      jQuery('#mobi_shop_online').css('display','none');
      jQuery('#mobi_shop_retail_atrium').css('display','none');
      jQuery('#mobi_shop_retail').css('display','block');
    }  
    else
    {
      jQuery('#mobi_freebies').css('display','none');
      jQuery('#mobi_brands').css('display','none');
      jQuery('#mobi_baby_expo').css('display','none');
      jQuery('#mobi_shop_online').css('display','none');
      jQuery('#mobi_shop_retail').css('display','none');
      jQuery('#mobi_shop_retail_atrium').css('display','none');
      jQuery('#mobi_category').css('display','block');
    }
  });

  jQuery('.cart_detail_box').on('click', '.addcart', function() {
    var nocache = new Date().getTime();
    var p_id = jQuery(this).attr('data-id');
    var m_id = jQuery(this).attr('data-mid');
    var attr = jQuery(this).attr('data-attr');
    var p_name = jQuery(this).attr('p-name');
    var p_amount = jQuery(this).attr('data-val');

    fbq('track', 'AddToCart', { 
        content_type: 'product',
        content_ids: ['MM-'+p_id],     
        content_name: p_name, 
        value: p_amount, 
        currency: 'SGD'
     });

    jQuery.ajax({
      url: path + "index.php?option=com_starbuy_slash&view=add_group_buy_item&format=raw&p_id=" +
        p_id + "&attr_id=" + attr + "&m_id=" + m_id + "&timex=" + nocache,
      cache: false,
      beforeSend: function() {},
      success: function(result) {
        var data = JSON.parse(result);
        jQuery('.cart_count').text(data.cart_total);
        if (data.status == 'added') {
          var status = 'ok';
          var title = 'Cart Added';
          var product = p_name;
          var qty = '1';
          var icon = 'fa fa-cart-plus';
          notify(status, title, product, qty, icon);
        } else if (data.status == 'update') {
          var status = 'ok';
          var title = 'Cart Update';
          var product = p_name;
          var qty = data.qty;
          var icon = 'fa fa-cart-plus';
          notify(status, title, product, qty, icon);
        } else if (data.status == 'error') {

          var status = 'error';
          var title = 'Something Wrong';
          var product = data.msg;
          var qty = 0;
          var icon = 'fa fa-bug';
          notify(status, title, product, qty, icon);
        } else {
          var status = 'error';
          var title = 'Oops!';
          var product = data.msg;
          var qty = 0;
          notify(status, title, product, qty, icon);
        }
      }
    });

  });

  

  jQuery('.cpy_code').on('click',function(){
         var dcode = jQuery(this).attr('data-code');
         if(dcode!='')
         {
            var $temp = jQuery("<input>");
            jQuery("body").append($temp);
            $temp.val(dcode).select();
            document.execCommand("copy");
            $temp.remove();
            jQuery.amaran({
              'theme': 'awesome ok',
              'content': {
                title: dcode,
                message: 'Copied',
                icon: 'fa fa-copy', 
                info: '' 
              },
              'position': 'top right',
              'outEffect': 'slideTop'
            });

         }
      });


  jQuery("#signupform").click(function() {
    jQuery('html, body').animate({
      scrollTop: jQuery("#ic_signupform").offset().top - 240
    }, 2000);
  });

  jQuery(".loc_subscribe_form").click(function() {
    jQuery('html, body').animate({
      scrollTop: jQuery("#ic_newsletter_form_v2").offset().top - 240
    }, 50);
  });

  jQuery(".focus_calender").click(function() {
    jQuery('html, body').animate({
      scrollTop: jQuery(".showroom_container").offset().top - 240
    }, 1000);
  });

  jQuery(".focusreg").click(function() {
    jQuery('html, body').animate({
      scrollTop: jQuery(".bbf_registration_form").offset().top - 240
    }, 1000);
  });
  jQuery(".ba_form_focus").click(function() {
    jQuery('html, body').animate({
      scrollTop: jQuery("#form_promama").offset().top - 240
    }, 1000);
  });
    jQuery(".newform_focus").click(function() {
    jQuery('html, body').animate({
      scrollTop: jQuery("#newform_promama").offset().top - 240
    }, 1000);
  });

  jQuery(".focus_form").click(function() {
    jQuery('html, body').animate({
      scrollTop: jQuery("#ic_newsletter_form_v2").offset().top - 240
    }, 1000);
  });

  jQuery(".pgb_focus_form").click(function() {
    jQuery('html, body').animate({
      scrollTop: jQuery("#pgb_promama").offset().top - 240
    }, 1000);
  });

  jQuery(".one_focus_form").click(function() {
    jQuery('html, body').animate({
      scrollTop: jQuery("#one_dollar_promama").offset().top - 240
    }, 1000);
  });
    jQuery(".focus_reg").click(function() {
    jQuery('html, body').animate({
      scrollTop: jQuery("#subscription_form").offset().top - 240
    }, 1000);
  });

   jQuery(".focus_subs").click(function() {
    jQuery('html, body').animate({
      scrollTop: jQuery("#subscription_form").offset().top - 240
    }, 1000);
  });

  jQuery(".mm__avail_prog_earlybird").click(function() {
    jQuery('html, body').animate({
      scrollTop: jQuery(".early_bird_action").offset().top - 280
    }, 1000);
  });

 jQuery(".mm__avail_prog_starbuy").click(function() {
    jQuery('html, body').animate({
      scrollTop: jQuery(".starbuy_action").offset().top - 280
    }, 1000);
  });
  
 jQuery(".mm__avail_prog_online").click(function() {
    jQuery('html, body').animate({
      scrollTop: jQuery(".online_action").offset().top - 280
    }, 1000);
  }); 


  function notify(status, title, product, qty, icon) {
    if (qty != 0 || qty != '') {
      jQuery.amaran({
        'theme': 'awesome ' + status,
        'content': {
          title: title,
          message: product,
          info: 'Qty: ' + qty,
          icon: icon
        },
        'position': 'top right',
        'outEffect': 'slideTop'
      });
    } else {
      jQuery.amaran({
        'theme': 'awesome ' + status,
        'content': {
          title: title,
          message: product,
          info: '',
          icon: 'fa fa-warning'
        },
        'position': 'top right',
        'outEffect': 'slideTop'
      });
    }
  }

  jQuery('.load_search_data').on('click', '.autosuggest_results_item', function() {
    var product_name = jQuery(this).text();
    jQuery('.search_bar').val(product_name);
    jQuery("#search_form").submit();
  });

  jQuery('.load_search_data_mob').on('click', '.autosuggest_results_item', function() {
    var product_name = jQuery(this).text();
    jQuery('.search_bar').val(product_name);
    jQuery("#search_form_mob").submit();
  });

  jQuery('.search_bar').on('click', function() {
    jQuery('.mm_autosuggest_container').css('display', 'block');
    search_suggestion()
  });

  jQuery('#s_search_mob').on('click', function() {
    jQuery('.mm_autosuggest_container').css('display', 'block');
    search_suggestion('s_search_mob')
  });
  jQuery('.search_bar').on('keyup', function() {
    jQuery('.mm_autosuggest_container').css('display', 'block');
    var p_name = jQuery(this).val();
    var check_source = jQuery(this).attr('id');
    var showroom_tab = jQuery('#showroom_tab').val();
    var product_search_link = 'https://www.mummysmarket.com.sg/onlinebabyfair/product/';
  
    var  pro_brand_link     = 'https://www.mummysmarket.com.sg/onlinebabyfair?s_tab=starbuy-sale&s_brand=';
    var  search_link        = 'https://www.mummysmarket.com.sg/onlinebabyfair?s_tab=starbuy-sale&s_search=';

    if (p_name != '') {

      jQuery.ajax({
        url: path + "index.php?option=com_starbuy_slash&view=get_search_product&type=starbuy&format=raw",
        data: { 'p_name' : p_name },
        beforeSend: function() {},
        success: function(result) {

          var data = JSON.parse(result);
          var html = '';
          html += '<div class="search_head"><div class="search_col1">STARBUY DEALS</div> <div class="search_col2">Cheapest price</div></div>';
          for (var i = 0; i < data.length; i++) {
            var pname = data[i].name.replace('%', '');
            pname = pname.replace(/\s+/g, '-').toLowerCase();
            pname = pname.replace('%', 'percent').toLowerCase();
            var link = product_search_link + data[i].id + '-' + pname;
            if (data[i].type == 'brand') {
              var str = data[i].name;
              var brand_nm = data[i].name.replace("'", "\'");
              brand_nm = brand_nm.replace(/\s+/g, '-').toLowerCase();
                link = pro_brand_link + data[i].id;
            
            } else if (data[i].type == 'search') {
              link = search_link + data[i].id;
              var str = data[i].name;
              str = str.toLowerCase().replace(/\b[a-z]/g, function(letter) {
                return letter.toUpperCase();
              });
            } else {
              var str = data[i].name;
            }
            html += '<p role="option" data-index="0" data-title="keywords" id="mm_autosuggest_results_1" class="autosuggest_results_item"><a href="' + link + '">' + str + '</a></p>';
          }
          if(check_source=='s_search_mob')
          {
            //jQuery('.load_search_data_mob').html(html);
          }
          else
          {
            //jQuery('.load_search_data').html(html);
          }
        }
      });

      jQuery('.load_ol_search_data_mob').css("display", "none");
      jQuery('.load_ol_search_data').css("display", "none");
      var product_brand_link = 'https://www.mummysmarket.com.sg/onlinebabyfair/brand/';
      var search_link = 'https://www.mummysmarket.com.sg/onlinebabyfair?s_search=';
      var p_name = jQuery(this).val();
      var check_source = jQuery(this).attr('id');
      var showroom_tab = jQuery('#showroom_tab').val();
      jQuery.ajax({
      url: path + "index.php?option=com_starbuy_slash&view=get_search_product&type=online&format=raw&p_name=''",
      data: { 'p_name' : p_name },
      beforeSend: function() {},
      success: function(result) {

        var data = JSON.parse(result);
        var html = '';
        html += '<div class="search_head"><div class="search_col1">ONLINE DEALS</div></div>';
        for (var i = 0; i < data.length; i++) {
          var pname = data[i].name.replace('%', '');
          pname = pname.replace(/\s+/g, '-').toLowerCase();
          pname = pname.replace('%', 'percent').toLowerCase();
          var link = product_search_link + data[i].id + '-' + pname;
          if (data[i].type == 'brand') {
            var str = data[i].name;

            var brand_nm = data[i].name.replace("'", "\'");
            brand_nm = brand_nm.replace(/\s+/g, '-').toLowerCase();
           /* if (showroom_tab == 'showroom' || showroom_tab == 'christmas_sale') {
              link = product_brand_link + data[i].id;
            } else {*/
              link = product_brand_link + brand_nm;
            //}
          } else if (data[i].type == 'search') {
            link = search_link + data[i].id;
            var str = data[i].name;
            str = str.toLowerCase().replace(/\b[a-z]/g, function(letter) {
              return letter.toUpperCase();
            });
          } else {
            var str = data[i].name;
          }
          html += '<p role="option" data-index="0" data-title="keywords" id="mm_autosuggest_results_0" class="autosuggest_results_item"><a href="' + link + '">' + str + '</a></p>';
        }
        if(check_source=='s_search_mob')
        {
          jQuery('.load_search_data_mob').html(html); 
         //activate expo  .load_ol_search_data  
         //jQuery('.load_ol_search_data_mob').html(html);
        }
        else
        {
          jQuery('.load_search_data').html(html);
          //activate expo  .load_ol_search_data 
          //jQuery('.load_ol_search_data').html(html);
        }
      }
    });
    } else {
      search_suggestion(check_source);
    }
  });

  function search_suggestion(check_source) {
    var p_name = jQuery('.search_bar').val();

    var showroom_tab = jQuery('#showroom_tab').val();
    var product_search_link = 'https://www.mummysmarket.com.sg/onlinebabyfair/product/';
    var product_brand_link = 'https://www.mummysmarket.com.sg/onlinebabyfair/brand/';
    var search_link = 'https://www.mummysmarket.com.sg/onlinebabyfair?s_search=';
    /*if (showroom_tab == 'showroom') {
      product_search_link = 'https://www.mummysmarket.com.sg/onlinebabyfair/product/showroom/';
      product_brand_link = 'https://www.mummysmarket.com.sg/onlinebabyfair?s_tab=showroom&s_brand=';
      search_link = 'https://www.mummysmarket.com.sg/onlinebabyfair?s_tab=showroom&s_search=';
    }
    if(showroom_tab == 'christmas_sale')
    {
      product_brand_link = 'https://www.mummysmarket.com.sg/onlinebabyfair?s_tab='+showroom_tab+'&s_brand=';
      search_link = 'https://www.mummysmarket.com.sg/onlinebabyfair?s_tab='+showroom_tab+'&s_search=';
    }*/
    jQuery('.load_ol_search_data_mob').css("display", "none");
    jQuery('.load_ol_search_data').css("display", "none");
    jQuery.ajax({

      url: path + "index.php?option=com_starbuy_slash&view=get_search_product&format=raw&p_name=''",
      beforeSend: function() {},
      success: function(result) {

        var data = JSON.parse(result);
        var html = '';
        html += '<div class="search_head"><div class="search_col1">Brand Suggestion</div></div>';
        for (var i = 0; i < data.length; i++) {
          var pname = data[i].name.replace('%', '');
          pname = pname.replace(/\s+/g, '-').toLowerCase();
          pname = pname.replace('%', 'percent').toLowerCase();
          var link = product_search_link + data[i].id + '-' + pname;
          if (data[i].type == 'brand') {
            var str = data[i].name;

            var brand_nm = data[i].name.replace("'", "\'");
            brand_nm = brand_nm.replace(/\s+/g, '-').toLowerCase();
            /*if (showroom_tab == 'showroom' || showroom_tab == 'christmas_sale') {
              link = product_brand_link + data[i].id;
            } else {*/
              link = product_brand_link + brand_nm;
            //}
          } else if (data[i].type == 'search') {
            link = search_link + data[i].id;
            var str = data[i].name;
            str = str.toLowerCase().replace(/\b[a-z]/g, function(letter) {
              return letter.toUpperCase();
            });
          } else {
            var str = data[i].name;
          }
          html += '<p role="option" data-index="0" data-title="keywords" id="mm_autosuggest_results_0" class="autosuggest_results_item"><a href="' + link + '">' + str + '</a></p>';
        }
        if(check_source=='s_search_mob')
        {
          jQuery('.load_search_data_mob').html(html);
        }
        else
        {
          jQuery('.load_search_data').html(html);
        }
      }
    
    });
  }

  jQuery(document).on('click', function(e) {
    if (jQuery(e.target).closest(".search_bar").length === 0) {
      jQuery(".mm_autosuggest_container").css('display', 'none');
    }
  });

  jQuery('.panel-collapse').on('show.bs.collapse', function() {
    jQuery(this).siblings('.panel-heading').addClass('active');
  });

  jQuery('.panel-collapse').on('hide.bs.collapse', function() {
    jQuery(this).siblings('.panel-heading').removeClass('active');
  });

  function collision($div1, $div2) {
    var x1 = $div1.offset().left;
    var w1 = 40;
    var r1 = x1 + w1;
    var x2 = $div2.offset().left;
    var w2 = 40;
    var r2 = x2 + w2;

    if (r1 < x2 || x1 > r2) return false;
    return true;

  }

  // // slider call

  jQuery('.price-range-slider').slider({
    range: true,
    min: 0,
    max: 2000,
    values: [0, 2000],
    step: 1,
    slide: function(event, ui) {

      jQuery('.ui-slider-handle:eq(0) .price-range-min').html('$' + ui.values[0]);
      jQuery('.ui-slider-handle:eq(1) .price-range-max').html('$' + ui.values[1]);
      jQuery('.price-range-both').html('<i>$' + ui.values[0] + ' - </i>$' + ui.values[1]);

      //

      if (ui.values[0] == ui.values[1]) {
        jQuery('.price-range-both i').css('display', 'none');
      } else {
        jQuery('.price-range-both i').css('display', 'inline');
      }

      //

      if (collision(jQuery('.price-range-min'), jQuery('.price-range-max')) == true) {
        jQuery('.price-range-min, .price-range-max').css('opacity', '0');
        jQuery('.price-range-both').css('display', 'block');
      } else {
        jQuery('.price-range-min, .price-range-max').css('opacity', '1');
        jQuery('.price-range-both').css('display', 'none');
      }

    }
  });

  jQuery('.ui-slider-range').append('<span class="price-range-both value"><i>$' + jQuery('#slider').slider('values', 0) + ' - </i>' + jQuery('#slider').slider('values', 1) + '</span>');

  jQuery('.ui-slider-handle:eq(0)').append('<span class="price-range-min value">$' + jQuery('.price-range-slider').slider('values', 0) + '</span>');

  jQuery('.ui-slider-handle:eq(1)').append('<span class="price-range-max value">$' + jQuery('.price-range-slider').slider('values', 1) + '</span>');



  jQuery('.marquee').marquee({
    //speed in milliseconds of the marquee
    duration: 9000,
    //gap in pixels between the tickers
    gap: 50,
    //time in milliseconds before the marquee will start animating
    delayBeforeStart: 0,
    //'left' or 'right'
    direction: 'left',
    //true or false - should the marquee be duplicated to show an effect of continues flow
    duplicated: true
  });
  jQuery(" #logo2").owlCarousel({
    navigation: false,
    slideSpeed: 50,
    autoPlay: true,
    loop: true,
    items: 4,
    itemsDesktop: [1000, 4], // 2 items between 1000px and 901px
    itemsDesktopSmall: [900, 3], // betweem 900px and 601px
    itemsTablet: [700, 2], // 2 items between 600 and 480
    itemsMobile: [479, 2], // 1 item between 479 and 0
    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>', '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>']
  });
  jQuery("#logo").owlCarousel({
    navigation: true,
    autoPlay: true,
    loop: true,
    items: 5,
    itemsDesktop: [1000, 5], // 2 items between 1000px and 901px
    itemsDesktopSmall: [900, 3], // betweem 900px and 601px
    itemsTablet: [700, 2], // 2 items between 600 and 480
    itemsMobile: [479, 2], // 1 item between 479 and 0
    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>', '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>']
  });

  jQuery("#Freebies-Perks").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    items: 1,
    itemsDesktop: [1500, 1],
    itemsDesktopSmall: [900, 1], // betweem 900px and 601px
    itemsTablet: [700, 1], // 2 items between 600 and 480
    itemsMobile: [479, 1], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ]
  });





  jQuery('#cbp-fwslider').cbpFWSlider();
  setInterval(function() {
    if ($('.cbp-fwnext').is(":visible")) {
      $('.cbp-fwnext').click();
    } else {
      $('.cbp-fwdots').find('span').click();
    }
  }, 5000);


  jQuery("#datepiccker").datepicker({
    changeMonth: true,
    changeYear: true,
    dateFormat: "yy-mm-dd",
    minDate: new Date('2015/01/01'),
    maxDate: '+10M'
  });

  jQuery("#datepiccker_mob").datepicker({
    changeMonth: true,
    changeYear: true,
    dateFormat: "yy-mm-dd",
    minDate: new Date('2015/01/01'),
    maxDate: '+10M'
  });

  jQuery("#datepiccker_dob").datepicker({
    changeMonth: true,
    changeYear: true,
    dateFormat: "yy-mm-dd",
    minDate: new Date('2015/01/01'),
    maxDate: '-1D'
  });

  jQuery("#datepiccker1").datepicker({
    changeMonth: true,
    changeYear: true,
    dateFormat: "yy-mm-dd",
    minDate: new Date('2020/02/28'),
    maxDate: new Date('2021/02/28')
  });

  jQuery("#datepiccker_2").datepicker({
    changeMonth: true,
    changeYear: true,
    dateFormat: "yy-mm-dd",
    minDate: new Date(),
    maxDate: '+9M'
  });

  jQuery("#sponsers").owlCarousel({
    autoPlay: 2000, //Set AutoPlay to 3 seconds
    dots: false,
    items: 3
  });

 
  var myDate = new Date('Jul 15 2024 00:00:00 GMT+0800');
 
  //myDate.setDate( myDate);
  jQuery("#countdown_new, #countdown_mobi").countdown(myDate, function (event) {
      $(this).html(
          event.strftime(
              '<div class="timer-wrapper"><div class="time">%D</div><span class="text">days</span></div><div class="timer-wrapper"><div class="time">%H</div><span class="text">hrs</span></div><div class="timer-wrapper"><div class="time">%M</div><span class="text">mins</span></div><div class="timer-wrapper"><div class="time">%S</div><span class="text">sec</span></div>'
          )
      );
  });

  var myExpoDate = new Date('Dec 16 2024 00:00:00 GMT+0800');
  jQuery("#expo_countdown, #expo_countdown_mobi").countdown(myExpoDate, function (event) {
      $(this).html(
          event.strftime(
              '<div class="timer-wrapper"><div class="time">%D</div><span class="text">days</span></div><div class="timer-wrapper"><div class="time">%H</div>:</div><div class="timer-wrapper"><div class="time">%M</div>:</div><div class="timer-wrapper"><div class="time">%S</div><span class="text">left</span></div>'
          )
      );
  });

  var current_expire = $('#main_countdown_timer').val();

  //var myDate = new Date(current_expire + ' GMT+0800');
    var myDate = new Date('Apr 18 2025 11:00:00 GMT+0800');
  //myDate.setDate( myDate);
  jQuery("#countdown, #countdown1, #countdown2, #countdown2").countdown(myDate, function(event) {
    $(this).html(
      event.strftime(
        '<div class="timer-wrapper timer-wrapper-extra"><div class="time time-extra">%D</div><div class="time_unit">Day</div></div><div class="timer-wrapper timer-wrapper-extra"><div class="time time-extra">%H</div><div class="time_unit">Hours</div></div><div class="timer-wrapper timer-wrapper-extra"><div class="time time-extra">%M</div><div class="time_unit">Minutes</div></div><div class="timer-wrapper timer-wrapper-extra"><div class="time time-extra">%S</div><div class="time_unit">Seconds</div></div>'
      )
    );
  });
    var myDate2 = new Date('Oct 07 2022 01:00:00  GMT+0800');
  jQuery('#clock').countdown(myDate2, function(event) {
     $(this).html(event.strftime('<div class="timer-wrapper"><div class="time">%D</div><span class="text">days</span></div><div class="timer-wrapper"><div class="time">%H</div><span class="text">hrs</span></div><div class="timer-wrapper"><div class="time">%M</div><span class="text">mins</span></div><div class="timer-wrapper"><div class="time">%S</div><span class="text">sec</span></div>'));
   });


  var myDate2 = new Date('Aug 16 2019 11:00:00  GMT+0800');
  //  myDate.setDate( myDate);
  jQuery("#countdown_groupbuy").countdown(myDate2, function(event) {
    $(this).html(
      event.strftime(
        '<div class="timer-wrapper"><div class="time">%D</div><span class="text">days</span></div><div class="timer-wrapper"><div class="time">%H</div><span class="text">hrs</span></div><div class="timer-wrapper"><div class="time">%M</div><span class="text">mins</span></div><div class="timer-wrapper"><div class="time">%S</div><span class="text">sec</span></div>'
      )
    );
  });

  var spl_countdown_timer = jQuery('#spl_countdown_timer').val();
   var limitedDate = new Date(spl_countdown_timer + ' GMT+0800');
  //LIMITED SALES COUNTER
  jQuery("#limitedsale_countdown").countdown(limitedDate, function(event) {
    $(this).html(
      event.strftime(
        '<div class="timer-wrapper"><div class="time">%Dd</div></div><div class="timer-wrapper"><div class="time">%Hh</div></div><div class="timer-wrapper"><div class="time">%Mm</div></div><div class="timer-wrapper"><div class="time">%Ss</div></div>'
      )
    );
  });

  jQuery("#mob_limitedsale_countdown").countdown(limitedDate, function(event) {
    $(this).html(
      event.strftime(
        '<div class="timer-wrapper"><div class="time">%Dd</div></div><div class="timer-wrapper"><div class="time">%Hh</div></div><div class="timer-wrapper"><div class="time">%Mm</div></div><div class="timer-wrapper"><div class="time">%Ss</div></div>'
      )
    );
  });

var Sale99Date = new Date('Oct 07 2021 23:59:59 GMT+0800');
  //Sale99Date SALES COUNTER
  jQuery(".mm_99_counter").countdown(Sale99Date, function(event) {
    $(this).html(
      event.strftime(
        'Start in <div class="timer-wrapper"><div class="time">%Dd</div></div>:<div class="timer-wrapper"><div class="time">%Hh</div></div>:<div class="timer-wrapper"><div class="time">%Mm</div></div>:<div class="timer-wrapper"><div class="time">%Ss</div></div>'
      )
    );
  });

  jQuery(".mob_99_counter").countdown(Sale99Date, function(event) {
    $(this).html(
      event.strftime(
        'Baby Fair Sale Start in <div class="timer-wrapper"><div class="time">%Dd</div></div>:<div class="timer-wrapper"><div class="time">%Hh</div></div>:<div class="timer-wrapper"><div class="time">%Mm</div></div>:<div class="timer-wrapper"><div class="time">%Ss</div></div>'
      )
    );
  });

   jQuery(".mob99_counter").countdown(Sale99Date, function(event) {
    $(this).html(
      event.strftime(
        'Baby Fair Sale Start in : <div class="timer-wrapper"><div class="time">%Dd</div></div>:<div class="timer-wrapper"><div class="time">%Hh</div></div>:<div class="timer-wrapper"><div class="time">%Mm</div></div>:<div class="timer-wrapper"><div class="time">%Ss</div></div>'
      )
    );
  });

  jQuery("#tabs").tabs();

  jQuery("#trending").smoothDivScroll({
    autoScrollingMode: "always",
    autoScrollingDirection: "endlessLoopRight",
    autoScrollingStep: 2,
    autoScrollingInterval: 20

  });


  // redesign_homepage_aug2020
  jQuery(".group_container").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    itemsDesktop: [1500, 5],
    itemsDesktopSmall: [990, 5],
    itemsTablet: [700, 2.3], // 2 items between 600 and 480
    itemsMobile: [479, 2.1], // 1 item between 479 and 0
    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ],
  });

  jQuery(".group_prodd_old").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    itemsDesktop: [1500,5],
    itemsDesktopSmall: [990, 4],
    itemsTablet: [700, 2.3], // 2 items between 600 and 480
    itemsMobile: [479, 2.1], // 1 item between 479 and 0
    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ],
  });

  jQuery(".continue_prodd").owlCarousel({
    rtl: false,
    loop: true,
    margin: 20,
    autoplay: true,
    slideTransition: 'linear',
    autoplayTimeout: 0,
    autoplaySpeed: 3000,
    autoplayHoverPause: true,
    itemsDesktop: [1500,5],
    itemsDesktopSmall: [990, 4],
    itemsTablet: [700, 2.3], // 2 items between 600 and 480
    itemsMobile: [479, 2.1], // 1 item between 479 and 0
    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ],
    responsive:{
        0:{
            items:2
        },
        479:{
            items:2
        },
        700:{
            items:3
        },
        990:{
            items:4
        },
        1500:{
            items:5
        }
    }
  });

  jQuery(".group_prodd").owlCarousel({
    loop: true,
    autoplay: true,
    autoplayTimeout: 800,
    autoplaySpeed: 1000,
    autoplayHoverPause: true,
    itemsDesktop: [1500,5],
    itemsDesktopSmall: [990, 4],
    itemsTablet: [700, 2.3], // 2 items between 600 and 480
    itemsMobile: [479, 2.1], // 1 item between 479 and 0
    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ],
     responsive:{
        0:{
            items:2.1
        },
        479:{
            items:2.1
        },
        700:{
            items:3.1
        },
        990:{
            items:5
        },
        1500:{
            items:5
        }
    }
  });

  jQuery(".group_plp").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    itemsDesktop: [1500,4],
    itemsDesktopSmall: [990, 3],
    itemsTablet: [700, 2.3], // 2 items between 600 and 480
    itemsMobile: [479, 2.1], // 1 item between 479 and 0
    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ],
  });


  jQuery(".group_container_prod_listing").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    itemsDesktop: [1500, 4],
    itemsDesktopSmall: [900, 3], // betweem 900px and 601px
    itemsTablet: [700, 2], // 2 items between 600 and 480
    itemsMobile: [479, 2], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ]
  });


  jQuery("#clearance_container, #popular, #latest").owlCarousel({
    navigation: true,
    autoPlay: true,
    loop: true,
    itemsDesktop: [1500, 4],
    itemsDesktop: [1200, 4],
    itemsDesktopSmall: [900, 3], // betweem 900px and 601px
    itemsTablet: [700, 2], // 2 items between 600 and 480
    itemsMobile: [479, 2], // 1 item between 479 and 0
    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>', '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>']
  });



  jQuery("#flash_sale_off").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    itemsDesktop: [1500, 6],
    itemsDesktopSmall: [900, 4], // betweem 900px and 601px
    itemsTablet: [700, 2], // 2 items between 600 and 480
    itemsMobile: [479, 2], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ]
  });

  jQuery(".recom_sale").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    itemsDesktop: [1500, 6],
    itemsDesktopSmall: [900, 4], // betweem 900px and 601px
    itemsTablet: [700, 2], // 2 items between 600 and 480
    itemsMobile: [479, 2], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ]
  });

  jQuery("#backtotop").click(function() {
    jQuery("html, body").animate({ scrollTop: 0 }, 1000);
  });

  jQuery("#category_slider").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    items: 2,
    itemsDesktop: [1500, 6],
    itemsDesktopSmall: [900, 4], // betweem 900px and 601px
    itemsTablet: [700, 2], // 2 items between 600 and 480
    itemsMobile: [479, 2], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ]
  });

  jQuery(".common_slider").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    items: 4,
    itemsDesktop: [1500, 4],
    itemsDesktopSmall: [900, 4], // betweem 900px and 601px
    itemsTablet: [700, 2], // 2 items between 600 and 480
    itemsMobile: [479, 2], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-chevron-left" aria-hidden="true"></i>',
      '<i class="fa fa-chevron-right" aria-hidden="true"></i>'
    ]
  });

    jQuery(".retail_gal_slider").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    items: 4,
    itemsDesktop: [1500, 4],
    itemsDesktopSmall: [900, 4], // betweem 900px and 601px
    itemsTablet: [700, 2], // 2 items between 600 and 480
    itemsMobile: [479, 2], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-chevron-left" aria-hidden="true"></i>',
      '<i class="fa fa-chevron-right" aria-hidden="true"></i>'
    ]
  });


  jQuery(".mm_promo_slider").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    items: 3,
    itemsDesktop: [1500, 2],
    itemsDesktopSmall: [900, 2], // betweem 900px and 601px
    itemsTablet: [700, 1], // 2 items between 600 and 480
    itemsMobile: [479, 1], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-chevron-left" aria-hidden="true"></i>',
      '<i class="fa fa-chevron-right" aria-hidden="true"></i>'
    ]
  });


 /*oct start*/
  jQuery(".age_grp_slider").owlCarousel({
    loop: true,
    autoplay: true,
    autoplayTimeout: 800,
    autoplaySpeed: 1000,
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    itemsDesktop: [1500, 5],
    itemsDesktopSmall: [900, 3], // betweem 900px and 601px
    itemsTablet: [700, 3], // 2 items between 600 and 480
    itemsMobile: [479, 3], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-chevron-left" aria-hidden="true"></i>',
      '<i class="fa fa-chevron-right" aria-hidden="true"></i>'
    ],
     responsive:{
        0:{
            items:3
        },
        479:{
            items:3
        },
        700:{
            items:3
        },
        990:{
            items:4
        },
        1500:{
            items:5
        }
    }
  });
  jQuery(".super_promo_slider").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    items: 4.2,
    itemsDesktop: [1500, 4.2],
    itemsDesktopSmall: [900, 4.2], // betweem 900px and 601px
    itemsTablet: [700, 2.2], // 2 items between 600 and 480
    itemsMobile: [479, 2.2], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-chevron-left" aria-hidden="true"></i>',
      '<i class="fa fa-chevron-right" aria-hidden="true"></i>'
    ]
  });

  jQuery(".highlight_slider").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    items: 5,
    itemsDesktop: [1500, 5],
    itemsDesktopSmall: [900, 3], // betweem 900px and 601px
    itemsTablet: [700, 3], // 2 items between 600 and 480
    itemsMobile: [479, 3], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-chevron-left" aria-hidden="true"></i>',
      '<i class="fa fa-chevron-right" aria-hidden="true"></i>'
    ]
  });
   jQuery(".newlaunch_slider").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    items: 5,
    itemsDesktop: [1500, 5],
    itemsDesktopSmall: [900, 3], // betweem 900px and 601px
    itemsTablet: [700, 3], // 2 items between 600 and 480
    itemsMobile: [479, 3], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-chevron-left" aria-hidden="true"></i>',
      '<i class="fa fa-chevron-right" aria-hidden="true"></i>'
    ]
  });
 /*oct end*/


  jQuery( document ).ready(function() {
    setTimeout(function() {
      jQuery('.cate__container').css('display','block');
      jQuery(".cate__container").fadeIn(5000);
    }, 300);
  }); 
  jQuery(".cate_slider").owlCarousel({
    autoplayHoverPause: true,
    navigation: true,
    autoPlay: true,
    loop: true,
    items: 5,
    itemsDesktop: [1500, 5],
    itemsDesktopSmall: [900, 5], // betweem 900px and 601px
    itemsTablet: [700, 3], // 2 items between 600 and 480
    itemsMobile: [479, 3], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-chevron-left" aria-hidden="true"></i>',
      '<i class="fa fa-chevron-right" aria-hidden="true"></i>'
    ]
  });

  jQuery("#category_slider_retail").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    items: 5,
    itemsDesktop: [1500, 5],
    itemsDesktopSmall: [900, 4], // betweem 900px and 601px
    itemsTablet: [700, 2], // 2 items between 600 and 480
    itemsMobile: [479, 2], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ]
  });

   jQuery("#brands_slider_retail").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    items: 5,
    itemsDesktop: [1500, 5],
    itemsDesktopSmall: [900, 4], // betweem 900px and 601px
    itemsTablet: [700, 2], // 2 items between 600 and 480
    itemsMobile: [479, 2], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ]
  });

  jQuery("#babyzen_slider").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    items: 3,
    itemsDesktop: [1500, 3],
    itemsDesktopSmall: [900, 3], // betweem 900px and 601px
    itemsTablet: [700, 2], // 2 items between 600 and 480
    itemsMobile: [479, 2], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ]
  });

  jQuery("#custom_slider_retail").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    items: 2,
    itemsDesktop: [1500, 2],
    itemsDesktopSmall: [900, 2], // betweem 900px and 601px
    itemsTablet: [700, 1], // 2 items between 600 and 480
    itemsMobile: [479, 1], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ]
  });

  jQuery(".brand_slider_retail").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    items: 1,
    itemsDesktop: [1500, 1],
    itemsDesktopSmall: [900, 1], // betweem 900px and 601px
    itemsTablet: [700, 1], // 2 items between 600 and 480
    itemsMobile: [479, 1], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ]
  });

  jQuery("#brand_slider").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    items: 2,
    itemsDesktop: [1500, 6],
    itemsDesktopSmall: [900, 4], // betweem 900px and 601px
    itemsTablet: [700, 2], // 2 items between 600 and 480
    itemsMobile: [479, 2], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ]
  });

  jQuery("#feature_brand_slider").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    items: 6,
    itemsDesktop: [1500, 6],
    itemsDesktopSmall: [900, 4.3], // betweem 900px and 601px
    itemsTablet: [700, 3.3], // 2 items between 600 and 480
    itemsMobile: [479, 3.3], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ]
  });
  jQuery("#feature_brand_sliders").owlCarousel({
    loop: true,
    autoplay: true,
    autoplayTimeout: 800,
    autoplaySpeed: 1000,
    autoplayHoverPause: true,
    navigation: false,
     items:6,
    itemsDesktop: [1500, 6],
    itemsDesktopSmall: [900, 3.3], // betweem 900px and 601px
    itemsTablet: [700, 2.3], // 2 items between 600 and 480
    itemsMobile: [479, 3.3], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ],
     responsive:{
        0:{
            items:3.3
        },
        479:{
            items:3.3
        },
        700:{
            items:3.3
        },
        990:{
            items:6
        },
        1500:{
            items:6
        }
      }
  });


  jQuery(".deals_scroll_container").owlCarousel({
    autoplayHoverPause: true,
    navigation: true,
    autoPlay: true,
    loop: true,
    items: 6,
    itemsDesktop: [1500, 5],
    itemsDesktopSmall: [900, 3], // betweem 900px and 601px
    itemsTablet: [700, 2], // 2 items between 600 and 480
    itemsMobile: [479, 2], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ]
  });

  jQuery(".adv_slider").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    items: 1,
    itemsDesktopSmall: [900, 2], // betweem 900px and 601px
    itemsTablet: [700, 1], // 2 items between 600 and 480
    itemsMobile: [479, 1], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ]
  });

  jQuery("#gift_slider").owlCarousel({
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    items: 1,
    itemsDesktopSmall: [900, 2], // betweem 900px and 601px
    itemsTablet: [700, 1], // 2 items between 600 and 480
    itemsMobile: [479, 1], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ]
  });
jQuery(init);
function init() { 
setTimeout(function() {
jQuery('.banner_desktop').css('display','block');
  jQuery("#webbanner_slider").owlCarousel({
    loop: true,
    autoplay: true,
    autoplayTimeout: 1200,
    autoplaySpeed: 1000,
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    items: 1,
    itemsDesktop: [1500, 1],
    itemsDesktopSmall: [900, 1], // betweem 900px and 601px
    itemsTablet: [700, 1], // 2 items between 600 and 480
    itemsMobile: [479, 1], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ]
  });
  }, 800);  
}

  jQuery("#mobbanner_slider").owlCarousel({
    loop: true,
    autoplay: true,
    autoplayTimeout: 1200,
    autoplaySpeed: 1000,
    autoplayHoverPause: true,
    navigation: false,
    autoPlay: true,
    loop: true,
    items: 1,
    itemsDesktop: [1500, 1],
    itemsDesktopSmall: [900, 1], // betweem 900px and 601px
    itemsTablet: [700, 1], // 2 items between 600 and 480
    itemsMobile: [479, 1], // 1 item between 479 and 0

    navigationText: ['<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>',
      '<i class="fa fa-arrow-circle-right" aria-hidden="true"></i>'
    ]
  });



  jQuery('.freebies_slider').owlCarousel({
    items: 1,
    loop: true,
    nav: false,
    dots: true,
    margin: 10,
    autoplay: true,
    autoplayTimeout: 2500
  });

   

   //Retail Walkin Appointment
   jQuery("#newWalkinAppointmentForm").submit(function(event) {
    event.preventDefault();
    var edd         = jQuery('input[name=appt_edd]').val();
    var phone       = jQuery('input[name=appt_mobile]').val();
    var first_name  = jQuery('input[name=appt_first_name]').val();
    var last_name   = jQuery('input[name=appt_last_name]').val();

    var father_name     = jQuery('input[name=father_name]').val();
    var father_mobile   = jQuery('input[name=father_mobile]').val();

    if (jQuery.trim(first_name) == '') {
      alert("Please enter your first name.");
      return false;
    }
    if (jQuery.trim(last_name) == '') {
      alert("Please enter your last name.");
      return false;
    }
    if (phone.length != 8) {
      alert("Please enter your 8 digit mobile number.");
      return false;
    }
    if (phone.charAt(0) != 8 && phone.charAt(0) != 9) {
      alert("Please enter valid 8 digit mobile number.");
      return false;
    }
    if (jQuery.trim(edd) == '') {
      alert("Please enter your edd.");
      return false;
    }
    if (jQuery.trim(father_name) == '') {
      alert("Please enter father name.");
      return false;
    }
    if (father_mobile.length != 8) {
      alert("Please enter your 8 digit father mobile number.");
      return false;
    }
    if (father_mobile.charAt(0) != 8 && father_mobile.charAt(0) != 9) {
      alert("Please enter valid 8 digit father mobile number.");
      return false;
    }
    var total_visitor = jQuery('select[name=total_visitor] option').filter(':selected').val();
    if (total_visitor == '') {
      alert("Please select visitor count.");
      return false;
    }
    var hospital = jQuery('select[name=hospital] option').filter(':selected').val();
    if (hospital == '') {
      alert("Please select hospital name.");
      return false;
    }
     var email = jQuery('input[name=appt_email]').val();
    if (!ValidateEmail(jQuery('input[name=appt_email]').val())) {
      alert(email + " is Invalid email address.");
    } else {
      jQuery.ajax({
        type: "POST",
        url: "index.php?option=com_brand&view=walkin_booking_appointment&format=raw",
        data: jQuery("#newWalkinAppointmentForm").serialize(),
        success: function(data) {
          if (data == 'success') {
            var dt = new Date();
            var time = dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
            var currentTime = new Date()
            var month = currentTime.getMonth() + 1
            var day = currentTime.getDate()
            var year = currentTime.getFullYear()
            var curr_date =  day + "-" + month + "-" + year;
             var html = '<h3>Mummys Market Retail Store</h3>';
             html += '<h3 class="calendar-name" style="color:red !important;">Note : Please show this QR-Code at Mummys Market Entrance for Both <b> Check-In & Check-Out </b></h3>';
             //html += '<p class="check-btn">CHECK-IN</p>';
             html += '<div class="">';
             html += '<p class="appointment-info"><i class="booked-icon booked-icon-calendar"></i>   '+curr_date+' at '+time+'</p>';
             html += '</div>';
             //html += '<h3>Please Show this QR Code. <br> Out from Mummys Market Store.</h3>';
             html +=' <img src="https://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=L|1&choe=UTF-8&chl=https://babyfair.mummysmarket.com.sg/services/appointment/confirmation?email='+email+'" width="100%">'
             html += '<div class="field">';
             html += '<p class="field-small-p">Thank you, Mummys Market Retail Store</p>';
             html += '</div>';
             $('.app_container').attr('id','wrapper');
             $('#app_container').addClass('dialog');
             $('#app_container').html(html);
            //alert('Your retail walk-in appointment with us is successful. \n Thank you, Mummys Market Retail Store');
            //location.reload();
          } else if (data == 'error') {
            alert('Something went wrong. Please try later.')
          } else if (data == 'invalid_email') {
            alert('Invalid email address.')
          } else {
            alert('Sorry! Please contact administrator.')
          }
        }
      });
    }
  });


  jQuery("#newWalkinAppointmentForm_1").submit(function(event) {
    event.preventDefault();
    var edd         = jQuery('input[name=appt_edd]').val();
    var dob         = jQuery('input[name=appt_dob]').val();
    var phone       = jQuery('input[name=appt_mobile]').val();
    var first_name  = jQuery('input[name=appt_first_name]').val();
    var last_name   = jQuery('input[name=appt_last_name]').val();

    if (jQuery.trim(first_name) == '') {
      alert("Please enter your first name.");
      return false;
    }
    if (jQuery.trim(last_name) == '') {
      alert("Please enter your last name.");
      return false;
    }
    if (phone.length != 8) {
      alert("Please enter your 8 digit mobile number.");
      return false;
    }
    if (phone.charAt(0) != 8 && phone.charAt(0) != 9) {
      alert("Please enter valid 8 digit mobile number.");
      return false;
    }
   

    var is_preg = $('.is_checked:checked').val();
    if(is_preg!=2)
    {
      if(is_preg==0)
      {
        if (jQuery.trim(edd) == '') {
          alert("Please enter Estimate Delivery Date.");
          return false;
        }
        var hospital = jQuery('select[name=hospital] option').filter(':selected').val();
        if (hospital == '') {
          alert("Please select hospital name.");
          return false;
        }
      }
      else
      {
        if (jQuery.trim(dob) == '') {
          alert("Please enter your Child Date of Birth.");
          return false;
        }
      }
    }
     var total_visitor = jQuery('select[name=total_visitor] option').filter(':selected').val();
    if (total_visitor == '') {
      alert("Please select visitor count.");
      return false;
    }
     var email = jQuery('input[name=appt_email]').val();
    if (!ValidateEmail(jQuery('input[name=appt_email]').val())) {
      alert(email + " is Invalid email address.");
    } else {
      jQuery.ajax({
        type: "POST",
        url: "index.php?option=com_brand&view=walkin_booking_appointment_1&format=raw",
        data: jQuery("#newWalkinAppointmentForm_1").serialize(),
        success: function(data) {
          if (data == 'success') {
            var dt = new Date();
            var time = dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
            var currentTime = new Date()
            var month = currentTime.getMonth() + 1
            var day = currentTime.getDate()
            var year = currentTime.getFullYear()
            var curr_date =  day + "-" + month + "-" + year;
             var html = '<h3>Mummys Market Retail Store</h3>';
             //html += '<h3 class="calendar-name" style="color:red !important;">Note : Please show this QR-Code at Mummys Market Entrance for Both <b> Check-In & Check-Out </b></h3>';
             //html += '<p class="check-btn">CHECK-IN</p>';
             html += '<div class="">';
             html += '<p class="appointment-info"><i class="booked-icon booked-icon-calendar"></i>   '+curr_date+' at '+time+'</p>';
             html += '</div>';
             //html += '<h3>Please Show this QR Code. <br> Out from Mummys Market Store.</h3>';
             //html +=' <img src="https://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=L|1&choe=UTF-8&chl=https://babyfair.mummysmarket.com.sg/services/appointment/confirmation?email='+email+'" width="100%">'
             html += '<div class="field">';
             html += '<p class="field-small-p">Thank you, Mummys Market Retail Store</p>';
             html += '</div>';
             $('.app_container').attr('id','wrapper');
             $('#app_container').addClass('dialog');
             $('#app_container').html(html);
            //alert('Your retail walk-in appointment with us is successful. \n Thank you, Mummys Market Retail Store');
            //location.reload();
          } else if (data == 'error') {
            alert('Something went wrong. Please try later.')
          } else if (data == 'invalid_email') {
            alert('Invalid email address.')
          } else {
            alert('Sorry! Please contact administrator.')
          }
        }
      });
    }
  });

  jQuery("#request_form").submit(function(event) {
    event.preventDefault();
    const userConfirmed = confirm('Are you sure you want to delete your account?');
    if (userConfirmed) {
      if (!ValidateEmail(jQuery('#request_form input[name="email"]').val())) {
        alert("Invalid email address.");
        return;
      }
      form_btn_status("#btn_submit", "disable");
      jQuery.ajax({
        type: "POST",
        url: "index.php?option=com_brand&view=account_deletion_request&format=raw",
        data: jQuery("#request_form").serialize(),
        success: function(data) {
          if(data=='success')
          {
             alert("We will delete your account and all related information. Once it's done, we will let you know through your registered email.");
             window.location.href='https://www.mummysmarket.com.sg'; 
          }
          else if(data=='error')
          {
            alert('Something went wrong, please try again');
            form_btn_status("#btn_submit", "enable");
          }
          else
          {
            alert(data);
          }
        }
      });
    }
  });

  //Newsletter
  jQuery(".newsletter_signup_form").submit(function(event) {
    event.preventDefault();
    if (!ValidateEmail(jQuery('.newsletter_signup_form input[name="email"]').val())) {
      alert("Invalid email address.");
      return;
    }
    jQuery('#newsletter_signup_form input[type="submit"]').attr('disabled', 'disabled');

    jQuery.ajax({
      type: "POST",
      url: "index.php?option=com_brand&view=newslettersignup&format=raw",
      data: jQuery(".newsletter_signup_form").serialize(),
      success: function(data) {
        alert("Thank you for your registration");
      }
    });
  });

  //Newsletter
  jQuery(".mob_subscribe_form").submit(function(event) {
    event.preventDefault();
    if (!ValidateEmail(jQuery('.mob_subscribe_form input[name="emailId"]').val())) {
      alert("Invalid email address.");
      return;
    }
    jQuery('.mob_subscribe_form input[type="submit"]').attr('disabled', 'disabled');

    jQuery.ajax({
      type: "POST",
      url: "https://www.mummysmarket.com.sg/index.php?option=com_brand&view=web_subscribe&format=raw",
      data: jQuery(".mob_subscribe_form").serialize(),
      success: function(data) {
        if(data=='success')
        {
          alert("Thank you for subscribing");
        }
        else if(data=='exist')
        {
          alert("You're already subscribed");
        }
        else if(data=='error')
        {
          alert("Oops! Something went wrong");
        }
        else
        {
          alert("Oops! Please enter vaid details");

        }
      }
    });
  });

  jQuery(".web_subscribe_form").submit(function(event) {
    event.preventDefault();
    if (!ValidateEmail(jQuery('.web_subscribe_form input[name="emailId"]').val())) {
      alert("Invalid email address.");
      return;
    }
    jQuery('.web_subscribe_form input[type="submit"]').attr('disabled', 'disabled');

    jQuery.ajax({
      type: "POST",
      url: "https://www.mummysmarket.com.sg/index.php?option=com_brand&view=web_subscribe&format=raw",
      data: jQuery(".web_subscribe_form").serialize(),
      success: function(data) {
        if(data=='success')
        {
          alert("Thank you for subscribing");
        }
        else if(data=='exist')
        {
          alert("You're already subscribed");
        }
        else if(data=='error')
        {
          alert("Oops! Something went wrong");
        }
        else
        {
          alert("Oops! Please enter vaid details");

        }
      }
    });
  });


  jQuery(".web_head_subscribe_form").submit(function(event) {
    event.preventDefault();
    if (!ValidateEmail(jQuery('.web_head_subscribe_form input[name="emailId"]').val())) {
      alert("Invalid email address.");
      return;
    }
    jQuery('.web_head_subscribe_form input[type="submit"]').attr('disabled', 'disabled');

    jQuery.ajax({
      type: "POST",
      url: "https://www.mummysmarket.com.sg/index.php?option=com_brand&view=web_subscribe&format=raw",
      data: jQuery(".web_head_subscribe_form").serialize(),
      success: function(data) {
        if(data=='success')
        {
          alert("Thank you for subscribing");
        }
        else if(data=='exist')
        {
          alert("You're already subscribed");
        }
        else if(data=='error')
        {
          alert("Oops! Something went wrong");
        }
        else
        {
          alert("Oops! Please enter vaid details");
        }
        jQuery('.web_head_subscribe_form input[name="emailId"]').val('');
      }
    });
  });

  jQuery(".mob_head_subscribe_form").submit(function(event) {
    event.preventDefault();
    if (!ValidateEmail(jQuery('.mob_head_subscribe_form input[name="emailId"]').val())) {
      alert("Invalid email address.");
      return;
    }
    jQuery('.mob_head_subscribe_form input[type="submit"]').attr('disabled', 'disabled');

    jQuery.ajax({
      type: "POST",
      url: "https://www.mummysmarket.com.sg/index.php?option=com_brand&view=web_subscribe&format=raw",
      data: jQuery(".mob_head_subscribe_form").serialize(),
      success: function(data) {
        if(data=='success')
        {
          alert("Thank you for subscribing");
        }
        else if(data=='exist')
        {
          alert("You're already subscribed");
        }
        else if(data=='error')
        {
          alert("Oops! Something went wrong");
        }
        else
        {
          alert("Oops! Please enter vaid details");
        }
        jQuery('.mob_head_subscribe_form input[name="emailId"]').val('');
      }
    });
  });

  jQuery("#newsletter_signup_form").submit(function(event) {
    event.preventDefault();
    if (!ValidateEmail(jQuery('#newsletter_signup_form input[name="email"]').val())) {
      alert("Invalid desktop address.");
      return;
    }
    jQuery('#newsletter_signup_form input[type="submit"]').attr('disabled', 'disabled');
    jQuery.ajax({
      type: "POST",
      url: "index.php?option=com_brand&view=newslettersignup&format=raw",
      data: jQuery(".newsletter_signup_form").serialize(),
      success: function(data) {
        alert("Thank you for your registration");
      }
    });




  });



  jQuery(".newsletter_signup #ic_signupform").submit(function(event) {
    event.preventDefault();

    if (!ValidateEmail(jQuery('#ic_signupform input[name="email"]').val())) {
      alert("Invalid email address.");
      return;
    } else {
      jQuery('.newsletter_signup #ic_signupform input[type="submit"]').attr('disabled', 'disabled');
      jQuery.ajax({
        type: "POST",
        url: "index.php?option=com_brand&view=newslettersignup&format=raw",
        data: jQuery(".newsletter_signup #ic_signupform").serialize(),
        success: function(data) {
          if (data == 1) {
            //jQuery('.newsletter_signup #ic_signupform #msg').append('<p style="float: left;padding-top: 5px;">Thank you for registering!<br>Meanwhile, stay tune to our event page for latest updates & more Freebies @<a href="https://www.facebook.com/events/253313645417724/" style="color:white"> Here <a></p>');
            jQuery('.newsletter_signup #ic_signupform #msg').append('<p style="float: left;padding-top: 5px;text-align: center;">Thank you for registering!</p>');
            jQuery('.newsletter_signup #ic_signupform  input[type="email"]').val('');
            jQuery('.newsletter_signup #ic_signupform  input[type="text"]').val('');




          }
          else if(data==3)
          {
            alert('Sorry! You are already registered. \n Thank You!');
          }
           else {
            // alert('Please enter your email address.');
          }

          jQuery('.newsletter_signup #ic_signupform #msg').html('<p style="float: left;padding-top: 5px;text-align: center;">Thank you for registering!</p>');


          if (jQuery('#z_value').val() == 'goodie-bag') {

            window.open("https://mummysmarket.com.sg", "_blank");
          } else if (jQuery('#z_value').val() == 'groupbuy-sub') {
            window.open("https://mummysmarket.com.sg", "_blank");
          } else if (jQuery('#z_value').val() == 'event-guide') {
            // window.open("https://mummysmarket.com.sg/images/pdf2019/shopping-guide.pdf", "_blank");
            alert("Thank you for your registration!");
            window.location.href = "https://mummysmarket.com.sg";
          } else if (jQuery('#z_value').val() == 'online-baby-fair') {
            // window.open("https://mummysmarket.com.sg/images/pdf2019/shopping-guide.pdf", "_blank");
            alert("Thank you for your registration!");
            window.location.href = "https://mummysmarket.com.sg";
          } else if (jQuery('#z_value').val() == 'real-goodie-bag') {
            window.open("https://mummysmarket.com.sg/thankyougoodiebag.html", "_blank");
          } else if (jQuery('#z_value').val() == 'preflash_sale') {
            window.open("https://mummysmarket.com.sg/PreFlashSale.html", "_blank");


          } else if (jQuery('#z_value').val() == 'pregnany-cash') {
            window.open("https://mummysmarket.com.sg/PregnancyCash.html", "_blank");

          } else if (jQuery('#z_value').val() == 'shop-with-confidence') {
            window.open("https://mummysmarket.com.sg/ShopWithConfidence.html", "_blank");

          } else if (jQuery('#z_value').val() == 'lowest-price-guaranteed') {
            window.open("https://mummysmarket.com.sg/LowestPriceGuaranteed.html", "_blank");


          } else if (jQuery('#z_value').val() == 'cash-voucher') {
            window.open("https://mummysmarket.com.sg/CashVouchers.html", "_blank");
            jQuery('#msg').append('<a href="https://mummysmarket.com.sg/images/2019/190815_cashvoucher_tnc.jpeg"><img src="https://mummysmarket.com.sg/images/2019/190815_cashvoucher_tnc.jpeg" /></a>');
          } 
          else if (jQuery('#z_value').val() == 'mm_babyfair_sale_jan2021') {
             alert('Thank you for your registration');
            location.href = "https://www.mummysmarket.com.sg/thankyoubabyfairdeals.html";

          }
          else {
            alert('Thank you for your registration');
          }

          console.log('Sign Up Triggered');
        }
      });
    }
  });

  jQuery(".newsletter_signup #ic_signupform2").submit(function(event) {
    event.preventDefault();
    if (!ValidateEmail(jQuery('input[name="email"]').val())) {
      alert("Invalid email address.");
    } else {
      //Disable #ic_signupform2 submit button
      jQuery('.newsletter_signup #ic_signupform2  :input[type="submit"]').prop('disabled', true);
      //Ajax
      jQuery.ajax({
        type: "POST",
        url: "index.php?option=com_brand&view=newslettersignup&format=raw",
        data: jQuery(".newsletter_signup #ic_signupform2").serialize(),
        success: function(data) {
          if (data == 1) {

            jQuery('.newsletter_signup #ic_signupform2 #goodiemsg').append('<p>Thank you for registering!</p>');
            jQuery('.newsletter_signup #ic_signupform2  input[type="email"]').val('');
            jQuery('.newsletter_signup #ic_signupform2  input[type="text"]').val('');
            jQuery('#goodiemsg').show();

            alert('Thank you for your registration');
          } else if (data == 3) {
            alert('You are already registered');
            if (jQuery('#z_value').val() == 'group-buy') {
              window.open("https://mummysmarket.com.sg/thankyou_pre_order.php", "_blank");
            }
          } else {
            alert('Please fill all the mandatory fieds.')
          }
          console.log(jQuery('#z_value').val());
          if (jQuery('#z_value').val() == 'goodie-bag') {

            // window.open("https://mummysmarket.com.sg/images/2018/GoodieBag-Voucher_web.jpg", "_blank");
          } else if (jQuery('#z_value').val() == 'event-guide') {
            //window.open("https://mummysmarket.com.sg/images/pdf2018/mummysmarketNov2018.pdf", "_blank");
          } else {
            //alert('Thank you for your registration');
          }

          jQuery('.newsletter_signup #ic_signupform #msg').html('<p style="float: left;padding-top: 5px;text-align: center;">Thank you for registering!</p>');
          console.log('Sign Up Triggered 2');

          //Enable #ic_signupform2 submit button
          jQuery('.newsletter_signup #ic_signupform2  :input[type="submit"]').prop('disabled', false);
        }
      });
    }
  });

  jQuery(".newsletter_signup #ic_newsletter_form").submit(function(event) {
    event.preventDefault();
    if (!ValidateEmail(jQuery('#ic_newsletter_form input[name="email"]').val())) {
      alert("Invalid email address.");
    } else {
      jQuery.ajax({
        type: "POST",
        url: "index.php?option=com_brand&view=newsletterform&format=raw",
        data: jQuery(".newsletter_signup #ic_newsletter_form").serialize(),
        success: function(data) {
          if (data == 'success') {
            alert('Thank you, You are successfully registered.');
            location.href = "https://www.mummysmarket.com.sg/";
          } else if (data == 'error') {
            alert('Something went wrong. Please try later.')
          } else if (data == 'invalid_email') {
            alert('Invalid email address.')
          } else {
            alert('Sorry! You are already registered.')
          }
        }
      });
    }
  });

  jQuery("#subscription_form").submit(function(event) {
    event.preventDefault();

    var f_name    =   jQuery('#subscription_form input[name=fname]').val();
    var l_name    =   jQuery('#subscription_form input[name=lname]').val();
    var edd       =   jQuery('#subscription_form input[name=edd]').val();
    var email     =   jQuery('#subscription_form input[name=email]').val();
    var phone     =   jQuery('#subscription_form input[name=phone]').val();
    var from      =   jQuery('#subscription_form input[name=from]').val();
    var hospital  =   jQuery('#subscription_form select[name=hospital] option').filter(':selected').val();
    var z_value      =   jQuery('#subscription_form input[name=z_value]').val();

    if (f_name == '' || l_name=='') 
    {
      alert("Please enter your name.");
      return false;
    }
    else if (!ValidateEmail(email)) {
      alert(email + " is Invalid email address.");
      return false;
    } 
    else if (phone.length != 8) {
      alert("Please enter 8 digit mobile number.");
      return false;
    }
    else if (phone.charAt(0) != 8 && phone.charAt(0) != 9) {
      alert("Enter 8 Digit Singapore Mobile Number.");
      return false;
    }
    else if (edd == '' && z_value!='shopping-magazine') {
      alert("Please enter your edd/dob.");
      return false;
    }else {
      form_btn_status("#btn_submit", "disable");
      jQuery.ajax({
        type: "POST",
        url: "index.php?option=com_brand&view=newsletterform&format=raw",
        data: jQuery("#subscription_form").serialize(),
        success: function(data) {

          if (data == 'success') 
          {
            alert('Thank you, You are successfully registered.');
            if(z_value == 'mm_preorder_july23')
            {
              location.href = "https://www.mummysmarket.com.sg/expo-preorder-deals";
            }
            else if(z_value == 'shopping-magazine')
            {
              location.href = "https://www.mummysmarket.com.sg/magazine-thankyou";
            }
            else if(z_value == 'prosperity-bbf')
            {
              location.href = "https://www.mummysmarket.com.sg/atrium-thankyou";
            }
            else if(z_value == 'sure-win-lucky-dip')
            {
              location.href = "https://www.mummysmarket.com.sg/thank-you-sure-win-lucky-dip";
            }
            else if(z_value == 'storewide-sale')
            {
              location.href = "https://www.mummysmarket.com.sg/thank-you-storewide-sale";
            }
            else
            {
              location.href = "https://www.mummysmarket.com.sg/thankyou-signup";
            }

          } else if (data == 'error') {
            alert('Something went wrong. Please try later.');
            form_btn_status("#btn_submit", "enable");
          } else if (data == 'invalid_email') {
            alert('Please enter valid email address.');
            form_btn_status("#btn_submit", "enable");
          } else {
            alert('Sorry! You are already registered.');
            form_btn_status("#btn_submit", "enable");
          }
        }
      });
    }
  });

  function form_btn_status(id,status){
    if(status == "disable"){
      jQuery(id).prop('disabled',true);
      jQuery(id).prop('value','Processing...');
      jQuery(id).css('background','#efeeec');
    }
    else if(status == "enable"){
      jQuery(id).prop('disabled',false);
      jQuery(id).prop('value','Submit');
      jQuery(id).css('background','#f35c9170');
    }
  }

  jQuery("#subscription_form_1").submit(function(event) {
    event.preventDefault();
    if (!ValidateEmail(jQuery('#subscription_form_1 input[name="email"]').val())) {
      alert("Invalid email address.");
    } else {
      jQuery.ajax({
        type: "POST",
        url: "index.php?option=com_brand&view=newsletterform&format=raw",
        data: jQuery("#subscription_form_1").serialize(),
        success: function(data) {
          if (data == 'success') {
            alert('Thank you, You are successfully registered.');
            /*setTimeout(function() {
              $('#mmsingup_forms').click();
            }, 1000);*/
            location.href = "https://www.mummysmarket.com.sg/";
          } else if (data == 'error') {
            alert('Something went wrong. Please try later.')
          } else if (data == 'invalid_email') {
            alert('Invalid email address.')
          } else {
            alert('Sorry! You are already registered.')
          }
        }
      });
    }
  });

  jQuery("#ic_newsletter_form_v2").submit(function(event) {
    event.preventDefault();
    var edd   = jQuery('input[name=edd]').val();
    var phone = jQuery('input[name=phone]').val();
    var from  = jQuery(this).find('input[name=from]').val();
    var sphone = jQuery('input[name=sphone]').val();
    if (edd == '') {
      alert("Please enter your edd.");
      return false;
    }
    if (phone.length != 8) {
      alert("Please enter 8 digit mobile number.");
      return false;
    }
    if (phone.charAt(0) != 8 && phone.charAt(0) != 9) {
      alert("Please enter valid 8 digit mobile number.");
      return false;
    }
  
    if(from=='free_cash_2022')
    {
        var coll_date = jQuery('#collection_date').val();
        if(coll_date=='' || coll_date==null)
        {
          alert("Please select collection date.");
          return false;
        }
    }

    /*if(sphone!='')
    {
      if (sphone.length != 8) {
        alert("Please enter 8 digit spouse mobile number.");
        return false;
      }
      if (sphone.charAt(0) != 8 && sphone.charAt(0) != 9) {
        alert("Please enter valid 8 digit spouse mobile number.");
        return false;
      }
      if (sphone == phone) 
      {
        alert("Please enter different spouse mobile number.");
        return false;
      }
    }*/

    if (!ValidateEmail(jQuery('#mm_input_email').val())) {
      var email = jQuery('#mm_input_email').val();
      alert(email + " is Invalid email address.");
    } else {

      if(from=='free_cash_2022' || from=='participating-brand')
      {
        $('#input_submit').prop('disabled', true);
        $('#input_submit').val('Processing..');
        $('#input_submit').css('color','#FFF');
        $('#input_submit').css('background-color','#EFEFEF');
      }
      if(from=='mm_preorder_oct22')
      {
        $('.newsletter_form_submit').prop('disabled', true);
        $('.newsletter_form_submit').val('Processing..');
        $('.newsletter_form_submit').css('color','#FFF');
        $('.newsletter_form_submit').css('background-color','#707070');
        jQuery(this).find('#input_tnc1').prop('checked',false);
      }

      jQuery.ajax({
        type: "POST",
        url: "https://www.mummysmarket.com.sg/index.php?option=com_brand&view=newsletterform&format=raw",
        data: jQuery("#ic_newsletter_form_v2").serialize(),
        success: function(data) {
          if (data == 'success') {
            alert('Thank you for subscribing. We have sent you an email to confirm your subscription!');
            if(from=='bbf_feb_2022')
            {
               //window.open("https://www.mummysmarket.com.sg/thankyoubabyfair.html");
               //alert('Thank you for your registration');
               location.href = "https://www.mummysmarket.com.sg/thankyoubabyfair.html";
            }
            else if(from == 'mm_preorder_july23')
            {
              location.href = "https://www.mummysmarket.com.sg/expo-preorder-deals";
            }
            else
            {
              location.href = "https://www.mummysmarket.com.sg/";
            }

          } else if (data == 'error') {
            alert('Something went wrong. Please try later.');
          } else if (data == 'invalid_email') {
            alert('Invalid email address.');
          }
          else if (data == 'invalid_fname') {
            alert('Enter valid first name.');
          }
          else if (data == 'invalid_lname') {
            alert('Enter valid last name.');
          }
          else if (data == 'invalid_phone') {
            alert('Enter valid phone number.');
          }
          else if (data == 'invalid_sname') {
            alert('Enter valid spouse name.');
          }
          else if (data == 'invalid_sphone') {
            alert('Enter valid spouse phone number.');
          } 
          else if (data == 'invalid_hospital') {
            alert('Select valid hospital name.');
          }else {
            alert('Sorry! You are already registered.');
          }
        }
      });
    }
  });


  jQuery("#club_illume_form").submit(function(event) {
    event.preventDefault();
    var f_name    =   jQuery('input[name=first_name]').val();
    var l_name    =   jQuery('input[name=last_name]').val();
    var edd       =   jQuery('input[name=edd]').val();
    var email     =   jQuery('input[name=email]').val();
    var phone     =   jQuery('input[name=phone]').val();
    var from      =   jQuery('input[name=from]').val();
    var hospital  =   jQuery('select[name=hospital] option').filter(':selected').val();
    var postal_code  =   jQuery('input[name=postal_code]').val();
    var address      =   jQuery('input[name=address]').val();

    if (f_name == '' || l_name=='') {
      alert("Please enter your name.");
      return false;
    }
    else if (!ValidateEmail(jQuery('#email').val())) {
      var email = jQuery('#email').val();
      alert(email + " is Invalid email address.");
      return false;
    } 
    else if (phone.length != 8) {
      alert("Please enter 8 digit mobile number.");
      return false;
    }
    else if (phone.charAt(0) != 8 && phone.charAt(0) != 9) {
      alert("Enter 8 Digit Singapore Mobile Number.");
      return false;
    }
    else if (postal_code == '') 
    {
      alert("Please enter postal code.");
      return false;
    }
    else if (address == '') 
    {
      alert("Please enter your address.");
      return false;
    }
    else if (edd == '') {
      alert("Please enter your edd.");
      return false;
    }
    else if (hospital=='') {
      alert("Please select hospital.");
      return false;
    } 
    else {
      jQuery('#club_illume_form_btn').prop('disabled',true);
      jQuery('#club_illume_form_btn').prop('value','Processing...');
      jQuery.ajax({
        type: "POST",
        url: "index.php?option=com_brand&view=mmsignup_form&format=raw",
        data: jQuery("#club_illume_form").serialize(),
        success: function(data) {
          if (data == 'success') {
            alert('Thank you for your registration. Successful registrants will be notified within 7 working days.');
            location.href="https://www.mummysmarket.com.sg";
            // location.href="https://www.mummysmarket.com.sg/thankyou_illume.html";
          } else {
            alert(data);
            jQuery('#club_illume_form_btn').prop('disabled',false);
            jQuery('#club_illume_form_btn').prop('value','Submit');
          } 
        }
      });
    }
  });

  jQuery("#nbm_preg_form").submit(function(event) {
    event.preventDefault();
    let s_title   =   'pmw';
    let campaign  =   'pmw_oct_21';
    var f_name    =   jQuery('input[name=first_name]').val();
    var l_name    =   jQuery('input[name=last_name]').val();
    var edd       =   jQuery('input[name=edd]').val();
    /*var dob       =   jQuery('input[name=dob]').val();*/
    var email     =   jQuery('input[name=email]').val();
    var phone     =   jQuery('input[name=phone]').val();
    var from      =   jQuery('input[name=from]').val();
    var hospital  =   jQuery('select[name=hospital] option').filter(':selected').val();
    var postal_code  =   jQuery('input[name=postal_code]').val();
    var address_1  =   jQuery('input[name=unit_number]').val();
    var address_2  =   jQuery('input[name=address]').val();
    let tnc_1     = jQuery('#check_1').val();
    let tnc_2     = jQuery('#check_4').val();

    let name_regex = /^([a-zA-Z]+\s*)+$/;
    if (!name_regex.test(f_name) || !name_regex.test(l_name)) {
      alert('Name should not contain symbols.');
      jQuery('#nbm_preg_form_btn').prop('disabled', false);
      jQuery('#nbm_preg_form_btn').val('Submit');
      jQuery('#nbm_preg_form_btn').css('background-color','#13328e');
      return;
    }

    if (f_name == '' || l_name=='') {
      alert("Please enter your name.");
      return false;
    }
    else if (!ValidateEmail(jQuery('#email').val())) {
      var email = jQuery('#email').val();
      alert(email + " is Invalid email address.");
      return false;
    } 
    else if (phone.length != 8) {
      alert("Please enter 8 digit mobile number.");
      return false;
    }
    else if (phone.charAt(0) != 8 && phone.charAt(0) != 9) {
      alert("Enter 8 Digit Singapore Mobile Number.");
      return false;
    }
    else if (postal_code == '') 
    {
      alert("Please enter postal code.");
      return false;
    }
    else if (address_2 == '') 
    {
      alert("Please enter your address.");
      return false;
    }
    else if (edd == '') {
      alert("Please enter your Estimated Delivery Date.");
      return false;
    }
    else {
      jQuery('#nbm_preg_form_btn').prop('disabled',true);
      jQuery('#nbm_preg_form_btn').prop('value','Processing...');

      let dataa = {
        s_title:s_title,
        campaign:campaign,
        name:f_name+' '+l_name,
        email:email,
        phone:phone,
        edd:edd,
        address_1:address_1,
        address_2:address_2,
        postal_code:postal_code,
        tnc_1:tnc_1,
        tnc_2:tnc_2
      };

      jQuery.ajax({
        type: "POST",
        url: "https://www.mummysmarket.com.sg/index.php?option=com_brand&view=online_seminar_registration_1&format=raw",
        data: dataa,
        success: function(res) {

          let {status,code,datas,msg,redirect} = JSON.parse(res);

          if(status == 'success'){
            location.href = redirect;
          }
          else
          {
            alert(msg);
          }
          
          jQuery('#nbm_preg_form_btn').prop('disabled', false);
          jQuery('#nbm_preg_form_btn').val('Submit');
          jQuery('#nbm_preg_form_btn').css('background-color','#13328e');

          /*if (data == 'success') {
            alert('Thank you for your registration. An email will be sent to you shortly.');
            location.href="https://www.mummysmarket.com.sg";
            // location.href="https://www.mummysmarket.com.sg/thankyou_illume.html";
          } else {
            alert(data);
            jQuery('#nbm_preg_form_btn').prop('disabled',false);
            jQuery('#nbm_preg_form_btn').prop('value','Submit');
          } */
        },
        error: function(request, error){
          alert("Ajax error");
        }  
      });
    }
  });

  jQuery("#nbm_todd_form").submit(function(event) {
    event.preventDefault();
    let s_title   =   'pmw-toddler';
    let campaign  =   'pmw_toddler_sept_21';
    var f_name    =   jQuery('input[name=first_name]').val();
    var l_name    =   jQuery('input[name=last_name]').val();
    var dob       =   jQuery('input[name=dob]').val();
    var email     =   jQuery('input[name=email]').val();
    var phone     =   jQuery('input[name=phone]').val();
    var c_fname   =   jQuery('input[name=child_fname]').val();
    var c_lname   =   jQuery('input[name=child_lname]').val();
    var from      =   jQuery('input[name=from]').val();
    var brand_name  =   jQuery('select[name=brand_name] option').filter(':selected').val();
    var postal_code  =   jQuery('input[name=postal_code]').val();
    var address_1  =   jQuery('input[name=unit_number]').val();
    var address_2  =   jQuery('input[name=address]').val();
    let tnc_1     = jQuery('#check_1').val();
    //let tnc_2     = jQuery('#check_2').val();
    let tnc_2     = jQuery('#check_4').val();

    let name_regex = /^([a-zA-Z]+\s*)+$/;
    if (!name_regex.test(f_name) || !name_regex.test(l_name) || !name_regex.test(c_fname) || !name_regex.test(c_lname)) {
      alert('Name should not contain symbols.');
      jQuery('#nbm_todd_form_btn').prop('disabled', false);
      jQuery('#nbm_todd_form_btn').val('Submit');
      jQuery('#nbm_todd_form_btn').css('background-color','#13328e');
      return;
    }

    if (f_name == '' || l_name=='') {
      alert("Please enter your name.");
      return false;
    }
    else if (!ValidateEmail(jQuery('#email').val())) {
      var email = jQuery('#email').val();
      alert(email + " is Invalid email address.");
      return false;
    } 
    else if (phone.length != 8) {
      alert("Please enter 8 digit mobile number.");
      return false;
    }
    else if (phone.charAt(0) != 8 && phone.charAt(0) != 9) {
      alert("Enter 8 Digit Singapore Mobile Number.");
      return false;
    }
    else if (postal_code == '') 
    {
      alert("Please enter postal code.");
      return false;
    }
    else if (address_2 == '') 
    {
      alert("Please enter your address.");
      return false;
    }
    if (c_fname == '' || c_lname=='') {
      alert("Please enter your Youngest child's name.");
      return false;
    }
    else if (dob == '') {
      alert("Please enter your Youngest child's Date of Birth.");
      return false;
    }
    else if(brand_name == '')
    {
      alert("Please select your Youngest child's current formaula milk brand .");
      return false;
    }
    else {
      jQuery('#nbm_todd_form_btn').prop('disabled',true);
      jQuery('#nbm_todd_form_btn').prop('value','Processing...');

      let dataa = {
        s_title:s_title,
        campaign:campaign,
        name:f_name+' '+l_name,
        email:email,
        phone:phone,
        dob:dob,
        child_fname:c_fname,
        child_lname:c_lname,
        brand_name:brand_name,
        address_1:address_1,
        address_2:address_2,
        postal_code:postal_code,
        tnc_1:tnc_1,
        tnc_2:tnc_2
      };

      jQuery.ajax({
        type: "POST",
        url: "https://www.mummysmarket.com.sg/index.php?option=com_brand&view=online_toddler_seminar_registration&format=raw",
        data: dataa,
        success: function(res) {

          let {status,code,datas,msg,redirect} = JSON.parse(res);

          if(status == 'success'){
            location.href = redirect;
          }
          else
          {
            alert(msg);
          }
          
          jQuery('#nbm_todd_form_btn').prop('disabled', false);
          jQuery('#nbm_todd_form_btn').val('Submit');
          jQuery('#nbm_todd_form_btn').css('background-color','#13328e');

          /*if (data == 'success') {
            alert('Thank you for your registration. An email will be sent to you shortly.');
            location.href="https://www.mummysmarket.com.sg";
            // location.href="https://www.mummysmarket.com.sg/thankyou_illume.html";
          } else {
            alert(data);
            jQuery('#nbm_todd_form_btn').prop('disabled',false);
            jQuery('#nbm_todd_form_btn').prop('value','Submit');
          } */
        },
        error: function(request, error){
          alert("Ajax error");
        }  
      });
    }
  });



  $("#form_ptp_reg").submit(function(event) {
    event.preventDefault();
    $.ajax({
      type: "POST",
      url: "index.php?option=com_brand&view=ptpregistration&format=raw",
      data: $("#form_ptp_reg").serialize(),
      success: function(response) {
        console.log(response);
        // let json = JSON.parse(response);
        // console.log(json.data);
        // let data = json.data;

        var data = response;

        if (data == 'success') {
          alert('Thank you, You are successfully registered.');
          location.href = "https://mummysmarket.com.sg/thankyouptp.html";
        } else if (data == 'error') {
          alert('Something went wrong. Please try later.')
        } else if (data == 'invalid_form') {
          alert('Form not completed.')
        } else if (data == 'invalid_email') {
          alert('Invalid email address.')
        } else if (data == 'exist') {
          alert('Sorry! You are already registered.')
        } else {
          alert('You have encountered an error.')
        }
      }
    });
  });

  jQuery(".bl_dfform #userinfo_form").submit(function(event) {
    event.preventDefault();
    var check_status = jQuery('#userinfo_form input[name="status_code"]').val();

    if (!ValidateEmail(jQuery('#userinfo_form input[name="email"]').val())) {
      alert("Invalid email address.");
    } else {

      if (check_status == 200) {
        jQuery.ajax({
          type: "POST",
          url: "index.php?option=com_starbuy_slash&view=userinfo&format=raw",
          data: jQuery(".bl_dfform #userinfo_form").serialize(),
          success: function(data) {
            //console.log('==-->',data);
            if (data == 'success') {
              alert('Thank you for submitting! Your Toddler Goodie Bag will be delivered to you soon!');
              location.href = "https://www.mummysmarket.com.sg/";
            } else if (data == 'error') {
              alert('Something went wrong. Please try later.')
            } else if (data == 'invalid_email') {
              alert('Please enter valid EmailId.')
            } 
            else if(data=='freebies_exist')
            {
              alert('Your phone number were not found in the freebies registration, please put in the same phone number that you have registered with to Submit! \nThank you!');
            }
            else if(data=='exist') {
              alert('Sorry! You already updated your details.');
            }
            else {
              alert('Something went wrong. \nPlease contact administrator');
            }
          }
        });
      } else {
        alert('Please enter only local address');
      }
    }
  });

  jQuery(".open_subscribe").on('click', function() {
    var web_sub = jQuery('[data-remodal-id=web_subscribe]').remodal();
    web_sub.open();
  });

  jQuery("#web_sub_form").submit(function(event) {
    event.preventDefault();
    if (!ValidateEmail(jQuery('#wsubscribe_email').val())) {
      var email = jQuery('#wsubscribe_email').val();
      alert(email + " is Invalid email address.");
    } else {
      jQuery.ajax({
        type: "POST",
        url: "https://www.mummysmarket.com.sg/index.php?option=com_brand&view=web_subscribe&format=raw",
        data: jQuery("#web_sub_form").serialize(),
        success: function(data) {
          //console.log('==-->',data);
          if (data == 'success') {
            alert('Thank you for subscribe with us!');
            jQuery('.remodal-close').click();
          } else if (data == 'error') {
            alert('Something went wrong. Please try later.')
          } else if (data == 'invalid_email') {
            alert('Please enter valid email address.')
          } else if (data == 'exist') {
            alert('Opps! You have already subscribed.')
            jQuery('.remodal-close').click();
          }
        }
      });
    }
  });

    jQuery( ".voucher_pop" ).on('click',function(){
     var vend_off =  jQuery('[data-remodal-id=vendor_off]').remodal();
  vend_off.open();
    });

  jQuery( ".mmcoupon_pop" ).on('click',function(){
     jQuery('.closebtn').click();
      var vend_off =  jQuery('[data-remodal-id=freebies]').remodal();
      vend_off.open();
    });
 //mm-promo-code
  // jQuery( ".get_category_lists" ).on('click','.sppb-img-responsive',function(){
  //    jQuery('.closebtn').click();
  //    var popup_category =  jQuery('[data-remodal-id=popup_category]').remodal();
  //     popup_category.open();
  //   });

    jQuery( ".eb_regg" ).on('click',function(){
     jQuery('.closebtn').click();
     var popup_category =  jQuery('[data-remodal-id=earlybird_register]').remodal();
      popup_category.open();
    });

  jQuery( ".get_category_lists" ).on('click','.sppb-img-responsive',function(){
      var cat_name = jQuery(this).attr('alt');
      if(cat_name!='')
      {
        jQuery.ajax({
          type: "POST",
          url: path + "index.php?option=com_brand&view=get_category_lists&format=raw",
          data: {category_name: cat_name},
          success: function(data) {
              var result = JSON.parse(data);
              var cat_data = result.cate;
              if(cat_data.length > 0)
              {     
                    var html = '<h1>'+result.title+'</h1>';
                    for (var i = 0; i < cat_data.length ; i++) {
                      html +='<div class="col-md-3 col-xs-4 col-sm-4 retail_category_img">';
                      html +='<a href="https://www.mummysmarket.com.sg/onlinebabyfair?s_cat='+cat_data[i].link+'" class="cat_img_cover">';
                      html +='<img src="https://www.mummysmarket.com.sg/images/home/retail_category/'+cat_name+'/'+cat_data[i].image+'" width="100%">';
                      html +='<span class="cat_name">'+cat_data[i].name+'</span>';
                      html +='</a>';
                      html +='</div>';
                    }
                jQuery('#load_category').html(html);
                setTimeout(function() {
                jQuery('.closebtn').click();
                var popup_category =  jQuery('[data-remodal-id=popup_category]').remodal();
                popup_category.open();
                }, 300);
              }

          }
        });
      }

  });

  jQuery(".get_subscribe").on('click', function() {
    var img = jQuery(this).attr('data-img');
    var pname = jQuery(this).attr('data-pname');
    var pid = jQuery(this).attr('data-id');
    jQuery('#prod_notify_image').attr('src', img);
    jQuery('#prod_name').text(pname);
    jQuery('#prod_sub_name').val(pname);
    jQuery('#prod_sub_id').val(pid);

    var prob_sub = jQuery('[data-remodal-id=product_subscribe]').remodal();
    prob_sub.open();
  });

  jQuery("#prod_sub_form").submit(function(event) {
    event.preventDefault();
    if (!ValidateEmail(jQuery('#psubscribe_email').val())) {
      var email = jQuery('#psubscribe_email').val();
      alert(email + " is Invalid email address.");
    } else {
      jQuery.ajax({
        type: "POST",
        url: path + "index.php?option=com_brand&view=product_subscribe&format=raw",
        data: jQuery("#prod_sub_form").serialize(),
        success: function(data) {
          //console.log('==-->',data);
          if (data == 'success') {
            alert('Thank you! We notify you asap!');
          } else if (data == 'error') {
            alert('Something went wrong. Please try later.')
          } else if (data == 'invalid_email') {
            alert('Please enter valid email address.')
          } else if (data == 'exist') {
            alert('Opps! You have already subscribed this product.')
          }
        }
      });
    }
  });

  jQuery("#offer_form").submit(function(event) {
    event.preventDefault();
    if (!ValidateEmail(jQuery('#vsubscribe_email').val())) {
      var email = jQuery('#vsubscribe_email').val();
      alert(email + " is Invalid email address.");
    } else {
      jQuery.ajax({
        type: "POST",
        url: "index.php?option=com_brand&view=voucher_subscribe&format=raw",
        data: jQuery("#offer_form").serialize(),
        success: function(data) {
          //console.log('==-->',data);
          if (data == 'success') {
            alert('Thank you for subscribing with us!');
            var vend_off_code = jQuery('[data-remodal-id=vendor_offcode]').remodal();
            vend_off_code.open();
          } else if (data == 'error') {
            alert('Something went wrong. Please try later.')
          } else if (data == 'invalid_email') {
            alert('Please enter valid email address.')
          } else if (data == 'exist') {
            alert('Opps! You have already subscribed.')
          }
        }
      });
    }
  });

  if (typeof YOUTUBE_VIDEO_MARGIN == 'undefined') {
    YOUTUBE_VIDEO_MARGIN = 5;
  }

  jQuery('.videoWrapper iframe').each(function(index, item) {

    var w = $(item).attr('width');
    var h = $(item).attr('height');
    var ar = h / w * 100;
    ar = ar.toFixed(2);

    //Style iframe    
    $(item).css('position', 'absolute');
    $(item).css('top', '0');
    $(item).css('left', '0');
    $(item).css('width', '100%');
    $(item).css('height', '100%');
    $(item).css('max-width', w + 'px');
    $(item).css('max-height', h + 'px');
    $(item).wrap('<div style="max-width:' + w + 'px;margin:10px auto; padding:' + YOUTUBE_VIDEO_MARGIN + 'px;" />');
    $(item).wrap('<div style="position: relative;padding-bottom: ' + ar + '%; height: 0; overflow: hidden;" />');

  });
  jQuery("#tabs-trending, #tabs-latest").hide();


});

function scrollToAnchor(aid) {
  var aTag = $("a[name='" + aid + "']");
  jQuery('html,body').animate({ scrollTop: aTag.offset().top }, 'slow');
}

function ValidateEmail(email) {
  var expr = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
  return expr.test(email);
};

jQuery(window).scroll(function() {
  // jQuery( '#tabs .scrollableArea' ).css( "width", "1800px" );
  // jQuery( '#clearance_container .scrollableArea' ).css( "width", "1170px" );

});

function openQRCamera(node) {
  var reader = new FileReader();
  reader.onload = function() {
    node.value = "";
    qrcode.callback = function(res) {
      if (res instanceof Error) {
        alert("No QR code found. Please make sure the QR code is within the camera's frame and try again.");
      } else {
        node.parentNode.previousElementSibling.value = res;
      }
    };
    qrcode.decode(reader.result);
  };
  reader.readAsDataURL(node.files[0]);
};

jQuery('.product_search').on('click', function() {
  search_product()
});

function search_product() {

  var filter_mode = jQuery("#filter_mode").val();
  if (filter_mode == '') {
    filter_mode = jQuery("#filter_mode_mob").val();
  }
  var s_cat = jQuery("#s_cat").val();
  if (s_cat == '') {
    s_cat = jQuery("#s_cat_mob").val();
  }
  var s_search = jQuery("#s_search").val();
  if (s_search == '') {
    s_search = jQuery("#s_search_mob").val();
  }
  jQuery.ajax({
    url: path + "index.php?option=com_starbuy_slash&view=search_product&format=raw",
    dataType: 'json',
    data: {
      'filter_mode': filter_mode,
      's_cat': s_cat,
      's_search': s_search
    },
    type: 'post',
    success: function(data) {},
  });
}

window.setInterval(function(){
  var randomTextVal = localStorage.getItem('setRandText');
  var randText = [
    "Biggest Preorder Sale Starts 17 Mar, 12PM! Get Insane Offers <a href='https://www.mummysmarket.com.sg/expo-preorder-sale'><u><b>Here</b></u></a>!",
    "Download our app to stay updated on upcoming fairs and enjoy more freebies. <a href='https://www.mummysmarket.com.sg/download-app'><b>Click here to download</b></a>!",
    // "Walk in & visit us instore for a full parenthood shopping experience! Open Daily 11am to 9pm. More about our store <a href='https://www.mummysmarket.com.sg/first-retail-store'><b>HERE</b></a>!",
    //"Shop Preorder Sale <a href='https://www.mummysmarket.com.sg/expo-preorder-sale' target='_blank'><u><b>Here</b></u></a>! Ends 8 Dec",
    //"Biggest Baby Fair in Southeast Asia starts 10-12 Jan @ Expo (Opens 11am) <a href='https://www.mummysmarket.com.sg/expo-starbuy-sale' target='_blank'><b>Browse Hottest Starbuy and Wishlist Now</b></a><b>!</b>",
    //"<a href='https://www.mummysmarket.com.sg/retail-x-atrium-sale'><b>Save Big at Prosperity Baby Fair 2024 Retail X Atrium Sale @ Suntec Tower 4 from 19 to 25 Feb</b></a>"
    ]; 
  var textlen   = Math.floor(Math.random()*randText.length);
  var random_text = randText[textlen];
  if(randomTextVal==random_text)
  {
    var result = randText.filter(function(elem){
    return elem != random_text; 
    });
    var textlen   = Math.floor(Math.random()*result.length);
    var random_text = result[textlen];
  }
  jQuery('.top_header_info').html(random_text);
  localStorage.setItem('setRandText', random_text);
}, 3000);

localStorage.setItem('setOrgTitle',jQuery(document).attr('title'))
var org_title     =   localStorage.getItem('setOrgTitle') ;
var title_arr       =   [];
var chk_cart_count    = jQuery('.cart_count').text();

window.setInterval(function(){
  var setRandTitle  =   localStorage.getItem('setRandTitle');
  var cart_count    = jQuery('.cart_count').text();
  if(cart_count!='0')
  {
    var cart_text     = '('+cart_count+') You left something behind!';
    var title_arr     =   [cart_text] 
    title_arr.push(org_title);
    var textlen   = Math.floor(Math.random()*title_arr.length);
    var random_title = title_arr[textlen];
    if(setRandTitle==random_title)
    {
      var result = title_arr.filter(function(elem){
       return elem != random_title; 
      });
      var textlen   = Math.floor(Math.random()*result.length);
      var random_title = result[textlen];
    }
    document.title = random_title;
    localStorage.setItem('setRandTitle', random_title);
  }
}, 1500);

/* STAR RATING SCRIPT */

jQuery(document).ready(function(){
  /* 1. Visualizing things on Hover - See next part for action on click */
  jQuery('#stars li').on('mouseover', function(){
    var onStar = parseInt(jQuery(this).data('value'), 10); // The star currently mouse on
   
    // Now highlight all the stars that's not after the current hovered star
    jQuery(this).parent().children('li.star').each(function(e){
      if (e < onStar) {
        jQuery(this).addClass('hover');
      }
      else {
        jQuery(this).removeClass('hover');
      }
    });
    
  }).on('mouseout', function(){
    jQuery(this).parent().children('li.star').each(function(e){
      jQuery(this).removeClass('hover');
    });
  });
  
  
  /* 2. Action to perform on click */
  jQuery('#stars li').on('click', function(){
    var onStar = parseInt(jQuery(this).data('value'), 10); // The star currently selected
    var stars = jQuery(this).parent().children('li.star');
    
    for (i = 0; i < stars.length; i++) {
      jQuery(stars[i]).removeClass('selected');
    }
    
    for (i = 0; i < onStar; i++) {
      jQuery(stars[i]).addClass('selected');
    }
    
    // JUST RESPONSE (Not needed)
    var ratingValue = parseInt(jQuery('#stars li.selected').last().data('value'), 10);
    var msg = "";
    jQuery('.success-box').css('display','flex');
    if (ratingValue > 3) {
        msg = "Thank you, You rated " + ratingValue + " stars. Do share about us with your friend's & family";
        jQuery('.customer_review_inputs').css('display','none');
        jQuery('.customer_share_experience').css('display','block');
    }
    else {
        msg = "Thank you, please tell us how we can improve your shopping experience.";
        jQuery('.customer_share_experience').css('display','none');
        jQuery('.customer_review_inputs').css('display','block');
    }

    jQuery.ajax({
      url: path + "index.php?option=com_starbuy_slash&view=customer_rating&format=raw",
      dataType: 'json',
      data: {
        'ratingValue': ratingValue
      },
      type: 'post',
      success: function(data) {
        
         if(data.status == 'success')
         {

              jQuery('#rating_state').css('display','block');
              jQuery('#rating_state').attr('src','images/scc.png');
              responseMessage(msg);
         }
         else
         {
              jQuery('#rating_state').css('display','block');
              jQuery('#rating_state').attr('src','images/err.png');
              responseMessage(data.msg);
         }
      },
    });
    
  });
  
  
});

function responseMessage(msg) {
  jQuery('.success-box').fadeIn(200);  
  jQuery('.success-box div.text-message').html("<span>" + msg + "</span>");
}


jQuery('.check_box_master').on('click', function(){
  var master_id = jQuery(this).attr('id');
  var checkbox = jQuery(this).is(':checked');
  if(checkbox)
  {
    jQuery('#'+master_id+'_1').css('display','block');
  }
  else
  {
    jQuery('#'+master_id+'_1').css('display','none');
  }

});

jQuery('#review-submit-btn').on('click', function(){
  jQuery('#review-submit-btn').prop('disabled',true);
  jQuery.ajax({
    url: path + "index.php?option=com_starbuy_slash&view=customer_reviews&format=raw",
    dataType: 'json',
    data: jQuery("#customer_review_form").serialize(),
    type: 'post',
    success: function(data) {
     
      responseMessage(data.msg);
      alert(data.msg);
      if(data.status == 'error')
      {
          jQuery('#rating_state').attr('src','images/err.png');
          jQuery('#review-submit-btn').prop('disabled',false);
      }
      else
      {
         jQuery('#rating_state').attr('src','images/scc.png');
         location.href='https://www.mummysmarket.com.sg/';
      }
     

    },
  });
});

jQuery('.mm_share').on('click',function(){

  var data_val = jQuery(this).attr('data-val');

  if(data_val=='mm_fbshare')
  {
      auto_trigger_fb_pixel('mm_fbshare');
  }
  else if(data_val=='whatsapp_share')
  {
      auto_trigger_fb_pixel('mm_whatsapp_share');
  }

});

function auto_trigger_fb_pixel(track_text) {
    if(track_text!='')
    {
        console.log(track_text);
      try {
          //FB Pixels
          fbq('track', track_text,
          {
            content_name: track_text+'_count',
            status: 1
          }
          );
      }
       catch (err) {
        setTimeout(function () { trigger_fb_pixel(); }, 3000);
        
      }
    }
}
