Subversion Repositories SmartDukaan

Rev

Rev 18757 | Rev 18759 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 18757 Rev 18758
Line 59... Line 59...
59
    $('#homeShop18Url').prop('href',url);
59
    $('#homeShop18Url').prop('href',url);
60
    $('#homeShop18Modal').modal('show');
60
    $('#homeShop18Modal').modal('show');
61
    return;
61
    return;
62
};
62
};
63
 
63
 
64
$(function(){   
64
$(function(){	
65
    if($('.scrollselector > .card').length>0) {
65
	if($('.scrollselector > .card').length>0) {
66
        setTimeout(function(){ document.location.reload(); }, 1000*15*60);
66
		setTimeout(function(){ document.location.reload(); }, 1000*15*60);
67
        if(typeof noscrolling == 'undefined') {
67
		if(typeof noscrolling == 'undefined') {
68
            $('.scrollselector').jscroll({
68
			$('.scrollselector').jscroll({
69
                loadingHtml: '<center><img src="/img/ajax-loader.gif" alt="Loading" /></center>',
69
				loadingHtml: '<center><img src="/img/ajax-loader.gif" alt="Loading" /></center>',
70
                autoTriggerUntil: 3,
70
			    autoTriggerUntil: 3,
71
                padding: 20,
71
			    padding: 20,
72
                callback:loadCartDetails
72
			    callback:loadCartDetails
73
            });
73
			});
74
        }
74
		}
75
    }
75
	}
76
    if($('.storeminprice').length>0) {
76
	if($('.storeminprice').length>0) {
77
        var globalminprice = 9999999;
77
		var globalminprice = 9999999;
78
        var globalminsku;
78
		var globalminsku;
79
        var globalmincashback = '';     
79
		var globalmincashback = '';		
80
        var globalminoffer = '';        
80
		var globalminoffer = '';		
81
        var calls = [];
81
		var calls = [];
82
        $('.storeminprice').each(function(){
82
		$('.storeminprice').each(function(){
83
            var temp = {'sort':$(this).data('searchorder'),'val':$(this)};
83
			var temp = {'sort':$(this).data('searchorder'),'val':$(this)};
84
            calls.push(temp);
84
			calls.push(temp);
85
        });
85
		});
86
        calls = sortByKey(calls,'sort');        
86
		calls = sortByKey(calls,'sort');		
87
        for(var i in calls){
87
		for(var i in calls){
88
            fetchLivePrice(calls[i]['val'])
88
			fetchLivePrice(calls[i]['val'])
89
        }               
89
		}				
90
    };
90
	};
91
    function sortByKey(array, key) {
91
	function sortByKey(array, key) {
92
        return array.sort(function(a, b) {
92
	    return array.sort(function(a, b) {
93
            var x = a[key]; var y = b[key];
93
	        var x = a[key]; var y = b[key];
94
            return ((x < y) ? -1 : ((x > y) ? 1 : 0));
94
	        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
95
        });
95
	    });
96
    };      
96
	};		
97
    function getCouponText(coupon){
97
	function getCouponText(coupon){
98
        return "<span class='red'>"+coupon+"</span>";
98
		return "<span class='red'>"+coupon+"</span>";
99
    };
99
	};
100
    function getGrossPriceText(gross_price,available_price){
100
	function getGrossPriceText(gross_price,available_price){
101
        if(gross_price == available_price)
101
		if(gross_price == available_price)
102
            return "";
102
			return "";
103
        return "Paytm cashback - "+(gross_price-available_price)+"<br>Net Price = <span class='red text-bigger'>"+available_price+"</span>"
103
		return "Paytm cashback - "+(gross_price-available_price)+"<br>Net Price = <span class='red text-bigger'>"+available_price+"</span>"
104
    }
104
	}
105
    function fetchLivePrice(obj){       
105
	function fetchLivePrice(obj){		
106
        ga('send', 'event', 'liveprice', 'fetch',$('#bestpriceproductname').html());
106
		ga('send', 'event', 'liveprice', 'fetch',$('#bestpriceproductname').html());
107
        var properties = {};
107
		var properties = {};
108
        properties.bundle_id = String($(obj).data('bundle_id'));
108
		properties.bundle_id = String($(obj).data('bundle_id'));
109
        properties.product_name = String($('#bestpriceproductname').html());
109
		properties.product_name = String($('#bestpriceproductname').html());
110
        pma.send('products','livesprice','fetch',me,properties);
110
		pma.send('products','livesprice','fetch',me,properties);
111
        var that = obj; 
111
		var that = obj;	
112
        var inStock = false;        
112
		var inStock = false;		
113
        var priceToCompare = 0;
113
		var priceToCompare = 0;
114
        var priceRange = "";
114
		var req = $.ajax({
115
        var req = $.ajax({
115
			url: '/store_products/getliveprice/'+$(that).data('bundle_id')+'/'+$(that).data('id'),
116
            url: '/store_products/getliveprice/'+$(that).data('bundle_id')+'/'+$(that).data('id'),
116
			// Tell jQuery we're expecting JSONP
117
            // Tell jQuery we're expecting JSONP
117
			dataType: "json",
118
            dataType: "json",
118
			// Tell YQL what we want and that we want JSON			
119
            // Tell YQL what we want and that we want JSON          
119
			method: 'get',
120
            method: 'get',
120
			// timeout: 30000,
121
            // timeout: 30000,
121
			// Work with the response
122
            // Work with the response
122
			success: function( response ) {
123
            success: function( response ) {
123
				if(response.success){
124
                if(response.success){
124
					var i = 0;	
125
                    var i = 0;  
125
					var minpriceindex = 0;		
126
                    var minpriceindex = 0;      
126
					if(response.products[i].in_stock == 1) {
127
                    if(response.products[i].in_stock == 1) {
127
						inStock = true;
128
                        inStock = true;
128
						var minprice = 9999999;//Math.round(response.products[i]['available_price']);
129
                        var minprice = 9999999;//Math.round(response.products[i]['available_price']);
129
						var minpriceurl = response.products[i]['marketPlaceUrl'];
130
                        var minpriceurl = response.products[i]['marketPlaceUrl'];
130
					}
131
                    }
131
					if(response.products.length>0){
132
                    if(response.products.length>0){
132
						//More than one products in store
133
                        //More than one products in store
133
						var variants = [];
134
                        var variants = [];
134
						var j = 0;
135
                        var j = 0;
135
						for(var i in response.products){								
136
                        for(var i in response.products){                                
136
							if(response.products[i].in_stock == 1){
137
                            if(response.products[i].in_stock == 1){
137
								if(response.products[i].gross_price && response.products[i].gross_price > response.products[i].available_price) {
138
                                if(response.products[i].gross_price && response.products[i].gross_price > response.products[i].available_price) {
138
									priceToCompare = response.products[i].gross_price;
139
                                    priceToCompare = response.products[i].gross_price;
139
								}else{
140
                                }else{
140
									priceToCompare = response.products[i].available_price;
141
                                    if (response.products[i].source_id == 4 && response.products[i].cheapestBulkPrice != 0) {
141
								}
142
                                                priceToCompare = response.products[i].cheapestBulkPrice;
142
								inStock = true;								
143
                                                if(response.products[i].packQuantity>1){
143
								if(priceToCompare && priceToCompare <= globalminprice) {
144
                                                    priceRange =(Math.round((response.products[i].cheapestBulkPrice/response.products[i].packQuantity) * 100) / 100)    + " - "
144
									if (typeof globalminsource != "undefined" && globalminsource==4 && priceToCompare==globalminprice){
145
                                                    + (Math.round((response.products[i].available_price/response.products[i].packQuantity) * 100) / 100) + " -/ per unit";
145
									} else {
146
                                                }
146
										globalminprice = Math.round(priceToCompare);
147
                                                else{
147
										globalminsku = response.products[i]._id;
148
                                                    priceRange = response.products[i].cheapestBulkPrice
148
										globalminsource = response.products[i].source_id;
149
                                                    + " - "
149
										globalminurl = response.products[i].marketPlaceUrl;
150
                                                    + response.products[i].available_price;
150
										globalminoffer = response.products[i].offer;
151
                                                }
151
										globalmincashback = getcashbackstring(response.products[i].cash_back_type,response.products[i].cash_back);
152
                                                
152
									}
153
 
153
								}
154
                                    } else {
154
								if(typeof minprice == 'undefined' || priceToCompare < minprice) {
155
                                        priceToCompare = response.products[i].available_price;
155
									minprice = Math.round(priceToCompare);
156
                                    }
156
									minpriceindex = j;
157
                                }
157
								}								
158
                                inStock = true;                             
158
								if(response.products[i].tagline && response.products[i].tagline.length>0 && $('#productoneliner').html().length==0) { 
159
                                if(priceToCompare && priceToCompare <= globalminprice) {
159
									$('#productoneliner').html(response.products[i].tagline).removeClass('hidden').show();									
160
                                    if (typeof globalminsource != "undefined" && globalminsource==4 && priceToCompare==globalminprice){
160
								}								
161
                                    } else {
161
								variants.push({'name' : response.products[i].source_product_name, 'source_id' : response.products[i].source_id, 'available_price' : Math.round(response.products[i].available_price), 'url' : response.products[i].marketPlaceUrl,'source_product_name' : response.products[i].source_product_name,'id' : response.products[i]._id,'cash_back_type' : response.products[i].cash_back_type,'cash_back' : response.products[i].cash_back,'coupon': response.products[i].coupon,'codAvailable' : response.products[i].codAvailable,'offer' : response.products[i].offer,'gross_price' : response.products[i].gross_price});
162
                                        globalminprice = Math.round(priceToCompare);
162
							}					
163
                                        globalminsku = response.products[i]._id;
163
							j++;
164
                                        globalminsource = response.products[i].source_id;
164
						}
165
                                        globalminurl = response.products[i].marketPlaceUrl;
165
						if(variants.length>1){
166
                                        globalminoffer = response.products[i].offer;
166
							variants.splice(minpriceindex,1);							
167
                                        globalmincashback = getcashbackstring(response.products[i].cash_back_type,response.products[i].cash_back);
167
							var variantslink = $('<span class="variants"> '+(variants.length+1)+' Options</span>');
168
                                    }
168
							$(that).parent().parent().find('.pull-left',0).append(variantslink);							
169
                                }
169
							$(variantslink).data('variants',variants).data('minprice',minprice);
170
                                if(typeof minprice == 'undefined' || priceToCompare < minprice) {
170
						}
171
                                    minprice = Math.round(priceToCompare);
171
					}
172
                                    minpriceindex = j;
172
					if(inStock){
173
                                }                               
173
						$(that).html(minprice).siblings('.cashbackamount').html(getcashbackstring(response.products[minpriceindex].cash_back_type,response.products[minpriceindex].cash_back)).parent().addClass('viewproduct');
174
                                if(response.products[i].tagline && response.products[i].tagline.length>0 && $('#productoneliner').html().length==0) { 
174
						
175
                                    $('#productoneliner').html(response.products[i].tagline).removeClass('hidden').show();                                  
175
						if($(that).parent().data('storename') == "Saholic")
176
                                }                               
176
						{
177
                                variants.push({'name' : response.products[i].source_product_name, 'source_id' : response.products[i].source_id, 'available_price' : Math.round(response.products[i].available_price), 'url' : response.products[i].marketPlaceUrl,'source_product_name' : response.products[i].source_product_name,'id' : response.products[i]._id,'cash_back_type' : response.products[i].cash_back_type,'cash_back' : response.products[i].cash_back,'coupon': response.products[i].coupon,'codAvailable' : response.products[i].codAvailable,'offer' : response.products[i].offer,'gross_price' : response.products[i].gross_price});
177
							var url = minpriceurl;
178
                            }                   
178
							var value = url.substring(url.lastIndexOf('-') + 1);
179
                            j++;
179
							$(that).parent().attr('data-identifier', value);
180
                        }
180
							$(that).parent().attr('data-proid', response.products[minpriceindex]['_id']);
181
                        if(variants.length>1){
181
						}
182
                            variants.splice(minpriceindex,1);                           
182
 
183
                            var variantslink = $('<span class="variants"> '+(variants.length+1)+' Options</span>');
183
						$('#name-'+$(that).data('id')).html(response.products[minpriceindex]['source_product_name']);
184
                            $(that).parent().parent().find('.pull-left',0).append(variantslink);                            
184
						if(response.products[minpriceindex]['coupon'] && response.products[minpriceindex]['coupon'].length>0){
185
                            $(variantslink).data('variants',variants).data('minprice',minprice);
185
							$('#couponcode-'+$(that).data('id')).show().find('span.red',0).html(getCouponText(response.products[minpriceindex]['coupon']));
186
                        }
186
						}			
187
                    }
187
						if(!response.products[minpriceindex]['codAvailable']){
188
                    if(inStock){
188
							$('#codstatus-'+$(that).data('id')).show().removeClass('codstatus');
189
                        $(that).html(minprice).siblings('.cashbackamount').html(getcashbackstring(response.products[minpriceindex].cash_back_type,response.products[minpriceindex].cash_back)).parent().addClass('viewproduct');
189
						}
190
                        
190
						if(response.products[minpriceindex]['gross_price'] && response.products[minpriceindex]['gross_price'] > 0){
191
                        if($(that).parent().data('storename') == "Saholic")
191
							$('#gross_price-'+$(that).data('id')).show().removeClass('gross_price').html(getGrossPriceText(response.products[minpriceindex]['gross_price'],response.products[minpriceindex]['available_price']));
192
                        {
192
						}
193
                            if (priceRange != "") {
193
						if(response.products[minpriceindex]['offer'].length>0){
194
                                        $(that).html(priceRange);
194
							$('#itemoffer-'+$(that).data('id')).show().html(response.products[minpriceindex]['offer']);
195
                            }
195
						}
196
                            var url = minpriceurl;
196
						$('#sku-'+$(that).data('id')).data('id',response.products[minpriceindex]['_id']).data('source',response.products[minpriceindex]['source_id']).data('price',response.products[minpriceindex]['available_price']).data('url',response.products[minpriceindex]['marketPlaceUrl']).removeClass('hidden');
197
                            var value = url.substring(url.lastIndexOf('-') + 1);
197
						if(globalminprice != 9999999) {
198
                            $(that).parent().attr('data-identifier', value);
198
							$('#bestprice').html(globalminprice).siblings('.cashbackamount').html(globalmincashback).siblings('.productoffer').html(globalminoffer);
199
                            $(that).parent().attr('data-proid', response.products[minpriceindex]['_id']);
199
							$('#beststorelink').data('id',globalminsku).data('source',globalminsource).data('price',globalminprice).data('url',globalminurl).removeClass('hidden');
200
                        }
200
							$('#bestpricecontainer').removeClass('hidden');
201
 
201
							if(typeof globalminsource!= "undefined") {
202
                        $('#name-'+$(that).data('id')).html(response.products[minpriceindex]['source_product_name']);
202
								if (globalminsource==4){
203
                        if(response.products[minpriceindex]['coupon'] && response.products[minpriceindex]['coupon'].length>0){
203
									var value = globalminurl.substring(globalminurl.lastIndexOf('-') + 1);
204
                            $('#couponcode-'+$(that).data('id')).show().find('span.red',0).html(getCouponText(response.products[minpriceindex]['coupon']));
204
									$('#beststorelink').attr('data-identifier', value);
205
                        }           
205
									$('#beststorelink').attr('data-proid', globalminsku);
206
                        if(!response.products[minpriceindex]['codAvailable']){
206
								} else {
207
                            $('#codstatus-'+$(that).data('id')).show().removeClass('codstatus');
207
									$('#beststorelink').removeAttr('data-identifier');
208
                        }
208
									$('#beststorelink').removeAttr('data-proid');
209
                        if(response.products[minpriceindex]['gross_price'] && response.products[minpriceindex]['gross_price'] > 0){
209
								}						
210
                            $('#gross_price-'+$(that).data('id')).show().removeClass('gross_price').html(getGrossPriceText(response.products[minpriceindex]['gross_price'],response.products[minpriceindex]['available_price']));
210
							}
211
                        }
211
						} 
212
                        if(response.products[minpriceindex]['offer'].length>0){
212
					} else{
213
                            $('#itemoffer-'+$(that).data('id')).show().html(response.products[minpriceindex]['offer']);
213
						ga('send', 'event', 'liveprice', 'outofstock', $('#bestpriceproductname').html());
214
                        }
214
						var properties = {};
215
                        $('#sku-'+$(that).data('id')).data('id',response.products[minpriceindex]['_id']).data('source',response.products[minpriceindex]['source_id']).data('price',response.products[minpriceindex]['available_price']).data('url',response.products[minpriceindex]['marketPlaceUrl']).removeClass('hidden');
215
						properties.sku = String(response.products[0]._id);
216
                        if(globalminprice != 9999999) {
216
						properties.source = String(response.products[0].source_id);
217
                            $('#bestprice').html(globalminprice).siblings('.cashbackamount').html(globalmincashback).siblings('.productoffer').html(globalminoffer);
217
						properties.product_name = String($('#bestpriceproductname').html());
218
                            $('#beststorelink').data('id',globalminsku).data('source',globalminsource).data('price',globalminprice).data('url',globalminurl).removeClass('hidden');
218
						pma.send('products','liveprice','outofstock',me,properties);
219
                            $('#bestpricecontainer').removeClass('hidden');
219
						outOfStockCount++;
220
                            if(typeof globalminsource!= "undefined") {
220
						$(that).parent().parent().remove();	
221
                                if (globalminsource==4){
221
					}
222
                                    if (priceRange != "") {
222
					if(!response.products[0].available_price){
223
                                                $('#bestprice').html(priceRange);
223
						// outOfStockCount++;
224
                                    }
224
						// $(that).parent().parent().remove();	
225
                                    var value = globalminurl.substring(globalminurl.lastIndexOf('-') + 1);
225
						var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
226
                                    $('#beststorelink').attr('data-identifier', value);
226
						$(that).html(btn);
227
                                    $('#beststorelink').attr('data-proid', globalminsku);
227
						// ga('send', 'event', 'liveprice', 'failed', response.products[0]._id);
228
                                } else {
228
						// console.log('failed for '+ response);
229
                                    $('#beststorelink').removeAttr('data-identifier');
229
						// properties = {};
230
                                    $('#beststorelink').removeAttr('data-proid');
230
						// properties.sku = String(response.products[0]._id); 
231
                                }                       
231
						// pma.send('products','liveprice','failed',me,properties);
232
                            }
232
					}					
233
                        } 
233
				} else{
234
                    } else{
234
					// outOfStockCount++;
235
                        ga('send', 'event', 'liveprice', 'outofstock', $('#bestpriceproductname').html());
235
					// $(that).parent().parent().remove();
236
                        var properties = {};
236
					var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
237
                        properties.sku = String(response.products[0]._id);
237
					$(that).html(btn);
238
                        properties.source = String(response.products[0].source_id);
238
					ga('send', 'event', 'liveprice', 'failure', response.products[0]._id);
239
                        properties.product_name = String($('#bestpriceproductname').html());
239
					properties = {};
240
                        pma.send('products','liveprice','outofstock',me,properties);
240
					properties.sku = String(response.products[0]._id); 
241
                        outOfStockCount++;
241
					pma.send('products','liveprice','failure',me,properties);
242
                        $(that).parent().parent().remove(); 
242
				}
243
                    }
243
				checkForOutStocks(outOfStockCount);
244
                    if(!response.products[0].available_price){
244
			},
245
                        // outOfStockCount++;
245
			error: function(request, status, err) {            	
246
                        // $(that).parent().parent().remove();  
246
        		var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
247
                        var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
247
				$(that).html(btn);
248
                        $(that).html(btn);
248
				try{
249
                        // ga('send', 'event', 'liveprice', 'failed', response.products[0]._id);
249
					if(response){
250
                        // console.log('failed for '+ response);
250
						ga('send', 'event', 'liveprice', 'error', response.products[0]._id);
251
                        // properties = {};
251
						var properties = {};
252
                        // properties.sku = String(response.products[0]._id); 
252
						properties.sku = String(response.products[0]._id);
253
                        // pma.send('products','liveprice','failed',me,properties);
253
						pma.send('products','livescore','error',me,properties);
254
                    }                   
254
					}						
255
                } else{
255
				} catch(e){}
256
                    // outOfStockCount++;
256
			}
257
                    // $(that).parent().parent().remove();
257
		});
258
                    var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
258
		livePriceCalls.push(req);
259
                    $(that).html(btn);
259
	};
260
                    ga('send', 'event', 'liveprice', 'failure', response.products[0]._id);
260
	function checkForOutStocks(count){
261
                    properties = {};
261
		if(count>=livePriceCalls.length){
262
                    properties.sku = String(response.products[0]._id); 
262
			$('#bestpricecontainer').html('<h4>Out of stock</h4>').removeClass('hidden');	
263
                    pma.send('products','liveprice','failure',me,properties);
263
		}		
264
                }
264
	};
265
                checkForOutStocks(outOfStockCount);
265
	$(document).on('click','.showless',function(){
266
            },
266
		$(this).addClass('hidden').siblings('.varnts').hide();
267
            error: function(request, status, err) {             
267
		$(this).parent().find('.variants',0).removeClass('hidden').addClass('justshow');
268
                var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
268
	});
269
                $(that).html(btn);
269
	$(document).on('click','.variants',function(){
270
                try{
270
		$('.storeproductinfo').empty();
271
                    if(response){
271
		var variants = $(this).data('variants');		
272
                        ga('send', 'event', 'liveprice', 'error', response.products[0]._id);
272
		var minprice = $(this).data('minprice');
273
                        var properties = {};
273
		$('#variantscount').html(variants.length);
274
                        properties.sku = String(response.products[0]._id);
274
		for(var i in variants){
275
                        pma.send('products','livescore','error',me,properties);
275
			if(variants[i].gross_price && variants[i].gross_price > variants[i].available_price) {
276
                    }                       
276
				var priceToDisplay = variants[i].gross_price;
277
                } catch(e){}
277
			}else{
278
            }
278
				var priceToDisplay = variants[i].available_price;
279
        });
279
			}
280
        livePriceCalls.push(req);
280
			if(minprice == priceToDisplay) {
281
    };
281
				var html = '<div class="clearfix varnts"></div><div class="col-xs-6 varnts text-small">'+variants[i].name+'</div><div class="col-xs-6 varnts viewproduct" data-source="'+variants[i].source_id+'" data-price="'+priceToDisplay+'" data-url="'+variants[i].url+'" data-id="'+variants[i].id+'"><span class="cashbackrupee varnts text-right" ></span> <span class="storeminprice">'+priceToDisplay+'</span><span class="cashbackamount">'+getcashbackstring(variants[i].cash_back_type,variants[i].cash_back)+'</span><span class="pull-right arrowright"></span>';
282
    function checkForOutStocks(count){
282
			} else {
283
        if(count>=livePriceCalls.length){
283
				var html = '<div class="clearfix varnts"></div><div class="col-xs-6 varnts text-small">'+variants[i].name+'</div><div class="col-xs-6 varnts viewproduct" data-source="'+variants[i].source_id+'" data-price="'+priceToDisplay+'" data-url="'+variants[i].url+'" data-id="'+variants[i].id+'"><span class="cashbackrupee varnts text-right" ></span> <span class="text-small">'+priceToDisplay+'</span><span class="cashbackamount">'+getcashbackstring(variants[i].cash_back_type,variants[i].cash_back)+'</span><span class="pull-right arrowright"></span>';
284
            $('#bestpricecontainer').html('<h4>Out of stock</h4>').removeClass('hidden');   
284
			}
285
        }       
285
			if(variants[i].gross_price && variants[i].gross_price>0){
286
    };
286
				html += '<p class="text-small">'+getGrossPriceText(variants[i].gross_price,variants[i].available_price)+'</p>';
287
    $(document).on('click','.showless',function(){
287
			}	
288
        $(this).addClass('hidden').siblings('.varnts').hide();
288
			if(variants[i].offer.length>0){
289
        $(this).parent().find('.variants',0).removeClass('hidden').addClass('justshow');
289
				html += '<p class="text-small">'+variants[i].offer+'</p>';
290
    });
290
			}	
291
    $(document).on('click','.variants',function(){
291
			if(variants[i].coupon && variants[i].coupon.length>0){
292
        $('.storeproductinfo').empty();
292
				html += '<p class="text-small">Use Coupon <span class="red">'+variants[i].coupon+'</span></p>';
293
        var variants = $(this).data('variants');        
293
			}
294
        var minprice = $(this).data('minprice');
294
			if(!variants[i].codAvailable){
295
        $('#variantscount').html(variants.length);
295
				html += '<p class="text-small">COD not available</p>';
296
        for(var i in variants){
296
			}			
297
            if(variants[i].gross_price && variants[i].gross_price > variants[i].available_price) {
297
			html += '</div></div>';
298
                var priceToDisplay = variants[i].gross_price;
298
			var row = $(html);			
299
            }else{
299
			$(this).parent().parent().append(row);			
300
                var priceToDisplay = variants[i].available_price;
300
		}
301
            }
301
		var showless = $('<div class="showless col-xs-9 text-right">Less <i class="glyphicon glyphicon-chevron-up"></i></span>');
302
            if(minprice == priceToDisplay) {
302
		$(this).parent().parent().append(showless);
303
                var html = '<div class="clearfix varnts"></div><div class="col-xs-6 varnts text-small">'+variants[i].name+'</div><div class="col-xs-6 varnts viewproduct" data-source="'+variants[i].source_id+'" data-price="'+priceToDisplay+'" data-url="'+variants[i].url+'" data-id="'+variants[i].id+'"><span class="cashbackrupee varnts text-right" ></span> <span class="storeminprice">'+priceToDisplay+'</span><span class="cashbackamount">'+getcashbackstring(variants[i].cash_back_type,variants[i].cash_back)+'</span><span class="pull-right arrowright"></span>';
303
		$(this).addClass('hidden');
304
            } else {
304
	});
305
                var html = '<div class="clearfix varnts"></div><div class="col-xs-6 varnts text-small">'+variants[i].name+'</div><div class="col-xs-6 varnts viewproduct" data-source="'+variants[i].source_id+'" data-price="'+priceToDisplay+'" data-url="'+variants[i].url+'" data-id="'+variants[i].id+'"><span class="cashbackrupee varnts text-right" ></span> <span class="text-small">'+priceToDisplay+'</span><span class="cashbackamount">'+getcashbackstring(variants[i].cash_back_type,variants[i].cash_back)+'</span><span class="pull-right arrowright"></span>';
305
	$('.categorytab').on('click','.categorytabcontrol.active',function(){
306
            }
306
		$(this).toggleClass('active');
307
            if(variants[i].gross_price && variants[i].gross_price>0){
307
		$('#preferences-'+$(this).data('id')).addClass('hidden');
308
                html += '<p class="text-small">'+getGrossPriceText(variants[i].gross_price,variants[i].available_price)+'</p>';
308
		$(this).parent().parent().children().find('.savecategorypreferences',0).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');
309
            }   
309
	});
310
            if(variants[i].offer.length>0){
310
	$('.categorytab').on('click','.categorytabcontrol:not(.active)',function(){
311
                html += '<p class="text-small">'+variants[i].offer+'</p>';
311
		$(this).parent().parent().find('.btn',0).click();
312
            }   
312
	});
313
            if(variants[i].coupon && variants[i].coupon.length>0){
313
	$('.categorytab').on('click','.editcategorypreferences',function(e){
314
                html += '<p class="text-small">Use Coupon <span class="red">'+variants[i].coupon+'</span></p>';
314
		var that = $(this);
315
            }
315
		$(that).removeClass('editcategorypreferences').addClass('savecategorypreferences').html('Done').addClass('btn-success');
316
            if(!variants[i].codAvailable){
316
		$('#togglepreferences-'+$(that).data('id')).toggleClass('active');
317
                html += '<p class="text-small">COD not available</p>';
317
		$('#preferences-'+$(that).data('id')).removeClass('hidden');
318
            }           
318
		$('.brandselector').each(function(){
319
            html += '</div></div>';
319
			if($(this).data('catid')==$(that).data('id')){
320
            var row = $(html);          
320
				$(this).addClass('active');
321
            $(this).parent().parent().append(row);          
321
			}
322
        }
322
		});
323
        var showless = $('<div class="showless col-xs-9 text-right">Less <i class="glyphicon glyphicon-chevron-up"></i></span>');
323
		$('.subcategoryselector').each(function(){
324
        $(this).parent().parent().append(showless);
324
			if($(this).data('catid')==$(that).data('id')){
325
        $(this).addClass('hidden');
325
				$(this).addClass('active');
326
    });
326
			}
327
    $('.categorytab').on('click','.categorytabcontrol.active',function(){
327
		});		
328
        $(this).toggleClass('active');
328
	});
329
        $('#preferences-'+$(this).data('id')).addClass('hidden');
329
	$('.categorytab').on('click','.savecategorypreferences',function(e){
330
        $(this).parent().parent().children().find('.savecategorypreferences',0).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');
330
		var that = $(this);
331
    });
331
		$(that).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');
332
    $('.categorytab').on('click','.categorytabcontrol:not(.active)',function(){
332
		$('#togglepreferences-'+$(that).data('id')).toggleClass('active');
333
        $(this).parent().parent().find('.btn',0).click();
333
		$.ajax({
334
    });
334
			url: $('#categorypreference-'+$(that).data('id')).attr('action'),
335
    $('.categorytab').on('click','.editcategorypreferences',function(e){
335
			data: $('#categorypreference-'+$(that).data('id')).serialize(),
336
        var that = $(this);
336
			// Tell jQuery we're expecting JSONP
337
        $(that).removeClass('editcategorypreferences').addClass('savecategorypreferences').html('Done').addClass('btn-success');
337
			dataType: "json",
338
        $('#togglepreferences-'+$(that).data('id')).toggleClass('active');
338
			// Tell YQL what we want and that we want JSON			
339
        $('#preferences-'+$(that).data('id')).removeClass('hidden');
339
			method: 'post',
340
        $('.brandselector').each(function(){
340
			// Work with the response
341
            if($(this).data('catid')==$(that).data('id')){
341
			success: function( response ) {
342
                $(this).addClass('active');
342
				if(response.success){
343
            }
343
					$('#preferences-'+$(that).data('id')).addClass('hidden');
344
        });
344
				}
345
        $('.subcategoryselector').each(function(){
345
			}
346
            if($(this).data('catid')==$(that).data('id')){
346
		});
347
                $(this).addClass('active');
347
		active = getCookie('shopcluesActive',1);
348
            }
348
		if(active && active == 'true'){
349
        });     
349
			$('.firsttimemsg').removeClass('hidden').show();
350
    });
350
		}		
351
    $('.categorytab').on('click','.savecategorypreferences',function(e){
351
		ga('send', 'event', 'preferences', 'update', me);
352
        var that = $(this);
352
		properties = pma.formDataToObject($('#categorypreference-'+$(this).data('id')).serializeArray());
353
        $(that).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');
353
		pma.send('preferences', 'update', 'set', me, properties);
354
        $('#togglepreferences-'+$(that).data('id')).toggleClass('active');
354
	});
355
        $.ajax({
355
	
356
            url: $('#categorypreference-'+$(that).data('id')).attr('action'),
356
	
357
            data: $('#categorypreference-'+$(that).data('id')).serialize(),
357
	$(document).on('click','.accsproduct',function(){
358
            // Tell jQuery we're expecting JSONP
358
		if (typeof(Storage) !== "undefined") {
359
            dataType: "json",
359
			localStorage.removeItem("productdetail");
360
            // Tell YQL what we want and that we want JSON          
360
			localStorage.setItem("productdetail", $(this).closest(".card").html());
361
            method: 'post',
361
		}
362
            // Work with the response
362
		$('#loadingModal').modal();
363
            success: function( response ) {
363
		var redirect_url = $(this).data('url');
364
                if(response.success){
364
		var call = apihost+"clicks/add/"+me+"/"+$(this).data('id')+'/'+$(this).data('source')+'/?url='+encodeURIComponent($(this).data('url'))+'&price='+$(this).data('price');
365
                    $('#preferences-'+$(that).data('id')).addClass('hidden');
365
		$.ajax({
366
                }
366
			url: call,
367
            }
367
			// The name of the callback parameter, as specified by the YQL service
368
        });
368
			jsonp: "callback",
369
        active = getCookie('shopcluesActive',1);
369
			// Tell jQuery we're expecting JSONP
370
        if(active && active == 'true'){
370
			dataType: "jsonp",
371
            $('.firsttimemsg').removeClass('hidden').show();
371
			// Tell YQL what we want and that we want JSON
372
        }       
372
			data: {
373
        ga('send', 'event', 'preferences', 'update', me);
373
				format: "json"
374
        properties = pma.formDataToObject($('#categorypreference-'+$(this).data('id')).serializeArray());
374
			},
375
        pma.send('preferences', 'update', 'set', me, properties);
375
			// Work with the response
376
    });
376
			success: function( response ) {
377
    
377
//				console.log(response);
378
    
378
				window.location = redirect_url;
379
    $(document).on('click','.accsproduct',function(){
379
			},
380
        if (typeof(Storage) !== "undefined") {
380
			error: function() {
381
            localStorage.removeItem("productdetail");
381
				window.location = redirect_url;
382
            localStorage.setItem("productdetail", $(this).closest(".card").html());
382
            }
383
        }
383
			});
384
        $('#loadingModal').modal();
384
	});
385
        var redirect_url = $(this).data('url');
385
	
386
        var properties = {};
386
	$(document).on('click','.viewproduct',function(e){
387
        properties.sku = String($(this).data('id'));
387
 
388
        properties.source = String($(this).data('source'));
388
		var proid = $(this).data("proid");
389
        properties.url = encodeURIComponent($(this).data('url'));
389
		var identifier = $(this).data("identifier");
390
        properties.price = String($(this).data('price'));
390
		
391
        pma.send('products','url','click',me,properties);
391
		if(typeof livePriceCalls != undefined) {
392
        var call = apihost+"clicks/add/"+me+"/"+$(this).data('id')+'/'+$(this).data('source')+'/?url='+encodeURIComponent($(this).data('url'))+'&price='+$(this).data('price');
392
	    	for(var i in livePriceCalls){
393
        $.ajax({
393
	    		livePriceCalls[i].abort();
394
            url: call,
394
	    	}
395
            // The name of the callback parameter, as specified by the YQL service
395
	    }
396
            jsonp: "callback",
396
		$('#loadingModal').modal();
397
            // Tell jQuery we're expecting JSONP
397
		if($(this).data('source')==2){
398
            dataType: "jsonp",
398
			//in case of flipkart, close popup after 5 seconds
399
            // Tell YQL what we want and that we want JSON
399
			setTimeout(function(){ $('#loadingModal').modal('hide');$('#customMessageModal').modal('hide'); }, 1000*10);			
400
            data: {
400
		}
401
                format: "json"
401
		var store = $(this).data('source');
402
            },
402
		var url = apihost+"clicks/add/"+me+"/"+$(this).data('id')+'/'+$(this).data('source')+'/?url='+encodeURIComponent($(this).data('url'))+'&price='+$(this).data('price');
403
            // Work with the response
403
		$.ajax({
404
            success: function( response ) {
404
			url: url,
405
//              console.log(response);
405
			// The name of the callback parameter, as specified by the YQL service
406
                window.location = redirect_url;
406
			jsonp: "callback",
407
            },
407
			// Tell jQuery we're expecting JSONP
408
            error: function() {
408
			dataType: "jsonp",
409
                window.location = redirect_url;
409
			// Tell YQL what we want and that we want JSON
410
            }
410
			data: {
411
            });
411
				format: "json"
412
    });
412
			},
413
    
413
			// Work with the response
414
    $(document).on('click','.viewproduct',function(e){
414
			success: function( response ) {
415
 
415
				if(response.success && response.type=='redirect'){
416
        var proid = $(this).data("proid");
416
					//console.log(store);
417
        var identifier = $(this).data("identifier");
417
					if(store == 5) {
418
        
418
						//check if shopclues is active or not
419
        if(typeof livePriceCalls != undefined) {
419
						active = getCookie('shopcluesActive',1);
420
            for(var i in livePriceCalls){
420
						response.url = 'http://mobilehotindia.com/r.html?'+Base64.encode(response.url);
421
                livePriceCalls[i].abort();
421
						if(active && active == 'true'){							
422
            }
422
							document.location = response.url;	
423
        }
423
							pma.send('apk','shopclues','active',me,null);
424
        $('#loadingModal').modal();
424
						}else{
425
        if($(this).data('source')==2){
425
							pma.send('apk','shopclues','inactive',me,null);
426
            //in case of flipkart, close popup after 5 seconds
426
							$('#loadingModal').modal('hide');
427
            setTimeout(function(){ $('#loadingModal').modal('hide');$('#customMessageModal').modal('hide'); }, 1000*10);            
427
							showShopcluesPopup(response.url);
428
        }
428
						}
429
        var store = $(this).data('source');
429
				  	} else if(store == 6 ) {
430
        var url = apihost+"clicks/add/"+me+"/"+$(this).data('id')+'/'+$(this).data('source')+'/?url='+encodeURIComponent($(this).data('url'))+'&price='+$(this).data('price');
430
				  		//display paytm help
431
        $.ajax({
431
//				  		if(needToDisplayPaytmPopup(me)){
432
            url: url,
432
//				  			showPaytmHelpPopup();
433
            // The name of the callback parameter, as specified by the YQL service
433
//					  		$('#oktatabyebye').on('click',function(){
434
            jsonp: "callback",
434
//					  			redirectToPaytm(response.url);	
435
            // Tell jQuery we're expecting JSONP
435
//					  		});	
436
            dataType: "jsonp",
436
//				  		}else{
437
            // Tell YQL what we want and that we want JSON
437
				  			redirectToPaytm(response.url);	
438
            data: {
438
//				  		}
439
                format: "json"
-
 
440
            },
-
 
441
            // Work with the response
-
 
442
            success: function( response ) {
-
 
443
                if(response.success && response.type=='redirect'){
-
 
444
                    //console.log(store);
-
 
445
                    if(store == 5) {
-
 
446
                        //check if shopclues is active or not
-
 
447
                        active = getCookie('shopcluesActive',1);
-
 
448
                        response.url = 'http://mobilehotindia.com/r.html?'+Base64.encode(response.url);
-
 
449
                        if(active && active == 'true'){                         
-
 
450
                            document.location = response.url;   
-
 
451
                            pma.send('apk','shopclues','active',me,null);
-
 
452
                        }else{
-
 
453
                            pma.send('apk','shopclues','inactive',me,null);
-
 
454
                            $('#loadingModal').modal('hide');
-
 
455
                            showShopcluesPopup(response.url);
-
 
456
                        }
-
 
457
                    } else if(store == 6 ) {
-
 
458
                        //display paytm help
-
 
459
//                      if(needToDisplayPaytmPopup(me)){
-
 
460
//                          showPaytmHelpPopup();
-
 
461
//                          $('#oktatabyebye').on('click',function(){
-
 
462
//                              redirectToPaytm(response.url);  
-
 
463
//                          }); 
-
 
464
//                      }else{
-
 
465
                            redirectToPaytm(response.url);  
-
 
466
//                      }
-
 
467
 
439
 
468
                    } 
440
                    } 
469
                      //for homeshop 18
441
                      //for homeshop 18
470
                      else if(store == 7)
442
                      else if(store == 7)
471
                      {
443
                      {
Line 486... Line 458...
486
                            setTimeout(function(){ document.location = response.url;}, 1000*3);         
458
                            setTimeout(function(){ document.location = response.url;}, 1000*3);         
487
                        } else{
459
                        } else{
488
                            document.location = response.url;   
460
                            document.location = response.url;   
489
                        }
461
                        }
490
                    } else if (store == 4) {
462
                    } else if (store == 4) {
491
                        var urll = apihost+"categories/saholicdeal/"+proid;
463
                    	var urll = apihost+"categories/saholicdeal/"+proid;
492
                        $.ajax({
464
                    	$.ajax({
493
                            method: "GET",
465
                            method: "GET",
494
                            url:  urll,
466
                            url:  urll,
495
                        },'json')
467
                        },'json')
496
                        .done(function(msg){
468
                        .done(function(msg){
497
                            if (typeof(Storage) !== "undefined") {
469
                        	if (typeof(Storage) !== "undefined") {
498
                                localStorage.removeItem("productdetail");
470
	                        	localStorage.removeItem("productdetail");
499
                                localStorage.setItem("productdetail",msg);
471
	                			localStorage.setItem("productdetail",msg);
500
                                document.location = apihost+"categories/dealdetail/"+identifier;
472
	                			document.location = apihost+"categories/dealdetail/"+identifier;
501
                            }
473
                        	}
502
                        });
474
                        });
503
                        
475
                    	
504
//                        response.url = '/r.html?'+Base64.encode(response.url);
476
//                        response.url = '/r.html?'+Base64.encode(response.url);
505
 
477
 
506
//                        document.location = response.url;
478
//                        document.location = response.url;
507
                    } 
479
                    } 
508
                    
480
					
509
                    else{
481
					else{
510
                        response.url = '/r.html?'+Base64.encode(response.url);
482
						response.url = '/r.html?'+Base64.encode(response.url);
511
 
483
 
512
                      document.location = response.url;
484
                      document.location = response.url;
513
                    }
485
					}
514
                }
486
                }
515
            },
487
            },
516
            error: function() {
488
            error: function() {
517
                document.location = url;
489
                document.location = url;
518
            }
490
            }
Line 852... Line 824...
852
    ga('send', 'event', 'filter', 'subcategory', 'reset');
824
    ga('send', 'event', 'filter', 'subcategory', 'reset');
853
    pma.send('filters','subcategory','reset',me);
825
    pma.send('filters','subcategory','reset',me);
854
});
826
});
855
 
827
 
856
function getJsonFromUrl() {
828
function getJsonFromUrl() {
857
      var query = location.search.substr(1);
829
	  var query = location.search.substr(1);
858
      var result = {};
830
	  var result = {};
859
      query.split("&").forEach(function(part) {
831
	  query.split("&").forEach(function(part) {
860
        var item = part.split("=");
832
	    var item = part.split("=");
861
        result[item[0]] = decodeURIComponent(item[1]);
833
	    result[item[0]] = decodeURIComponent(item[1]);
862
      });
834
	  });
863
      return result;
835
	  return result;
864
    }
836
	}
865
 
837
 
866
$(document).on('click','.applyfilter',function(){
838
$(document).on('click','.applyfilter',function(){
867
    var str = window.location.search;
839
	var str = window.location.search;
868
    var urlplus = '';
840
    var urlplus = '';
869
    var urldet = getJsonFromUrl();
841
    var urldet = getJsonFromUrl();
870
    
842
    
871
    $(this).prop('disabled',true);
843
    $(this).prop('disabled',true);
872
    $('#loadingModal').modal();
844
    $('#loadingModal').modal();
Line 887... Line 859...
887
            subcatnames.push($(this).parent().siblings('.subcategoryname').html());
859
            subcatnames.push($(this).parent().siblings('.subcategoryname').html());
888
        }
860
        }
889
    });
861
    });
890
    
862
    
891
    if($("#brandselecter").length == 0 && urldet['brands'] != undefined && urldet['brands'] != ''){
863
    if($("#brandselecter").length == 0 && urldet['brands'] != undefined && urldet['brands'] != ''){
892
        brands = urldet['brands'];
864
    	brands = urldet['brands'];
893
    }
865
    }
894
    if($("#subcategoryselecter").length == 0 && urldet['subcategories'] != undefined && urldet['subcategories'] != ''){
866
    if($("#subcategoryselecter").length == 0 && urldet['subcategories'] != undefined && urldet['subcategories'] != ''){
895
        subcategories = urldet['subcategories'];
867
    	subcategories = urldet['subcategories'];
896
    }
868
    }
897
    
869
    
898
 
870
 
899
        if(brands.length==0 && subcategories.length==0){
871
        if(brands.length==0 && subcategories.length==0){
900
            $('#loadingModal').modal('hide');
872
        	$('#loadingModal').modal('hide');
901
//          $('clearfilters').click();
873
//        	$('clearfilters').click();
902
//          setCookie('brandschosen', '', -1, true);
874
//        	setCookie('brandschosen', '', -1, true);
903
//            setCookie('subcategorieschosen','',-1, true); 
875
//            setCookie('subcategorieschosen','',-1, true);	
904
            var url = '';
876
        	var url = '';
905
            if($('#brandselecter').prop('action') !== undefined )
877
        	if($('#brandselecter').prop('action') !== undefined )
906
            {
878
        	{
907
                url = $('#brandselecter').prop('action'); 
879
        		url = $('#brandselecter').prop('action'); 
908
            }
880
        	}
909
            if($('#subcategoryselecter').prop('action') !== undefined )
881
        	if($('#subcategoryselecter').prop('action') !== undefined )
910
            {
882
        	{
911
                url = $('#subcategoryselecter').prop('action'); 
883
        		url = $('#subcategoryselecter').prop('action'); 
912
            }
884
        	}
913
            document.location = url; 
885
        	document.location = url; 
914
            
886
            
915
//            $('#message').html('Please choose a few brands/subcategories first').removeClass('hidden');
887
//            $('#message').html('Please choose a few brands/subcategories first').removeClass('hidden');
916
//            setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
888
//            setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
917
//            $(this).prop('disabled',false);
889
//            $(this).prop('disabled',false);
918
//            return false;
890
//            return false;
Line 965... Line 937...
965
            var postdata = {'user_id':me,'type':'brandnsubcategory','filters':dataStr};
937
            var postdata = {'user_id':me,'type':'brandnsubcategory','filters':dataStr};
966
            $.post( "/user_filters/add", postdata, function( data ) {
938
            $.post( "/user_filters/add", postdata, function( data ) {
967
                $('#loadingModal').modal('hide');
939
                $('#loadingModal').modal('hide');
968
                $(this).prop('disabled',false);
940
                $(this).prop('disabled',false);
969
                if($("#brandselecter").length == 0 && urldet['brands'] != undefined && urldet['brands'] != ''){
941
                if($("#brandselecter").length == 0 && urldet['brands'] != undefined && urldet['brands'] != ''){
970
                    url = $("#subcategoryselecter").prop('action');
942
                	url = $("#subcategoryselecter").prop('action');
971
                    brands = urldet['brands'];
943
                	brands = urldet['brands'];
972
                    document.location = url.split('?')[0]+'?brands='+brands+"&subcategories="+subcategories.join("^");
944
                	document.location = url.split('?')[0]+'?brands='+brands+"&subcategories="+subcategories.join("^");
973
                }
945
                }
974
                else if($("#subcategoryselecter").length == 0 && urldet['subcategories'] != undefined && urldet['subcategories'] != ''){
946
                else if($("#subcategoryselecter").length == 0 && urldet['subcategories'] != undefined && urldet['subcategories'] != ''){
975
                    url = $('#brandselecter').prop('action');
947
                	url = $('#brandselecter').prop('action');
976
                    subcategories = urldet['subcategories'];
948
                	subcategories = urldet['subcategories'];
977
                    document.location = url.split('?')[0]+'?brands='+brands.join('^')+"&subcategories="+subcategories;
949
                	document.location = url.split('?')[0]+'?brands='+brands.join('^')+"&subcategories="+subcategories;
978
                }
950
                }
979
//                document.location = url+'&brands='+brands.join('^')+"&subcategories="+subcategories.join("^");
951
//                document.location = url+'&brands='+brands.join('^')+"&subcategories="+subcategories.join("^");
980
            });
952
            });
981
        }
953
        }
982
//    }
954
//    }
Line 1133... Line 1105...
1133
function selectChosenBrands(){
1105
function selectChosenBrands(){
1134
 
1106
 
1135
    var urldet = getJsonFromUrl();
1107
    var urldet = getJsonFromUrl();
1136
 
1108
 
1137
    if (urldet['brands'] !=undefined && urldet['brands'] !="") {
1109
    if (urldet['brands'] !=undefined && urldet['brands'] !="") {
1138
        var brands = urldet['brands'].split('^');
1110
    	var brands = urldet['brands'].split('^');
1139
            for(var i in brands){
1111
	        for(var i in brands){
1140
                $('[data-brandid="'+brands[i]+'"]').removeClass('hidden').find('.filterbrand',0).trigger( "click" );
1112
	        	$('[data-brandid="'+brands[i]+'"]').removeClass('hidden').find('.filterbrand',0).trigger( "click" );
1141
            }
1113
	        }
1142
        }
1114
    	}
1143
    
1115
    
1144
    if (urldet['subcategories'] != undefined && urldet['subcategories'] != "") {
1116
    if (urldet['subcategories'] != undefined && urldet['subcategories'] != "") {
1145
        var subcategories = urldet['subcategories'].split('^');
1117
    	var subcategories = urldet['subcategories'].split('^');
1146
        for(var i in subcategories){
1118
    	for(var i in subcategories){
1147
                $('.subcategory').filter(function() { 
1119
	            $('.subcategory').filter(function() { 
1148
                    return $(this).data("brandid") == subcategories[i];
1120
	                return $(this).data("brandid") == subcategories[i];
1149
                }).removeClass('hidden').find('.filtersubcategory',0).trigger( "click" );
1121
	            }).removeClass('hidden').find('.filtersubcategory',0).trigger( "click" );
1150
            }
1122
	        }
1151
        }
1123
    	}
1152
    
1124
    
1153
}
1125
}
1154
 
1126
 
1155
function clearFilters(){
1127
function clearFilters(){
1156
    setCookie('brandschosen', '', -1, true);
1128
	setCookie('brandschosen', '', -1, true);
1157
    setCookie('subcategorieschosen','',-1, true);
1129
	setCookie('subcategorieschosen','',-1, true);
1158
}
1130
}
1159
function showPosition(position) {
1131
function showPosition(position) {
1160
    setCookie('latitude',position.coords.latitude,1,true); 
1132
    setCookie('latitude',position.coords.latitude,1,true); 
1161
    setCookie('longitude',position.coords.longitude,1,true);    
1133
    setCookie('longitude',position.coords.longitude,1,true);    
1162
}
1134
}
1163
$(function () {
1135
$(function () {
1164
    $("#popovertrigger5").popover('hide').remove();
1136
	$("#popovertrigger5").popover('hide').remove();
1165
    $('.data-up:first').append('<a id="popovertrigger5"  data-container="body" data-toggle="popover" data-placement="left" data-content="Quick buy multiple items together"></a>');
1137
	$('.data-up:first').append('<a id="popovertrigger5"  data-container="body" data-toggle="popover" data-placement="left" data-content="Quick buy multiple items together"></a>');
1166
    setPopOver("popovertrigger5", ".plusqtybutton", 'click', 3000);
1138
	setPopOver("popovertrigger5", ".plusqtybutton", 'click', 3000);
1167
    callBackFunction = function(){
1139
	callBackFunction = function(){
1168
        return document.location.pathname=="/category/6";       
1140
		return document.location.pathname=="/category/6";		
1169
    };
1141
	};
1170
    setPopOver("popovertrigger4", callBackFunction,undefined,3000);
1142
	setPopOver("popovertrigger4", callBackFunction,undefined,3000);
1171
    //$('[data-toggle="popover"]#'+id).popover('show');
1143
	//$('[data-toggle="popover"]#'+id).popover('show');
1172
    if (navigator.geolocation) {
1144
	if (navigator.geolocation) {
1173
        navigator.geolocation.getCurrentPosition(showPosition);
1145
        navigator.geolocation.getCurrentPosition(showPosition);
1174
    } 
1146
    } 
1175
});
1147
});
1176
 
1148
 
1177
function setPopOver(poid, callBack1, eventString, fadeAfter){
1149
function setPopOver(poid, callBack1, eventString, fadeAfter){
1178
    var cname = 'popover-count-'+me+'-'+poid;
1150
	var cname = 'popover-count-'+me+'-'+poid;
1179
    var cookieval = getCookie(cname,1);
1151
	var cookieval = getCookie(cname,1);
1180
    if(typeof callBack1=="function"){
1152
	if(typeof callBack1=="function"){
1181
        if (callBack1()){
1153
		if (callBack1()){
1182
            var cname = 'popover-count-'+me+'-'+poid;
1154
			var cname = 'popover-count-'+me+'-'+poid;
1183
            var cookieval = getCookie(cname,1);
1155
			var cookieval = getCookie(cname,1);
1184
            $('#' + poid).popover('hide');
1156
			$('#' + poid).popover('hide');
1185
            if(!cookieval || cookieval == 'NaN' || cookieval == ''){
1157
			if(!cookieval || cookieval == 'NaN' || cookieval == ''){
1186
                incrementPopupCount(poid,0,'popover-count-');
1158
				incrementPopupCount(poid,0,'popover-count-');
1187
            } else if(cookieval > 0) {
1159
			} else if(cookieval > 0) {
1188
                incrementPopupCount(poid, cookieval, 'popover-count-');
1160
				incrementPopupCount(poid, cookieval, 'popover-count-');
1189
            }
1161
			}
1190
            setLastShown(poid,'popover-lastshown-');
1162
			setLastShown(poid,'popover-lastshown-');
1191
        }
1163
		}
1192
    } else {
1164
	} else {
1193
        $('div.content').on(eventString, callBack1, function(){
1165
		$('div.content').on(eventString, callBack1, function(){
1194
            var cname = 'popover-count-'+me+'-'+poid;
1166
			var cname = 'popover-count-'+me+'-'+poid;
1195
            var cookieval = getCookie(cname,1);
1167
			var cookieval = getCookie(cname,1);
1196
            $('#' + poid).popover('hide');
1168
			$('#' + poid).popover('hide');
1197
            if(!cookieval || cookieval == 'NaN' || cookieval == ''){
1169
			if(!cookieval || cookieval == 'NaN' || cookieval == ''){
1198
                incrementPopupCount(poid,0,'popover-count-');
1170
				incrementPopupCount(poid,0,'popover-count-');
1199
            } else if(cookieval > 0) {
1171
			} else if(cookieval > 0) {
1200
                incrementPopupCount(poid, cookieval, 'popover-count-');
1172
				incrementPopupCount(poid, cookieval, 'popover-count-');
1201
            }
1173
			}
1202
            setLastShown(poid,'popover-lastshown-');
1174
			setLastShown(poid,'popover-lastshown-');
1203
        }); 
1175
		}); 
1204
    }
1176
	}
1205
    
1177
	
1206
    if(typeof fadeAfter!="undefined"){
1178
	if(typeof fadeAfter!="undefined"){
1207
        var s = setInterval(function(){
1179
		var s = setInterval(function(){
1208
            if($('#' + poid +':in-viewport').length>0) {
1180
			if($('#' + poid +':in-viewport').length>0) {
1209
                setTimeout(function(){
1181
				setTimeout(function(){
1210
                    $('#' + poid).popover('hide');
1182
					$('#' + poid).popover('hide');
1211
                }, fadeAfter);
1183
				}, fadeAfter);
1212
                clearInterval(s);
1184
				clearInterval(s);
1213
            }
1185
			}
1214
        }, 2000);
1186
		}, 2000);
1215
    }
1187
	}
1216
        
1188
     	
1217
    var cname = 'popover-lastshown-'+me+'-'+poid;
1189
	var cname = 'popover-lastshown-'+me+'-'+poid;
1218
    var lastshown = getCookie(cname,1);
1190
	var lastshown = getCookie(cname,1);
1219
    if(cookieval=='' || cookieval == 'NaN' || !cookieval){              
1191
	if(cookieval=='' || cookieval == 'NaN' || !cookieval){				
1220
        showpopover(poid);
1192
		showpopover(poid);
1221
    } 
1193
	} 
1222
    //Donot show popover anymore as long as we don't find a suitable solution
1194
	//Donot show popover anymore as long as we don't find a suitable solution
1223
    else{
1195
	else{
1224
        var d = new Date();
1196
		var d = new Date();
1225
        var t = d.getTime();
1197
		var t = d.getTime();
1226
        if(t-lastshown>18*3600*1000){
1198
		if(t-lastshown>18*3600*1000){
1227
            if(cookieval>=2){
1199
			if(cookieval>=2){
1228
                return false;
1200
				return false;
1229
            }else{
1201
			}else{
1230
                showpopover(poid);              
1202
				showpopover(poid);				
1231
            }
1203
			}
1232
        }
1204
		}
1233
    }
1205
	}
1234
    ga('send', 'event', 'popover', me, cookieval);
1206
	ga('send', 'event', 'popover', me, cookieval);
1235
}
1207
}
1236
$('.getapp').on('click',function(){
1208
$('.getapp').on('click',function(){
1237
    /*var that = $(this);
1209
    /*var that = $(this);
1238
    var req = $.ajax({
1210
    var req = $.ajax({
1239
        url: 'http://104.200.25.40:8057/appAffiliates/generateRedirectUrl/'+me+'/'+$(that).data('id'),
1211
        url: 'http://104.200.25.40:8057/appAffiliates/generateRedirectUrl/'+me+'/'+$(that).data('id'),