PHP 7.4.33
Preview: phonecart.js Size: 78.95 KB
/home/godevadmin/public_html/admin/js/phonecart.js

//---------- Init
updateMiniCart();
window.addEventListener('scroll', checkScroll);
//window.onscroll = function () { checkScroll() };
var header = document.getElementsByTagName("header")[0];
var sticky = header.offsetTop;
if (!window.location.href.includes('checkout')) {
    setCookie("cart_tab_store", "0");
    setCookie("cart_tab", "");
}
function checkScroll() {
    if (window.pageYOffset > sticky) {
        header.classList.add("sticky");
    } else {
        header.classList.remove("sticky");
    }
}
$(window).on("resize", function (event) {
    if ($(window).width() < 415)
        $('txtSearch').attr('placeholder', 'Search...');
    else
        $('txtSearch').attr('placeholder', 'Search for products...');
});
//---------- Common
var cartKey = 'cart_grocery';
function toggleInnerCart() {
    $('.clsMiniCart').toggleClass('active');
	updateMiniCart();
}
window.onclick = function (event) {
    if (event.target == document.getElementById('minicart')) {
        $('.clsMiniCart').removeClass('active');
    }
}
function getCartTotalByKey(key) {
	var member_discount=$('#memberdis').val();
	
    var items = 0;
    var qty = 0;
    var grandTotal = 0;
    var lstCart = [];
    var cart = window.localStorage.getItem(key);
    if (cart != null && cart != '') {
        lstCart = JSON.parse(cart);
        if (lstCart.length > 0) {
            items = lstCart.length;
            for (var i = 0; i < lstCart.length; i++) {
				if(member_discount > 0 && (lstCart[i].section=='grocery' || lstCart[i].section=='food')){
					var calp=getpriceaftermemberdiscount(lstCart[i].calcprice,member_discount);
					lstCart[i].total=(parseFloat(calp) * parseInt(lstCart[i].qty)).toFixed(2);
					
					
				}
				grandTotal += parseFloat(lstCart[i].total);
                qty += parseInt(lstCart[i].qty);
            }
        }
    }
    return [items, grandTotal, qty];
}
function checkStoreZip() {  //x3 (this, index, tiffin)
    if (getCookie('postalcode').trim() != '') {
        if (getCookie('postalcode').trim() != $('#zipcode').val().trim()) {
					
						var cookie_zipcode = getCookie('postalcode').trim();
						var current_zipcode = $('#zipcode').val().trim();
						
						var flgConfirm = changeZipcode(cookie_zipcode, current_zipcode);																				
						
						if(flgConfirm == true)
						{											
								$('#zipcode').val(current_zipcode);
						}
						return flgConfirm;
            
            /*var flgConfirm = confirm('Your cart will get clear on changing zipcode! Continue222?');
            if (flgConfirm)
                localStorage.clear();
            else
                $('#zipcode').val(getCookie('postalcode').trim());
            return flgConfirm;*/
        }
    }
    return true;
}
//---------- Minicart
var lastMiniSID = '';
function updateMiniCart() {
    var grocery = getCartTotalByKey('cart_grocery');
    var food = getCartTotalByKey('cart_food');
    var giftcard = getCartTotalByKey('cart_giftcard');
	var shefcart = getCartTotalByKey('cart_shef');
	var eventcart = getCartTotalByKey('cart_events');
    var netamt = $("#netamt").val(0);
    var netamtshef = $("#netamtshef").val(0);
    var totalItems = grocery[0] + food[0] + giftcard[0]+shefcart[0]+eventcart[0];
    var totalQty = grocery[2] + food[2] + giftcard[2]+shefcart[2]+eventcart[2];
	var quickllyitemcount=grocery[2] + food[2] + giftcard[2] + eventcart[2];;
    var shefitemcount = shefcart[2];
	var eventitemcount=eventcart[2];
	
    $('.clsCart2 span')[0].innerText = totalQty;
	 $('.mobilestickycart label')[0].innerText = totalQty;
    /*if (totalItems > 1)
        $('.clsCart3 span')[0].innerText = totalItems + ' items';
    else
        $('.clsCart3 span')[0].innerText = totalItems + ' item';*/
    // Clear            
    removeMiniStoreSlider();
    //$('.clsInnerCart .clsSlider a').remove();
    $('.clsInnerCart .clsCompleteCart').html('');
	$('.clsInnerCart .clsCompleteCartshef').html('');
    // Get updated data
    var lstCart = [];
    var cart = window.localStorage.getItem('cart_grocery');
    if (cart != null && cart != '')
        lstCart = JSON.parse(cart);
    cart = window.localStorage.getItem('cart_food');
    if (cart != null && cart != '') {
        var tmp = JSON.parse(cart);
        for (var i = 0; i < tmp.length; i++)
            lstCart.push(tmp[i]);
    }
    cart = window.localStorage.getItem('cart_giftcard');
    if (cart != null && cart != '') {
        var tmp = JSON.parse(cart);
        for (var i = 0; i < tmp.length; i++)
            lstCart.push(tmp[i]);
    }
	 cart = window.localStorage.getItem('cart_events');
    if (cart != null && cart != '') {
        var tmp = JSON.parse(cart);
        for (var i = 0; i < tmp.length; i++)
            lstCart.push(tmp[i]);
    }
	cart = window.localStorage.getItem('cart_shef');
    if (cart != null && cart != '') {
        var tmp = JSON.parse(cart);
        for (var i = 0; i < tmp.length; i++)
            lstCart.push(tmp[i]);
    }
    // Add data
    var lstStores = [];
    if (lstCart.length > 0) {
        for (var i = 0; i < lstCart.length; i++) {
            if (!lstStores.includes(lstCart[i].sid)) {
                lstStores.push(lstCart[i].sid);
                if(lstCart[i].section=='shef'){
					
                selectMiniStore(lstCart[i].sid, lstCart[i].sname);
				} else {
					
                var template = $('#tempMiniCart-Store').html();
                template = template.replace('[SID]', lstCart[i].sid);
                template = template.replace('[Name]', lstCart[i].sname);
                $('.clsInnerCart .clsSlider').append(template);
                   
                selectMiniStore(lstCart[i].sid, lstCart[i].sname);
				}
            }
        }
       /* if (lastMiniSID == '')
            selectMiniStore($('.clsInnerCart .clsSlider a:first-child')[0]);
        else {
            var mini_sore = $('.clsInnerCart .clsSlider a[data-sid=' + lastMiniSID + ']');
            if (mini_sore.length > 0)
                selectMiniStore(mini_sore[0]);
            else
                selectMiniStore($('.clsInnerCart .clsSlider a:first-child')[0]);
        }*/
       if(quickllyitemcount>0){
        $('#lnkProceedToCheckout').show();
		} else {
		$('#lnkProceedToCheckout').hide();	
		}
        $('#lblCartEmpty').hide();
        addMiniStoreSlider();
        
        //Update amount on proceed to checkout button
        var netamt = $("#netamt").val();
        var tempNew = $('#tmpChkOutBtn').html();
        tempNew = tempNew.replace('[NETAMOUNT]', parseFloat(netamt).toFixed(2));
        $('#lnkProceedToCheckout').html('');
				$('#lnkProceedToCheckout').append(tempNew);
		
		var netamtshef = $("#netamtshef").val();
		 var sheftempNew = $('#sheftmpChkOutBtn').html();
        sheftempNew = sheftempNew.replace('[NETAMOUNTSHEF]', parseFloat(netamtshef).toFixed(2));
        $('#lnkshefcheckout').html('');
				$('#lnkshefcheckout').append(sheftempNew);

        
    } else {
        $('#lnkProceedToCheckout').hide();
        $('#lblCartEmpty').show();
        $(".totalorderamountbystore").hide();
        $("#fdBtn").hide();
        //$('.clsInnerCart .clsMinOrderAmt').hide();
				//$('.clsInnerCart .totalorderamountbystore').hide();
        $('.clsInnerCart .clsCartProds .clsCartProd').remove();
    }
	if(quickllyitemcount >0 && shefitemcount>0){
		$("#fdBtn").hide();
		$('.tempcarthead').show();
		$('.allcartwrapper').addClass('active');
		$('#lnkshefcheckout').show();
	} else if(quickllyitemcount >0) {
		$('.allcartwrapper').removeClass('active');
		 $('.maincarthead').text('Quicklly Cart');
		 $('#lnkshefcheckout').hide();
		 $('.tempcarthead').hide();
		 $("#fdBtn").show();
	} else if(shefitemcount>0){
		$('.allcartwrapper').addClass('active');
		 $('.maincarthead').text('Shef Cart');
		 $('#lnkshefcheckout').show();
		 $('.tempcarthead').hide();
		  $("#fdBtn").hide();
	}  else {
		$('.allcartwrapper').addClass('active');
		$('.maincarthead').text('Quicklly Cart');
		$('#lnkshefcheckout').hide();
		$('.tempcarthead').hide();
		$("#fdBtn").hide();
	}
	if(quickllyitemcount==eventitemcount){
		$("#fdBtn").hide();
	}
}
function selectMiniStore(sid, sname) {
	
		lnkdatasetsid = sid
		lnkdatasetsname = sname
    lastMiniSID = lnkdatasetsid;
	
	var memberminorderamount = 0;
    //$('.clsInnerCart .clsSlider a').removeClass('active');
    //$(lnk).addClass('active');
    // Get updated data
    $('#tempStoreProd .clsCartStores .clsCartStoreTemp').remove();
    $('#tempStoreProd .clsCartProds .clsCartProd').remove();
	$('#sheftempStoreProd .clsCartStores .clsCartStoreTemp').remove();
    $('#sheftempStoreProd .clsshefCartProds').html('')
    var minorderAmt = '';
	var storeAmt = 0.00;
		var netamt = $("#netamt").val();
		var storePic = [];
    var hasProd = false;
    var lstCart = [];
	var netamtshef = $("#netamtshef").val();
		var shefstoreAmt=0.00;
		var shefstorePic = [];
        
    var cart = window.localStorage.getItem('cart_grocery');
    if (cart != null && cart != '') {
        lstCart = JSON.parse(cart);
        if (lstCart.length > 0) {
            for (var i = 0; i < lstCart.length; i++) {
                if (lstCart[i].sid == lnkdatasetsid) {
                    hasProd = true;
                    if (lstCart[i].minorder != undefined)
                        minorderAmt = lstCart[i].minorder;
					
										storePic[lstCart[i].sname] = lstCart[i].simg;
					 storeAmt=(parseFloat(storeAmt)+ parseFloat(lstCart[i].total)).toFixed(2);
                    var template = $('#tempMiniCart-Prod').html();
                    template = template.replace('images/quicly-logo-black.png', lstCart[i].photo);
                    template = template.replace('[Name1]', lstCart[i].name);
                    template = template.replace('[Name2]', ucwords(lstCart[i].name));
                    
                    if(lstCart[i].price != undefined)
                    template = template.replace('[UnitPrice]', lstCart[i].price);
                    else
                    template = template.replace('[UnitPrice]', lstCart[i].calcprice);
                    
                    template = template.replace('[Price]', lstCart[i].total);
                    template = template.replace('[i]', i);
                    template = template.replace('[Key]', 'cart_grocery');
                    template = template.replace('[i1]', i);
                    template = template.replace('[Key1]', 'cart_grocery');
                    template = template.replace('[i2]', i);
                    template = template.replace('[Key2]', 'cart_grocery');
					template = template.replace('[Key3]', 'cart_grocery');
                    template = template.replace('[k]', i);
                    template = template.replace('[KeyR]', 'cart_grocery');
                    template = template.replace('[qty]', lstCart[i].qty);
                    template = template.replace('[qty]', lstCart[i].qty);
                    template = template.replace('[pid]', lstCart[i].pid);
                    template = template.replace('[pid]', lstCart[i].pid);
                    template = template.replace('[pid]', lstCart[i].pid);
                    template = template.replace('[pid]', lstCart[i].pid);
                    template = template.replace('[pid2]', lstCart[i].pid);
                    if (lstCart[i].remarks != null && lstCart[i].remarks.trim() != '')
                        template = template.replace('[Remarks]', lstCart[i].remarks);
                    else
                        template = template.replace('[Remarks]', '');
					
					if (lstCart[i].subscriptiontype != null && lstCart[i].subscriptiontype.trim() != '')
                        template = template.replace('[sub]', lstCart[i].subscriptiontype);
                    else
                        template = template.replace('[sub]', '');
                    template = template.replace('[pid]', lstCart[i].pid);
                    $('#tempStoreProd .clsCartProds').append(template);
                   
                    
                }
            }
        }
    }
    lstCart = [];
    cart = window.localStorage.getItem('cart_food');
    if (cart != null && cart != '') {
        lstCart = JSON.parse(cart);
        if (lstCart.length > 0) {
            for (var i = 0; i < lstCart.length; i++) {
                if (lstCart[i].sid == lnkdatasetsid) {
                    hasProd = true;
                    if (lstCart[i].minorder != undefined)
                        minorderAmt = lstCart[i].minorder;
                        
                    storePic[lstCart[i].sname] = lstCart[i].simg;
					    storeAmt=(parseFloat(storeAmt)+ parseFloat(lstCart[i].total)).toFixed(2);
                    var template = $('#tempMiniCart-Prod').html();
                    template = template.replace('images/quicly-logo-black.png', lstCart[i].photo);
                    template = template.replace('[Name1]', lstCart[i].name);
                    template = template.replace('[Name2]', ucwords(lstCart[i].name));
                    if(lstCart[i].price != undefined)
                    template = template.replace('[UnitPrice]', lstCart[i].price);
                    else
                    template = template.replace('[UnitPrice]', lstCart[i].calcprice);
                    template = template.replace('[Price]', lstCart[i].total);
                    template = template.replace('[i]', i);
                    template = template.replace('[Key]', 'cart_food');
                    template = template.replace('[i1]', i);
                    template = template.replace('[Key1]', 'cart_food');
                    template = template.replace('[i2]', i);
                    template = template.replace('[Key2]', 'cart_food');
					template = template.replace('[Key3]', 'cart_food');
                    template = template.replace('[k]', i);
                    template = template.replace('[KeyR]', 'cart_food');
                    template = template.replace('[qty]', lstCart[i].qty);
                    
                    template = template.replace('[pid2]', lstCart[i].pid);
                    if (lstCart[i].remarks != null && lstCart[i].remarks.trim() != '')
                        template = template.replace('[Remarks]', lstCart[i].remarks);
                    else
                        template = template.replace('[Remarks]', '');
						
						
					if (lstCart[i].subscriptiontype != null && lstCart[i].subscriptiontype.trim() != '')
                        template = template.replace('[sub]', lstCart[i].subscriptiontype);
                    else
                        template = template.replace('[sub]', '');
                    $('#tempStoreProd .clsCartProds').append(template);
                }
            }
        }
    }
        lstCart = [];
    cart = window.localStorage.getItem('cart_events');
    if (cart != null && cart != '') {
        lstCart = JSON.parse(cart);
        if (lstCart.length > 0) {
            for (var i = 0; i < lstCart.length; i++) {
                if (lstCart[i].sid == lnkdatasetsid) {
                    hasProd = true;
                    if (lstCart[i].minorder != undefined)
                        minorderAmt = lstCart[i].minorder;
                        
                    storePic[lstCart[i].sname] = lstCart[i].simg;
					    storeAmt=(parseFloat(storeAmt)+ parseFloat(lstCart[i].total)).toFixed(2);
                    var template = $('#tempMiniCart-Prod').html();
                    template = template.replace('images/quicly-logo-black.png', lstCart[i].photo);
                    template = template.replace('[Name1]', lstCart[i].name);
                    template = template.replace('[Name2]', ucwords(lstCart[i].name));
                    if(lstCart[i].price != undefined)
                    template = template.replace('[UnitPrice]', lstCart[i].price);
                    else
                    template = template.replace('[UnitPrice]', lstCart[i].calcprice);
                    template = template.replace('[Price]', lstCart[i].total);
                    template = template.replace('[i]', i);
                    template = template.replace('[Key]', 'cart_events');
                    template = template.replace('[i1]', i);
                    template = template.replace('[Key1]', 'cart_events');
                    template = template.replace('[i2]', i);
                    template = template.replace('[Key2]', 'cart_events');
					template = template.replace('[Key3]', 'cart_events');
                    template = template.replace('[k]', i);
                    template = template.replace('[KeyR]', 'cart_events');
                    template = template.replace('[qty]', lstCart[i].qty);
                    
                    template = template.replace('[pid2]', lstCart[i].pid);
                    if (lstCart[i].remarks != null && lstCart[i].remarks.trim() != '')
                        template = template.replace('[Remarks]', lstCart[i].remarks);
                    else
                        template = template.replace('[Remarks]', '');
						
						
					if (lstCart[i].subscriptiontype != null && lstCart[i].subscriptiontype.trim() != '')
                        template = template.replace('[sub]', lstCart[i].subscriptiontype);
                    else
                        template = template.replace('[sub]', '');
                    $('#tempStoreProd .clsCartProds').append(template);
                }
            }
        }
    }
    lstCart = [];
    cart = window.localStorage.getItem('cart_giftcard');
    if (cart != null && cart != '') {
        lstCart = JSON.parse(cart);
        if (lstCart.length > 0) {
            for (var i = 0; i < lstCart.length; i++) {
                if (lstCart[i].sid == lnkdatasetsid) {
                    hasProd = true;
                    if (lstCart[i].minorder != undefined)
                        minorderAmt = lstCart[i].minorder;
					
										storePic[lstCart[i].sname] = lstCart[i].simg;
										storeAmt=(parseFloat(storeAmt)+ parseFloat(lstCart[i].total)).toFixed(2);
                    var template = $('#tempMiniCart-Prod').html();
                    template = template.replace('images/quicly-logo-black.png', lstCart[i].photo);
                    template = template.replace('[Name1]', lstCart[i].name);
                    template = template.replace('[Name2]', ucwords(lstCart[i].name));
                    
                    if(lstCart[i].price != undefined)
                    template = template.replace('[UnitPrice]', lstCart[i].price);
                    else
                    template = template.replace('[UnitPrice]', lstCart[i].calcprice);
                    
                    template = template.replace('[Price]', lstCart[i].total);
                    template = template.replace('[i]', i);
                    template = template.replace('[Key]', 'cart_giftcard');
                    template = template.replace('[i1]', i);
                    template = template.replace('[Key1]', 'cart_giftcard');
                    template = template.replace('[i2]', i);
                    template = template.replace('[Key2]', 'cart_giftcard');
					template = template.replace('[Key3]', 'cart_giftcard');
                    template = template.replace('[k]', i);
                    template = template.replace('[KeyR]', 'cart_giftcard');
                    template = template.replace('[qty]', lstCart[i].qty);
                    template = template.replace('[qty]', lstCart[i].qty);
                    template = template.replace('[pid]', lstCart[i].pid);
                    template = template.replace('[pid]', lstCart[i].pid);
                    template = template.replace('[pid]', lstCart[i].pid);
                    template = template.replace('[pid]', lstCart[i].pid);
                    template = template.replace('[pid2]', lstCart[i].pid);
                    if (lstCart[i].deliveryto != null && lstCart[i].deliveryto.trim() != '')
                        template = template.replace('[Remarks]', 'Deliver To: '+lstCart[i].deliveryto);
                    else
                        template = template.replace('[Remarks]', '');
					
					if (lstCart[i].subscriptiontype != null && lstCart[i].subscriptiontype.trim() != '')
                        template = template.replace('[sub]', lstCart[i].subscriptiontype);
                    else
                        template = template.replace('[sub]', '');
                    template = template.replace('[pid]', lstCart[i].pid);
                    $('#tempStoreProd .clsCartProds').append(template);
                }
            }
        }
    }
   lstCart = [];
    cart = window.localStorage.getItem('cart_shef');
    if (cart != null && cart != '') {
        lstCart = JSON.parse(cart);
        if (lstCart.length > 0) {
            for (var i = 0; i < lstCart.length; i++) {
                if (lstCart[i].sid == lnkdatasetsid) {
                    hasProd = true;
                    if (lstCart[i].minorder != undefined)
                        minorderAmt = lstCart[i].minorder;
                        
                    shefstorePic[lstCart[i].sname] = lstCart[i].simg;
					    shefstoreAmt=(parseFloat(shefstoreAmt)+ parseFloat(lstCart[i].total)).toFixed(2);
                    var template = $('#sheftempMiniCart-Prod').html();
                    template = template.replace('images/quicly-logo-black.png', lstCart[i].photo);
                    template = template.replace('[Name1]', lstCart[i].name);
                    template = template.replace('[Name2]', ucwords(lstCart[i].name));
                    if(lstCart[i].price != undefined)
                    template = template.replace('[UnitPrice]', lstCart[i].price);
                    else
                    template = template.replace('[UnitPrice]', lstCart[i].calcprice);
                    template = template.replace('[Price]', lstCart[i].total);
                    template = template.replace('[i]', i);
                    template = template.replace('[Key]', 'cart_shef');
                    template = template.replace('[i1]', i);
                    template = template.replace('[Key1]', 'cart_shef');
                    template = template.replace('[i2]', i);
                    template = template.replace('[Key2]', 'cart_shef');
                    template = template.replace('[k]', i);
                    template = template.replace('[KeyR]', 'cart_shef');
                    template = template.replace('[qty]', lstCart[i].qty);
                    
                    template = template.replace('[pid2]', lstCart[i].pid);
                    if (lstCart[i].remarks != null && lstCart[i].remarks.trim() != '')
                        template = template.replace('[Remarks]', lstCart[i].remarks);
                    else
                        template = template.replace('[Remarks]', '');
						
						
					
                    $('#sheftempStoreProd .clsshefCartProds').append(template);
                }
            }
        }
    } 
    
    var lstStores = [];   
    if (!lstStores.includes(lnkdatasetsid)) {
        lstStores.push(lnkdatasetsid);
				if(sname=='Shef'){
			
				var template2 = $('#sheftempMiniCart-Stores').html();
				
				template2 = template2.replace('images/no-img.jpg', shefstorePic[lnkdatasetsname]);
				 $('#sheftempStoreProd .clsCartStores').append(template2);	
		} else {
				var template1 = $('#tempMiniCart-Stores').html();
				template1 = template1.replace('[TotalOrderAmount]', lnkdatasetsname);
				template1 = template1.replace('[TotalPrice]', storeAmt);
				if(memberminorderamount==1){
					minorderAmt=0;
					template1 = template1.replace('[MinOrderAmt]', minorderAmt);
				} else {
				template1 = template1.replace('[MinOrderAmt]',minorderAmt );	
				}
				
				template1 = template1.replace('images/no-img.jpg', storePic[lnkdatasetsname]);
				
				var get_tab_index = getCookie('grocery_tab_index');
				//alert(get_tab_index);
				if(memberminorderamount==1){
					template1 = template1.replace('[WarnMsg]', '');
				}
				else if(parseFloat(storeAmt) < parseFloat(minorderAmt) && get_tab_index == 0)
				{
					var restAmt = parseFloat(minorderAmt) - parseFloat(storeAmt);	
					restAmt = restAmt.toFixed(2);	
					template1 = template1.replace('[WarnMsg]', '<div class="totalwarningmsg">Add <font color="green">$'+restAmt+'</font> to reach the order minimum of $'+minorderAmt+'</div>');
				}
				else{
					template1 = template1.replace('[WarnMsg]', '');
				}
				$('#tempStoreProd .clsCartStores').append(template1);
				}	
				
				if(get_tab_index == 1){
					$("#fdBtn").hide();
					$(".totalorderamountbystore").hide();
				}
				else{
					$("#fdBtn").show();
					$(".totalorderamountbystore").show();
				}
				netamt = parseFloat(netamt) + parseFloat(storeAmt);
				$("#netamt").val(netamt);	
                netamtshef = parseFloat(netamtshef) + parseFloat(shefstoreAmt);
                $("#netamtshef").val(netamtshef);	 				
                
         	       				
		}
    
var templateNew = $('#tempStoreProd').html();
	var templateNew2 = $('#sheftempStoreProd').html();
	if(sname=='Shef') {
	$('.clsInnerCart .clsCompleteCartshef').append(templateNew2);
	} else{
		 $('.clsInnerCart .clsCompleteCart').append(templateNew);
	
	}
    
    if (hasProd) {
        //$('.clsInnerCart .clsMinOrderAmt')[0].innerText = ' Minimum Order Value $' + minorderAmt + '  Total: $' + storeAmt;
				//$('.clsInnerCart .totalorderamountbystore')[0].innerText =   lnkdatasetsname;
        //$('.clsInnerCart .clsMinOrderAmt').show();
				//$('.clsInnerCart .totalorderamountbystore').show();
    } else {
        //$('.clsInnerCart .clsMinOrderAmt').hide();
				//$('.clsInnerCart .totalorderamountbystore').hide();
	}  
}
function removeMiniCartProd(i, key) {
    var lstCart = [];
    var cart = window.localStorage.getItem(key);
    if (cart != null && cart != '')
        lstCart = JSON.parse(cart);
	$("#box"+lstCart[i].pid).hide();
    $("#val"+lstCart[i].pid).val(0);
    $("#clsaddbtn"+lstCart[i].pid).show();
    if (lstCart.length > 0)
       
	if(key == 'cart_events'){
    $("#prod-loader").show();
		$.ajax({
        url: 'ajax-events.php',
        type: 'POST',
        data: {cartid: lstCart[i].cartid, eid: lstCart[i].eid, action: 'releaseqty'},
		cache: false,
		success: function (data) {
		$("#prod-loader").hide();
		lstCart.splice(i, 1);
    window.localStorage.setItem(key, JSON.stringify(lstCart));
	    updateMiniCart();
    resetPhpCart();
		}
		})
	}
		else {
        lstCart.splice(i, 1);
    window.localStorage.setItem(key, JSON.stringify(lstCart));
    //var sid = $('.clsInnerCart .clsSlider a.active')[0].dataset.sid;
    updateMiniCart();
    resetPhpCart();
		}
    //if ($('.clsInnerCart .clsSlider a[data-sid="' + sid + '"]').length > 0)
        //$('.clsInnerCart .clsSlider a[data-sid="' + sid + '"]').click();
    //else
        //$('.clsInnerCart .clsSlider a:first-child').click();
    if(key == 'cart_grocery'){
        restoreProdQty();
    } else if(key=='cart_food'){
        restoreFoodProdQty();
        
    }
   
}

function ucwords(str)
{
	str = str.toLowerCase().replace(/\b[a-z]/g, function(letter) {
			return letter.toUpperCase();
	});
	return str;
}

function addMiniStoreSlider() {
    $('.clsInnerCart .clsSlider').slick({
        infinite: false,
        slidesToScroll: 1,
        autoplay: false,
        variableWidth: true,
        arrows: true,
        prevArrow: '<i class="left">&#x2039;</i>',
        nextArrow: '<i class="right">&#x203A;</i>',
        centerMode: false,
        dots: false
    });
}
function removeMiniStoreSlider() {
    if ($('.clsInnerCart .clsSlider').hasClass('slick-initialized'))
        $('.clsInnerCart .clsSlider').slick('unslick');
}
function addQtyMiniCart(i, key) {
    var lstCart = [];
    var cart = window.localStorage.getItem(key);
    if (cart != null && cart != '')
        lstCart = JSON.parse(cart);
    if (lstCart.length > 0) {
        var qty = lstCart[i].qty;
        qty = parseInt(qty) + 1;
		if(key=='cart_shef'){
			var maxqty = lstCart[i].maxqty;
			if(qty > maxqty){
					qty = parseInt(qty) - 1;                
					alert("You have reached Max. limit to add quantity, You can't add more then "+maxqty+" items in the cart!");
					return false;
				}
		} else if(qty > 20){
					qty = parseInt(qty) - 1;                
					alert("You have reached Max. limit to add quantity, You can't add more then 20 items in the cart!");
					return false;
				}
        updateMiniCartQty(i, qty, key);
    }
    if(key == 'cart_grocery'){
        restoreProdQty();
    } else if(key=='cart_food'){
        restoreFoodProdQty();
       ;
    }
    
    resetPhpCart();
}
function removeQtyMiniCart(i, key , pid) {
    var lstCart = [];
    var cart = window.localStorage.getItem(key);
    if (cart != null && cart != '')
        lstCart = JSON.parse(cart);
    if (lstCart.length > 0) {
        var qty = lstCart[i].qty;
        qty = parseInt(qty) - 1;
        if (qty == 0){             
            removeMiniCartProd(i, key);
            if($('#product .clsProdAdd[data-pid="' + pid + '"]').length !=0 ){
                //$('#product .clsProdAdd[data-pid="' + pid + '"]').parent().parent().parent().remove()
                $('#product .clsProdAdd[data-pid="' + pid + '"]').parent().parent().parent().parent().parent().remove()
            }   
            else if($('.clsProdAdd1[data-pid="' + pid + '"]').length !=0 ){
							$('.clsProdAdd1[data-pid="' + pid + '"]').show();
							$('.clsProdAdd1[data-pid="' + pid + '"]').closest('.clsFoodProdCnt').find('.clsFoodQty').remove();
            } 
            else if($('.clsProdAdd2[data-pid="' + pid + '"]').length !=0 ){
							$('.clsProdAdd2[data-pid="' + pid + '"]').show();
							$('.clsProdAdd2[data-pid="' + pid + '"]').closest('.clsFoodProdCnt').find('.clsNationQty').remove();
            }
			 $("#box"+pid).hide();
            $("#clsaddbtn"+pid).show();
        }else{
            updateMiniCartQty(i, qty, key);
        }  
         $("#val"+pid).val(qty);		
    }
    if(key == 'cart_grocery'){
        restoreProdQty();
    } else if(key=='cart_food'){
        restoreFoodProdQty();
        
    }
    
    resetPhpCart();
}
function updateMiniCartQty(i, qty, key) {
    var lstCart = [];
    var cart = window.localStorage.getItem(key);
    if (cart != null && cart != '')
        lstCart = JSON.parse(cart);
        
     if(qty > 20){
         alert("You have reached Max. limit to add quantity, You can't add more then 20 items in the cart!");
         qty = 20;// for old user if some one already added more then 20 items in the cart
     }   
    if (lstCart.length > 0) {
        lstCart[i].qty = qty;
        lstCart[i].total = (parseFloat(lstCart[i].calcprice) * parseInt(lstCart[i].qty)).toFixed(2);
        lstCart[i].tax = (parseFloat(lstCart[i].baseTax) * parseInt(lstCart[i].qty)).toFixed(2);
        if (lstCart[i].addOnBaseQtys != undefined && lstCart[i].addOnBaseQtys != '') {
            var arrTmpNewQty = lstCart[i].addOnBaseQtys.split(',');
            var tmpQty = '';
			var tempremarks='';
            for (let j = 0; j < arrTmpNewQty.length; j++){
                tmpQty += (parseInt(arrTmpNewQty[j]) * lstCart[i].qty) + ',';
				  if (lstCart[i].addOns != undefined && lstCart[i].addOns != '' && lstCart[i].addOns.length >0 && lstCart[i].section=='organic-box') {
				var temaddon=lstCart[i].addOns[j];
				var pqty_html=(parseInt(arrTmpNewQty[j]) * lstCart[i].qty);
				if(pqty_html > 1){
				pqty_html = '(x'+ pqty_html +')';
				} else {
					pqty_html='';
				}
				tempremarks += temaddon.name + ' ('+ temaddon.size + ') ' + pqty_html + ', ';
			   }
			     if (lstCart[i].addOns != undefined && lstCart[i].addOns != '' && lstCart[i].addOns.length >0 && lstCart[i].section=='mithaas') {
				var temaddon=lstCart[i].addOns[j];
				var pqty_html=(parseInt(arrTmpNewQty[j]) * lstCart[i].qty);
				if(pqty_html > 1){
				pqty_html = '(x'+ pqty_html +')';
				} else {
					pqty_html='';
				}
				tempremarks += temaddon.name + ' ('+ temaddon.size + ') ' + pqty_html + ', ';
			   }
			    if (lstCart[i].addOns != undefined && lstCart[i].addOns != '' && lstCart[i].addOns.length >0 && lstCart[i].section=='events') {
				var temaddon=lstCart[i].addOns[j];
				var pqty_html=(parseInt(arrTmpNewQty[j]) * lstCart[i].qty);
				if(pqty_html > 1){
				pqty_html = '(x'+ pqty_html +')';
				} else {
					pqty_html='';
				}
				tempremarks += temaddon.name + pqty_html + ', ';
			   }
			}
			if(tempremarks != ''){
				tempremarks = tempremarks.substr(0, tempremarks.length - 2);
				lstCart[i].remarks=tempremarks;
				lstCart[i].customize=tempremarks;
			}
            if (tmpQty != '')
                tmpQty = tmpQty.substr(0, tmpQty.length - 1);
            lstCart[i].addOnQtys = tmpQty;
        }
    }
    window.localStorage.setItem(key, JSON.stringify(lstCart));
    updateMiniCart();
}
//---------- Grocery
function addToCart(lnk, flgPrepend = false) {
    $(lnk).hide();
	var uremarks='Replace with Best Match';
    var parent = $(lnk).parent();
    var template = $('#tempQty').html();
    if (flgPrepend)
        $(parent).prepend(template);
    else
        $(parent).append(template);
    var lstCart = [];
    var cart = window.localStorage.getItem('cart_grocery');
    if (cart != null && cart != '')
        lstCart = JSON.parse(cart);
    var flgAdd = true;
    if (lstCart.length > 0) {
        for (var j = 0; j < lstCart.length; j++) {
            if (lstCart[j].pid == lnk.dataset.pid) {
								var tempQty = parseInt(lstCart[j].qty) + 1;
								if(tempQty > 20){
									alert("You have reached Max. limit to add quantity, You can't add more then 20 items in the cart!");
									return false;
								}
								else{
                lstCart[j].qty = parseInt(lstCart[j].qty) + 1;
                lstCart[j].total = (parseFloat(lstCart[j].calcprice) * parseInt(lstCart[j].qty)).toFixed(2);
								}
                flgAdd = false;
                //resetPhpCart();
                break;
            }
        }
    }
    if (flgAdd) {
        var prod_total = parseFloat(lnk.dataset.price) * 1;
        var newProd = {
            cart_type: 'grocery',
            section: 'grocery',
            section_type: 'grocery',
            sid: lnk.dataset.sid,
            sname: lnk.dataset.sname,
            simg: lnk.dataset.simg,
            smin: lnk.dataset.smin,
            minorder: lnk.dataset.minorder,
            pid: lnk.dataset.pid,
            name: lnk.dataset.name,
            qty: 1,
            price: lnk.dataset.price,
            calcprice: lnk.dataset.price,
            baseTax: lnk.dataset.tax,
            tax: lnk.dataset.tax,
            total: prod_total,
            photo: lnk.dataset.photo,
			      uremarks: uremarks
        }
        lstCart.push(newProd);
        lnk.dataset.i = (lstCart.length - 1);
    }
   
    //else
    //    $(lnk).parent().find('select').val(lstCart[i].qty);
    window.localStorage.setItem("cart_grocery", JSON.stringify(lstCart));
    updateMiniCart();
    resetPhpCart();
    restoreProdQty();    
    //flying effect start by sachin
	if(screen.width < 768) {
		 var basket = $('.mobilestickycart');
	} else {
		 var basket = $('.clsCart2');
	}
   
    var imgtodrag = $('#img_' + lnk.dataset.pid).eq(0);
    if (imgtodrag) {
        var imgtoclone = imgtodrag.clone().offset({top: imgtodrag.offset().top, left: imgtodrag.offset().left}).css({'opacity': '0.5', 'position': 'absolute', 'height': '150px', 'width': '150px', 'z-index': '99999900'}).appendTo($('body')).animate({'top': basket.offset().top + 10, 'left': basket.offset().left + 10, 'width': 75, 'height': 75}, 1000, 'easeInOutExpo');
        //setTimeout(function(){basket.effect("shake",{times:2},200)},1500);
        imgtoclone.animate({'width': 0, 'height': 0},
                function () {
                    $(this).detach()
                })
}
//flying effect ends$("#box").animate({height: "300px"});
}
function ddlQty_onChange(ddl) {
    var lnkAddToCart = $(ddl).closest('.clsProd').find('.clsProdAdd')[0];
    if (ddl.value == '0') {
        removeFromCart(lnkAddToCart.dataset.i, 'cart_grocery');
        $(lnkAddToCart).removeAttr("data-i");
        var parent = $(ddl).parent();
        var mainparent = $(ddl).parent().parent();
        $(parent).remove();
        $(mainparent).find('.clsProdAdd').show();
        resetPhpCart();
    } else {
        //flying effect start by sachin
        if(screen.width < 768) {
		 var basket = $('.mobilestickycart');
	} else {
		 var basket = $('.clsCart2');
	}
        var imgtodrag = $('#img_' + lnkAddToCart.dataset.pid).eq(0);
        if (imgtodrag) {
            var imgtoclone = imgtodrag.clone().offset({top: imgtodrag.offset().top, left: imgtodrag.offset().left}).css({'opacity': '0.5', 'position': 'absolute', 'height': '150px', 'width': '150px', 'z-index': '99999900'}).appendTo($('body')).animate({'top': basket.offset().top + 10, 'left': basket.offset().left + 10, 'width': 75, 'height': 75}, 1000, 'easeInOutExpo');
            //setTimeout(function(){basket.effect("shake",{times:2},200)},1500);
            imgtoclone.animate({'width': 0, 'height': 0},
                    function () {
                        $(this).detach()
                    })
        }
        //flying effect ends$("#box").animate({height: "300px"});
        updateCartQty(lnkAddToCart.dataset.i, parseInt(ddl.value), 'cart_grocery');
        resetPhpCart();
    }
}
function updateCartQty(i, qty, key) {
    var lstCart = [];
    var cart = window.localStorage.getItem(key);
    if (cart != null && cart != '')
        lstCart = JSON.parse(cart);
    if (lstCart.length > 0) {
        lstCart[i].qty = qty;
        lstCart[i].total = (parseFloat(lstCart[i].calcprice) * parseInt(lstCart[i].qty)).toFixed(2);
        lstCart[i].tax = (parseFloat(lstCart[i].baseTax) * parseInt(lstCart[i].qty)).toFixed(2);
        if (lstCart[i].addOnBaseQtys != undefined && lstCart[i].addOnBaseQtys != '') {
            var arrTmpNewQty = lstCart[i].addOnBaseQtys.split(',');
            var tmpQty = '';
			var tempremarks='';
            for (let j = 0; j < arrTmpNewQty.length; j++) {
                tmpQty += (parseInt(arrTmpNewQty[j]) * lstCart[i].qty) + ',';
				  if (lstCart[i].addOns != undefined && lstCart[i].addOns != '' && lstCart[i].addOns.length >0 && lstCart[i].section=='organic-box') {
				var temaddon=lstCart[i].addOns[j];
				var pqty_html=(parseInt(arrTmpNewQty[j]) * lstCart[i].qty);
				if(pqty_html > 1){
				pqty_html = '(x'+ pqty_html +')';
				} else {
					pqty_html='';
				}
				tempremarks += temaddon.name + ' ('+ temaddon.size + ') ' + pqty_html + ', ';
			   }
			     if (lstCart[i].addOns != undefined && lstCart[i].addOns != '' && lstCart[i].addOns.length >0 && lstCart[i].section=='events') {
				var temaddon=lstCart[i].addOns[j];
				var pqty_html=(parseInt(arrTmpNewQty[j]) * lstCart[i].qty);
				if(pqty_html > 1){
				pqty_html = '(x'+ pqty_html +')';
				} else {
					pqty_html='';
				}
				tempremarks += temaddon.name + pqty_html + ', ';
			   }
			}
			if(tempremarks != ''){
				tempremarks = tempremarks.substr(0, tempremarks.length - 2);
				lstCart[i].remarks=tempremarks;
				lstCart[i].customize=tempremarks;
			}
            if (tmpQty != '')
                tmpQty = tmpQty.substr(0, tmpQty.length - 1);
            lstCart[i].addOnQtys = tmpQty;
        }
        
       
    }
    window.localStorage.setItem(key, JSON.stringify(lstCart));
    updateMiniCart();
    restoreProdQty(); 
}
function removeFromCart(i, key) {
    var lstCart = [];
    var cart = window.localStorage.getItem(key);
    if (cart != null && cart != '')
        lstCart = JSON.parse(cart);
    if (lstCart.length > 0){
      
        lstCart.splice(i, 1);
		}
    window.localStorage.setItem(key, JSON.stringify(lstCart));
    updateMiniCart();
    resetPhpCart();
    restoreProdQty(); 
}
function restoreProdQty(flgPrepend = false) {
    var lstCart = [];
    var cart = window.localStorage.getItem('cart_grocery');
    if (cart != null && cart != '')
        lstCart = JSON.parse(cart);
    if (lstCart.length > 0) {
        var template = $('#tempQty').html();
        for (i = 0; i < lstCart.length; i++) {
            var prodAdd = $('.clsProdAdd[data-pid="' + lstCart[i].pid + '"]');
            for (j = 0; j < prodAdd.length; j++) {
                prodAdd[j].dataset.i = i;
                $(prodAdd[j]).hide();
                var parent = $(prodAdd[j]).parent();
                 if ($(parent).find('.clsQty select').length == 0) {
                    if (flgPrepend)
                        $(parent).prepend(template);
                    else
                        $(parent).append(template);
                }
                $(parent).find('.clsQty select')[0].value = lstCart[i].qty;
            }
			 $("#val"+lstCart[i].pid).val(lstCart[i].qty);
        }
        var ddls = $('.clsProd .clsQty select');
        if (ddls.length > 0) {
            for (i = 0; i < ddls.length; i++) {
                var parent = $(ddls[i]).parent();
                var mainparent = $(ddls[i]).parent().parent();
                var btnAddToCart = $(mainparent).find('.clsProdAdd');
                var tmpCart = lstCart.filter(function (el) {
                    return el.pid == btnAddToCart[0].dataset.pid;
                });
                if (tmpCart == null || tmpCart.length == 0) {
                    $(parent).remove();
                    $(btnAddToCart).show();
                }
            }
        }
    } else {
        var ddls = $('.clsProd .clsQty select');
        if (ddls.length > 0) {
            for (i = 0; i < ddls.length; i++) {
                var parent = $(ddls[i]).parent();
                    var mainparent = $(ddls[i]).parent().parent();
                    $(parent).remove();
                    $(mainparent).find('.clsProdAdd').show();
                }
            }
    }
    getOrderSummery()
}

function restoreFoodProdQty() {
    var lstCart = [];
    var cart = window.localStorage.getItem('cart_food');
    if (cart != null && cart != '')
        lstCart = JSON.parse(cart);
    if (lstCart.length > 0) {
        var template = $('#tempQty').html();
        for (i = 0; i < lstCart.length; i++) {
            var prodAdd = $('.clsProdAdd[data-pid="' + lstCart[i].pid + '"]');
             
            for (j = 0; j < prodAdd.length; j++) {
                prodAdd[j].dataset.i = i;
                $(prodAdd[j]).hide();
                var parent = $(prodAdd[j]).parent();
                 if ($(parent).find('.clsQty select').length == 0) {
                          $(parent).append(template);
                 }
                $(parent).find('.clsQty select')[0].value = lstCart[i].qty;
            }
        }
    }  
    getOrderSummery();
}
//---------- Food
function addToCart_Food(lnk) {
	var parent = $(lnk).parent();
    var lstCart = [];
    var cart = window.localStorage.getItem('cart_food');
    if (cart != null && cart != '')
        lstCart = JSON.parse(cart);
    var tmp_remarks = '';
    var total_tax = 0;
    // Customize
    var custom = '';
    var cus = $('.clsCustomize input[type=radio]:checked');
    for (i = 0; i < cus.length; i++) {
        //tmp_remarks += cus[i].value + ', ';
        custom += cus[i].name + ': ' + cus[i].value + ', ';
        tmp_remarks += cus[i].name + ': ' + cus[i].value + ', ';
    }
    if (custom != '') {
        custom = custom.substr(0, custom.length - 2);
        tmp_remarks = tmp_remarks.substr(0, tmp_remarks.length - 2);
    }
    // Addons
    var lstAddOn = [];
    var addOnIDArr = '';
    var addOnQtyArr = '';
    var addOnCost = 0;
    var addOnMRP = 0;
    var adds = $('.clsAddOns select');
    for (i = 0; i < adds.length; i++) {
        if (i == 0) {
            if (tmp_remarks == '')
                tmp_remarks = "Addons: ";
            else
                tmp_remarks += ". Addons: ";
        }
        var addOnData = $(adds[i]).closest('.clsDetails').find('.clsProdAdd')[0].dataset;
        addOnCost += parseFloat(addOnData.price) * parseInt(adds[i].value);
        addOnMRP += parseFloat(addOnData.mrp) * parseInt(adds[i].value);
        total_tax += parseFloat(addOnData.tax) * parseInt(adds[i].value);
        if (adds[i].value > 1)
            tmp_remarks += addOnData.name + ' (x' + adds[i].value + '), ';
        else
            tmp_remarks += addOnData.name + ', ';
        addOnIDArr += addOnData.pid + ',';
        addOnQtyArr += adds[i].value + ',';
        var a = {
            pid: addOnData.pid,
            name: addOnData.name,
            qty: adds[i].value,
            price: addOnData.price,
            mrp: addOnData.mrp,
            tax: addOnData.tax,
            photo: addOnData.photo
        }
        lstAddOn.push(a);
    }
    if (tmp_remarks != '')
        tmp_remarks = tmp_remarks.substr(0, tmp_remarks.length - 2);
    if (addOnIDArr != '')
        addOnIDArr = addOnIDArr.substr(0, addOnIDArr.length - 1);
    if (addOnQtyArr != '')
        addOnQtyArr = addOnQtyArr.substr(0, addOnQtyArr.length - 1);
    var flgAdd = true;
    if (lstCart.length > 0) {
        for (var i = 0; i < lstCart.length; i++) {
            if (lstCart[i].pid == lnk.dataset.pid &&
                    lstCart[i].remarks == tmp_remarks) {
                lstCart[i].qty = parseInt(lstCart[i].qty) + 1;
                lstCart[i].total = ((parseFloat(lstCart[i].calcprice) * parseInt(lstCart[i].qty))).toFixed(2);
                lstCart[i].tax = ((parseFloat(lstCart[i].baseTax) * parseInt(lstCart[i].qty))).toFixed(2);
                if (lstCart[i].addOnQtys != '') {
                    var arrTmpNewQty = lstCart[i].addOnQtys.split(',');
                    var tmpQty = '';
                    for (let j = 0; j < arrTmpNewQty.length; j++)
                        tmpQty += (parseInt(arrTmpNewQty[j]) * lstCart[i].qty) + ',';
                    if (tmpQty != '')
                        tmpQty = tmpQty.substr(0, tmpQty.length - 1);
                    lstCart[i].addOnQtys = tmpQty;
                }
                flgAdd = false;
                resetPhpCart();

               

            }
            if(lstCart[i].sid == lnk.dataset.sid && lstCart[i].section == 'food'){
                //lstCart[i].deliveryFromTime =  $('#hdnDeliveryFromTime').val();
                lstCart[i].deliveryFromTime =  '';
                lstCart[i].deliveryToTime =  '';
            }
        }
    }
    if (flgAdd) {
        var prod_calc_Price = (parseFloat(lnk.dataset.price) + addOnCost).toFixed(2);
        var prod_mrp = (parseFloat(lnk.dataset.mrp) + addOnMRP).toFixed(2);
        var prod_total = prod_calc_Price * 1;
        total_tax += parseFloat(lnk.dataset.tax) * 1;
         var currentTime = '';
         //alert(currentTime);
        var newProd = {
            cart_type: 'food',
            section: 'food',
            section_type: 'food',
			sid: lnk.dataset.sid,
            sname: lnk.dataset.sname,
            simg: lnk.dataset.simg,
            smin: lnk.dataset.smin,
            minorder: lnk.dataset.minorder,
            pid: lnk.dataset.pid,
            name: lnk.dataset.name,
            qty: 1,
            price: lnk.dataset.price,
            baseTax: parseFloat(lnk.dataset.tax),
            tax: total_tax,
            calcprice: prod_calc_Price,
            mrp: prod_mrp,
            total: prod_total.toFixed(2),
            photo: lnk.dataset.photo,
            remarks: tmp_remarks,
            customize: custom,
            addOns: lstAddOn,
            addOnIDs: addOnIDArr,
            addOnBaseQtys: addOnQtyArr,
            addOnQtys: addOnQtyArr,
            deliveryDate: '',
            deliveryFromTime: '',
            deliveryToTime: '',
            selectedCurrentTime: currentTime
        }
        lstCart.push(newProd);
        
    }
    window.localStorage.setItem("cart_food", JSON.stringify(lstCart));
    updateMiniCart();
    resetPhpCart();
		if(screen.width < 768) {
		 var basket = $('.mobilestickycart');
	} else {
		 var basket = $('.clsCart2');
	}
   
    var imgtodrag = $('#img_' + lnk.dataset.pid).eq(0);
    if (imgtodrag) {
        var imgtoclone = imgtodrag.clone().offset({top: imgtodrag.offset().top, left: imgtodrag.offset().left}).css({'opacity': '0.5', 'position': 'absolute', 'height': '150px', 'width': '150px', 'z-index': '99999900'}).appendTo($('body')).animate({'top': basket.offset().top + 10, 'left': basket.offset().left + 10, 'width': 75, 'height': 75}, 1000, 'easeInOutExpo');
        //setTimeout(function(){basket.effect("shake",{times:2},200)},1500);
        imgtoclone.animate({'width': 0, 'height': 0},
                function () {
                    $(this).detach()
                })
}
}


//---------- Cart Review
function restoreCartSection() {
    // if(getCookie("cart_tab") == "")
    //     selectCartSection('');
    // else
    //     selectCartSection(getCookie("cart_tab"));
    selectCartSection('');
    if(!allowCurbsidePickup()){
        if(getCookie('grocery_tab_index') == '1'){
            setCookie('grocery_tab_index', '0');
            refreshPhpCart();
        }
    }
    if (getCookie('grocery_tab_index') == '')
        setCookie('grocery_tab_index', '0');
    if (getCookie('grocery_tab_index') == '0')
        $('.clsCartItems .clsCartSection a:first-child').addClass('active');
    else
        $('.clsCartItems .clsCartSection a:last-child').addClass('active');
}
function selectCartSection(type) {
    setCookie("cart_tab", type);
    //$('.clsCartSection a').removeClass('active');
    if (type == '') {
        //$('.clsCartSection a:nth-child(1)').addClass('active');
        cartKey = '';
    } else if (type == 'Groceries') {
        //$('.clsCartSection a:nth-child(2)').addClass('active');
        cartKey = 'cart_grocery';
    } else {
        //$('.clsCartSection a:nth-child(3)').addClass('active');
        cartKey = 'cart_food';
    }
    getStores();
}
function getStores() {
    var first_sname = '';
    if ($(window).width() < 800)
        removeCartStoreSlider();
    $('#stores a').remove();
    $('#product .clsCartProd').remove();
    var lstCart = [], lstStores = [], cart = [];
    var allstore_total = 0, allstore_items = 0;
    if (cartKey == '')
        lstCart = getAllCart();
    else {
        var cart = window.localStorage.getItem(cartKey);
        if (cart != null && cart != '')
            lstCart = JSON.parse(cart);
    }
    if (lstCart.length > 0) {
        for (var i = 0; i < lstCart.length; i++) {
            if (i == 0)
                first_sname = lstCart[i].sname;
            if (!lstStores.includes(lstCart[i].sid)) {
                lstStores.push(lstCart[i].sid);
                var tmpArr = lstCart.filter(function (el) {
                    return el.sid == lstCart[i].sid;
                });
                var totalProds = tmpArr.length;
                var total = 0;
				var member_discount=$('#memberdis').val();
               
                for (j = 0; j < tmpArr.length; j++){
					
					if(member_discount > 0 && (tmpArr[j].section=='grocery' || tmpArr[j].section=='food')){
						tmpArr[j].calcprice=getpriceaftermemberdiscount(tmpArr[j].calcprice,member_discount);
						total += parseFloat(tmpArr[j].calcprice) * parseInt(tmpArr[j].qty);
					} 
					else if(tmpArr[j].section=='moments'){
						total += parseFloat(tmpArr[j].calcprice);
					}
					else {
                    total += parseFloat(tmpArr[j].calcprice) * parseInt(tmpArr[j].qty);
					}
				}
                allstore_total += total;
                allstore_items += totalProds;
                var template = $('#tempStore').html();
                template = template.replace('[SID]', lstCart[i].sid);
                template = template.replace('[SID2]', lstCart[i].sid);
                template = template.replace('[Simg]', lstCart[i].simg);
                template = template.replace('[Name]', lstCart[i].sname);
                template = template.replace('[Name2]', lstCart[i].sname);
                template = template.replace('[total]', total.toFixed(2));
                if (totalProds > 1)
                    template = template.replace('[items]', totalProds + ' items');
                else
                    template = template.replace('[items]', totalProds + ' item');
                $('#stores').append(template);
            }
        }
        if (lstStores.length > 0) {
            var template = $('#tempStore').html();
            template = template.replace('[SID]', '0');
            template = template.replace('[SID2]', '0');
            template = template.replace('[Simg]', '/images/allstores.png');
            template = template.replace('[Name]', '');
            template = template.replace('[Name2]', '');
            template = template.replace('[total]', allstore_total.toFixed(2));
            if (totalProds > 1)
                template = template.replace('[items]', allstore_items + ' items');
            else
                template = template.replace('[items]', allstore_items + ' item');
            $('#stores').prepend(template);
            var flgAutoSel = true;
            if (getCookie('cart_tab_store') != "") {
                var storeLink = $('#stores a[data-sid="' + getCookie('cart_tab_store') + '"]');
                if (storeLink.length > 0) {
                    $(storeLink).click();
                    flgAutoSel = false;
                }
            }
            if (flgAutoSel)
                getCart($('#stores a:first-child'), lstStores[0], first_sname);
            if ($(window).width() < 800)
                addCartStoreSlider();
        }
    } else {
        if (cartKey == '')
            $('#lblCartStoreName')[0].innerText = "You do not have any item in cart";
        else if (cartKey == 'cart_grocery')
            $('#lblCartStoreName')[0].innerText = "You do not have any item in Grocery";
		 else if (cartKey == 'cart_events')
            $('#lblCartStoreName')[0].innerText = "You do not have any item in Events";
        else
            $('#lblCartStoreName')[0].innerText = "You do not have any item in Food";
    }
    //sachin starts
    //getCartPgTotal();
    getSectionCartTotal();
    // sachin ends
}
function getCart(lnk, sid, name) {
    setCookie("cart_tab_store", sid);
    $('#lblCartStoreName')[0].innerText = "Items in your " + name + " cart";
    $('#stores a').removeClass('active');
    $(lnk).addClass('active');
	var member_discount=$('#memberdis').val();
    var lstCart = [];
    if (cartKey == '') {
        lstCart = getAllCart();
    } else {
        var cart = window.localStorage.getItem(cartKey);
        if (cart != null && cart != '')
            lstCart = JSON.parse(cart);
    }
    if (lstCart.length > 0) {
        $('#product .clsCartProd').remove();
        var itemIndx = 0;
        var lastSec = '';
        for (var i = 0; i < lstCart.length; i++) {
            var tmpSec = lstCart[i].section;
						if (tmpSec != 'grocery' && tmpSec != 'giftcard' && tmpSec != 'events')
                tmpSec = 'food';
            if (lastSec != tmpSec) {
                lastSec = tmpSec;
                itemIndx = 0;
            }
            if (sid == '0' || lstCart[i].sid == sid) {
                var template = $('#tempProduct').html();
                template = template.replace('[i]', itemIndx);
                template = template.replace('[i2]', itemIndx);
				 template = template.replace('[i3]', itemIndx);
				  template = template.replace('[i4]', itemIndx);
                template = template.replace('[name]', lstCart[i].name);
                template = template.replace('[name2]', lstCart[i].name);
               
				
                     if(member_discount > 0 && (lstCart[i].section=='grocery' || lstCart[i].section=='food')){
                      var mprice=getpriceaftermemberdiscount(lstCart[i].calcprice,member_discount);
                       template = template.replace('[price]', parseFloat(mprice).toFixed(2));
                       } else {
                       template = template.replace('[price]', parseFloat(lstCart[i].calcprice).toFixed(2));
                      }
					 
					 
                template = template.replace('[qty]', lstCart[i].qty);
                template = template.replace('[photo]', lstCart[i].photo);
                template = template.replace('[pid]', lstCart[i].pid);
                template = template.replace('[ptotal]', lstCart[i].total);
                template = template.replace('[pid2]', lstCart[i].pid);
				if (lstCart[i].uremarks != null || lstCart[i].uremarks !='' && lstCart[i].section=='grocery'){
                    //$('#product .clsCartProd').find('.checkreplace').html('');
					template = template.replace('[uremarks]', lstCart[i].uremarks);
					template = template.replace('[uremarks1]', lstCart[i].uremarks);
					template = template.replace('[uremarks2]', lstCart[i].uremarks);
					template = template.replace('[uremarks3]', lstCart[i].uremarks);
					template = template.replace('[groceryclass]', 'groceryclass');
					//$('#product .clsCartProd').find('.checkreplace').html('');
					if(lstCart[i].uremarks=='Call Us Before Replacing'){
						template = template.replace('[replacephoto]', 'call-black.svg');
					} else if(lstCart[i].uremarks=='Do Not Replace'){
						template = template.replace('[replacephoto]', 'do-not-replace-black.svg');
					} else {
						template = template.replace('[replacephoto]', 'replace-black.svg');
					}
					 template = template.replace('[SHOWHIDE]', 'showcheck');
					 template = template.replace('[SHOWHIDE1]', '');
					 template = template.replace('[CHECKENABLE]', 'check[]');
					
                } else {
					template = template.replace('[uremarks]', '');
					template = template.replace('[uremarks1]', '');
					template = template.replace('[uremarks2]', '');
					template = template.replace('[uremarks3]', '');
					template = template.replace('[groceryclass]', '');
					template = template.replace('[SHOWHIDE]', 'hidecheck');
					template = template.replace('[SHOWHIDE1]', 'hidecheck');
					template = template.replace('[CHECKENABLE]', 'uncheck[]');
				}
                if (lstCart[i].remarks == null)
                    template = template.replace('[remarks]', '');
                else
                    template = template.replace('[remarks]', lstCart[i].remarks);
				 if (lstCart[i].subscriptiontype == null)
                    template = template.replace('[sub]', '');
                else
                    template = template.replace('[sub]', lstCart[i].subscriptiontype);
                var tmpKey = '';
                if (lstCart[i].section == 'grocery')
                    tmpKey = 'cart_grocery';
                else if (lstCart[i].section == 'giftcard')
                    tmpKey = 'cart_giftcard';
				else if (lstCart[i].section == 'events')
                    tmpKey = 'cart_events';
                else
                    tmpKey = 'cart_food';
                template = template.replace('[key]', tmpKey);
                template = template.replace('[key2]', tmpKey);
				template = template.replace('[key3]', tmpKey);
                template = template.replace('[pid]', lstCart[i].pid);
				
				
				
                if(member_discount > 0 && (lstCart[i].section=='grocery' || lstCart[i].section=='food' )){
					
                       var newprice=getpriceaftermemberdiscount(lstCart[i].calcprice,member_discount);
                        if(parseFloat(newprice) < parseFloat(lstCart[i].calcprice)){
							 template = template.replace('[mrp]', '<del class="strike-price">$' + lstCart[i].calcprice  + '</del>');
						} else {
							 template = template.replace('[mrp]', '');
						}
                       } else if(lstCart[i].mrp != null && lstCart[i].mrp != ''){
                    if(parseFloat(lstCart[i].calcprice) < parseFloat(lstCart[i].mrp))
                        template = template.replace('[mrp]', '<del class="strike-price">$' + lstCart[i].mrp  + '</del>');
                    else
                        template = template.replace('[mrp]', '');
                }
                else
                    template = template.replace('[mrp]', '');

                $('#product').append(template);
               
                
				$(".qty_cart_events").attr('disabled',true);
                var lastProd = $('#product .clsCartProd:last-child');
                if (lstCart[i].remarks != null && lstCart[i].remarks.trim() != '')
                    $(lastProd).find('.extra').append('<p>' + lstCart[i].remarks + '</p>');
                $(lastProd).find('select').val(lstCart[i].qty);
                if (lstCart[i].section == 'giftcard')
									$(lastProd).find('.extra').append('<p>Deliver To: ' + lstCart[i].deliveryto + '</p>');
            }
            itemIndx += 1;
        }
    } else {
		$(".user-replacement-option").hide();
	}
}
function getCartPgTotal() {
    var grocery = getCartTotalByKey('cart_grocery');
    var food = getCartTotalByKey('cart_food');
    var giftcard = getCartTotalByKey('cart_giftcard')
	 var events = getCartTotalByKey('cart_events');
    var totalItems = grocery[0] + food[0] + giftcard[0] + events[0];
    var totalCost = grocery[1] + food[1] + giftcard[1] + events[1];
    // Result
    if (totalItems > 1)
        $('#lblSubItems')[0].innerText = '(' + totalItems + ' items)';
    else
        $('#lblSubItems')[0].innerText = '(' + totalItems + ' item)';
    $('#lblGrandTotal')[0].innerText = '$' + totalCost.toFixed(2);
}
function getAllCart() {
    var lstCart = [];
	var lstCartgroceryCheck = [];
    var tmp_cart = window.localStorage.getItem("cart_grocery");
    if (tmp_cart != null && tmp_cart != ''){
        lstCart = JSON.parse(tmp_cart);
		lstCartgroceryCheck = JSON.parse(tmp_cart);
	   	
	} 
	 if (lstCartgroceryCheck.length > 0) {
		 $(".user-replacement-option").show();
	 } else {
		$(".user-replacement-option").hide(); 
	 }
    tmp_cart = window.localStorage.getItem("cart_food");
    if (tmp_cart != null && tmp_cart != '') {
        if (lstCart.length == 0)
            lstCart = JSON.parse(tmp_cart);
        else {
            var tmpLst = JSON.parse(tmp_cart);
            lstCart = lstCart.concat(tmpLst);
        }
    }
	tmp_cart = window.localStorage.getItem("cart_events");
    if (tmp_cart != null && tmp_cart != '') {
        if (lstCart.length == 0)
            lstCart = JSON.parse(tmp_cart);
        else {
            var tmpLst = JSON.parse(tmp_cart);
            lstCart = lstCart.concat(tmpLst);
        }
    }
    tmp_cart = window.localStorage.getItem("cart_giftcard");
    if (tmp_cart != null && tmp_cart != '') {
        if (lstCart.length == 0)
            lstCart = JSON.parse(tmp_cart);
        else {
            var tmpLst = JSON.parse(tmp_cart);
            lstCart = lstCart.concat(tmpLst);
        }
    }
    return lstCart;
}
//sachin start
function getSectionCartTotal() {
    //getGrandTotal();
    var grocery = getCartTotalByKey('cart_grocery');
    var food = getCartTotalByKey('cart_food');
    var giftcard = getCartTotalByKey('cart_giftcard');
	var events = getCartTotalByKey('cart_events');
    var totalItemsGrocery = grocery[0];
    var totalItemsFood = food[0];
	var totalItemsEvent = events[0];
    var totalItemsGiftCard = giftcard[0];
    var totalCostGrocery = grocery[1];
    var totalCostFood = food[1];
	 var totalCostEvent = events[1];
    var totalCostGiftCard = giftcard[1];
	var totalitemquicklly=grocery[0]+food[0]+giftcard[0]+events[0];
    // Result Grocery
    if (totalItemsGrocery > 1)
        $('#lblSubItemsGrocery')[0].innerText = '(' + totalItemsGrocery + ' items)';
    else
        $('#lblSubItemsGrocery')[0].innerText = '(' + totalItemsGrocery + ' item)';
    $('#lblGrandTotalGrocery')[0].innerText = '$' + totalCostGrocery.toFixed(2);
    // Result Food
    if (totalItemsFood > 1)
        $('#lblSubItemsFood')[0].innerText = '(' + totalItemsFood + ' items)';
    else
        $('#lblSubItemsFood')[0].innerText = '(' + totalItemsFood + ' item)';
    $('#lblGrandTotalFood')[0].innerText = '$' + totalCostFood.toFixed(2);
    // Result Total
    if (totalItemsGiftCard > 1)
        $('#lblSubItemsGiftCard')[0].innerText = '(' + totalItemsGiftCard + ' items)';
    else
        $('#lblSubItemsGiftCard')[0].innerText = '(' + totalItemsGiftCard + ' item)';
    $('#lblGrandTotalGiftCard')[0].innerText = '$' + totalCostGiftCard.toFixed(2);
	
	// Result Events
    if (totalItemsEvent > 1)
        $('#lblSubItemsEvent')[0].innerText = '(' + totalItemsEvent + ' items)';
    else
        $('#lblSubItemsEvent')[0].innerText = '(' + totalItemsEvent + ' item)';
    $('#lblGrandTotalEvent')[0].innerText = '$' + totalCostEvent.toFixed(2);
	
	if(totalitemquicklly==totalItemsEvent) {
		$('.grocerysection').hide();
		$('.foodsection').hide();
		$('.gifcardsection').hide();
		$('#deliverystatetext').hide();
		$('.clsCartBox .clsCartSection').hide();
		$('div#loginpanelguess .frmheading').text('Billing Address');
	}
	if(totalItemsEvent > 0) {
		$('.eventsection').show();
	} else {
	$('.eventsection').hide();	
	}
	if(totalItemsGiftCard > 0) {
		$('.gifcardsection').show();
	} else {
	$('.gifcardsection').hide();	
	}
    // Result Total
    var totalCost = grocery[1] + food[1] + giftcard[1] + events[1];
    $('#hdnCartTotal').val(totalCost.toFixed(2));
    if (getCookie('flgRefreshCart') !== '1') {
        refreshPhpCart();
    }
}
function setCartDeliveryType(lnk, indx) {
    if(indx == 1){ //Pickup
        if(!allowCurbsidePickup()){
            alert('Curbside pick up is not available for the selected products!');
            return;
        }
    } 
    setCookie('grocery_tab_index', indx);
    resetPhpCart();
    refreshPhpCart();
    //$('.clsCartSection a').removeClass('active');
    //$(lnk).addClass('active');
}
function resetPhpCart() {
//		setCookie('flgRefreshCart','0',1);
    document.cookie = "flgRefreshCart" + "=0" + ";" + ";path=/";
    $('#hdnCartGrocery').val(window.localStorage.getItem('cart_grocery'));
    $('#hdnCartFood').val(window.localStorage.getItem('cart_food'));
	$('#hdnCartEvents').val(window.localStorage.getItem('cart_events'));
    $('#hdnCartGiftCard').val(window.localStorage.getItem('cart_giftcard'));
    $('#cartsubmit').click();
	
}
function refreshPhpCart() {
    //setCookie('flgRefreshCart','1',1);
    document.cookie = "flgRefreshCart" + "=1" + ";" + ";path=/";
    $('#hdnCartGrocery').val(window.localStorage.getItem('cart_grocery'));
    $('#hdnCartFood').val(window.localStorage.getItem('cart_food'));
    $('#hdnCartGiftCard').val(window.localStorage.getItem('cart_giftcard'));
	$('#hdnCartEvents').val(window.localStorage.getItem('cart_events'));
    $('#cartsubmit').click();
}
//sachin ends
function ddlQtyCartPg_onChange(ddl, key) {
    updateCartQty(ddl.dataset.i, parseInt(ddl.value), key);
    var sid = $('#stores a.active')[0].dataset.sid;
    getStores();
    $('#stores a[data-sid="' + sid + '"]').click();
    refreshPhpCart();
}
function removeFromCartPg(i, key) {
    removeFromCart(i, key);
    var sid = $('#stores a.active')[0].dataset.sid;
    getStores();
    if ($('#stores a[data-sid="' + sid + '"]').length > 0)
        $('#stores a[data-sid="' + sid + '"]').click();
    else
        $('#stores a:first-child').click();
    refreshPhpCart();
}

function getGrandTotal() {
 
    jsonObj = {
        'lstCartGrocery': JSON.parse(window.localStorage.getItem('cart_grocery')),
        'lstCartFood': JSON.parse(window.localStorage.getItem('cart_food')),
        'lstCartGiftcard': JSON.parse(window.localStorage.getItem('cart_giftcard')),
        'Tip': 0
    }
    $.ajax({
        url: "review-order.php",
        dataType: "json",
        data: {jsonData: jsonObj},
        type: "POST",
        success: function (data) {
            $('.clsPgLoader').hide();
            //alert('Total:' +  data.grandTotal + ", Tax = " + data.tax);
            //$('#lblGrandTotal')[0].innerText = '$' + data.grandTotal;
            // store grand total in hidden input
            // calc Tip: hidden input = parse float * tip
            // new grand total
        },
        error: function (jqXHR, exception) {
            var msg = '';
            if (jqXHR.status === 0) {
                msg = 'Not connect.\n Verify Network.';
            } else if (jqXHR.status == 404) {
                msg = 'Requested page not found. [404]';
            } else if (jqXHR.status == 500) {
                msg = 'Internal Server Error [500].';
            } else if (exception === 'parsererror') {
                msg = 'Requested JSON parse failed.';
            } else if (exception === 'timeout') {
                msg = 'Time out error.';
            } else if (exception === 'abort') {
                msg = 'Ajax request aborted.';
            } else {
                msg = 'Uncaught Error.\n' + jqXHR.responseText;
            }
            $('.clsPgLoader').hide();
        }
    });
}
function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
    var expires = "expires=" + d.toUTCString();
    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
        }
        if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}


function getOrderSummery() {
  
      var jsonObj = {
         'CartGrocery': JSON.parse(window.localStorage.getItem('cart_grocery')),
        'CartFood': JSON.parse(window.localStorage.getItem('cart_food')),
        'CartGiftcard': JSON.parse(window.localStorage.getItem('cart_giftcard')),
      }
      resetPhpCart();
      $.ajax({
        url: "ajax-order-summery.php",
         dataType: "text",
         data: {jsonData: jsonObj},
         type: "POST",
        success: function (data) {
             $('.clsPgLoader').hide();
              
             $('.cartright-box-two').html(data);
             var grocery = getCartTotalByKey('cart_grocery');
             var food = getCartTotalByKey('cart_food');
             var giftcard = getCartTotalByKey('cart_giftcard');
			 var events = getCartTotalByKey('cart_events');

            var totalItemsGrocery = grocery[0];
            var totalItemsFood = food[0];
			 var totalItemsEvent = events[0];
            var totalItemsGiftcard = giftcard[0];
            var totalCostGrocery = grocery[1];
            var totalCostFood = food[1];
			var totalCostEvent = events[1];
            var totalCostGiftcard = giftcard[1];
            // Result Grocery
            if (totalItemsGrocery > 1)
                 $('#lblSubItemsGrocery')[0].innerText = '(' + totalItemsGrocery + ' items)';
             else
                 $('#lblSubItemsGrocery')[0].innerText = '(' + totalItemsGrocery + ' item)';
  
            $('#lblGrandTotalGrocery')[0].innerText = '$' + totalCostGrocery.toFixed(2);
             // Result Food
             if (totalItemsFood > 1)
                 $('#lblSubItemsFood')[0].innerText = '(' + totalItemsFood + ' items)';
             else
                 $('#lblSubItemsFood')[0].innerText = '(' + totalItemsFood + ' item)';
            $('#lblGrandTotalFood')[0].innerText = '$' + totalCostFood.toFixed(2);
			
			 // Result Event
             if (totalItemsEvent > 1)
                 $('#lblSubItemsEvent')[0].innerText = '(' + totalItemsEvent + ' items)';
             else
                 $('#lblSubItemsEvent')[0].innerText = '(' + totalItemsEvent + ' item)';
            $('#lblGrandTotalEvent')[0].innerText = '$' + totalCostEvent.toFixed(2);
            
            // Result Gift Card
             if (totalItemsGiftcard > 1)
                 $('#lblSubItemsGiftcard')[0].innerText = '(' + totalItemsGiftcard + ' items)';
             else
                 $('#lblSubItemsGiftcard')[0].innerText = '(' + totalItemsGiftcard + ' item)';
            $('#lblGrandTotalGiftcard')[0].innerText = '$' + totalCostGiftcard.toFixed(2);
            
             // Result Total
            var totalCost = grocery[1] + food[1];
             $('#hdnCartTotal').val(totalCost.toFixed(2));
             var first_sname = '';
            if ($(window).width() < 800)
                removeCartStoreSlider();
            $('#stores a').remove();
            $('#product .clsCartProd').remove();
            var lstCart = [], lstStores = [], cart = [];
            var allstore_total = 0, allstore_items = 0;
            if (cartKey == '')
                lstCart = getAllCart();
            else {
                 var cart = window.localStorage.getItem(cartKey);
                 if (cart != null && cart != '')
                     lstCart = JSON.parse(cart);
             }
 
            if (lstCart.length > 0) {
                 for (var i = 0; i < lstCart.length; i++) {
                     if (i == 0)
                         first_sname = lstCart[i].sname;
 
                     if (!lstStores.includes(lstCart[i].sid)) {
 
                        lstStores.push(lstCart[i].sid);
                         var tmpArr = lstCart.filter(function (el) {
                             return el.sid == lstCart[i].sid;
                         });
                       var totalProds = tmpArr.length;
                        var total = 0;
                        for (j = 0; j < tmpArr.length; j++)
                            total += parseFloat(tmpArr[j].calcprice) * parseInt(tmpArr[j].qty);
                        allstore_total += total;
                        allstore_items += totalProds;
                        var template = $('#tempStore').html();
                        template = template.replace('[SID]', lstCart[i].sid);
                        template = template.replace('[SID2]', lstCart[i].sid);
                        template = template.replace('[Simg]', lstCart[i].simg);
                        template = template.replace('[Name]', lstCart[i].sname);
                        template = template.replace('[Name2]', lstCart[i].sname);
                        template = template.replace('[total]', total.toFixed(2));
                        if (totalProds > 1)
                            template = template.replace('[items]', totalProds + ' items');
                        else
                            template = template.replace('[items]', totalProds + ' item');
                        $('#stores').append(template);
                    }
                }
                if (lstStores.length > 0) {
                    var template = $('#tempStore').html();
                    template = template.replace('[SID]', '0');
                    template = template.replace('[SID2]', '0');
                    template = template.replace('[Simg]', '/images/allstores.png');
                    template = template.replace('[Name]', '');
                    template = template.replace('[Name2]', '');
                    template = template.replace('[total]', allstore_total.toFixed(2));
                    if (totalProds > 1)
                        template = template.replace('[items]', allstore_items + ' items');
                    else
                        template = template.replace('[items]', allstore_items + ' item');
                    $('#stores').prepend(template);
                    var flgAutoSel = true;
                    if (getCookie('cart_tab_store') != "") {
                        var storeLink = $('#stores a[data-sid="' + getCookie('cart_tab_store') + '"]');
                        if (storeLink.length > 0) {
                            $(storeLink).click();
                            flgAutoSel = false;
                        }
                    }
                    if (flgAutoSel)
                        getCart($('#stores a:first-child'), lstStores[0], first_sname);
                    if ($(window).width() < 800)
                        addCartStoreSlider();
                }
            } else {
                if (cartKey == '')
                    $('#lblCartStoreName')[0].innerText = "You do not have any item in cart";
                else if (cartKey == 'cart_grocery')
                    $('#lblCartStoreName')[0].innerText = "You do not have any item in Grocery";
                else
                    $('#lblCartStoreName')[0].innerText = "You do not have any item in Food";
            }
          },
        error: function (jqXHR, exception) {
            var msg = '';
             if (jqXHR.status === 0) {
                 msg = 'Not connect.\n Verify Network.';
             } else if (jqXHR.status == 404) {
                 msg = 'Requested page not found. [404]';
             } else if (jqXHR.status == 500) {
                 msg = 'Internal Server Error [500].';
             } else if (exception === 'parsererror') {
                 msg = 'Requested JSON parse failed.';
             } else if (exception === 'timeout') {
                 msg = 'Time out error.';
             } else if (exception === 'abort') {
                 msg = 'Ajax request aborted.';
             } else {
                 msg = 'Uncaught Error.\n' + jqXHR.responseText;
             }
            $('.clsPgLoader').hide();
        }
    });

}
function searchStore(keyValue, myArray){
    for (var i=0; i < myArray.length; i++) {
        if (myArray[i].storeid === keyValue) {
            return myArray[i];
        }
    }
    return false;
}
function openSlotDialog(id) {
    $('#' + id).fadeIn('fast', function () {
        $(this).find('.clsDialog-Box').slideDown('normal');
        $(this).find('.clsDialog-Box').css({'pointer-events': 'auto'});
    });
}
function closeSlotDialog(id) {
    $('#' + id).find('.clsDialog-Box').slideUp('fast', function () {
        $('#' + id).fadeOut('fast');
        $('#' + id).find('.clsDialog-Box').css({'pointer-events': 'none'});
    });
}


function searchQtyByPidSize(pid, sizeid, myArray){
    for (var i=0; i < myArray.length; i++) {
        if (myArray[i].pid=== pid && myArray[i].sizeid == sizeid) {
            return  [myArray[i], i];
        }
    }
    return false;
}
  
 function deleteFromArray(lstCart) {
    for (var i = 0; i < lstCart.length; i++) {

        if (lstCart.length > 0) {
            if (lstCart[i].section == 'seasoning' && lstCart[i].subscriptiontype != $('#hdnSubcriptionTYpe').val()) {
                lstCart.splice(i, 1);
              lstCart =  deleteFromArray(lstCart)
            }  

        }

    } 
    return lstCart;
}

 





function getpriceaftermemberdiscount(rawprice,discount){
  var discountedprice=(parseFloat(rawprice)-(parseFloat(rawprice)*discount)/100).toFixed(2);
  return discountedprice;
}

Directory Contents

Dirs: 2 × Files: 11

Name Size Perms Modified Actions
bootstrap DIR
- drwxrwxr-x 2023-11-07 19:59:50
Edit Download
- drwxrwxr-x 2023-11-07 19:59:50
Edit Download
40.98 KB lrwxrwxr-x 2023-11-07 19:59:50
Edit Download
11.15 KB lrwxrwxr-x 2023-11-07 19:59:50
Edit Download
92.62 KB lrwxrwxr-x 2023-11-07 19:59:50
Edit Download
84.33 KB lrwxrwxr-x 2023-11-07 19:59:50
Edit Download
441.14 KB lrwxrwxr-x 2023-11-07 19:59:50
Edit Download
70.63 KB lrwxrwxr-x 2023-11-07 19:59:50
Edit Download
21.56 KB lrwxrwxr-x 2023-11-07 19:59:50
Edit Download
2.47 KB lrwxrwxr-x 2023-11-07 19:59:50
Edit Download
22.44 KB lrwxrwxr-x 2023-11-07 19:59:50
Edit Download
78.95 KB lrwxrwxr-x 2023-11-07 19:59:50
Edit Download
3.76 KB lrwxrwxr-x 2023-11-07 19:59:50
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).