function OnChangePrice(attr_id,pid,type){
  
  $.ajax({
     url:"fetch_attr_data.php",
     method:"POST",
     dataType:"json",
     data:{attr_id:attr_id},
     success:function(data)
     {
     
      $('#'+type+'_mrp'+pid).html("₹"+data.mrp);
      $('#'+type+'_sale_price'+pid).text("₹"+data.sale_price);

      var percent = Math.round(((data.mrp - data.sale_price)*100) /data.mrp,0)+"%";
      $('#'+type+'_precentage'+pid).text(percent);

      $('#'+type+'_price'+pid).val(data.sale_price);
      $('#'+type+'_attr_id'+pid).val(data.id);
      // $('.badge').text(data.total_item);
     }
    });
}





$(document).ready(function(){

  load_cart_data();

  function load_cart_data()
  {

    $.ajax({
     url:"fetch_cart.php",
     method:"POST",
     dataType:"json",
     success:function(data)
     {
      // console.log(data);
      $('#cart_details').html(data.cart_details);
      $('.total_price').text(data.total_price);
      $('.badge').text(data.total_item);
      $('#left_cart_item').text('('+data.total_item+' items)');
     }
    });
  }

  $(document).on('click', '.new_arival_add_to_cart', function(){
          
          var product_id = $(this).attr("id");
          
          var product_name = $('#new_arival_name'+product_id).val();
          var product_price = $('#new_arival_price'+product_id).val();
          var product_mrp = $('#new_arival_mrp'+product_id).val();
          var product_quantity = $('#new_arival_quantity'+product_id).val();
          var action = "add";
          
          if(product_quantity > 0)
          {
            // alert(product_id);
           $.ajax({
            url:"add_to_cart.php",
            method:"POST",
            data:{product_id:product_id, product_name:product_name, product_price:product_price,product_mrp:product_mrp,product_quantity:product_quantity, action:action},
            success:function(data)
            {
             load_cart_data();
             toastr.optionsOverride = 'positionclass = "toast-bottom-left"';
             toastr.options.positionClass = 'toast-bottom-left';
             toastr.success('Item has been Added into Cart..!');
             
             $('#view_cart'+product_id).css('display','inline-block');
             
            }
           });
          }
          else
          {
           alert("Please Enter Number of Quantity");
          }
   });


  $(document).on('click', '.best_seller_add_to_cart', function(){
          
          var product_id = $(this).attr("id");
          
          var product_name = $('#best_seller_name'+product_id).val();
          var product_price = $('#best_seller_price'+product_id).val();
          var product_mrp = $('#best_seller_mrp'+product_id).val();
          var product_quantity = $('#best_seller_quantity'+product_id).val();
          var action = "add";
          
          if(product_quantity > 0)
          {
            // alert(product_id);
           $.ajax({
            url:"add_to_cart.php",
            method:"POST",
            data:{product_id:product_id, product_name:product_name, product_price:product_price,product_mrp:product_mrp,product_quantity:product_quantity, action:action},
            success:function(data)
            {
             load_cart_data();
             toastr.optionsOverride = 'positionclass = "toast-bottom-left"';
             toastr.options.positionClass = 'toast-bottom-left';
             toastr.success('Item has been Added into Cart..!');
             
             $('#view_cart'+product_id).css('display','inline-block');
             
            }
           });
          }
          else
          {
           alert("Please Enter Number of Quantity");
          }
   });

  $(document).on('click', '.featured_add_to_cart', function(){
          
          var product_id = $(this).attr("id");
          
          var product_name = $('#featured_name'+product_id).val();
          var product_price = $('#featured_price'+product_id).val();
          var product_mrp = $('#featured_mrp'+product_id).val();
          var product_quantity = $('#featured_quantity'+product_id).val();
          var action = "add";
          
          if(product_quantity > 0)
          {
            // alert(product_id);
           $.ajax({
            url:"add_to_cart.php",
            method:"POST",
            data:{product_id:product_id, product_name:product_name, product_price:product_price,product_mrp:product_mrp,product_quantity:product_quantity, action:action},
            success:function(data)
            {
             load_cart_data();
             toastr.optionsOverride = 'positionclass = "toast-bottom-left"';
             toastr.options.positionClass = 'toast-bottom-left';
             toastr.success('Item has been Added into Cart..!');
             
             $('#view_cart'+product_id).css('display','inline-block');
             
            }
           });
          }
          else
          {
           alert("Please Enter Number of Quantity");
          }
   });

  $(document).on('click', '.sales_add_to_cart', function(){
          
          var product_id = $(this).attr("id");
          
          var product_name = $('#sales_name'+product_id).val();
          var product_price = $('#sales_price'+product_id).val();
          var product_mrp = $('#sales_mrp'+product_id).val();
          var product_quantity = $('#sales_quantity'+product_id).val();
          var action = "add";
          
          if(product_quantity > 0)
          {
            // alert(product_id);
           $.ajax({
            url:"add_to_cart.php",
            method:"POST",
            data:{product_id:product_id, product_name:product_name, product_price:product_price,product_mrp:product_mrp,product_quantity:product_quantity, action:action},
            success:function(data)
            {
             load_cart_data();
             toastr.optionsOverride = 'positionclass = "toast-bottom-left"';
             toastr.options.positionClass = 'toast-bottom-left';
             toastr.success('Item has been Added into Cart..!');
             
             $('#view_cart'+product_id).css('display','inline-block');
             
            }
           });
          }
          else
          {
           alert("Please Enter Number of Quantity");
          }
   });


  $(document).on('click', '.relatedproduct_add_to_cart', function(){
          
          var product_id = $(this).attr("id");
          
          var product_name = $('#relatedproduct_name'+product_id).val();
          var product_price = $('#relatedproduct_price'+product_id).val();
          var product_mrp = $('#relatedproduct_mrp'+product_id).val();
          var product_quantity = $('#relatedproduct_quantity'+product_id).val();
          var action = "add";
          
          if(product_quantity > 0)
          {
            // alert(product_id);
           $.ajax({
            url:"add_to_cart.php",
            method:"POST",
            data:{product_id:product_id, product_name:product_name, product_price:product_price,product_mrp:product_mrp,product_quantity:product_quantity, action:action},
            success:function(data)
            {
             load_cart_data();
             toastr.optionsOverride = 'positionclass = "toast-bottom-left"';
             toastr.options.positionClass = 'toast-bottom-left';
             toastr.success('Item has been Added into Cart..!');
             
             $('#view_cart'+product_id).css('display','inline-block');
             
            }
           });
          }
          else
          {
           alert("Please Enter Number of Quantity");
          }
   });


  // $(document).on('click', '.top_selling_add_to_cart', function(){
  //        var product_id = $(this).attr("id");
  //         var attr_id = $('#top_selling_attr_id'+product_id).val();
  //         var product_name = $('#top_selling_name'+product_id).val();
  //         var product_price = $('#top_selling_price'+product_id).val();
  //         var product_quantity = $('#top_selling_quantity'+product_id).val();
  //         var action = "add";
          
  //         if(product_quantity > 0)
  //         {
  //           // alert(product_id);
  //          $.ajax({
  //           url:"add_to_cart.php",
  //           method:"POST",
  //           data:{product_id:product_id,attr_id:attr_id, product_name:product_name, product_price:product_price, product_quantity:product_quantity, action:action},
  //           success:function(data)
  //           {
  //             load_cart_data();
  //            toastr.optionsOverride = 'positionclass = "toast-bottom-left"';
  //            toastr.options.positionClass = 'toast-bottom-left';
  //            toastr.success('Item has been Added into Cart..!');
  //            $('#view_cart_top_selling'+product_id).css('display','inline-block');
  //           }
  //          });
  //         }
  //         else
  //         {
  //          alert("Please Enter Number of Quantity");
  //         }
  //   });

  $(document).on('click', '.delete', function(){
      // alert();
      var product_id = $(this).attr("id");
      var action = 'remove';
       $('#loader').show();
       $.ajax({
        url:"remove_product.php",
        method:"POST",
        data:{product_id:product_id, action:action},
        success:function()
        {
         load_cart_data();
         $('#loader').hide();
         toastr.optionsOverride = 'positionclass = "toast-bottom-left"';
          toastr.options.positionClass = 'toast-bottom-left';
           toastr.error('Item has been Remove from Cart..!');
         //$('#cart-popover').popover('hide');
         
        }
       })
   });



});
 

$(document).ready(function (e) {


  $(function() {      
      let isMobile = window.matchMedia("only screen and (max-width: 760px)").matches;

      if (isMobile) {
        $('#collapseExample').removeClass('show');
        $('#collapseExample').addClass('hide');
      }else{
        $('#collapseExample').addClass('show');
        $('#collapseExample').removeClass('hide');
      }
   });

    $("#checkbtn").click(function(){
      
         if($('#collapseExample').hasClass('show')){
          // alert();
            $('#collapseExample').removeClass('show');
            $('#collapseExample').addClass('hide');
         }else{
          $('#collapseExample').addClass('show');
          $('#collapseExample').removeClass('hide');
         }
     });


    // $("#checkcouponlink").click(function(){
    //   alert();
      
    //      if($('.toogle_coupon').hasClass('coupon_hide')){
    //       // alert();
    //         $('.toogle_coupon').removeClass('coupon_hide');
    //         $('.toogle_coupon').addClass('coupon_show');
    //      }else{
    //       $('.toogle_coupon').addClass('coupon_hide');
    //       $('.toogle_coupon').removeClass('coupon_show');
    //      }
    //  });
         
});



let myCarousel = document.querySelectorAll('#featureContainer .carousel .carousel-item');
myCarousel.forEach((el) => {
  const minPerSlide =5
  let next = el.nextElementSibling
  for (var i=1; i<minPerSlide; i++) {
    if (!next) {
      // wrap carousel by using first child
      next = myCarousel[0]
    }
    let cloneChild = next.cloneNode(true)
    el.appendChild(cloneChild.children[0])
    next = next.nextElementSibling
  }
})