	
  var productLoadMore = false;
  var productSkip = 0;
  var productTake = 9;
  var proSubCat = "";
  var loadMoreProcess  = false;
  var l_category;
  var l_sub_category;
  var l_sub_category_name;
  function product_list(category,sub_category,sub_category_name){
    $("html, body").animate({ scrollTop: 0 }, "slow");
    $("#main-Content").html("");
    productSkip = 0;
    loadMoreProcess = false;
    l_category = category;
    l_sub_category = sub_category;
    l_sub_category_name = sub_category_name;
    $("#page-loading").show();
    $.post("product_list.php", {category : category,sub_category:sub_category,sub_category_name:sub_category_name,take : productTake,skip : productSkip}, function(result){
      
      data = JSON.parse(result);
      productLoadMore = data["next"];
      productSkip = data["skip"];
      proSubCat = sub_category;
     
      $('#main-Content').append(
        $('<div/>')
          .attr("id", "product-content")
          .addClass("container-xxl flex-grow-1 container-p-y")
          .append('<h4 class="fw-bold py-3 mb-4"><span class=" fw-light">'+category+' /</span><span class=" fw-light"> '+sub_category_name+' </span> </h4>')
          .append("<script type=\"text/javascript\">$(window).scroll(function() {console.log($(document).height() - $(window).height());console.log($(window).scrollTop()); if($(window).scrollTop()+100 > $(document).height() - $(window).height()) {if(productLoadMore){ load_more_product_list()}} })</script>")
          .append("<div/>")
            .attr("id", "product-row")
            .addClass("row mb-5")
            .append(data["products"].join(''))
      );
      cart_btn();
      $("#page-loading").hide();
  });
  }

  var load_more_success = function(result){
       data = JSON.parse(result);
       productLoadMore = data["next"];
       productSkip = data["skip"]; 
       $('#product-row').append(data["products"].join(''))
       $("#page-loading").hide();
       loadMoreProcess = false;
  }

  function load_more_product_list(){
    if(!loadMoreProcess){
      loadMoreProcess = true;
       $("#page-loading").show();
      $.post("product_list.php", {category : l_category,sub_category:proSubCat,sub_category_name:l_sub_category_name,take : productTake,skip : productSkip},load_more_success);
    }
    
  }

  

  function product_list_by_name(pro_name){
     $("#page-loading").show();
    $.post("product_list_search.php", {pro_name : pro_name}, function(result){
      $("#main-Content").html(result);
       $("#page-loading").hide();
  });
  }
  function page_cart(){
    $("#main-Content").html("");
    $("#div-cart-stick").html("");
  	$.post("cart.php", {}, function(result){
	    $("#main-Content").html(result);
	});
  }
  function page_order(){
    $("#main-Content").html("");
    $("#div-cart-stick").html("");
  	$.post("create_order.php", {}, function(result){
	    $("#main-Content").html(result);
	});
  }
  function page_payment(){
    $("#main-Content").html("");
    $("#div-cart-stick").html("");
  	$.post("payment.php", {}, function(result){
	    $("#main-Content").html(result);
	});
  }
  /*
  const img = document.getElementsByTagName("img")
	img.addEventListener("error", function(event) {
	  event.target.src = "https://via.placeholder.com/150/"
	  event.onerror = null
	})*/
  function add_cart(id,code,name,desc,price,img,warranty){
  	$.post("add_cart.php", {id : id,code : code,name : name,desc : desc,price : price,img : img,warranty : warranty}, function(result){
	    Swal.fire({
		  position: 'top-end',
		  timer: 5000,
		  html:result
		})
      cart_btn();
	});
  }

  function cart_add_qty($pro_id){
  	$.post("cart.php", {action:'1',pro_id : $pro_id}, function(result){
	    $("#main-Content").html(result);
      cart_btn();
	});
  }
  function cart_minus_qty($pro_id){
  	$.post("cart.php", {action:'2',pro_id : $pro_id}, function(result){
	    $("#main-Content").html(result);
      cart_btn();
	});
  }
  function cart_delete_item($pro_id){
  	$.post("cart.php", {action:'3',pro_id : $pro_id}, function(result){
	    $("#main-Content").html(result);
      cart_btn();
	});
  }

  function order_confirm(e){
     Swal.fire({
        position: 'top-end',
        timer: 3000,
        html:'Confirm Order Success !!',
        showConfirmButton: false,
    });
     $(e).hide();


  }
  function cart_btn(){
      $.get("cart-btn.php", {}, function(result){
        $("#div-cart-btn").html(result);
        $("#div-cart-stick").html(result);
        
    });
  }

function changeCurrency(el){
	 var value = el.value;  
	 $.post("changeCurrency.php", {currency:value}, function(result){
	   window.location.href = "https://itmecom.com";
	});
}




