
/* Product Listing based on Page Scroll */
/* Class Page */
function Page(){
	
	/* Private variables */
	var __PAGE=1,uniqueID=new Array(),__DEALEND=false,__HOLD=false,viewType='grid', sortBy=default_catalog_listing;
	this.ajaxResponses=new Array();
	
	/* Methods */
	/* Function to get the page number */
	this.getPageNumber=function(){
		return __PAGE;
	}
	/* Function to increment the page number */
	this.setPageNumber=function(newVal){
		__PAGE = (newVal >='0') ? newVal : (__PAGE+1);
	}
	/* Function to push the unique iD which is generated during the GetJSON function */
	this.setUniqueIDs=function(unique){
		uniqueID.push(unique);
	}
	/* Function to retriev ethe unfique IDs */
	this.getUniqueIDs=function(unique){
		return uniqueID;
	}
	/* Function to check the product list end or not */
	this.getProductsEndStatus=function(){
		return __DEALEND;
	}
	/* Function to set the product end status is End and no product is vailable for Listing */
	this.setProductsEndStatus=function(){
		__DEALEND = true;
	}
	this.resetProductsEndStatus=function(){
		__DEALEND = false;
	}
	this.checkAjaxHold=function(){
		return __HOLD;
	}
	this.ajaxHold=function(bool){
		__HOLD = bool;
	}
	
	/* Function to get the catalog product listing view mode */
	this.getViewType=function(){
		return viewType;
	}
	/* Function to switch view mode */
	this.setViewType=function(newViewType){
		viewType = newViewType;
	}
	/* To get the catalog product listing sort by */
	this.getSortBy=function(){
		return sortBy;
	}
	/* To set sort by */
	this.setSortBy=function(newSortBy){
		sortBy = newSortBy;
	}
	this.lazyLoad = function(uniqueID) {
        $("[uniqueid='" + uniqueID + "'] .lazy").lazyload({
            effect: "fadeIn",
			event : "sporty",
            threshold: -20
        });
		$("[uniqueid='" + uniqueID + "'] .lazy").trigger("sporty")
		//addToCompare.markCheckedItems();
    }
	
	/* this.lazyLoad=function(uniqueID){
		$("[uniqueid='"+uniqueID+"'] .lazy").lazyload({ 
			effect : "fadeIn",
			threshold:200
		}).trigger("scroll");
		
	} */
}

/* Create an Object of Page Class */
var page=new Page();
var totCatCnt = 0;
$(document).ready(function () {

	$(document).on("click",".qkView:not(.detail)", function(){
		var productAndOptionID = $(this).attr('rel');
                var sp = productAndOptionID.split("-");
		var productID = $(this).attr('productid');
		var checked = $("[rel=checkbox_compare_"+productID+"]").prop('checked');
		var geturl = '/index/ajaxQuickView/id/'+productAndOptionID+'/l/'+languageID+'/checked/'+checked+'/originCatalogID/'+originCatalogID;
		$.ajax({
			url: GLOBAL_BASE_PATH + geturl,
			method: "GET",
			cache: true,
			global: false,
			success: function(qvHtml) {
				$("#CategoryPopup").empty().html(qvHtml);	//Append the new HTML into listing DIV
                                $("#selectedProductOption").val(sp[1]);
				fn_change_options('', productID);
				lightbox_open();
			}
		});
	
	
	});
       
	jQuery.expr[":"].contains = jQuery.expr.createPseudo(function(arg) {
		return function( elem ) {
			return jQuery(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
		};
	});


	
	
	
	
	window.document.onkeydown = function(e) {
		if(!e){ e = event; }
		if(e.keyCode == 27){ lightbox_close(); }
	}
	
	
	$(document).on("click","#view_more_products",function () {
		if(!page.getProductsEndStatus() && !page.checkAjaxHold()){
			/* Condition to check whether the scroll is Bottom */
			var multiProductListDiv = $("#prodListingUl").children('li:last');			
			if(multiProductListDiv.length>0){
				var multiProductListDivTop = multiProductListDiv.position().top;
				var multiProductListDivHeight = multiProductListDiv.height();
					var searchVar = setNavOptions('C');
					var key	= searchVar[1];
					if(typeof page.ajaxResponses[key] == 'undefined') {
						var paramData	=	searchVar[0];
						paramData.lan	=	languageID;
                                                paramData.ckey	=	lastCatkey;
						var uniqueID = paramData['uniqueID'];						
						$.ajax({
							url:GLOBAL_BASE_PATH + '/api/product/ajaxList/',
							type: "POST",
							cache: true,
							data: paramData,
							dataType:'json',
							beforeSend: function () {
								page.ajaxHold(true);
								$(".pop_loader").removeClass('hide');
								$(".pop_loader").show();
							},
							complete:function(){
								page.ajaxHold(false);
								$(".pop_loader").addClass('hide');
								$(".pop_loader").hide();
							}
						}).done(function(data) {
							if(!$.isEmptyObject(data)){
                                                                
                                                                var tempDataCnt = data.length;
                                                                var tempData    = data[tempDataCnt-1];
                                                                //products = $.merge( products ,data);
								page.setPageNumber();
                                                                //var tempData = $.parseJSON(tempData);
                                                                 
								if(paramData.viewType=='grid'){
									var resHtml= $("#CatelogGridTemplate").render(data,{"viewType" : paramData.viewType,"listUsersWishListItems":listUsersWishListItems});
								}
								else {
									var resHtml= $("#CatelogGridTemplate").render(data,{"viewType" : paramData.viewType,"listUsersWishListItems":listUsersWishListItems});
								}
                                                                
                                                                //alert($(resHtml).find('.custValues').html());
								/* Append the new HTML into listing DIV  */
								$("#prodListingUl").append(resHtml);
                                                                var sp = tempData['custName'].split("~");
                                                                for(nb=0;nb<sp.length;nb++) {
                                                                  
                                                                   var op = tempData['custOptionVals'][sp[nb]].split("~");
                                                                   
                                                                   for(nbc=0;nbc<op.length;nbc++) {
                                                                       
                                                                        var cn = 0;
                                                                        var optval = op[nbc].split("|");
                                                                         $(".attrCustOptionList_"+sp[nb]+" li").children( ".searchCustOptID_"+sp[nb] ).filter(function() {
                                                                             if($(this).val()==optval[0]) {
                                                                                 cn = 1;
                                                                             }
                                                                         });
                                                                         if(cn<=0) {
                                                                            var custLabelValue = '<li><input type="checkbox" refinehead="'+sp[nb]+'" refineval="'+optval[1]+'" id="searchCustOptID_'+optval[0]+'" rel="'+sp[nb]+'" name="searchCustOptID_'+sp[nb]+'[]" value="'+optval[0]+'" class="searchCustOptID_'+sp[nb]+' custsearch">';
                                                                            custLabelValue =  custLabelValue + '<label class="attributeSearchLabel font-weight-normal my-2" id="searchCustLabel_'+optval[0]+'" for="searchCustOptID_'+optval[0]+'"><span class="d-flex">';
                                                                            if(optval[2]!='') {
                                                                                custLabelValue = custLabelValue+"<img src='"+custImgPath+"/uploads/catalog/custom-option-variant/"+optval[2]+"' width='87' height='32' class='img-fluid mr-2 pr-1' alt='image'/>";
                                                                            }
                                                                            custLabelValue = custLabelValue + optval[1]+'</span></label></li>';                                                                                            
                                                                            $(".attrCustOptionList_"+sp[nb]).append(custLabelValue);  
                                                                         }
                                                                        /*if (check(optval[0],sp[nb])==true) { 
                                                                       
                                                                        } else {
                                                                            var custLabelValue = '<li><input type="checkbox" disabled="" refinehead="'+sp[nb]+'" refineval="'+sp[nb]+'" id="searchCustOptID_'+sp[nb]+'" rel="'+sp[nb]+'" name="searchCustOptID_'+sp[nb]+'[]" value="'+optval[0]+'" class="searchCustOptID_'+sp[nb]+'">';
                                                                            var custLabelValue =  custLabelValue + '<label class="attributeSearchLabel" disabled="" id="searchCustLabel_'+sp[nb]+'" for="searchCustOptID_'+sp[nb]+'">'+optval[1]+' cc '+optval[0]+'</label></li>';
                                                                                                                                                                            
                                                                            $(".attrCustOptionList_"+sp[nb]).append(custLabelValue);
                                                                        }*/
                                                                   }
                                                                  
                                                                    //$(".attrCustOptionList_"+sp[nb]).append(tempData['custOptionVals'][sp[nb]]);
                                                                }
                                                                var bodyStylesContent = tempData['bodyStyles'].split("~");
                                                                for(bc=0;bc<bodyStylesContent.length;bc++) {
                                                                     var cbn = 0;
                                                                        var typeval = bodyStylesContent[bc];
                                                                        var typedis = bodyStylesContent[bc];
                                                                        typeval = typeval.replace(" ","_");
                                                                         $(".attrOptionList li").children( ".searchAttrOptID" ).filter(function() {
                                                                             if($(this).val()==typeval) {
                                                                                 cbn = 1;
                                                                             }
                                                                         });
                                                                         
                                                                         if(cbn<=0) {
                                                                            var typeLabelValue = '<li><input type="checkbox" refinehead="'+typedis+'" refineval="'+typedis+'" id="searchAttrOptID_'+typeval+'" rel="bodytype" class="searchAttrOptID" name="searchAttrOptID[]" value="'+typeval+'">';
                                                                            typeLabelValue =  typeLabelValue + '<label class="attributeSearchLabel" id="searchAttrLabel_'+typeval+'" for="searchAttrOptID_'+typeval+'">';
                                                                            
                                                                            typeLabelValue = typeLabelValue +typedis+'</label></li>';                                                                                            
                                                                            $(".attrOptionList").append(typeLabelValue); 
                                                                         }
                                                                }
								$("#view_more_products").removeClass('hide');
								page.ajaxResponses[key] = {content:resHtml,uniqueID:uniqueID};
								page.lazyLoad(uniqueID);
								/* Set the counter timer [Only for newly generated DIVs] */
								/* Also push the unique iDs into Array */
                                                                if($("#prodListingUl").children('li').length>=productsCountVar){
                                                                    page.setProductsEndStatus();
                                                                    $("#view_more_products").addClass('hide');
                                                                }
                                                                    
							}else{
								page.setProductsEndStatus();
								$("#view_more_products").addClass('hide');
							}	
						});
					}else{
						page.setPageNumber();
						var theResponse = page.ajaxResponses[key];
						$("#prodListingUl").append(theResponse['content']);
						page.lazyLoad(theResponse['uniqueID']);
					}
				
			}
		}
	});
        var check = function(li,newvar) {
            
                                                                            
                                                                            return $(".attrCustOptionList_"+newvar+" li").children( ".searchCustOptID_"+newvar ).filter(function(i, li2) {
                                                                                //alert($(li2).val()+" pp "+li);
                                                                                return $(li2).val() == $(li);
                                                                        }).length > 0;
                                                                       };
	/*
	$(window).scroll(function () {
		if(!page.getProductsEndStatus() && !page.checkAjaxHold()){
			var multiProductListDiv = $("#prodListingUl").children('li:last');			
			if(multiProductListDiv.length>0){
				var multiProductListDivTop = multiProductListDiv.position().top;
				var multiProductListDivHeight = multiProductListDiv.height();
				if ($(window).scrollTop() >= (multiProductListDivTop-multiProductListDivHeight) || $(window).scrollTop() == $(document).height() - $(window).height()) {
					
					var searchVar = setNavOptions();
					var key	= searchVar[1];
					if(typeof page.ajaxResponses[key] == 'undefined') {
						var paramData	=	searchVar[0];
						paramData.lan	=	languageID;
						var uniqueID = paramData['uniqueID'];						
						$.ajax({
							url:GLOBAL_BASE_PATH + '/api/product/ajaxList/',
							type: "POST",
							cache: true,
							data: paramData,
							dataType:'json',
							beforeSend: function () {
								page.ajaxHold(true);
								$(".pop_loader").removeClass('hide');
							},
							complete:function(){
								page.ajaxHold(false);
								$(".pop_loader").addClass('hide');
							}
						}).done(function(data) {
							if(!$.isEmptyObject(data)){
								page.setPageNumber();
								if(paramData.viewType=='grid'){
									var resHtml= $("#CatelogGridTemplate").render(data,{"viewType" : paramData.viewType,"listUsersWishListItems":listUsersWishListItems});
								}
								else {
									var resHtml= $("#CatelogListTemplate").render(data,{"viewType" : paramData.viewType,"listUsersWishListItems":listUsersWishListItems});
								}
								$("#prodListingUl").append(resHtml);
								page.ajaxResponses[key] = {content:resHtml,uniqueID:uniqueID};
								page.lazyLoad(uniqueID);
							}else{
								page.setProductsEndStatus();
							}	
						});
					}else{
						page.setPageNumber();
						var theResponse = page.ajaxResponses[key];
						$("#prodListingUl").append(theResponse['content']);
						page.lazyLoad(theResponse['uniqueID']);
					}
				}
			}
		}
	});
	*/
	/* toggle : grid view  and list view */
	$(document).on("click",".viewType", function(){
		var thisObj = $(this);
		$(".viewType").removeClass('active');
		thisObj.addClass('active');
                page.setViewType(thisObj.attr('id'));
		if(!page.checkAjaxHold()){	
			switch(thisObj.attr('id')){
				case 'grid':
					$("#prodListingUl").removeClass('list-view');
					break;
				case 'list':
					$("#prodListingUl").addClass('list-view');
					break;
					
			}
		}	
	});
	
    $(document).on("click", ".sortby", function() {
        var thisObj = $(this);
        $(".FltrSort,.sort-select").text($(this).text());
		$(".sortby").removeClass("active");
		$(this).addClass("active");
		$(this).closest(".mob_sort").toggleClass("sorToggle");
        $(this).closest('ul').removeClass('hidden-Mob');
        $('.FltrSort').removeClass('drop-up')
        $(".sortby").prev("span").removeClass("visible");
        thisObj.prev("span").addClass("visible");
        page.setSortBy(thisObj.attr('id'));
        page.setPageNumber(0);
        page.resetProductsEndStatus();
		initProductSearch();
    });
	$(document).on("click", ".items", function() {
        var thisObj = $(this);
		$(this).closest(".tabSelect").removeClass("active");
		$(this).closest(".mob_items").toggleClass("sorToggle");
        thisObj.prev("span").addClass("visible");
		$('.items').removeClass("active");
        thisObj.addClass("active");
        page.setItems(thisObj.attr('items'));
        page.setPageNumber(0);
        page.resetProductsEndStatus();
		initProductSearch();
	});
    
    
	$(document).on("click",".clearAttributeSearch", function(){
		/*var thisRel = $(this).attr('rel');
		if($(".searchAttrOptID[rel='"+thisRel+"']:checked").length>0)
		{
			$(".searchAttrOptID[rel='"+thisRel+"']").prop("checked",false);
			$(".searchAttrOptID[rel='"+thisRel+"']").removeAttr("disabled");
			initProductSearch();
		}	*/
            $("#attrSearchFilter").val('');
            $("#attrSearchFilter").trigger('keyup');
            if($(".searchAttrOptID:checked").length>0)
		{	
			$(".searchAttrOptID").prop("checked",false);
			$(".searchAttrOptID").removeAttr("disabled");
			return true;
		}
                initProductSearch();
		return false;
	});
        $(document).on("click",".clearCustSearch", function(){
		/*var thisRel = $(this).attr('rel');
		if($(".searchAttrOptID[rel='"+thisRel+"']:checked").length>0)
		{
			$(".searchAttrOptID[rel='"+thisRel+"']").prop("checked",false);
			$(".searchAttrOptID[rel='"+thisRel+"']").removeAttr("disabled");
			initProductSearch();
		}	*/
            var thisRel = $(this).attr('rel');
            $("#attrSearchCustFilter_"+thisRel).val('');
            $("#attrSearchCustFilter_"+thisRel).trigger('keyup');
            if($(".searchCustOptID_"+thisRel+":checked").length>0)
		{	
			$(".searchCustOptID_"+thisRel).prop("checked",false);
			$(".searchCustOptID_"+thisRel).removeAttr("disabled");
			return true;
		}
                initProductSearch();
		return false;
	});
        $(document).on("click",".clearCatSearch", function(){
		
            $("#attrSearchCatFilter").val('');
            $("#attrSearchCatFilter").trigger('keyup');
            if($(".searchAttrOptID:checked").length>0)
		{	
			$(".searchAttrCatID").prop("checked",false);
			$(".searchAttrCatID").removeAttr("disabled");
			return true;
		}
                initProductSearch();
		return false;
	});
	$(document).on("click",".searchAttrOptID", function(){
            
		initProductSearch();
	});
        $(document).on("click",".searchAttrCatID", function(){
                
                
                            var piddet = $(this).attr("refinehead").split("_");
                            var pid=piddet[1];
                            var cnt=piddet[2];
                            if(pid<=0) {                          
                               
                                if($(".parent_"+$(this).attr("rel")).length>0) {
                                    $(".parent_"+$(this).attr("rel")).prop('checked', this.checked);
                                }
                            } else {
                                 var re = $(".child_"+pid).attr("refinehead").split("_");
                                 if(re[2]==$(".parent_"+pid+":checked").length) {
                                     $(".child_"+pid).prop('checked', this.checked);
                                 } else {
                                     $(".child_"+pid).prop('checked', false);
                                 }
                            }
                        
                        //return false;
		initProductSearch();
	});
        /*if($("#hidCustName").val()!='') {
            var hidCustName= $("#hidCustName").val().split("~");
            for(r=0;r<hidCustName.length;r++) {
                var n = hidCustName[r];
                $(document).on("click",".searchCustOptID_"+n, function(){
                        initProductSearch();
                });
            }
        }*/
        $(document).on("click",".custsearch", function(){
                        initProductSearch();
        });
        
	priceSliderLoad();
	$(document).on("click",".searchDiscountRange", function(){
		initProductSearch();
	});
        if(_section=='mobile'){ 
           
	$(document).on("click","#applyNow", function(){
            initProductSearch($(this));
            $(".filter-contents").hide();
            
	});
	$(document).on("click","#applyCancel", function(){

            $(".filter-contents").hide();
			$(".clearAllSearch").trigger("click");			
			$("#applyNow").trigger("click");	
			$(".selected_filter").html("None Applied");			
            
	});
        }else{
        $(document).on("change",".checkbox_brandIDs", function(){
		initProductSearch();
	}); 
    }
	
	$(document).on("click",".clearPriceRange", function(){		
		if(resetPriceRange())
		{ 
			initProductSearch();
		}	
	});
        $(document).on("click",".clearPriceEmiRange", function(){		
		if(resetPriceEmiRange())
		{ 
			initProductSearch();
		}	
	});
        
	$(document).on("click",".clearDiscountRange", function(){		
		if(resetDiscountSearch())
		{ 
			initProductSearch();
		}	
	});
	$(document).on("click",".clearAllSearch", function(){	
             
                bmwCode = ''; 
		var clearBrandSearchVar =clearBrandSearch();
		var resetPriceRangeVar = resetPriceRange();
                var resetPriceEmiRangeVar = resetPriceEmiRange();
		//var resetDiscountSearchVar = resetDiscountSearch();
		var resetAttributeSearchVar = resetAttributeSearchAll();
                var resetCatAttributeSearchVar = resetCatAttributeSearch();
                var resetCustAttributeSearchVar = resetCustAllAttributeSearch();
		
		if(clearBrandSearchVar 
			|| resetPriceRangeVar	
                        || resetPriceEmiRangeVar				
			|| resetAttributeSearchVar
                        || resetCatAttributeSearchVar
                        || resetCustAttributeSearchVar)
		{	
			initProductSearch();
		}	
	});
	
	if($( ".listMenuScroll" ).length>0)
	{
		//$('.listMenuScroll').mCustomScrollbar();
	}	
        $(".attrSearchCatFilter").keyup(function(){
		var filter = $(this).val();
		var thisObj = $(this);
		var visibleCount = 0;
		thisObj.next(".listMenuScroll").find(".brand-cat-list li").each(function(){
			if ($(this).text().search(new RegExp(filter, "i")) < 0) {
				$(this).fadeOut();
			} else {
				visibleCount++;
				$(this).show();			
			}
		});
		//if(visibleCount>5)	
			//thisObj.next(".listMenuScroll").mCustomScrollbar();
		//else
			//thisObj.next(".listMenuScroll").mCustomScrollbar('destroy');
	});
	$(".attrSearchFilter").keyup(function(){
		var filter = $(this).val();
		var thisObj = $(this);
		var visibleCount = 0;
		thisObj.next(".listMenuScroll").find(".attrOptionList li").each(function(){
			if ($(this).text().search(new RegExp(filter, "i")) < 0) {
				$(this).fadeOut();
			} else {
				visibleCount++;
				$(this).show();			
			}
		});
		//if(visibleCount>5)	
			//thisObj.next(".listMenuScroll").mCustomScrollbar();
		//else
			//thisObj.next(".listMenuScroll").mCustomScrollbar('destroy');
	});
	$(".attrSearchCustFilter").keyup(function(){
		var filter = $(this).val();
                var rel = $(this).attr('rel');
                
		var thisObj = $(this);
		var visibleCount = 0;
		thisObj.next(".listMenuScroll").find(".attrCustOptionList_"+rel+" li").each(function(){
			if ($(this).text().search(new RegExp(filter, "i")) < 0) {
				$(this).fadeOut();
			} else {
				visibleCount++;
				$(this).show();			
			}
		});
		//if(visibleCount>5)	
			//thisObj.next(".listMenuScroll").mCustomScrollbar();
		//else
			//thisObj.next(".listMenuScroll").mCustomScrollbar('destroy');
	});
	
	$(document).on('keyup',"#filterBrands",function(){
		var val = this.value;
		$(".li_brandIDs").find("label:not(:contains("+val+"))").parent('li').hide();
		$(".li_brandIDs").find("label:Contains(" + val + ")").parent('li').show();
		if($(".li_brandIDs:visible").length >5)	
			$(this).next(".listMenuScroll").mCustomScrollbar();
		else
			$(this).next(".listMenuScroll").mCustomScrollbar('destroy');
	}).on("click","#clearBrands",function(){
		clearBrandSearch();
		initProductSearch();
	});
	
	
	
	
	
	if(typeof __discountQueryString != 'undefined')
	{
		$("#searchDiscountRange_"+__discountQueryString).prop("checked",true);
	}
	$(document).on("click",".filters-top-selected .deleteFilter", function(){
		var thisRel = $(this).attr('rel');
               
		switch(thisRel){
			case 'price':
				resetPriceRange();
				break;
                        case 'emi':
				resetPriceEmiRange();
				break;        
			case 'discount':
				resetDiscountSearch();
				break;
			default:
				$(".checkbox_brandIDs[value='"+thisRel+"']").prop('checked',false);
				$("#searchAttrOptID_"+thisRel).prop("checked",false);
                                $("#searchCustOptID_"+thisRel).prop("checked",false);
                                $("#searchAttrCatID_"+thisRel).prop("checked",false);
                                $(".parent_"+thisRel).prop('checked', false);
                                
                                var parent = $(this).attr('rid');
                                if($(this).hasClass( "cat_"+thisRel ) && parent>0) {
                                    $(".child_"+parent).prop('checked', false);
                                    $(".cat_"+parent).remove();
                                  
                                }
                                if($(this).hasClass( "cat_"+thisRel )) {                                   
                                    totCatCnt = parseFloat($(".series").length)-parseFloat(1);
                                   
                                    if(totCatCnt<=0) {
                                        $(".catdis").removeClass('hide');
                                    }
                                }
                                
		}
		$(this).remove();
		initProductSearch($(this));
	});
	$(document).on("click",".filters-top-selected .deleteFilterHead", function(){
		var thisRel = $(this).attr('rel');
/* 		$("#filters-top-selected_"+thisRel).remove();
		if($(".searchAttrOptID[rel='"+thisRel+"']:checked").length>0)
		{
			$(".searchAttrOptID[rel='"+thisRel+"']").prop("checked",false);
			initProductSearch();
		} */	
	});
	if(typeof __queryStringMode!='undefined' && __queryStringMode>0)
	{
		setNavOptions('S');	
	}
        setNavOptions('S');
});

        function priceSliderLoad() {
           
            if($( "#price-range" ).length>0 && typeof __priceRangeMin != 'undefined' && typeof __priceRangeMax != 'undefined')
	{
		var range1=__priceRangeMin;		
		if(__priceRangeMinCustom)
		range1=__priceRangeMinCustom;
		
		var range2=__priceRangeMax;		
		if(__priceRangeMaxCustom)
		range2=__priceRangeMaxCustom;
		
        if ($('html').attr('dir') == 'rtl') {
            $("#price-range").slider({
                range: true,
                min: __priceRangeMin,
                max: __priceRangeMax,
                values: [range1, range2],
                isRTL: true,
                stop: function (event, ui) {
                    $("#priceSliderHid").val("1");
                    initProductSearch();
                },
                slide: function (event, ui) {
                    /*if (ui.value < __priceRangeMin + 1)
                        return false;*/
                    $("#price-amount").html(formatCurrency(ui.values[0], 'Full') + " - " + formatCurrency(ui.values[1], 'Full'));
                    $("#price-amount-min").val(ui.values[0]);
                    $("#price-amount-max").val(ui.values[1]);
                    $("#price-range-min").html(formatCurrency(ui.values[0], 'Full'));
                    $("#price-range-max").html(formatCurrency(ui.values[1], 'Full'));
                }
            });
        } else {
            $("#price-range").slider({
                range: true,
                min: __priceRangeMin,
                max: __priceRangeMax,
                values: [range1, range2],
                stop: function (event, ui) {
                    $("#priceSliderHid").val("1");
                    initProductSearch();
                },
                slide: function (event, ui) {
                    /*if (ui.value < __priceRangeMin + 1)
                        return false;*/
                    $("#price-amount").html(formatCurrency(ui.values[0], 'Full') + " - " + formatCurrency(ui.values[1], 'Full'));
                    $("#price-amount-min").val(ui.values[0]);
                    $("#price-amount-max").val(ui.values[1]);
                    $("#price-range-min").html(formatCurrency(ui.values[0], 'Full'));
                    $("#price-range-max").html(formatCurrency(ui.values[1], 'Full'));
                }
            });
        }
        
		$( "#price-amount" ).html(formatCurrency($( "#price-range" ).slider( "values", 0 ),'Full') +
		  " - " + formatCurrency($( "#price-range" ).slider( "values", 1 ),'Full') );
        $( "#price-range-min" ).html(formatCurrency($( "#price-range" ).slider( "values", 0 ),'Full'));
        $( "#price-range-max" ).html(formatCurrency($( "#price-range" ).slider( "values", 1 ),'Full'));
	}
        if($( "#financerangeslider" ).length>0 && typeof __emiRangeMin != 'undefined' && typeof __emiRangeMax != 'undefined')
	{
		var range1=__emiRangeMin;		
		if(__emiRangeMinCustom)
		range1=__emiRangeMinCustom;
		
		var range2=__emiRangeMax;		
		if(__emiRangeMaxCustom)
		range2=__emiRangeMaxCustom;
		
        if ($('html').attr('dir') == 'rtl') {
            $("#financerangeslider").slider({
                range: true,
                min: __emiRangeMin,
                max: __emiRangeMax,
                values: [range1, range2],
                isRTL: true,
                stop: function (event, ui) {
                    $("#priceEmiSliderHid").val("1");
                    initProductSearch();
                },
                slide: function (event, ui) {
                    /*if (ui.value < __emiRangeMin + 1)
                        return false;*/
                    $("#emi-amount").html(formatCurrency(ui.values[0], 'Full') + " - " + formatCurrency(ui.values[1], 'Full'));
                    $("#emi-amount-min").val(ui.values[0]);
                    $("#emi-amount-max").val(ui.values[1]);
                    $("#emi-range-min").html(formatCurrency(ui.values[0], 'Full'));
                    $("#emi-range-max").html(formatCurrency(ui.values[1], 'Full'));
                }
            });
        } else {
            $("#financerangeslider").slider({
                range: true,
                min: __emiRangeMin,
                max: __emiRangeMax,
                values: [range1, range2],
                stop: function (event, ui) {
                    $("#priceEmiSliderHid").val("1");
                    initProductSearch();
                },
                slide: function (event, ui) {
                    /*if (ui.value < __emiRangeMin + 1)
                        return false;*/
                    $("#emi-amount").html(formatCurrency(ui.values[0], 'Full') + " - " + formatCurrency(ui.values[1], 'Full'));
                    $("#emi-amount-min").val(ui.values[0]);
                    $("#emi-amount-max").val(ui.values[1]);
                    $("#emi-range-min").html(formatCurrency(ui.values[0], 'Full'));
                    $("#emi-range-max").html(formatCurrency(ui.values[1], 'Full'));
                }
            });
        }
        
		$( "#emi-amount" ).html(formatCurrency($( "#financerangeslider" ).slider( "values", 0 ),'Full') +
		  " - " + formatCurrency($( "#financerangeslider" ).slider( "values", 1 ),'Full') );
        $( "#emi-range-min" ).html(formatCurrency($( "#financerangeslider" ).slider( "values", 0 ),'Full'));
        $( "#emi-range-max" ).html(formatCurrency($( "#financerangeslider" ).slider( "values", 1 ),'Full'));
	}
        }
	function clearBrandSearch(){
		$(".checkbox_brandIDs").prop('checked',false);
		$(".li_brandIDs").show();
		$("#filterBrands").val('').focus();
		return true;
	}
	function lightbox_open(){
		//window.scrollTo(0,0);
		$("#CategoryPopup, #CategoryFade").fadeIn();
	}
	function lightbox_close(){
		$(".zoomContainer").hide();
		$("#CategoryPopup, #CategoryFade").fadeOut();
	}
	
	function setNavOptions(arg)
	{	
		var navDataObj = [];
		var attrDataObj = [];
                var custDataObj = [];
                var catIDs = [];
		var attributeOptionIdString  = '';
                var attributeCatIdString  = '';
		var i = 1;
		var priceRangeMinForKey = '';
		var priceRangeMaxForKey = '';
		var priceRangeMin = '';
		var priceRangeMax = '';
                var emiRangeMinForKey = '';
		var emiRangeMaxForKey = '';
		var emiRangeMin = '';
		var emiRangeMax = '';
		var discountRange = '';
		var attributeNavObj = {};
		var attributeNavObjHtml = '';
                var attributeCustIdString = ''; 
               
		if($(".searchAttrOptID").length>0)
		{
                         
			$(".searchAttrOptID:checked").each(function(){
			attributeOptionIdString = attributeOptionIdString + $(this).val() + '_';
			attrDataObj.push({
				attribute: $(this).attr("rel"),
				option: $(this).val()
			});
			var thisRel = $(this).attr("rel");
			if(typeof attributeNavObj[thisRel]=='undefined')
			{
				attributeNavObj[thisRel] = {};
				attributeNavObj[thisRel].values = [];
			}
			attributeNavObj[thisRel].label = lblBodyType;//$(this).attr("refinehead");
                        attributeNavObj[thisRel].labelkey ='attr';
			attributeNavObj[thisRel].values.push({
				text: $(this).attr("refineval"),
				id: $(this).attr("refineval").replace(" ","_")
			}); 
			});
                        if($(".searchAttrOptID:checked").length<=0) {
                            resetAttributeSearch();
                            bmwCode = ''; 
                        } 
                        
		}	
                if($(".searchAttrCatID").length>0)
		{
                        
                        
			$(".searchAttrCatID:checked").each(function(){
                            
                           
                            var piddet = $(this).attr("refinehead").split("_");
                            var pid=piddet[1];                            
                            
			attributeCatIdString = attributeCatIdString + $(this).val() + '_';
			catIDs.push({				
				option: $(this).attr("rel")
			});
			var thisRel = $(this).attr("rel");
			if(typeof attributeNavObj[thisRel]=='undefined')
			{
				attributeNavObj[thisRel] = {};
				attributeNavObj[thisRel].values = [];
			}
			attributeNavObj[thisRel].label = lblBrowse;//$(this).attr("refinehead");
                        attributeNavObj[thisRel].labelkey ='cats';
			attributeNavObj[thisRel].values.push({
				text: $(this).attr("refineval"),
				id: $(this).val(),
                                pid: pid
			}); 
			});
                        if($(".searchAttrCatID:checked").length<=0) {
                            resetCatAttributeSearch();
                        }else {
                            if($("#priceSliderHid").val()=='') {
                                resetPriceRange();
                           }
                            if($("#priceEmiSliderHid").val()=='') {
                                resetPriceEmiRange();
                           }
                        }
                        
		}	
                
                if($("#hidCustName").val()!='') {
                    var hidCustName= $("#hidCustName").val().split("~");
                    for(r=0;r<hidCustName.length;r++) {
                        var n = hidCustName[r];
                        
                        if($(".searchCustOptID_"+n).length>0)
                        {
                           
                                $(".searchCustOptID_"+n+":checked").each(function(){
                              
                                attributeCustIdString = attributeCustIdString + $(this).val() + '_';
                                custDataObj.push({
                                        attribute: $(this).attr("rel"),
                                        option: $(this).val()
                                });
                                var thisRel = $(this).attr("rel");
                                if(typeof attributeNavObj[thisRel]=='undefined')
                                {
                                        attributeNavObj[thisRel] = {};
                                        attributeNavObj[thisRel].values = [];
                                }
                                attributeNavObj[thisRel].label = $(this).attr("rel");//$(this).attr("refinehead");	
                                attributeNavObj[thisRel].labelkey ='custattr';
                                attributeNavObj[thisRel].values.push({
                                        text: $(this).attr("refineval"),
                                        id: $(this).val()
                                }); 
                                });
                                if($(".searchCustOptID_"+n+":checked").length<=0) {
                                    resetCustAttributeSearch(n);
                                }
                        }	
                    }
                }
                
		var uniqueID = +new Date;
                var tempPriceRangeMin = '';
                var tempPriceRangeMax = '';
                 var tempEmiRangeMin = '';
                var tempEmiRangeMax = '';

		priceRangeMin = $.trim($( "#price-amount-min" ).val());
		priceRangeMax = $.trim($( "#price-amount-max" ).val());
		discountRange = $.trim($("input[name='searchDiscountRange']:checked").val());
		
		if($( "#price-range" ).length>0 && (priceRangeMin!=__priceRangeMin
			|| priceRangeMax!=__priceRangeMax))
		{
                    
			attributeNavObj['price'] = {};
			attributeNavObj['price'].values = [];
			attributeNavObj['price'].label = $( "#price-amount-min" ).attr("refinehead");
                        attributeNavObj['price'].labelkey ='price';
			attributeNavObj['price'].values.push({
				text: $( "#price-amount" ).html(),
				id: 'price'
			}); 
                        
                        tempPriceRangeMin = priceRangeMin;
                        tempPriceRangeMax = priceRangeMax;
		}
                
                emiRangeMin = $.trim($( "#emi-amount-min" ).val());
		emiRangeMax = $.trim($( "#emi-amount-max" ).val());
		
		
		if($( "#financerangeslider" ).length>0 && (emiRangeMin!=__emiRangeMin
			|| emiRangeMax!=__emiRangeMax))
		{
			attributeNavObj['emi'] = {};
			attributeNavObj['emi'].values = [];
			attributeNavObj['emi'].label = $( "#emi-amount-min" ).attr("refinehead");
                        attributeNavObj['emi'].labelkey ='emi';
			attributeNavObj['emi'].values.push({
				text: $( "#emi-amount" ).html(),
				id: 'emi'
			}); 
                        tempEmiRangeMin = emiRangeMin;
                        tempEmiRangeMax = emiRangeMax;
		
		}
		
		//var brandIDs =[];
		//var brandText =[];
		/*if($(".checkbox_brandIDs:checked").length>0){
			if(typeof attributeNavObj['brand']=='undefined')
				{
				attributeNavObj['brand'] = {};
				attributeNavObj['brand'].values = [];
				}
				attributeNavObj['brand'].values = [];
				attributeNavObj['brand'].label = lblBrands;	
			$(".checkbox_brandIDs:checked").each(function(){
				brandIDs.push(this.value);
				attributeNavObj['brand'].values.push({
					text: $(this).attr('text'),
					id: this.value
				});
			});
			
			
			
		}*/
		
		
		var globalCatalogUrlTemp = globalCatalogUrl;
                var tempbodytype = '';
                var tempval = '';
                var tempcatval = '';
                var tempprice = '';
                var tempemiprice = '';
		$.each(attributeNavObj,function(attributeNavObjIndex, attributeNavObjValue){
                    
			attributeNavObjHtml = attributeNavObjHtml + '<div class="filters-top-selected" id="filters-top-selected_'+attributeNavObjIndex+'">';
			if(attributeNavObjValue.values.length>1)
			{
				//attributeNavObjHtml = attributeNavObjHtml + '<a class="deleteFilterHead" title="'+lblRemove+' '+attributeNavObjValue.label+'" href="Javascript:void(0);" rel='+attributeNavObjIndex+'>';
			}		
			//attributeNavObjHtml = attributeNavObjHtml + attributeNavObjValue.label;
			if(attributeNavObjValue.values.length>1)
			{
				attributeNavObjHtml = attributeNavObjHtml + '</a>';
			}
			//attributeNavObjHtml = attributeNavObjHtml +' : ';		
                       /* if(attributeNavObjIndex=='bodytype') {
                            
                        } else {
                            if(attributeNavObjIndex=='lblColor' || attributeNavObjIndex=='lblUpholstery') {
                                var tempval = '';
                            }
                            
                        }*/
			$.each(attributeNavObjValue.values,function(index, valueObj){
                                var sep = '';
								if(attributeNavObjIndex=='bodytype') {
									 var finalData = valueObj.text.replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, '-');
                                     var finalText = finalData.toLowerCase();
                                    if(tempbodytype=='') {
                                        tempbodytype = valueObj.text;
										tempbodytype = finalText;
                                    } else {
                                        tempbodytype = tempbodytype+'~'+valueObj.text;
										tempbodytype = tempbodytype+'~'+finalText;
                                    }
                                }
                                if(attributeNavObjValue.labelkey=='cats') {
                                    if(tempcatval=='') {
                                        tempcatval = valueObj.id;
                                    } else {
                                        tempcatval = tempcatval+'~'+valueObj.id;
                                    }
                                }
                                if(attributeNavObjValue.labelkey=='custattr') {
                                    if(tempval=='') {
                                        tempval = valueObj.id;
                                    } else {
                                        tempval = tempval+'~'+valueObj.id;
                                    }
                                }
                                if(attributeNavObjIndex=='price') {
                                    tempprice = $( "#price-amount-min" ).val()+'~'+$( "#price-amount-max" ).val();
                                    
                                } 
                                 if(attributeNavObjIndex=='emi') {
                                    tempemiprice = $( "#emi-amount-min" ).val()+'~'+$( "#emi-amount-max" ).val();
                                    
                                } 
                                if(attributeNavObjValue.labelkey=='cats') {
                                    totCatCnt           = totCatCnt + 1;
                                    attributeNavObjHtml = attributeNavObjHtml + '<a class="deleteFilter mr-2 mb-2 series cat_'+valueObj.id+' mr-2" rid="'+valueObj.pid+'" title="'+lblRemove+' '+valueObj.text+'" href="Javascript:void(0);" rel='+valueObj.id+'>'+valueObj.text+'<i class="icon-close ml-3 cursor-pointer"></i></a>';
                                } else {
                                    attributeNavObjHtml = attributeNavObjHtml + '<a class="deleteFilter mr-2 mb-2" title="'+lblRemove+' '+valueObj.text+'" href="Javascript:void(0);" rel="'+valueObj.id+'">'+valueObj.text+'<i class="icon-close ml-3 cursor-pointer"></i></a>';
                                }                                
			});	
                        
			attributeNavObjHtml = attributeNavObjHtml + '</div>';
                        
		});
                if(tempcatval!='') {
                    globalCatalogUrlTemp = globalCatalogUrlTemp+tempcatval+"/";
                }
                if(tempbodytype!='') {
                    globalCatalogUrlTemp = globalCatalogUrlTemp+'bodytype/'+tempbodytype+"/";
                }
                        
                if(tempval!='') {
                    globalCatalogUrlTemp = globalCatalogUrlTemp+'custattr/'+tempval+"/";

                }
                if(tempprice!='') {
                    globalCatalogUrlTemp = globalCatalogUrlTemp+'price/'+tempprice+"/";

                }
                 if(tempemiprice!='') {
                    globalCatalogUrlTemp = globalCatalogUrlTemp+'emi/'+tempemiprice+"/";

                }
                
		if(attributeNavObjHtml!='')
		{
                        
			$(".refined-box-content").html(attributeNavObjHtml).show();
                        $(".refined-box-content").removeClass('hide');
			$(".filters-top-selected:last").css('border','0');	
                       
		}
		else
		{
			$(".refined-box-content").html('').hide();
		}
                 if(arg!='S') {
                         history.pushState(null, null, globalCatalogUrlTemp);
                        }
		navDataObj=
					{
						page:page.getPageNumber(),
						userGroupID:userGroupID,
						viewType:page.getViewType(),
						categoryID:catIDs,
						brandIDs:brandIDs,
						sortBy:'price_asc',
						keyword:$.stringify(searchKeyword),
						uniqueID:uniqueID,
						attrDataObj:attrDataObj,
                                                custDataObj:custDataObj,
						priceRangeMin:tempPriceRangeMin,
						priceRangeMax:tempPriceRangeMax,
                                                emiRangeMin:tempEmiRangeMin,
						emiRangeMax:tempEmiRangeMax,
						discountRange:discountRange,
                        parentCategoryID:originCatalogID,
                        brandID:brandID,                       
                        bmwCode:bmwCode,
                        urlCat:urlCat,
                        urlBodyStyle:urlBodyStyle
					};
               
		if(typeof businessID!='undefined' && businessID>0){
			navDataObj['businessID']=businessID;
		}
		if(priceRangeMin)			
		priceRangeMinForKey = priceRangeMin.replace(".","_");	
		if(priceRangeMax)			
		priceRangeMaxForKey = priceRangeMax.replace(".","_");	
		if(emiRangeMin)			
		emiRangeMinForKey = emiRangeMin.replace(".","_");	
		if(emiRangeMax)			
		emiRangeMaxForKey = emiRangeMax.replace(".","_");	
		
		var pageKey = attributeCatIdString+attributeOptionIdString+attributeCustIdString+page.getPageNumber()+page.getViewType()+page.getSortBy()+priceRangeMinForKey+priceRangeMaxForKey+emiRangeMinForKey+emiRangeMaxForKey+brandID+brandIDs;	
		return [navDataObj,pageKey];
	}	
	function initProductSearch(obj)
	{
	
	 if(_section!='mobile' || $(obj).attr("id")=="applyNow"|| $(obj).attr("class")=="deleteFilter"){ 
		page.setPageNumber(0);
		page.resetProductsEndStatus();
		var searchVar = setNavOptions('C');				
		var key	= searchVar[1];
              
                //alert(key+ " pp "+typeof page.ajaxResponses[key] );
		if(typeof page.ajaxResponses[key] == 'undefined' || 1==1) 
		{
                    
			var paramData	=	searchVar[0];
			var uniqueID = paramData['uniqueID'];
			$.ajax({
				url: GLOBAL_BASE_PATH + '/series/ajaxGetProducts/',
				type: "POST",
				cache: true,
				data: searchVar[0],
				beforeSend: function () {
					page.ajaxHold(true);
					$(".pop_loader").removeClass('hide');
				},
				complete:function(){
					page.ajaxHold(false);
					$(".pop_loader").addClass('hide');
				if( $(obj).attr("id")=="applyNow"){ 
				$(".selected_filter").html("Applied");
				}		
				}
			}).done(function(resHtmlData) {
                                
				if($.trim(resHtmlData) != ''){
                                        $(".ajax-cust").remove();
                                        $(".prodBodyStyles").remove();
                                        $(".priceRangeDiv").remove();
                                        $("#hidCustName").remove();
                                        var tempData = $.parseJSON(resHtmlData);
                                        var resHtml  = tempData['html'];
                                        var customdet= tempData['customdetails'];
                                        var bodytypes= tempData['bodyStyles'];
                                        var priceValues= tempData['priceRangesVals'];

					page.setPageNumber();
					$(".productListing").empty().html(resHtml);
					$("#productsCount").empty().html(productsCountVar);
                                        //alert(priceValues);
                                        
                                        $(".priceEmiDiv").html(priceValues);
                                        priceSliderLoad();
                                        $("#demo-refine").append(bodytypes);
                                        $("#demo-refine").append(customdet);
                                        $('.scrollbox').mCustomScrollbar({
                                            theme: "scrollbox",
                                            scrollButtons: {
                                                enable: false
                                            }
                                        });
                                        $("#priceSliderHid").val("");
                                        $("#priceEmiSliderHid").val("");
					if(productsCountVar=="0" || parseFloat(productsCountVar)<=parseFloat(productPageCount)){
						$("#view_more_products").addClass('hide');
					}else{
						$("#view_more_products").removeClass('hide');
					}
					/* this function is declared in addtocompare.feature.js page */
					//addToCompare.markCheckedItems();
					page.ajaxResponses[key] = {content:resHtml,uniqueID:uniqueID};
					/*var attributeListObj = $.parseJSON(attributeList);				
					$(".searchAttrOptID").attr("disabled","disabled");				
					$.each(attributeListObj,function(key) {
						$("#searchAttrOptID_"+key).removeAttr("disabled");
					});	*/
					page.lazyLoad(uniqueID);
				}
			});	
		}
		else
		{
			page.setPageNumber(1);
			var theResponse = page.ajaxResponses[key];
			$(".productListing").empty().html(theResponse['content']);
			$("#productsCount").empty().html(productsCountVar);
			if(productsCountVar=="0"){
				$("#view_more_products").addClass('hide');
			}else{
				$("#view_more_products").removeClass('hide');
			}
			/* this function is declared in addtocompare.feature.js page */
			//addToCompare.markCheckedItems();
			page.lazyLoad(theResponse['uniqueID']);
		}
		}
		var scrollTop=$(".productListing").position().top;
		$('html,body').animate({scrollTop:scrollTop},'slow');	
	}
	function resetPriceRange() 
	{
		if($( "#price-range" ).length>0)
		{
			if($( "#price-amount-min" ).val()!=__priceRangeMin
			|| $( "#price-amount-max" ).val()!=__priceRangeMax)
			{
				var $slider = $("#price-range");
				$slider.slider("values", 0, __priceRangeMin);
				$slider.slider("values", 1, __priceRangeMax);
				$( "#price-amount" ).html(formatCurrency(__priceRangeMin,'Full') +
				  " - " + formatCurrency(__priceRangeMax,'Full') );
				$( "#price-amount-min" ).val(__priceRangeMin);
				$( "#price-amount-max" ).val(__priceRangeMax);	
				return true;
			}	
		}
		return false;
	}
        function resetPriceEmiRange() 
	{
		if($( "#financerangeslider" ).length>0)
		{
			if($( "#emi-amount-min" ).val()!=__emiRangeMin
			|| $( "#emi-amount-max" ).val()!=__emiRangeMax)
			{
				var $slider = $("#financerangeslider");
				$slider.slider("values", 0, __emiRangeMin);
				$slider.slider("values", 1, __emiRangeMax);
				$( "#emi-amount" ).html(formatCurrency(__emiRangeMin,'Full') +
				  " - " + formatCurrency(__emiRangeMax,'Full') );
				$( "#emi-amount-min" ).val(__emiRangeMin);
				$( "#emi-amount-max" ).val(__emiRangeMax);	
				return true;
			}	
		}
		return false;
	}
	function resetDiscountSearch()
	{
		if($("input[name='searchDiscountRange']:checked").length>0)
		{
			$("input[name='searchDiscountRange']").prop("checked",false);	
			return true;
		}
		return false;
	}
	function resetAttributeSearch()
	{
		if($(".searchAttrOptID:checked").length<=0)
		{	
			$(".searchAttrOptID").prop("checked",false);
			$(".searchAttrOptID").removeAttr("disabled");
			return true;
		}else {
                       // $(".searchAttrOptID").prop("checked",false);
			//$(".searchAttrOptID").removeAttr("disabled");
			//return true;
                }
		return false;
	}
        function resetAttributeSearchAll()
	{
		$(".searchAttrOptID").prop("checked",false);
		$(".searchAttrOptID").removeAttr("disabled");
		return false;
               
	}
        function resetCatAttributeSearch()
	{
               
		if($(".searchAttrCatID:checked").length<=0)
		{	
			$(".searchAttrCatID").prop("checked",false);
			$(".searchAttrCatID").removeAttr("disabled");
			return true;
		} else {
                        $(".searchAttrCatID").prop("checked",false);
			$(".searchAttrCatID").removeAttr("disabled");
			return true;
                }
		return false;
	}
        function resetCustAllAttributeSearch() {
            $(".custsearch").prop("checked",false);
            $(".custsearch").removeAttr("disabled");
        }
        function resetCustAttributeSearch(arg)
	{
		if($(".searchCustOptID_"+arg+":checked").length<=0)
		{	
			$(".searchAttrOptID_"+arg).prop("checked",false);
			$(".searchAttrOptID_"+arg).removeAttr("disabled");
			return true;
		}
		return false;
	}
	
    //Fliter section 
$(document).ready(function(e) {
    //Filter
    $(document).on("click", '.FltrIco', function() {
        if ($(this).hasClass('drop-up')) {
            $(".prdctFilter").addClass("sorToggle");
            $(".prdctFilterMo").find(".drop-up").addClass("drop-up");
            $(this).removeClass("drop-up");
            $('header.affix').css("z-index","9999");
        } else {
            $(".prdctFilter").removeClass("sorToggle");
            $(".prdctFilterMo").find(".drop-up").removeClass("drop-up");
            $('.mob_sort').addClass("sorToggle");
            $(this).addClass("drop-up");
            $('header.affix').css("z-index","0");
        }
    });
    //Sort By
    $(document).on("click", '.FltrSort', function() {
        if ($(this).hasClass('drop-up')) {
            $(".prdctFilterMo").find(".drop-up").addClass("drop-up");
            $('.mob_sort').addClass("sorToggle");
            $(this).removeClass("drop-up");
        } else {
            $(".prdctFilter").addClass("sorToggle");
            $(".prdctFilterMo").find(".drop-up").removeClass("drop-up");
            $('.mob_sort').removeClass("hidden-Mob sorToggle");
            $(this).addClass("drop-up");
        }

    });
    $(document).on("click", '.widget-tab-sel', function() {
        $(this).parent().toggleClass('open');
        //$(this).next('.hidden-Mob').slideToggle();
		$(this).next('ul').toggleClass("hidden-Mob");

    });

    $(document).on("click", '.FltrSctn .expand-clsps', function() {
        $(this).next(".list-wrap").toggleClass("sort_collapse").slideToggle();
        $(this).parents(".FltrSctn").children(".expand-clsps").toggleClass('plus-ico');
        
    });
    $(document).on("click", '.sort-select', function() {
        $(this).parent().toggleClass('active');
    });
    
});

//$( function() {
//    if ($('html').attr('dir') == 'rtl') {
//        $("#financerangeslider").slider({
//            range: 'min',
//            min: 0,
//            max: 10000,
//            step: 50,
//            isRTL: true,
//            slide: function (event, ui) {
//                $("#finance-range-max").html(formatCurrency(ui.value, 'Full'));
//            }
//        });
//    } else {
//        $("#financerangeslider").slider({
//            range: 'min',
//            min: 0,
//            max: 10000,
//            step: 50,
//            slide: function (event, ui) {
//                $("#finance-range-max").html(formatCurrency(ui.value, 'Full'));
//            }
//        });
//    }
//    $( "#finance-range-max" ).html(formatCurrency($( "#financerangeslider" ).slider( "values", 1 ),'Full'));
//});
if ($(window).width() > 991) {
    $('.scrollbox').mCustomScrollbar({
        theme: "scrollbox",
        scrollButtons: {
            enable: false
        }
    });
}
