$(document).ready(function () {
GetRecords();
});
var pageIndex = 0;
var pageCount;
var recordsPerPage = 6;
$(window).scroll(function () {
if ($(window).scrollTop() == 0) {
GetRecords();
}
else if (($(window).scrollTop() + 100) == (($(document).height() + 100) - $(window).height())) {
GetRecords();
}
});
function SetRecordsPerPage() {
var width = $(window).width();
var recordPerHeight = parseInt($(window).height() / 100);
if (width < 600) {
recordsPerPage = recordPerHeight * 1 + 2;
}
else if (width < 900) {
recordsPerPage = recordPerHeight * 2;
}
else {
recordsPerPage = recordPerHeight * 3;
}
}
function GetRecords() {
document.getElementById("lblEmptyList").style.display = "none";
SetRecordsPerPage();
pageIndex++;
// var itemId = "0";
var itemId = document.getElementById("hdnSelectedCategory").value.split(",")[2] != undefined ? document.getElementById("hdnSelectedCategory").value.split(",")[2] : "0";
var brandId = "0";
var searchString = "";
if (document.getElementById("hdfFltrBrand") != null && document.getElementById("hdfFltrBrand").value != "") {
brandId = document.getElementById("hdfFltrBrand").value;
}
if (document.getElementById("hdfFltrItem") != null && document.getElementById("hdfFltrItem").value != "") {
itemId = document.getElementById("hdfFltrItem").value;
}
// To remove the page count *** if (pageIndex == 1 || pageIndex <= pageCount) {
if (pageIndex >= 0) {
document.getElementById("Listloader").style.display = "block";
var Url;
var data1;
if (window.location.href.indexOf("q") == -1) {
Url = "/ProductList.aspx/GetProductsByCategoryId";
data1 = '{pageIndex: ' + pageIndex + ',recordsPerPage: ' + recordsPerPage + ',SelectedCategory: ' + JSON.stringify(document.getElementById("hdnSelectedCategory").value) + ',BrandId: ' + JSON.stringify(brandId) + ',ItemId: ' + JSON.stringify(itemId) + '}';
} else {
searchString = GetParameterValues("q");
document.getElementById("lblfilterItemDisplay").innerHTML = (searchString.replace('#', '')).toUpperCase();
Url = "/ProductList.aspx/GetProductsByKeyword";
data1 = '{pageIndex: ' + pageIndex + ',recordsPerPage: ' + recordsPerPage + ',keyword: ' + JSON.stringify(searchString) + ',BrandId: ' + JSON.stringify(brandId) + ',ItemId: ' + JSON.stringify(itemId) + '}';
}
$.ajax({
type: "POST",
url: Url,
data: data1,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
});
}
}
function GetParameterValues(param) {
var url = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < url.length; i++) {
var urlparam = url[i].split('=');
if (urlparam[0] == param) {
return decodeURIComponent(urlparam[1]);
}
}
}
function toTitleCase(str) {
return str.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
}
function OnSuccess(response) {
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
pageCount = parseInt(xml.find("PageCount").eq(0).find("PageCount").text());
var products = xml.find("ProductList");
var volumeandquantity = xml.find("VolumeandQuantity");
if (products.length == 0 && pageIndex == 1) {
$("#dvProductList").html('');
document.getElementById("Listloader").style.display = "none";
document.getElementById("products").style.minHeight = "20px";
document.getElementById("lblEmptyList").style.display = "block";
return false;
}
//All Products Loop
products.each(function () {
var product = $(this);
var div = $("#dvProductListDesign").eq(0).clone(true);
$("#dvList1", div).css("display", "block");
$("#dvList1", div).attr("ID", "dvList");
if ($("#hdnDivClear").val().length == 0) {
$("#dvProductList").html('');
$("#hdnDivClear").val('done');
}
var sltActualVolumePrice = $("#ddlActualVolumePrice", div);
$(sltActualVolumePrice).html('');
$('#divOfferSummary', div).html('');
var currentProductId = product.find("ProductId").text();
var DiscountSet = 0;
var cartvalueset = 0;
//All volumes Loop
volumeandquantity.each(function () {
var volumequantity = $(this);
var xmlProductId = volumequantity.find("ProductId").text();
if (currentProductId == xmlProductId) {
// var outofStock = volumequantity.find("CurrentQuantity").text() != "0" ? "1" : "0"; // if ((sltActualVolumePrice).children(":selected").val() === "" || (sltActualVolumePrice).children(":selected").val() === undefined) {
var selected = volumequantity.find("IsOutOfStock").text() == "0" ? "selected" : ""; // if ((sltActualVolumePrice).children(":selected").val() === "" || (sltActualVolumePrice).children(":selected").val() === undefined) {
//Offer
var discountPercentage = parseInt(volumequantity.find("DiscountPercent").text());
if (discountPercentage != null && discountPercentage > 0) {
$('#divOffer', div).attr('style', 'display: block');
$('#divOfferText', div).html(discountPercentage + '% Off');
$('#divImgOffer', div).attr('style', 'display: block');
$('#divOfferSummary', div).attr('style', 'display: -webkit-inline-box');
$('#divOfferSummary', div).append(volumequantity.find("Volume").text() + " : ₹" + volumequantity.find("Price").text() + " ₹" + volumequantity.find("OriginalPrice").text() + "
");
DiscountSet = 1;
if (cartvalueset == 0) {
$(".spanQuantityInCart", div).attr("ID", "spanQtyInCart" + volumequantity.find("SellerProductStockId").text());
GetCartCount(volumequantity.find("SellerProductStockId").text());
cartvalueset = 1;
$(".spanQuantityInCart", div).attr('style', 'display: grid');
}
} else if (DiscountSet == 0) {
$('#divOffer', div).attr('style', 'display: none');
$('#divOfferSummary', div).attr('style', 'display: none');
if (cartvalueset == 0) {
$(".spanQuantityInCart", div).attr("ID", "spanQtyInCart" + volumequantity.find("SellerProductStockId").text());
GetCartCount(volumequantity.find("SellerProductStockId").text());
cartvalueset = 1;
$(".spanQuantityInCart", div).attr('style', 'display: grid');
}
}
// var selected = volumequantity.find("IsOutOfStock").text() == "false"? "selected" : ""; // if ((sltActualVolumePrice).children(":selected").val() === "" || (sltActualVolumePrice).children(":selected").val() === undefined) {
if (volumequantity.find("IsOutOfStock").text() == "0" || volumequantity.find("IsOutOfStock").text() == "false")
selected="selected"
else
selected = ""
//out of stock
if (selected == "") {
if (!$('#divOutofStock', div).css("display") == "none" || ($('#divOutofStock', div).css("display") == "none" && $(sltActualVolumePrice).html().trim() == "")) {
$('#divOutofStock', div).attr('style', 'display: grid');
$('#spnPlus', div).attr('style', 'display: none');
$('#spnMinus', div).attr('style', 'display: none');
$(".spanQuantityInCart", div).attr('style', 'display: none');
}
} else {
$(".spanQuantityInCart", div).attr("ID", "spanQtyInCart" + volumequantity.find("SellerProductStockId").text());
GetCartCount(volumequantity.find("SellerProductStockId").text());
$(".spanQuantityInCart", div).attr('style', 'display: grid');
$('#divOutofStock', div).attr('style', 'display: none');
$('#spnPlus', div).attr('onclick', 'qtyplusClick1(this)');
$('#spnMinus', div).attr('onclick', 'qtyminusClick1(this)');
$('#spnPlus', div).attr('style', 'display: grid');
$('#spnMinus', div).attr('style', 'display: grid');
}
$(sltActualVolumePrice).append("");
}
});
$(".productName", div).html(product.find("ProductName").text());
$(".price", div).html(product.find("Price").text());
$(".productImage", div).attr("src", "https://cdn1.Myrightbuy.com/images/" + product.find("ImageName").text().replace('_Thumb', '_M'));
$("#dvProductList").append(div);
var url = GetNameForURL("/" + product.find("ProductName").text().replace("'", "") + "/p/" + product.find("ProductRefId").text());
$("#aProductImage", div).attr("href", url);
});
document.getElementById("Listloader").style.display = "none";
}