Subversion Repositories SmartDukaan

Rev

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

Rev 15274 Rev 15310
Line 1... Line 1...
1
var livePriceCalls = [];
1
var livePriceCalls = [];
2
var outOfStockCount = 0;
2
var outOfStockCount = 0;
3
function getcashbackstring(type,value) {
3
function getcashbackstring(type,value) {
4
	// console.log(type+' '+value);
-
 
5
	if(value==0){
4
	if(value==0){
6
		return '';
5
		return '';
7
	}
6
	}
8
	if(type==2){
7
	if(type==2){
9
		return ' +'+value+' Cashback';
8
		return ' +'+value+' Cashback';
Line 54... Line 53...
54
			// Tell YQL what we want and that we want JSON			
53
			// Tell YQL what we want and that we want JSON			
55
			method: 'get',
54
			method: 'get',
56
			// timeout: 30000,
55
			// timeout: 30000,
57
			// Work with the response
56
			// Work with the response
58
			success: function( response ) {
57
			success: function( response ) {
59
				// console.log(response);
-
 
60
				if(response.success){
58
				if(response.success){
61
					var i = 0;	
59
					var i = 0;	
62
					var minpriceindex = 0;				
60
					var minpriceindex = 0;				
63
					if(response.products[i].in_stock == 1) {inStock = true;}
61
					if(response.products[i].in_stock == 1) {inStock = true;}
64
					if(response.products[i].in_stock == 1) {
62
					if(response.products[i].in_stock == 1) {
65
						var minprice = Math.round(response.products[i]['available_price']);
63
						var minprice = Math.round(response.products[i]['available_price']);
66
						var minpriceurl = response.products[i]['marketPlaceUrl'];
64
						var minpriceurl = response.products[i]['marketPlaceUrl'];
67
						console.log(minprice);
-
 
68
					}
65
					}
69
					if(response.products.length>0){
66
					if(response.products.length>0){
70
						//More than one products in store
67
						//More than one products in store
71
						var variants = [];
68
						var variants = [];
72
						// var i = 0;
69
						// var i = 0;
73
						for(var i in response.products){	
70
						for(var i in response.products){	
74
							if(response.products[i].in_stock == 1){
71
							if(response.products[i].in_stock == 1){
75
								inStock = true;
72
								inStock = true;
76
								// console.log(response.products[i]);
-
 
77
								if(response.products[i].available_price && response.products[i].available_price < globalminprice) {
73
								if(response.products[i].available_price && response.products[i].available_price < globalminprice) {
78
									globalminprice = Math.round(response.products[i].available_price);
74
									globalminprice = Math.round(response.products[i].available_price);
79
									globalminsku = response.products[i]._id;
75
									globalminsku = response.products[i]._id;
80
									var globalminsource = response.products[i].source_id;
76
									var globalminsource = response.products[i].source_id;
81
									var globalminurl = response.products[i].marketPlaceUrl;
77
									var globalminurl = response.products[i].marketPlaceUrl;
Line 96... Line 92...
96
						}
92
						}
97
					}
93
					}
98
					if(inStock){
94
					if(inStock){
99
						$(that).html(minprice).siblings('.cashbackamount').html(getcashbackstring(response.products[minpriceindex].cash_back_type,response.products[minpriceindex].cash_back)).parent().addClass('viewproduct');
95
						$(that).html(minprice).siblings('.cashbackamount').html(getcashbackstring(response.products[minpriceindex].cash_back_type,response.products[minpriceindex].cash_back)).parent().addClass('viewproduct');
100
						$('#name-'+$(that).data('id')).html(response.products[minpriceindex]['source_product_name']);
96
						$('#name-'+$(that).data('id')).html(response.products[minpriceindex]['source_product_name']);
101
						// console.log(response.products[minpriceindex]);
-
 
102
						$('#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');
97
						$('#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');
103
						// console.log(globalminprice+' '+globalminsku);
-
 
104
						if(globalminprice != 9999999) {
98
						if(globalminprice != 9999999) {
105
							$('#bestprice').html(globalminprice).siblings('.cashbackamount').html(globalmincashback);
99
							$('#bestprice').html(globalminprice).siblings('.cashbackamount').html(globalmincashback);
106
							$('#beststorelink').data('id',globalminsku).data('source',globalminsource).data('price',globalminprice).data('url',globalminurl).removeClass('hidden');
100
							$('#beststorelink').data('id',globalminsku).data('source',globalminsource).data('price',globalminprice).data('url',globalminurl).removeClass('hidden');
107
							$('#bestpricecontainer').removeClass('hidden');
101
							$('#bestpricecontainer').removeClass('hidden');
108
						} 
102
						} 
Line 125... Line 119...
125
					$(that).html(btn);
119
					$(that).html(btn);
126
					ga('send', 'event', 'liveprice', 'failure', response.products[0]._id);
120
					ga('send', 'event', 'liveprice', 'failure', response.products[0]._id);
127
				}
121
				}
128
				checkForOutStocks(outOfStockCount);
122
				checkForOutStocks(outOfStockCount);
129
			},
123
			},
130
			error: function(request, status, err) {
124
			error: function(request, status, err) {            	
131
				//console.log(status+' '+err+' '+request);
-
 
132
            	// if (status == "timeout") {
-
 
133
            		var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
125
        		var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
134
					$(that).html(btn);
126
				$(that).html(btn);
135
					try{
127
				try{
136
						if(response){
128
					if(response){
137
							ga('send', 'event', 'liveprice', 'error', response.products[0]._id);
129
						ga('send', 'event', 'liveprice', 'error', response.products[0]._id);
138
						}						
130
					}						
139
					} catch(e){}
131
				} catch(e){}
140
				// } else {
-
 
141
					// $(that).parent().parent().remove();
-
 
142
				// }
-
 
143
			}
132
			}
144
		});
133
		});
145
		livePriceCalls.push(req);
134
		livePriceCalls.push(req);
146
	};
135
	};
147
	function checkForOutStocks(count){
136
	function checkForOutStocks(count){
Line 155... Line 144...
155
	});
144
	});
156
	$(document).on('click','.variants',function(){
145
	$(document).on('click','.variants',function(){
157
		$('.storeproductinfo').empty();
146
		$('.storeproductinfo').empty();
158
		var variants = $(this).data('variants');
147
		var variants = $(this).data('variants');
159
		var minprice = $(this).data('minprice');
148
		var minprice = $(this).data('minprice');
160
		// console.log(variants);
-
 
161
		$('#variantscount').html(variants.length);
149
		$('#variantscount').html(variants.length);
162
		for(var i in variants){
150
		for(var i in variants){
163
			// console.log(variants[i]);
-
 
164
			// var row = $('<div class="row storeproductinfo"><div class="col-xs-7">'+variants[i].source_product_name+'</div><div class="col-xs-3">'+variants[i].available_price+'</div><div class="col-xs-2"><button class="btn btn-primary btn-xs viewproduct" type="button" data-id="'+variants[i].id+'">Buy</button></div></div>');
-
 
165
			// $('#storeproducts').parent().append(row);
-
 
166
			// var row = $('<div class="clearfix varnts"></div><div class="col-xs-6 varnts text-small">'+variants[i].name+'</div><div class="col-xs-4 varnts"><span class="cashbackrupee"></span> <span>'+variants[i].available_price+'</span><span class="cashbackamount">'+getcashbackstring(variants[i].cash_back_type,variants[i].cash_back)+'</span></div><div class="col-xs-2 viewproduct varnts text-right" data-source="'+variants[i].source_id+'" data-price="'+variants[i].available_price+'" data-url="'+variants[i].url+'" data-id="'+variants[i].id+'"><button type="button" class="btn-xs btn btn-success">BUY</button></div>');
-
 
167
			if(minprice == variants[i].available_price) {
151
			if(minprice == variants[i].available_price) {
168
				var row = $('<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="'+variants[i].available_price+'" data-url="'+variants[i].url+'" data-id="'+variants[i].id+'"><span class="cashbackrupee varnts text-right" ></span> <span class="storeminprice">'+variants[i].available_price+'</span><span class="cashbackamount">'+getcashbackstring(variants[i].cash_back_type,variants[i].cash_back)+'</span><span class="pull-right arrowright"></span></div></div>');
152
				var row = $('<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="'+variants[i].available_price+'" data-url="'+variants[i].url+'" data-id="'+variants[i].id+'"><span class="cashbackrupee varnts text-right" ></span> <span class="storeminprice">'+variants[i].available_price+'</span><span class="cashbackamount">'+getcashbackstring(variants[i].cash_back_type,variants[i].cash_back)+'</span><span class="pull-right arrowright"></span></div></div>');
169
			} else {
153
			} else {
170
				var row = $('<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="'+variants[i].available_price+'" data-url="'+variants[i].url+'" data-id="'+variants[i].id+'"><span class="cashbackrupee varnts text-right" ></span> <span>'+variants[i].available_price+'</span><span class="cashbackamount">'+getcashbackstring(variants[i].cash_back_type,variants[i].cash_back)+'</span><span class="pull-right arrowright"></span></div></div>');
154
				var row = $('<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="'+variants[i].available_price+'" data-url="'+variants[i].url+'" data-id="'+variants[i].id+'"><span class="cashbackrupee varnts text-right" ></span> <span>'+variants[i].available_price+'</span><span class="cashbackamount">'+getcashbackstring(variants[i].cash_back_type,variants[i].cash_back)+'</span><span class="pull-right arrowright"></span></div></div>');
171
			}			
155
			}			
Line 212... Line 196...
212
				}
196
				}
213
			}
197
			}
214
		});
198
		});
215
		ga('send', 'event', 'preferences', 'update', me);
199
		ga('send', 'event', 'preferences', 'update', me);
216
	});
200
	});
217
	// $('.row').on('click','.viewproduct',function(e){
-
 
218
	$(document).on('click','.viewproduct',function(e){
201
	$(document).on('click','.viewproduct',function(e){
219
		if(typeof livePriceCalls != undefined) {
202
		if(typeof livePriceCalls != undefined) {
220
	    	for(var i in livePriceCalls){
203
	    	for(var i in livePriceCalls){
221
	    		// console.log('killing ajax call '+i);
-
 
222
	    		livePriceCalls[i].abort();
204
	    		livePriceCalls[i].abort();
223
	    	}
205
	    	}
224
	    }
206
	    }
225
		$('#loadingModal').modal();
207
		$('#loadingModal').modal();
226
		if($(this).data('source')==2){
208
		if($(this).data('source')==2){
227
			//in case of flipkart, close popup after 5 seconds
209
			//in case of flipkart, close popup after 5 seconds
228
			setTimeout(function(){ $('#loadingModal').modal('hide'); }, 1000*5);			
210
			setTimeout(function(){ $('#loadingModal').modal('hide'); }, 1000*5);			
229
		}
211
		}
230
		var store = $(this).data('source');
212
		var store = $(this).data('source');
231
		// console.log($(this).data('id'));
-
 
232
		var url = apihost+"clicks/add/"+me+"/"+$(this).data('id')+'/'+$(this).data('source')+'/?url='+encodeURIComponent($(this).data('url'))+'&price='+$(this).data('price');
213
		var url = apihost+"clicks/add/"+me+"/"+$(this).data('id')+'/'+$(this).data('source')+'/?url='+encodeURIComponent($(this).data('url'))+'&price='+$(this).data('price');
233
		$.ajax({
214
		$.ajax({
234
			url: url,
215
			url: url,
235
			// The name of the callback parameter, as specified by the YQL service
216
			// The name of the callback parameter, as specified by the YQL service
236
			jsonp: "callback",
217
			jsonp: "callback",
Line 243... Line 224...
243
			// Work with the response
224
			// Work with the response
244
			success: function( response ) {
225
			success: function( response ) {
245
				if(response.success && response.type=='redirect'){
226
				if(response.success && response.type=='redirect'){
246
					if(store == 1) {
227
					if(store == 1) {
247
						document.location = '/r.html?'+Base64.encode(response.url);
228
						document.location = '/r.html?'+Base64.encode(response.url);
-
 
229
					} else if (store == 3 || store == 2) {
248
					} else if (store == 3) {
230
						if (store == 2){
-
 
231
							response.url = 'http://mobilehotindia.com/r.html?'+Base64.encode(response.url);
-
 
232
						}
249
						if(response.showmessage == 1) {
233
						if(response.showmessage == 1) {
250
							$('#loadingModal').modal('hide');
234
							$('#loadingModal').modal('hide');
251
							$('#customMessage').html(response.message);
235
							$('#customMessage').html(response.message);
252
							$('#customMessageModal').modal('show');
236
							$('#customMessageModal').modal('show');							
253
							setTimeout(function(){ $('#customMessageModal').modal('hide'); document.location = response.url;}, 1000*3);			
237
							setTimeout(function(){ $('#customMessageModal').modal('hide'); document.location = response.url;}, 1000*3);			
254
						}else{
238
						} else{
255
							document.location = response.url;	
239
							document.location = response.url;	
256
						}
240
						}
257
					} else if (store == 2){
-
 
258
						fkmobileurl = 'http://mobilehotindia.com/r.html?'+Base64.encode(response.url);
-
 
259
						if(response.showmessage == 1) {
-
 
260
							$('#loadingModal').modal('hide');
-
 
261
							$('#customMessage').html(response.message);
-
 
262
							$('#customMessageModal').modal('show');
-
 
263
							setTimeout(function(){ $('#customMessageModal').modal('hide'); document.location = fkmobileurl;}, 1000*3);			
-
 
264
						}else{
-
 
265
							document.location = fkmobileurl;	
-
 
266
						}
-
 
267
					} else {
241
					} else {
268
						document.location = response.url;
242
						document.location = response.url;
269
					}										
243
					}										
270
				}
244
				}
-
 
245
			},
-
 
246
			error: function() {
-
 
247
				document.location = url;
271
			}
248
			}
272
		});
249
		});
273
		ga('send', 'event', 'product', 'click', $(this).data('url'));
250
		ga('send', 'event', 'product', 'click', $(this).data('url'));
274
	});
251
	});
275
	$('.jscroll-inner').on('click','.likedeal',function(e){	
252
	$('.jscroll-inner').on('click','.likedeal',function(e){	
Line 301... Line 278...
301
		ga('send', 'event', 'product', 'like', $(this).data('id'));
278
		ga('send', 'event', 'product', 'like', $(this).data('id'));
302
	});
279
	});
303
	$('#myModal').on('click','#unlikebtn',function(e){
280
	$('#myModal').on('click','#unlikebtn',function(e){
304
		e.preventDefault();
281
		e.preventDefault();
305
		var url = $('#unlikeproductform').attr('action')+'?'+$('#unlikeproductform').serialize()
282
		var url = $('#unlikeproductform').attr('action')+'?'+$('#unlikeproductform').serialize()
306
		// console.log(url);
-
 
307
		$.ajax({
283
		$.ajax({
308
			url: url,
284
			url: url,
309
			// The name of the callback parameter, as specified by the YQL service
285
			// The name of the callback parameter, as specified by the YQL service
310
			jsonp: "callback",
286
			jsonp: "callback",
311
			// Tell jQuery we're expecting JSONP
287
			// Tell jQuery we're expecting JSONP
Line 314... Line 290...
314
			data: {
290
			data: {
315
				format: "json"
291
				format: "json"
316
			},
292
			},
317
			// Work with the response
293
			// Work with the response
318
			success: function( response ) {
294
			success: function( response ) {
319
				// console.log(response);						
-
 
320
			}
295
			}
321
		});
296
		});
322
		$('#myModal').modal('hide');
297
		$('#myModal').modal('hide');
323
		ga('send', 'event', 'brand', 'hide', $('#myModal').find('#productToHide',0).val());
298
		ga('send', 'event', 'brand', 'hide', $('#myModal').find('#productToHide',0).val());
324
	})
299
	})
Line 326... Line 301...
326
		var that = $(this);
301
		var that = $(this);
327
		if($(that).hasClass('active')){
302
		if($(that).hasClass('active')){
328
			//User has already liked it,so remove like
303
			//User has already liked it,so remove like
329
			var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/dislike";	
304
			var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/dislike";	
330
		}else{
305
		}else{
331
			// console.log('show modal');
-
 
332
			$('#myModal').find('#productToHide',0).val($(this).data('id'));
306
			$('#myModal').find('#productToHide',0).val($(this).data('id'));
333
			//$('#myModal').modal();
-
 
334
			var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/dislike";
307
			var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/dislike";
335
		}
308
		}
336
		$.ajax({
309
		$.ajax({
337
			url: url,
310
			url: url,
338
			// The name of the callback parameter, as specified by the YQL service
311
			// The name of the callback parameter, as specified by the YQL service
Line 459... Line 432...
459
	});
432
	});
460
	$(document).on('click','.banner',function(){		
433
	$(document).on('click','.banner',function(){		
461
		ga('send', 'event', 'banners', 'click', $(this).data('name'));
434
		ga('send', 'event', 'banners', 'click', $(this).data('name'));
462
	});
435
	});
463
});
436
});
464
function setCookie(cname, cvalue, days) {
437
function setCookie(cname, cvalue, days, forceCookie) {
-
 
438
	if(typeof(Storage) !== "undefined" && !forceCookie) {
-
 
439
		localStorage.setItem(cname, cvalue);
-
 
440
	} else{
465
    var d = new Date();
441
		var d = new Date();
466
    d.setTime(d.getTime() + (days*24*60*60*1000));
442
	    d.setTime(d.getTime() + (days*24*60*60*1000));
467
    var expires = "expires="+d.toUTCString();
443
	    var expires = "expires="+d.toUTCString();
468
    document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
444
	    document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
-
 
445
	}    
469
}
446
}
470
 
447
 
471
function getCookie(cname) {
448
function getCookie(cname,forceCookie) {
-
 
449
	if(typeof(Storage) !== "undefined" && !forceCookie) {
-
 
450
	    return localStorage.getItem(cname);
-
 
451
	} else {	   
472
    var name = cname + "=";
452
	    var name = cname + "=";
473
    var ca = document.cookie.split(';');
453
	    var ca = document.cookie.split(';');
474
    for(var i=0; i<ca.length; i++) {
454
	    for(var i=0; i<ca.length; i++) {
475
        var c = ca[i];
455
	        var c = ca[i];
476
        while (c.charAt(0)==' ') c = c.substring(1);
456
	        while (c.charAt(0)==' ') c = c.substring(1);
477
        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
457
	        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
478
    }
458
	    }
479
    return "";
459
	    return "";
-
 
460
	}
480
}
461
}
-
 
462
 
481
function showpopup(id,count,interval){
463
function showpopup(id,count,interval){
482
	var cname = 'notif-count-'+me+'-'+id;
464
	var cname = 'notif-count-'+me+'-'+id;
483
	var cookieval = getCookie(cname);
465
	var cookieval = getCookie(cname);
484
	var cname = 'notif-lastshown-'+me+'-'+id;
466
	var cname = 'notif-lastshown-'+me+'-'+id;
485
	var lastshown = getCookie(cname);
467
	var lastshown = getCookie(cname);
486
	if(cookieval==''){		
468
	if(!cookieval || cookieval == 'NaN' || cookieval==''){		
487
		incrementPopupCount(id,0,'notif-count-');
469
		incrementPopupCount(id,0,'notif-count-');
488
		setLastShown(id,'notif-lastshown-');
470
		setLastShown(id,'notif-lastshown-');
489
		return true;
471
		return true;
490
	} else{
472
	} else{
491
		var d = new Date();
473
		var d = new Date();
492
		var t = d.getTime();
474
		var t = d.getTime();
493
		console.log(t-lastshown);
-
 
494
		console.log(interval*60*1000);
-
 
495
		if(t-lastshown>interval*60*1000){
475
		if(t-lastshown>interval*60*1000){
496
			if(cookieval>=count){
476
			if(cookieval>=count){
497
				return false;
477
				return false;
498
			}else{
478
			}else{
499
				setLastShown(id,'notif-lastshown-');
479
				setLastShown(id,'notif-lastshown-');
Line 556... Line 536...
556
$(document).on('click','.applyfilter',function(){	
536
$(document).on('click','.applyfilter',function(){	
557
	var brands = [];
537
	var brands = [];
558
	var brandnames = [];
538
	var brandnames = [];
559
	$('.filterbrand').each(function(){
539
	$('.filterbrand').each(function(){
560
		if($(this).prop('checked')){
540
		if($(this).prop('checked')){
561
			// console.log($(this).parent().siblings('.brandname').html());
-
 
562
			brands.push($(this).val());
541
			brands.push($(this).val());
563
			brandnames.push($(this).parent().siblings('.brandname').html());
542
			brandnames.push($(this).parent().siblings('.brandname').html());
564
		}		
543
		}		
565
	});
544
	});
566
	if(brands.length==0){
545
	if(brands.length==0){
567
		$('#message').html('Please choose a few brands first').removeClass('hidden');
546
		$('#message').html('Please choose a few brands first').removeClass('hidden');
568
		setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
547
		setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
569
		return false;
548
		return false;
570
	}else{
549
	}else{
571
		setCookie('brandschosen', brands, 1);
550
		setCookie('brandschosen', brands, 1, true);
572
		var url = $('#brandselecter').prop('action');
551
		var url = $('#brandselecter').prop('action');
573
		ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
552
		ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
574
		var postdata = {'user_id':me,'type':'brand','filters':brandnames.join('|')};
553
		var postdata = {'user_id':me,'type':'brand','filters':brandnames.join('|')};
575
		$.post( "/user_filters/add", postdata, function( data ) {
554
		$.post( "/user_filters/add", postdata, function( data ) {
576
		  document.location = url+'&brands='+brands.join('^');
555
		  document.location = url+'&brands='+brands.join('^');
Line 589... Line 568...
589
	  return $(this).data("brand").toLowerCase().indexOf($(that).val().toLowerCase()) != -1;
568
	  return $(this).data("brand").toLowerCase().indexOf($(that).val().toLowerCase()) != -1;
590
	}).removeClass('hidden','slow');
569
	}).removeClass('hidden','slow');
591
});
570
});
592
$(document).on('click','.filterbrand',function(){
571
$(document).on('click','.filterbrand',function(){
593
	var clicked = $(this).parent().parent();
572
	var clicked = $(this).parent().parent();
594
	console.log(clicked.prop('class'));
-
 
595
	// clicked.find('.filterbrand',0).prop('checked',true);
-
 
596
	// all the LIs above the clicked one
573
	// all the LIs above the clicked one
597
	var previousAll = clicked.prevAll();
574
	var previousAll = clicked.prevAll();
598
 
575
 
599
	// only proceed if it's not already on top (no previous siblings)
576
	// only proceed if it's not already on top (no previous siblings)
600
	if(previousAll.length > 0) {
577
	if(previousAll.length > 0) {
Line 621... Line 598...
621
	  previousAll.css({'position': 'static', 'top': 0}); 
598
	  previousAll.css({'position': 'static', 'top': 0}); 
622
	}});
599
	}});
623
	}
600
	}
624
})
601
})
625
$(document).on('click','.clearfilters',function(){
602
$(document).on('click','.clearfilters',function(){
626
	setCookie('brandschosen', '', -1);
603
	setCookie('brandschosen', '', -1, true);
627
	ga('send', 'event', 'filter', 'brand', 'clearfilters');
604
	ga('send', 'event', 'filter', 'brand', 'clearfilters');
628
	var postdata = {'user_id':me,'type':'clear'};
605
	var postdata = {'user_id':me,'type':'clear'};
629
	$.post("/user_filters/add", postdata, function( data ) {
606
	$.post("/user_filters/add", postdata, function( data ) {
630
	  document.location.reload();
607
	  document.location.reload();
631
	});	
608
	});	
632
});
609
});
633
function selectChosenBrands(){
610
function selectChosenBrands(){
634
	var brandschosen = getCookie('brandschosen');
611
	var brandschosen = getCookie('brandschosen',true);
635
	if(brandschosen && brandschosen.length>0){
612
	if(brandschosen && brandschosen.length>0){
636
		var brands = brandschosen.split(',');
613
		var brands = brandschosen.split(',');
637
		for(var i in brands){
614
		for(var i in brands){
638
			$('.brand').filter(function() { 
615
			$('.brand').filter(function() { 
639
			  	return $(this).data("brandid") == brands[i];
616
			  	return $(this).data("brandid") == brands[i];
Line 641... Line 618...
641
		}
618
		}
642
	}
619
	}
643
}
620
}
644
$(function () {
621
$(function () {
645
	var poid = 'popovertrigger';
622
	var poid = 'popovertrigger';
646
	/*
-
 
647
  var popovershown = getCookie('popovershown');
-
 
648
  if(!popovershown){
-
 
649
  	popovershown = 0;
-
 
650
  }
-
 
651
  if(popovershown < 2){
-
 
652
  	$('[data-toggle="popover"]').popover({'html':true});
-
 
653
  	$('[data-toggle="popover"]').trigger('click');
-
 
654
  }  
-
 
655
  */
-
 
656
  $('#dropdownMenu1').on('click',function(){
-
 
657
  	$('#popovertrigger').popover('hide');
-
 
658
  	incrementPopupCount(poid,0,'popover-count-');
-
 
659
	setLastShown(poid,'popover-lastshown-');
-
 
660
  })
-
 
661
   
-
 
662
  	var cname = 'popover-count-'+me+'-'+poid;
623
	var cname = 'popover-count-'+me+'-'+poid;
663
	var cookieval = getCookie(cname);
624
	var cookieval = getCookie(cname);
-
 
625
	$('#dropdownMenu1').on('click',function(){
-
 
626
		var cname = 'popover-count-'+me+'-'+poid;
-
 
627
		var cookieval = getCookie(cname);
-
 
628
		$('#popovertrigger').popover('hide');
-
 
629
		if(!cookieval || cookieval == 'NaN' || cookieval == ''){
-
 
630
			incrementPopupCount(poid,0,'popover-count-');
-
 
631
		} else {
-
 
632
			incrementPopupCount(poid, cookieval, 'popover-count-');
-
 
633
		}
-
 
634
		setLastShown(poid,'popover-lastshown-');
-
 
635
	})
-
 
636
     	
664
	var cname = 'popover-lastshown-'+me+'-'+poid;
637
	var cname = 'popover-lastshown-'+me+'-'+poid;
665
	var lastshown = getCookie(cname);
638
	var lastshown = getCookie(cname);
666
	if(cookieval==''){				
639
	if(cookieval=='' || cookieval == 'NaN' || !cookieval){				
667
		showpopover(poid);
640
		showpopover(poid);
668
	} else{
641
	} else{
669
		var d = new Date();
642
		var d = new Date();
670
		var t = d.getTime();
643
		var t = d.getTime();
671
		console.log('time elapsed '+(t-lastshown));
-
 
672
		if(t-lastshown>18*3600*1000){
644
		if(t-lastshown>18*3600*1000){
673
			if(cookieval>2){
645
			if(cookieval>=2){
674
				return false;
646
				return false;
675
			}else{
647
			}else{
676
				showpopover(poid);
648
				showpopover(poid);				
677
			  	incrementPopupCount(poid,cookieval,'popover-count-');
-
 
678
				setLastShown(poid,'popover-lastshown-');
-
 
679
			}
649
			}
680
		}
650
		}
681
	}
651
	}
682
});
652
});
683
function showpopover(id){
653
function showpopover(id){
Line 686... Line 656...
686
}
656
}
687
$(document).on('click','.nodeals',function(){
657
$(document).on('click','.nodeals',function(){
688
	document.location = $(this).data('href');
658
	document.location = $(this).data('href');
689
})
659
})
690
var Base64 = {
660
var Base64 = {
691
 
-
 
692
 
-
 
693
    _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
661
    _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
694
 
-
 
695
 
-
 
696
    encode: function(input) {
662
    encode: function(input) {
697
        var output = "";
663
        var output = "";
698
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
664
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
699
        var i = 0;
665
        var i = 0;
700
 
-
 
701
        input = Base64._utf8_encode(input);
666
        input = Base64._utf8_encode(input);
702
 
-
 
703
        while (i < input.length) {
667
        while (i < input.length) {
704
 
-
 
705
            chr1 = input.charCodeAt(i++);
668
            chr1 = input.charCodeAt(i++);
706
            chr2 = input.charCodeAt(i++);
669
            chr2 = input.charCodeAt(i++);
707
            chr3 = input.charCodeAt(i++);
670
            chr3 = input.charCodeAt(i++);
708
 
671
 
709
            enc1 = chr1 >> 2;
672
            enc1 = chr1 >> 2;
710
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
673
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
711
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
674
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
712
            enc4 = chr3 & 63;
675
            enc4 = chr3 & 63;
713
 
-
 
714
            if (isNaN(chr2)) {
676
            if (isNaN(chr2)) {
715
                enc3 = enc4 = 64;
677
                enc3 = enc4 = 64;
716
            } else if (isNaN(chr3)) {
678
            } else if (isNaN(chr3)) {
717
                enc4 = 64;
679
                enc4 = 64;
718
            }
680
            }
719
 
-
 
720
            output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
681
            output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
721
 
-
 
722
        }
682
        }
723
 
-
 
724
        return output;
683
        return output;
725
    },
684
    },
726
 
685
 
727
 
686
 
728
    decode: function(input) {
687
    decode: function(input) {
729
        var output = "";
688
        var output = "";
730
        var chr1, chr2, chr3;
689
        var chr1, chr2, chr3;
731
        var enc1, enc2, enc3, enc4;
690
        var enc1, enc2, enc3, enc4;
732
        var i = 0;
691
        var i = 0;
733
 
-
 
734
        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
692
        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
735
 
-
 
736
        while (i < input.length) {
693
        while (i < input.length) {
737
 
-
 
738
            enc1 = this._keyStr.indexOf(input.charAt(i++));
694
            enc1 = this._keyStr.indexOf(input.charAt(i++));
739
            enc2 = this._keyStr.indexOf(input.charAt(i++));
695
            enc2 = this._keyStr.indexOf(input.charAt(i++));
740
            enc3 = this._keyStr.indexOf(input.charAt(i++));
696
            enc3 = this._keyStr.indexOf(input.charAt(i++));
741
            enc4 = this._keyStr.indexOf(input.charAt(i++));
697
            enc4 = this._keyStr.indexOf(input.charAt(i++));
742
 
-
 
743
            chr1 = (enc1 << 2) | (enc2 >> 4);
698
            chr1 = (enc1 << 2) | (enc2 >> 4);
744
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
699
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
745
            chr3 = ((enc3 & 3) << 6) | enc4;
700
            chr3 = ((enc3 & 3) << 6) | enc4;
746
 
-
 
747
            output = output + String.fromCharCode(chr1);
701
            output = output + String.fromCharCode(chr1);
748
 
-
 
749
            if (enc3 != 64) {
702
            if (enc3 != 64) {
750
                output = output + String.fromCharCode(chr2);
703
                output = output + String.fromCharCode(chr2);
751
            }
704
            }
752
            if (enc4 != 64) {
705
            if (enc4 != 64) {
753
                output = output + String.fromCharCode(chr3);
706
                output = output + String.fromCharCode(chr3);
754
            }
707
            }
755
 
-
 
756
        }
708
        }
757
 
-
 
758
        output = Base64._utf8_decode(output);
709
        output = Base64._utf8_decode(output);
759
 
-
 
760
        return output;
710
        return output;
761
 
-
 
762
    },
711
    },
763
 
712
 
764
    _utf8_encode: function(string) {
713
    _utf8_encode: function(string) {
765
        string = string.replace(/\r\n/g, "\n");
714
        string = string.replace(/\r\n/g, "\n");
766
        var utftext = "";
715
        var utftext = "";
767
 
-
 
768
        for (var n = 0; n < string.length; n++) {
716
        for (var n = 0; n < string.length; n++) {
769
 
-
 
770
            var c = string.charCodeAt(n);
717
            var c = string.charCodeAt(n);
771
 
-
 
772
            if (c < 128) {
718
            if (c < 128) {
773
                utftext += String.fromCharCode(c);
719
                utftext += String.fromCharCode(c);
774
            }
720
            }
775
            else if ((c > 127) && (c < 2048)) {
721
            else if ((c > 127) && (c < 2048)) {
776
                utftext += String.fromCharCode((c >> 6) | 192);
722
                utftext += String.fromCharCode((c >> 6) | 192);
Line 779... Line 725...
779
            else {
725
            else {
780
                utftext += String.fromCharCode((c >> 12) | 224);
726
                utftext += String.fromCharCode((c >> 12) | 224);
781
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
727
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
782
                utftext += String.fromCharCode((c & 63) | 128);
728
                utftext += String.fromCharCode((c & 63) | 128);
783
            }
729
            }
784
 
-
 
785
        }
730
        }
786
 
-
 
787
        return utftext;
731
        return utftext;
788
    },
732
    },
789
 
733
 
790
    _utf8_decode: function(utftext) {
734
    _utf8_decode: function(utftext) {
791
        var string = "";
735
        var string = "";
792
        var i = 0;
736
        var i = 0;
793
        var c = c1 = c2 = 0;
737
        var c = c1 = c2 = 0;
794
 
-
 
795
        while (i < utftext.length) {
738
        while (i < utftext.length) {
796
 
-
 
797
            c = utftext.charCodeAt(i);
739
            c = utftext.charCodeAt(i);
798
 
-
 
799
            if (c < 128) {
740
            if (c < 128) {
800
                string += String.fromCharCode(c);
741
                string += String.fromCharCode(c);
801
                i++;
742
                i++;
802
            }
743
            }
803
            else if ((c > 191) && (c < 224)) {
744
            else if ((c > 191) && (c < 224)) {
Line 809... Line 750...
809
                c2 = utftext.charCodeAt(i + 1);
750
                c2 = utftext.charCodeAt(i + 1);
810
                c3 = utftext.charCodeAt(i + 2);
751
                c3 = utftext.charCodeAt(i + 2);
811
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
752
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
812
                i += 3;
753
                i += 3;
813
            }
754
            }
814
 
-
 
815
        }
755
        }
816
 
-
 
817
        return string;
756
        return string;
818
    }
757
    }
819
 
-
 
820
}
758
}
821
759