jQuery(window).on('load',function(){$("#preloader").fadeOut("slow");});$(document).ready(function(){load_shopping_cart();/*load_wish_item();*/});function load_shopping_cart(){$('.btn_cart').removeClass('active1');$('.btn_cart.tocart').html('ADD TO CART');$('.btn_cart .btn-outlined').html('ADD TO CART');var tableData='';$.post("connection/my_cart_conn",{load_mini_cart:'data'},function(data){var tot_qty=0;var tot_amount=0;tableData+='<div class="minicart-content-wrapper" style="margin:10px"></div>';if(data===''){tableData+='<hr><p>Your cart is currently empty.</p>';}else{tableData+='';$.each(data[0],function(index,data){tot_qty+=parseInt(data.Qty);tot_amount+=parseInt(data.Qty)*parseFloat(data.price);tableData+='<div class="content col-md-12"><div class="col-md-9" style="padding-left: 10px; padding-right:10px;" align=center><h6 style=margin:0px><a href="product-details?id='+data.Item_Code+'">'+data.name+'</a></h6><span class="prize">LKR '+data.price+' X '+data.Qty+'</span></div><div class="col-md-3" style="padding-left: 0px; padding-right:10px;"><a href="product-details?id='+data.Item_Code+'"><img src="backend/upload/item/'+data.Item_Code+'/'+data.img+'" alt="'+data.name+'" width="50px"></a></div></div><hr style="margin-top:5px; margin-bottom:12px; width:75%;" center>';});tableData+='<div class="content col-md-12"><div class="mini_action checkout col-md-6" style="padding-bottom: 15px;"><a class="btn btn-inverse" href="checkout">CHECKOUT</a> </div> <div class="mini_action cart  col-md-6" style="padding-bottom: 15px;"><a class="btn btn-inverse" href="my-cart">VIEW CART</a> </div></div>';$.each(data[1],function(index,data){var item_id=data;$('.btn_itm_'+item_id).addClass('active1');$('.tocart.btn_itm_'+item_id).html('ADDED TO CART');$('.btn-outlined.btn_itm_'+item_id).html('ADDED TO CART');});}
	tableData+='</div>';$('.minicart__active').html('').append(tableData);$('.product_qun').text(tot_qty+' item(s)');$('.tot').text('LKR '+parseFloat(tot_amount).toFixed(2));$('.cart_qty_small').text(tot_qty+' Items');$('#tot_amount').text('LKR '+parseFloat(tot_amount).toFixed(2));var container=$('.minicart__active');$('.micart__close').on('click',function(){container.removeClass('is-visible');});$(".remove_btn").click(function(){var id=$(this).attr('data-value');$.post('connection/my_cart_conn',{remove_item:'data',id:id},function(data){load_shopping_cart();},"json");});},"json");}
$(".btn_cart").click(function(){var item_id=$(this).val();var qty1=$('#input-quantity').val();
	if(qty1>=1){qty=qty1;}else{qty=1;}$.post('connection/my_cart_conn',{add_to_cart:'data',item_id:item_id,qty:qty},function(data){if(data.msgType===1){showSuccessMsg();load_shopping_cart();}else if(data.msgType===3){showStockOutMsg();}},"json");$('#productmodal').modal('hide');$('#itm_qty').val(1);});function load_cart_table(){var tableData='';$.post("connection/my_cart_conn",{load_mini_cart:'data'},function(data){var tot_amount=0;var sub_tot=0;var dis_tot=0;var tot=0;$('#g_tot').text('0.00');if(data===''){$('.price-total').hide();$("#pre_loader").fadeOut();tableData+='<blockquote>Your cart is currently empty.</blockquote>';}else{tableData+='<table width="100%" class="table-bordered" style="margin-bottom:20px;"><thead><tr class="title-top"><th width="15%" class="product-thumbnail">Image</th><th class="product-name" width="30%">Product</th><th width="15%" class="product-price">Unit Price <br>(LKR)</th><th class="product-quantity" width="15%">Quantity</th><th width="15%" class="product-subtotal">Subtotal <br>(LKR)</th><th class="product-remove" width="10%">Remove</th></tr></thead><tbody>';$.each(data[0],function(index,data){tot=(data.Qty)*(data.price);sub_tot+=(data.Qty)*(data.price);tot_amount+=tot;tableData+='<tr><td class="product-thumbnail"><a href="product-details?id='+data.Item_Code+'"><img src="backend/upload/item/'+data.Item_Code+'/'+data.img+'" alt="'+data.name+'" width="75" style="padding:10px"></a></td><td class="product-name"  style="text-align:left; padding-left: 20px"><a href="product-details?id='+data.Item_Code+'">'+data.name+'</a></td><td class="product-price"><span class="amount">'+data.price+'</span></td><td class="product-quantity"><div style="display:inline-flex;align-items: center;"><input type="number" value="'+data.Qty+'" min=1 id="qty_'+data.id+'" onkeypress="return isNumberKey(event, this)" autocomplete="off" class="form-control" style="width:60px;"> &nbsp;<a href="javascript:void(0);" class="qty_up" data-value="'+data.id+'" title="Edit Quantity"><i class="fa fa-pencil"></i></a></div></td><td class="product-subtotal">'+parseFloat(tot).toFixed(2)+'</td><td class="product-remove"><a href="javascript:void(0);" class="product-remove" title="Remove Item" data-value="'+data.id+'"><i class="fa fa-trash-o"></i></a></td></tr>';});tableData+='</tbody></table>';$('.price-total').show();}
	dis_tot=sub_tot-tot_amount;$('#shop_tbl').html('').append(tableData);$('#sub_tot').text(parseFloat(sub_tot).toFixed(2));$('#g_tot').text(parseFloat(tot_amount).toFixed(2));$('#dis_tot').text(parseFloat(dis_tot).toFixed(2));$('#net_amount').val(parseFloat(tot_amount).toFixed(2));$(".product-remove").click(function(){$("#pre_loader").fadeIn();var id=$(this).attr('data-value');$.post('connection/my_cart_conn',{remove_item:'data',id:id},function(data){load_cart_table();showRemoveMsg();setTimeout(function(){load_shopping_cart();get_delivery_fee();},1000);},"json");});$(".qty_up").click(function(){$("#pre_loader").fadeIn();var id=$(this).attr('data-value');var qty=$('#qty_'+id).val();$.post('connection/my_cart_conn',{update_qty:'data',id:id,qty:qty},function(data){if(data.msgType===3){showStockOutMsg();}setTimeout(function(){load_cart_table();load_shopping_cart();
	get_delivery_fee();
},500);},"json");});},"json");}
	$(".btn_wish").click(function(){var item_id=$(this).attr('data-product-id');$.post('connection/my_cart_conn',{add_to_wishlist:'data',item_id:item_id},function(data){if(data.msgType===1){$('#wish_'+item_id).toggleClass('fa-heart-o fa-heart');$('#wish2_'+item_id).hide();load_wish_item();}else if(data.msgType===3){window.location.href='sign-in';}else{}},"json");});function load_wish_item(){$('.btn_wish').removeClass('active');$('.btn_wish2').html('Add To Wishlist');$.post("connection/my_cart_conn",{wish_btn_disable:'data'},function(data){if(data===''){$('.tot_wish').text('0');}else{$.each(data,function(index,data){var item_id=data.item_id;$('.btn_wh_'+item_id).addClass('active');$('.btn_wish2.btn_wh_'+item_id).html('Added To Wishlist');});$('.tot_wish').text(data.length);}},"json");}
	showSuccessMsg=function(){'use strict';resetPosition();$.toast({heading:'New item has been added to your cart',closeButton:true,text:'',showHideTransition:'slide',icon:'success',bgColor:'#51a351',progressBar:true,loaderBg:'#42671a',position:'bottom-right',textColor:'#fff'})};showRemoveMsg=function(){'use strict';resetPosition();$.toast({heading:'Successfully Removed.',closeButton:true,text:'',showHideTransition:'slide',icon:'success',progressBar:true,loaderBg:'#42671a',position:'bottom-right',textColor:'#fff'})};showStockOutMsg=function(){'use strict';resetPosition();$.toast({heading:'Stock Not Available',closeButton:true,text:'',showHideTransition:'slide',icon:'success',bgColor:'#c41f24',progressBar:true,loaderBg:'#e82c19',textColor:'#fff',position:'bottom-right',})};resetPosition=function(){$('.jq-toast-wrap').removeClass('bottom-left bottom-right top-left top-right mid-center');$(".jq-toast-wrap").css({"top":"","left":"","bottom":"","right":""});};function isNumberKey(evt,obj){var charCode=(evt.which)?evt.which:event.keyCode
		var value=obj.value;var dotcontains=value.indexOf(".")!=-1;if(dotcontains)
		if(charCode==46)return false;if(charCode==46)return true;if(charCode<=57&&charCode>=48)
		return true;return false;}
		$(".btn_view").click(function(){var item_id=$(this).attr('data-product-id');$('#itm_cart_btn').attr('data-product-id',item_id);$('#itm_wish_btn').attr('data-product-id',item_id);$('#itm_qty').val(1);$('#itm_name').text('');$('#itm_code').text('');$('#itm_availble').text('');$('#itm_price').text('');$('#itm_old_price').text('');$('.itm_imgs').html('');$('#itm_old_price').removeClass('hidden');$.post("connection/my_cart_conn",{get_item_details:"data",item_id:item_id},function(data){var stk=clz=ct=aut='';$('#itm_name').text(data[0].name);$('#itm_code').text(data[0].item_code);if(data[0].stk==0&&data[0].weight>0){stk='In Stock';$('#itm_btn_view').show();}else{stk='Out of Stock';$('#itm_btn_view').hide();}
			$('#itm_availble').text(stk);var old_price=data[0].price;if(data[0].dis==0){var new_price=old_price;clz='hidden';}else{var new_price=(old_price-(old_price*data[0].dis/100));clz='';}
			$('#itm_price').text('LKR '+parseFloat(new_price).toFixed(2));$('#itm_old_price').text('LKR '+parseFloat(old_price).toFixed(2));$('#itm_old_price').addClass(clz);var f_img=data[0].fimg;var b_img=data[0].bimg;var front_img=back_img=itm_imgs='';if(f_img===''){front_img='noimg.jpg';}else{front_img=f_img;}
			itm_imgs+='<div class="single-slide"><img src="image/items/'+front_img+'" alt="'+data[0].name+'"></div>';$('.itm_imgs').html(itm_imgs);},"json");});