Subversion Repositories SmartDukaan

Rev

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

Rev 15232 Rev 15243
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 296... Line 277...
296
		ga('send', 'event', 'product', 'like', $(this).data('id'));
277
		ga('send', 'event', 'product', 'like', $(this).data('id'));
297
	});
278
	});
298
	$('#myModal').on('click','#unlikebtn',function(e){
279
	$('#myModal').on('click','#unlikebtn',function(e){
299
		e.preventDefault();
280
		e.preventDefault();
300
		var url = $('#unlikeproductform').attr('action')+'?'+$('#unlikeproductform').serialize()
281
		var url = $('#unlikeproductform').attr('action')+'?'+$('#unlikeproductform').serialize()
301
		// console.log(url);
-
 
302
		$.ajax({
282
		$.ajax({
303
			url: url,
283
			url: url,
304
			// The name of the callback parameter, as specified by the YQL service
284
			// The name of the callback parameter, as specified by the YQL service
305
			jsonp: "callback",
285
			jsonp: "callback",
306
			// Tell jQuery we're expecting JSONP
286
			// Tell jQuery we're expecting JSONP
Line 309... Line 289...
309
			data: {
289
			data: {
310
				format: "json"
290
				format: "json"
311
			},
291
			},
312
			// Work with the response
292
			// Work with the response
313
			success: function( response ) {
293
			success: function( response ) {
314
				// console.log(response);						
-
 
315
			}
294
			}
316
		});
295
		});
317
		$('#myModal').modal('hide');
296
		$('#myModal').modal('hide');
318
		ga('send', 'event', 'brand', 'hide', $('#myModal').find('#productToHide',0).val());
297
		ga('send', 'event', 'brand', 'hide', $('#myModal').find('#productToHide',0).val());
319
	})
298
	})
Line 321... Line 300...
321
		var that = $(this);
300
		var that = $(this);
322
		if($(that).hasClass('active')){
301
		if($(that).hasClass('active')){
323
			//User has already liked it,so remove like
302
			//User has already liked it,so remove like
324
			var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/dislike";	
303
			var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/dislike";	
325
		}else{
304
		}else{
326
			// console.log('show modal');
-
 
327
			$('#myModal').find('#productToHide',0).val($(this).data('id'));
305
			$('#myModal').find('#productToHide',0).val($(this).data('id'));
328
			//$('#myModal').modal();
-
 
329
			var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/dislike";
306
			var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/dislike";
330
		}
307
		}
331
		$.ajax({
308
		$.ajax({
332
			url: url,
309
			url: url,
333
			// The name of the callback parameter, as specified by the YQL service
310
			// The name of the callback parameter, as specified by the YQL service
Line 454... Line 431...
454
	});
431
	});
455
	$(document).on('click','.banner',function(){		
432
	$(document).on('click','.banner',function(){		
456
		ga('send', 'event', 'banners', 'click', $(this).data('name'));
433
		ga('send', 'event', 'banners', 'click', $(this).data('name'));
457
	});
434
	});
458
});
435
});
459
function setCookie(cname, cvalue, days) {
436
function setCookie(cname, cvalue, days, forceCookie) {
-
 
437
	if(typeof(Storage) !== "undefined" && !forceCookie) {
-
 
438
		localStorage.setItem(cname, cvalue);
-
 
439
	} else{
460
    var d = new Date();
440
		var d = new Date();
461
    d.setTime(d.getTime() + (days*24*60*60*1000));
441
	    d.setTime(d.getTime() + (days*24*60*60*1000));
462
    var expires = "expires="+d.toUTCString();
442
	    var expires = "expires="+d.toUTCString();
463
    document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
443
	    document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
-
 
444
	}    
464
}
445
}
465
 
446
 
466
function getCookie(cname) {
447
function getCookie(cname,forceCookie) {
-
 
448
	if(typeof(Storage) !== "undefined" && !forceCookie) {
-
 
449
	    return localStorage.getItem(cname);
-
 
450
	} else {	   
467
    var name = cname + "=";
451
	    var name = cname + "=";
468
    var ca = document.cookie.split(';');
452
	    var ca = document.cookie.split(';');
469
    for(var i=0; i<ca.length; i++) {
453
	    for(var i=0; i<ca.length; i++) {
470
        var c = ca[i];
454
	        var c = ca[i];
471
        while (c.charAt(0)==' ') c = c.substring(1);
455
	        while (c.charAt(0)==' ') c = c.substring(1);
472
        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
456
	        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
473
    }
457
	    }
474
    return "";
458
	    return "";
-
 
459
	}
475
}
460
}
-
 
461
 
476
function showpopup(id,count,interval){
462
function showpopup(id,count,interval){
477
	var cname = 'notif-count-'+me+'-'+id;
463
	var cname = 'notif-count-'+me+'-'+id;
478
	var cookieval = getCookie(cname);
464
	var cookieval = getCookie(cname);
479
	var cname = 'notif-lastshown-'+me+'-'+id;
465
	var cname = 'notif-lastshown-'+me+'-'+id;
480
	var lastshown = getCookie(cname);
466
	var lastshown = getCookie(cname);
481
	if(cookieval==''){		
467
	if(!cookieval || cookieval == 'NaN' || cookieval==''){		
482
		incrementPopupCount(id,0,'notif-count-');
468
		incrementPopupCount(id,0,'notif-count-');
483
		setLastShown(id,'notif-lastshown-');
469
		setLastShown(id,'notif-lastshown-');
484
		return true;
470
		return true;
485
	} else{
471
	} else{
486
		var d = new Date();
472
		var d = new Date();
487
		var t = d.getTime();
473
		var t = d.getTime();
488
		console.log(t-lastshown);
-
 
489
		console.log(interval*60*1000);
-
 
490
		if(t-lastshown>interval*60*1000){
474
		if(t-lastshown>interval*60*1000){
491
			if(cookieval>=count){
475
			if(cookieval>=count){
492
				return false;
476
				return false;
493
			}else{
477
			}else{
494
				setLastShown(id,'notif-lastshown-');
478
				setLastShown(id,'notif-lastshown-');
Line 551... Line 535...
551
$(document).on('click','.applyfilter',function(){	
535
$(document).on('click','.applyfilter',function(){	
552
	var brands = [];
536
	var brands = [];
553
	var brandnames = [];
537
	var brandnames = [];
554
	$('.filterbrand').each(function(){
538
	$('.filterbrand').each(function(){
555
		if($(this).prop('checked')){
539
		if($(this).prop('checked')){
556
			// console.log($(this).parent().siblings('.brandname').html());
-
 
557
			brands.push($(this).val());
540
			brands.push($(this).val());
558
			brandnames.push($(this).parent().siblings('.brandname').html());
541
			brandnames.push($(this).parent().siblings('.brandname').html());
559
		}		
542
		}		
560
	});
543
	});
561
	if(brands.length==0){
544
	if(brands.length==0){
562
		$('#message').html('Please choose a few brands first').removeClass('hidden');
545
		$('#message').html('Please choose a few brands first').removeClass('hidden');
563
		setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
546
		setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
564
		return false;
547
		return false;
565
	}else{
548
	}else{
566
		setCookie('brandschosen', brands, 1);
549
		setCookie('brandschosen', brands, 1, true);
567
		var url = $('#brandselecter').prop('action');
550
		var url = $('#brandselecter').prop('action');
568
		ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
551
		ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
569
		var postdata = {'user_id':me,'type':'brand','filters':brandnames.join('|')};
552
		var postdata = {'user_id':me,'type':'brand','filters':brandnames.join('|')};
570
		$.post( "/user_filters/add", postdata, function( data ) {
553
		$.post( "/user_filters/add", postdata, function( data ) {
571
		  document.location = url+'&brands='+brands.join('^');
554
		  document.location = url+'&brands='+brands.join('^');
Line 584... Line 567...
584
	  return $(this).data("brand").toLowerCase().indexOf($(that).val().toLowerCase()) != -1;
567
	  return $(this).data("brand").toLowerCase().indexOf($(that).val().toLowerCase()) != -1;
585
	}).removeClass('hidden','slow');
568
	}).removeClass('hidden','slow');
586
});
569
});
587
$(document).on('click','.filterbrand',function(){
570
$(document).on('click','.filterbrand',function(){
588
	var clicked = $(this).parent().parent();
571
	var clicked = $(this).parent().parent();
589
	console.log(clicked.prop('class'));
-
 
590
	// clicked.find('.filterbrand',0).prop('checked',true);
-
 
591
	// all the LIs above the clicked one
572
	// all the LIs above the clicked one
592
	var previousAll = clicked.prevAll();
573
	var previousAll = clicked.prevAll();
593
 
574
 
594
	// only proceed if it's not already on top (no previous siblings)
575
	// only proceed if it's not already on top (no previous siblings)
595
	if(previousAll.length > 0) {
576
	if(previousAll.length > 0) {
Line 616... Line 597...
616
	  previousAll.css({'position': 'static', 'top': 0}); 
597
	  previousAll.css({'position': 'static', 'top': 0}); 
617
	}});
598
	}});
618
	}
599
	}
619
})
600
})
620
$(document).on('click','.clearfilters',function(){
601
$(document).on('click','.clearfilters',function(){
621
	setCookie('brandschosen', '', -1);
602
	setCookie('brandschosen', '', -1, true);
622
	ga('send', 'event', 'filter', 'brand', 'clearfilters');
603
	ga('send', 'event', 'filter', 'brand', 'clearfilters');
623
	var postdata = {'user_id':me,'type':'clear'};
604
	var postdata = {'user_id':me,'type':'clear'};
624
	$.post("/user_filters/add", postdata, function( data ) {
605
	$.post("/user_filters/add", postdata, function( data ) {
625
	  document.location.reload();
606
	  document.location.reload();
626
	});	
607
	});	
627
});
608
});
628
function selectChosenBrands(){
609
function selectChosenBrands(){
629
	var brandschosen = getCookie('brandschosen');
610
	var brandschosen = getCookie('brandschosen',true);
630
	if(brandschosen && brandschosen.length>0){
611
	if(brandschosen && brandschosen.length>0){
631
		var brands = brandschosen.split(',');
612
		var brands = brandschosen.split(',');
632
		for(var i in brands){
613
		for(var i in brands){
633
			$('.brand').filter(function() { 
614
			$('.brand').filter(function() { 
634
			  	return $(this).data("brandid") == brands[i];
615
			  	return $(this).data("brandid") == brands[i];
Line 636... Line 617...
636
		}
617
		}
637
	}
618
	}
638
}
619
}
639
$(function () {
620
$(function () {
640
	var poid = 'popovertrigger';
621
	var poid = 'popovertrigger';
641
	/*
-
 
642
  var popovershown = getCookie('popovershown');
-
 
643
  if(!popovershown){
-
 
644
  	popovershown = 0;
-
 
645
  }
-
 
646
  if(popovershown < 2){
-
 
647
  	$('[data-toggle="popover"]').popover({'html':true});
-
 
648
  	$('[data-toggle="popover"]').trigger('click');
-
 
649
  }  
-
 
650
  */
-
 
651
  $('#dropdownMenu1').on('click',function(){
-
 
652
  	$('#popovertrigger').popover('hide');
-
 
653
  	incrementPopupCount(poid,0,'popover-count-');
-
 
654
	setLastShown(poid,'popover-lastshown-');
-
 
655
  })
-
 
656
   
-
 
657
  	var cname = 'popover-count-'+me+'-'+poid;
622
	var cname = 'popover-count-'+me+'-'+poid;
658
	var cookieval = getCookie(cname);
623
	var cookieval = getCookie(cname);
-
 
624
	$('#dropdownMenu1').on('click',function(){
-
 
625
		var cname = 'popover-count-'+me+'-'+poid;
-
 
626
		var cookieval = getCookie(cname);
-
 
627
		$('#popovertrigger').popover('hide');
-
 
628
		if(!cookieval || cookieval == 'NaN' || cookieval == ''){
-
 
629
			incrementPopupCount(poid,0,'popover-count-');
-
 
630
		} else {
-
 
631
			incrementPopupCount(poid, cookieval, 'popover-count-');
-
 
632
		}
-
 
633
		setLastShown(poid,'popover-lastshown-');
-
 
634
	})
-
 
635
     	
659
	var cname = 'popover-lastshown-'+me+'-'+poid;
636
	var cname = 'popover-lastshown-'+me+'-'+poid;
660
	var lastshown = getCookie(cname);
637
	var lastshown = getCookie(cname);
661
	if(cookieval==''){				
638
	if(cookieval=='' || cookieval == 'NaN' || !cookieval){				
662
		showpopover(poid);
639
		showpopover(poid);
663
	} else{
640
	} else{
664
		var d = new Date();
641
		var d = new Date();
665
		var t = d.getTime();
642
		var t = d.getTime();
666
		console.log('time elapsed '+(t-lastshown));
-
 
667
		if(t-lastshown>18*3600*1000){
643
		if(t-lastshown>18*3600*1000){
668
			if(cookieval>2){
644
			if(cookieval>=2){
669
				return false;
645
				return false;
670
			}else{
646
			}else{
671
				showpopover(poid);
647
				showpopover(poid);				
672
			  	incrementPopupCount(poid,cookieval,'popover-count-');
-
 
673
				setLastShown(poid,'popover-lastshown-');
-
 
674
			}
648
			}
675
		}
649
		}
676
	}
650
	}
677
});
651
});
678
function showpopover(id){
652
function showpopover(id){
Line 681... Line 655...
681
}
655
}
682
$(document).on('click','.nodeals',function(){
656
$(document).on('click','.nodeals',function(){
683
	document.location = $(this).data('href');
657
	document.location = $(this).data('href');
684
})
658
})
685
var Base64 = {
659
var Base64 = {
686
 
-
 
687
 
-
 
688
    _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
660
    _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
689
 
-
 
690
 
-
 
691
    encode: function(input) {
661
    encode: function(input) {
692
        var output = "";
662
        var output = "";
693
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
663
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
694
        var i = 0;
664
        var i = 0;
695
 
-
 
696
        input = Base64._utf8_encode(input);
665
        input = Base64._utf8_encode(input);
697
 
-
 
698
        while (i < input.length) {
666
        while (i < input.length) {
699
 
-
 
700
            chr1 = input.charCodeAt(i++);
667
            chr1 = input.charCodeAt(i++);
701
            chr2 = input.charCodeAt(i++);
668
            chr2 = input.charCodeAt(i++);
702
            chr3 = input.charCodeAt(i++);
669
            chr3 = input.charCodeAt(i++);
703
 
670
 
704
            enc1 = chr1 >> 2;
671
            enc1 = chr1 >> 2;
705
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
672
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
706
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
673
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
707
            enc4 = chr3 & 63;
674
            enc4 = chr3 & 63;
708
 
-
 
709
            if (isNaN(chr2)) {
675
            if (isNaN(chr2)) {
710
                enc3 = enc4 = 64;
676
                enc3 = enc4 = 64;
711
            } else if (isNaN(chr3)) {
677
            } else if (isNaN(chr3)) {
712
                enc4 = 64;
678
                enc4 = 64;
713
            }
679
            }
714
 
-
 
715
            output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
680
            output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
716
 
-
 
717
        }
681
        }
718
 
-
 
719
        return output;
682
        return output;
720
    },
683
    },
721
 
684
 
722
 
685
 
723
    decode: function(input) {
686
    decode: function(input) {
724
        var output = "";
687
        var output = "";
725
        var chr1, chr2, chr3;
688
        var chr1, chr2, chr3;
726
        var enc1, enc2, enc3, enc4;
689
        var enc1, enc2, enc3, enc4;
727
        var i = 0;
690
        var i = 0;
728
 
-
 
729
        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
691
        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
730
 
-
 
731
        while (i < input.length) {
692
        while (i < input.length) {
732
 
-
 
733
            enc1 = this._keyStr.indexOf(input.charAt(i++));
693
            enc1 = this._keyStr.indexOf(input.charAt(i++));
734
            enc2 = this._keyStr.indexOf(input.charAt(i++));
694
            enc2 = this._keyStr.indexOf(input.charAt(i++));
735
            enc3 = this._keyStr.indexOf(input.charAt(i++));
695
            enc3 = this._keyStr.indexOf(input.charAt(i++));
736
            enc4 = this._keyStr.indexOf(input.charAt(i++));
696
            enc4 = this._keyStr.indexOf(input.charAt(i++));
737
 
-
 
738
            chr1 = (enc1 << 2) | (enc2 >> 4);
697
            chr1 = (enc1 << 2) | (enc2 >> 4);
739
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
698
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
740
            chr3 = ((enc3 & 3) << 6) | enc4;
699
            chr3 = ((enc3 & 3) << 6) | enc4;
741
 
-
 
742
            output = output + String.fromCharCode(chr1);
700
            output = output + String.fromCharCode(chr1);
743
 
-
 
744
            if (enc3 != 64) {
701
            if (enc3 != 64) {
745
                output = output + String.fromCharCode(chr2);
702
                output = output + String.fromCharCode(chr2);
746
            }
703
            }
747
            if (enc4 != 64) {
704
            if (enc4 != 64) {
748
                output = output + String.fromCharCode(chr3);
705
                output = output + String.fromCharCode(chr3);
749
            }
706
            }
750
 
-
 
751
        }
707
        }
752
 
-
 
753
        output = Base64._utf8_decode(output);
708
        output = Base64._utf8_decode(output);
754
 
-
 
755
        return output;
709
        return output;
756
 
-
 
757
    },
710
    },
758
 
711
 
759
    _utf8_encode: function(string) {
712
    _utf8_encode: function(string) {
760
        string = string.replace(/\r\n/g, "\n");
713
        string = string.replace(/\r\n/g, "\n");
761
        var utftext = "";
714
        var utftext = "";
762
 
-
 
763
        for (var n = 0; n < string.length; n++) {
715
        for (var n = 0; n < string.length; n++) {
764
 
-
 
765
            var c = string.charCodeAt(n);
716
            var c = string.charCodeAt(n);
766
 
-
 
767
            if (c < 128) {
717
            if (c < 128) {
768
                utftext += String.fromCharCode(c);
718
                utftext += String.fromCharCode(c);
769
            }
719
            }
770
            else if ((c > 127) && (c < 2048)) {
720
            else if ((c > 127) && (c < 2048)) {
771
                utftext += String.fromCharCode((c >> 6) | 192);
721
                utftext += String.fromCharCode((c >> 6) | 192);
Line 774... Line 724...
774
            else {
724
            else {
775
                utftext += String.fromCharCode((c >> 12) | 224);
725
                utftext += String.fromCharCode((c >> 12) | 224);
776
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
726
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
777
                utftext += String.fromCharCode((c & 63) | 128);
727
                utftext += String.fromCharCode((c & 63) | 128);
778
            }
728
            }
779
 
-
 
780
        }
729
        }
781
 
-
 
782
        return utftext;
730
        return utftext;
783
    },
731
    },
784
 
732
 
785
    _utf8_decode: function(utftext) {
733
    _utf8_decode: function(utftext) {
786
        var string = "";
734
        var string = "";
787
        var i = 0;
735
        var i = 0;
788
        var c = c1 = c2 = 0;
736
        var c = c1 = c2 = 0;
789
 
-
 
790
        while (i < utftext.length) {
737
        while (i < utftext.length) {
791
 
-
 
792
            c = utftext.charCodeAt(i);
738
            c = utftext.charCodeAt(i);
793
 
-
 
794
            if (c < 128) {
739
            if (c < 128) {
795
                string += String.fromCharCode(c);
740
                string += String.fromCharCode(c);
796
                i++;
741
                i++;
797
            }
742
            }
798
            else if ((c > 191) && (c < 224)) {
743
            else if ((c > 191) && (c < 224)) {
Line 804... Line 749...
804
                c2 = utftext.charCodeAt(i + 1);
749
                c2 = utftext.charCodeAt(i + 1);
805
                c3 = utftext.charCodeAt(i + 2);
750
                c3 = utftext.charCodeAt(i + 2);
806
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
751
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
807
                i += 3;
752
                i += 3;
808
            }
753
            }
809
 
-
 
810
        }
754
        }
811
 
-
 
812
        return string;
755
        return string;
813
    }
756
    }
814
 
-
 
815
}
757
}
816
758