Subversion Repositories SmartDukaan

Rev

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

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