Subversion Repositories SmartDukaan

Rev

Rev 15019 | Rev 15042 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
14386 anikendra 1
var livePriceCalls = [];
14432 anikendra 2
var outOfStockCount = 0;
14773 anikendra 3
function getcashbackstring(type,value) {
14797 anikendra 4
	// console.log(type+' '+value);
14773 anikendra 5
	if(value==0){
6
		return '';
7
	}
8
	if(type==2){
14789 anikendra 9
		return ' +'+value+' Cashback';
14773 anikendra 10
	}else if(type==1){
14789 anikendra 11
		return ' +'+value+'% Cashback';
14773 anikendra 12
	}else{
13
		return '';
14
	}
15
}
16
 
13984 anikendra 17
$(function(){	
18
	if($('.scroll > .card').length>0) {
14969 anikendra 19
		setTimeout(function(){ document.location.reload(); }, 1000*15*60);
13820 anikendra 20
		$('.scroll').jscroll({
21
			loadingHtml: '<center><img src="/img/ajax-loader.gif" alt="Loading" /></center>',
22
		    autoTriggerUntil: 3,
23
		    padding: 20,
24
		});
25
	}
13901 anikendra 26
	if($('.storeminprice').length>0) {
27
		var globalminprice = 9999999;
14773 anikendra 28
		var globalminsku;
29
		var globalmincashback = '';		
14345 anikendra 30
		var calls = [];
13901 anikendra 31
		$('.storeminprice').each(function(){
14345 anikendra 32
			var temp = {'sort':$(this).data('searchorder'),'val':$(this)};
33
			calls.push(temp);
34
		});
35
		calls = sortByKey(calls,'sort');		
36
		for(var i in calls){
37
			fetchLivePrice(calls[i]['val'])
14969 anikendra 38
		}				
14345 anikendra 39
	};
40
	function sortByKey(array, key) {
41
	    return array.sort(function(a, b) {
42
	        var x = a[key]; var y = b[key];
43
	        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
44
	    });
45
	};
14432 anikendra 46
	function fetchLivePrice(obj){		
14969 anikendra 47
		ga('send', 'event', 'liveprice', 'fetch', $(obj).data('bundle_id'));
14432 anikendra 48
		var that = obj;	
49
		var inStock = false;		
14386 anikendra 50
		var req = $.ajax({
14345 anikendra 51
			url: '/store_products/getliveprice/'+$(that).data('bundle_id')+'/'+$(that).data('id'),
52
			// Tell jQuery we're expecting JSONP
53
			dataType: "json",
54
			// Tell YQL what we want and that we want JSON			
55
			method: 'get',
14430 anikendra 56
			// timeout: 30000,
14345 anikendra 57
			// Work with the response
58
			success: function( response ) {
14685 anikendra 59
				// console.log(response);
14345 anikendra 60
				if(response.success){
61
					var i = 0;	
62
					var minpriceindex = 0;				
14797 anikendra 63
					if(response.products[i].in_stock == 1) {inStock = true;}
64
					if(response.products[i].in_stock == 1) {
65
						var minprice = Math.round(response.products[i]['available_price']);
66
						var minpriceurl = response.products[i]['marketPlaceUrl'];
67
						console.log(minprice);
68
					}
14345 anikendra 69
					if(response.products.length>0){
70
						//More than one products in store
71
						var variants = [];
72
						// var i = 0;
73
						for(var i in response.products){	
14685 anikendra 74
							if(response.products[i].in_stock == 1){
75
								inStock = true;
76
								// console.log(response.products[i]);
77
								if(response.products[i].available_price && response.products[i].available_price < globalminprice) {
78
									globalminprice = Math.round(response.products[i].available_price);
79
									globalminsku = response.products[i]._id;
80
									var globalminsource = response.products[i].source_id;
14773 anikendra 81
									var globalminurl = response.products[i].marketPlaceUrl;
82
									var globalmincashback = getcashbackstring(response.products[i].cash_back_type,response.products[i].cash_back);
14685 anikendra 83
								}
14797 anikendra 84
								if(typeof minprice == 'undefined' || response.products[i].available_price <= minprice) {
14685 anikendra 85
									minprice = Math.round(response.products[i].available_price);
86
									minpriceindex = i;
14700 anikendra 87
								}
14799 anikendra 88
								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});
14685 anikendra 89
							}						
13901 anikendra 90
						}
14685 anikendra 91
						if(variants.length>1){
14700 anikendra 92
							variants.splice(minpriceindex,1);
14713 anikendra 93
							var variantslink = $('<span class="variants"> '+(variants.length+1)+' Options</span>');
94
							$(that).parent().parent().find('.pull-left',0).append(variantslink);							
14799 anikendra 95
							$(variantslink).data('variants',variants).data('minprice',minprice);
13948 anikendra 96
						}
14345 anikendra 97
					}
98
					if(inStock){
14797 anikendra 99
						$(that).html(minprice).siblings('.cashbackamount').html(getcashbackstring(response.products[minpriceindex].cash_back_type,response.products[minpriceindex].cash_back)).parent().addClass('viewproduct');
14689 anikendra 100
						$('#name-'+$(that).data('id')).html(response.products[minpriceindex]['source_product_name']);
14685 anikendra 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');
14357 anikendra 103
						// console.log(globalminprice+' '+globalminsku);
14345 anikendra 104
						if(globalminprice != 9999999) {
14773 anikendra 105
							$('#bestprice').html(globalminprice).siblings('.cashbackamount').html(globalmincashback);
14685 anikendra 106
							$('#beststorelink').data('id',globalminsku).data('source',globalminsource).data('price',globalminprice).data('url',globalminurl).removeClass('hidden');
14345 anikendra 107
							$('#bestpricecontainer').removeClass('hidden');
14432 anikendra 108
						} 
14386 anikendra 109
					} else{
14969 anikendra 110
						ga('send', 'event', 'liveprice', 'outofstock', response.products[0]._id);
14432 anikendra 111
						outOfStockCount++;
14345 anikendra 112
						$(that).parent().parent().remove();	
13901 anikendra 113
					}
14345 anikendra 114
					if(!response.products[0].available_price){
14434 anikendra 115
						// outOfStockCount++;
116
						// $(that).parent().parent().remove();	
117
						var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
118
						$(that).html(btn);
14969 anikendra 119
						ga('send', 'event', 'liveprice', 'failed', response.products[0]._id);
120
					}					
14386 anikendra 121
				} else{
14434 anikendra 122
					// outOfStockCount++;
123
					// $(that).parent().parent().remove();
124
					var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
125
					$(that).html(btn);
14969 anikendra 126
					ga('send', 'event', 'liveprice', 'failure', response.products[0]._id);
13901 anikendra 127
				}
14432 anikendra 128
				checkForOutStocks(outOfStockCount);
14345 anikendra 129
			},
14386 anikendra 130
			error: function(request, status, err) {
131
				//console.log(status+' '+err+' '+request);
14430 anikendra 132
            	// if (status == "timeout") {
133
            		var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
14434 anikendra 134
					$(that).html(btn);
14969 anikendra 135
					ga('send', 'event', 'liveprice', 'error', response.products[0]._id);
14430 anikendra 136
				// } else {
137
					// $(that).parent().parent().remove();
138
				// }
14345 anikendra 139
			}
13901 anikendra 140
		});
14386 anikendra 141
		livePriceCalls.push(req);
14357 anikendra 142
	};
14432 anikendra 143
	function checkForOutStocks(count){
144
		if(count>=livePriceCalls.length){
145
			$('#bestpricecontainer').html('<h4>Out of stock</h4>').removeClass('hidden');	
14969 anikendra 146
		}		
14432 anikendra 147
	};
14687 anikendra 148
	$(document).on('click','.showless',function(){
149
		$(this).addClass('hidden').siblings('.varnts').hide();
150
		$(this).parent().find('.variants',0).removeClass('hidden').addClass('justshow');
151
	});
13901 anikendra 152
	$(document).on('click','.variants',function(){
153
		$('.storeproductinfo').empty();
14685 anikendra 154
		var variants = $(this).data('variants');
14799 anikendra 155
		var minprice = $(this).data('minprice');
14685 anikendra 156
		// console.log(variants);
14026 anikendra 157
		$('#variantscount').html(variants.length);
13901 anikendra 158
		for(var i in variants){
14392 anikendra 159
			// console.log(variants[i]);
14685 anikendra 160
			// 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>');
161
			// $('#storeproducts').parent().append(row);
14789 anikendra 162
			// 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>');
14849 anikendra 163
			if(minprice == variants[i].available_price) {
164
				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>');
165
			} else {
14797 anikendra 166
				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>');
14849 anikendra 167
			}			
14687 anikendra 168
			$(this).parent().parent().append(row);			
13901 anikendra 169
		}
14713 anikendra 170
		var showless = $('<div class="showless col-xs-9 text-right">Less <i class="glyphicon glyphicon-chevron-up"></i></span>');
14687 anikendra 171
		$(this).parent().parent().append(showless);
172
		$(this).addClass('hidden');
13901 anikendra 173
	});
13695 anikendra 174
	$('.categorytab').on('click','.categorytabcontrol.active',function(){
175
		$(this).toggleClass('active');
176
		$('#preferences-'+$(this).data('id')).addClass('hidden');
177
		$(this).parent().parent().children().find('.savecategorypreferences',0).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');
178
	});
13759 anikendra 179
	$('.categorytab').on('click','.categorytabcontrol:not(.active)',function(){
180
		$(this).parent().parent().find('.btn',0).click();
181
	});
13695 anikendra 182
	$('.categorytab').on('click','.editcategorypreferences',function(e){
183
		var that = $(this);
184
		$(that).removeClass('editcategorypreferences').addClass('savecategorypreferences').html('Done').addClass('btn-success');
185
		$('#togglepreferences-'+$(that).data('id')).toggleClass('active');
186
		$('#preferences-'+$(that).data('id')).removeClass('hidden');
187
		$('.brandselector').each(function(){
188
			if($(this).data('catid')==$(that).data('id')){
189
				$(this).addClass('active');
190
			}
191
		});
192
	});
193
	$('.categorytab').on('click','.savecategorypreferences',function(e){
194
		var that = $(this);
195
		$(that).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');
196
		$('#togglepreferences-'+$(that).data('id')).toggleClass('active');
197
		$.ajax({
198
			url: $('#categorypreference-'+$(that).data('id')).attr('action'),
199
			data: $('#categorypreference-'+$(that).data('id')).serialize(),
200
			// Tell jQuery we're expecting JSONP
201
			dataType: "json",
202
			// Tell YQL what we want and that we want JSON			
203
			method: 'post',
204
			// Work with the response
205
			success: function( response ) {
206
				if(response.success){
207
					$('#preferences-'+$(that).data('id')).addClass('hidden');
208
				}
209
			}
210
		});
211
		ga('send', 'event', 'preferences', 'update', me);
212
	});
13901 anikendra 213
	// $('.row').on('click','.viewproduct',function(e){
214
	$(document).on('click','.viewproduct',function(e){
14386 anikendra 215
		if(typeof livePriceCalls != undefined) {
216
	    	for(var i in livePriceCalls){
14392 anikendra 217
	    		// console.log('killing ajax call '+i);
14386 anikendra 218
	    		livePriceCalls[i].abort();
219
	    	}
220
	    }
13686 anikendra 221
		$('#loadingModal').modal();
14952 anikendra 222
		if($(this).data('source')==2){
223
			//in case of flipkart, close popup after 5 seconds
224
			setTimeout(function(){ $('#loadingModal').modal('hide'); }, 1000*5);			
225
		}
14392 anikendra 226
		// console.log($(this).data('id'));
14345 anikendra 227
		var url = apihost+"clicks/add/"+me+"/"+$(this).data('id')+'/'+$(this).data('source')+'/?url='+encodeURIComponent($(this).data('url'))+'&price='+$(this).data('price');
13579 anikendra 228
		$.ajax({
229
			url: url,
230
			// The name of the callback parameter, as specified by the YQL service
231
			jsonp: "callback",
232
			// Tell jQuery we're expecting JSONP
233
			dataType: "jsonp",
234
			// Tell YQL what we want and that we want JSON
235
			data: {
236
				format: "json"
237
			},
238
			// Work with the response
239
			success: function( response ) {
240
				if(response.success && response.type=='redirect'){
241
					document.location = response.url;
242
				}
243
			}
244
		});
14432 anikendra 245
		ga('send', 'event', 'product', 'click', $(this).data('url'));
13583 anikendra 246
	});
13719 anikendra 247
	$('.jscroll-inner').on('click','.likedeal',function(e){	
13583 anikendra 248
		var that = $(this);
13682 anikendra 249
		if($(that).hasClass('active')){
13583 anikendra 250
			//User has already liked it,so remove like
251
			var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/like";	
252
		}else{
253
			var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/like";
254
		}
255
		$.ajax({
256
			url: url,
257
			// The name of the callback parameter, as specified by the YQL service
258
			jsonp: "callback",
259
			// Tell jQuery we're expecting JSONP
260
			dataType: "jsonp",
261
			// Tell YQL what we want and that we want JSON
262
			data: {
263
				format: "json"
264
			},
265
			// Work with the response
266
			success: function( response ) {
267
				if(response.success){
13672 anikendra 268
					$(that).toggleClass('active');
269
					$(that).parent().find('li.dislikedeal',0).removeClass('active');
13583 anikendra 270
				}
271
			}
272
		});
13686 anikendra 273
		ga('send', 'event', 'product', 'like', $(this).data('id'));
13583 anikendra 274
	});
13688 anikendra 275
	$('#myModal').on('click','#unlikebtn',function(e){
13682 anikendra 276
		e.preventDefault();
277
		var url = $('#unlikeproductform').attr('action')+'?'+$('#unlikeproductform').serialize()
14392 anikendra 278
		// console.log(url);
13682 anikendra 279
		$.ajax({
280
			url: url,
281
			// The name of the callback parameter, as specified by the YQL service
282
			jsonp: "callback",
283
			// Tell jQuery we're expecting JSONP
284
			dataType: "jsonp",
285
			// Tell YQL what we want and that we want JSON
286
			data: {
287
				format: "json"
288
			},
289
			// Work with the response
290
			success: function( response ) {
291
				// console.log(response);						
292
			}
293
		});
294
		$('#myModal').modal('hide');
13686 anikendra 295
		ga('send', 'event', 'brand', 'hide', $('#myModal').find('#productToHide',0).val());
13682 anikendra 296
	})
13719 anikendra 297
	$('.jscroll-inner').on('click','.dislikedeal',function(e){			
13583 anikendra 298
		var that = $(this);
13682 anikendra 299
		if($(that).hasClass('active')){
13583 anikendra 300
			//User has already liked it,so remove like
301
			var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/dislike";	
302
		}else{
14392 anikendra 303
			// console.log('show modal');
13682 anikendra 304
			$('#myModal').find('#productToHide',0).val($(this).data('id'));
14139 anikendra 305
			//$('#myModal').modal();
13583 anikendra 306
			var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/dislike";
307
		}
308
		$.ajax({
309
			url: url,
310
			// The name of the callback parameter, as specified by the YQL service
311
			jsonp: "callback",
312
			// Tell jQuery we're expecting JSONP
313
			dataType: "jsonp",
314
			// Tell YQL what we want and that we want JSON
315
			data: {
316
				format: "json"
317
			},
318
			// Work with the response
319
			success: function( response ) {
320
				if(response.success){
13672 anikendra 321
					$(that).toggleClass('active');
322
					$(that).parent().find('li.likedeal',0).removeClass('active');
13583 anikendra 323
				}
324
			}
325
		});
13686 anikendra 326
		ga('send', 'event', 'product', 'dislike', $(this).data('id'));
13583 anikendra 327
	});
13731 anikendra 328
	$('.deletefav').on('click',function(){
329
		var that = $(this);
330
		$('#loadingModal').modal();
331
		var url = apihost+"/user_actions/deletefav/"+me+"/"+$(this).data('id');			
332
		$.ajax({
333
			url: url,
334
			// The name of the callback parameter, as specified by the YQL service
335
			jsonp: "callback",
336
			// Tell jQuery we're expecting JSONP
337
			dataType: "jsonp",
338
			// Tell YQL what we want and that we want JSON
339
			data: {
340
				format: "json"
341
			},
342
			// Work with the response
343
			success: function( response ) {
344
				$('#loadingModal').modal('hide');
345
				if(response.success){			
346
					$('#fav-'+$(that).data('id')).hide('slow');
347
				}
348
			}
349
		});
350
		ga('send', 'event', 'favourites', 'remove', $(this).data('id'));
351
	});
352
	$('.clearfavs').on('click',function(){
353
		var that = $(this);
354
		$('#loadingModal').modal();
14300 anikendra 355
		var url = apihost+"/user_actions/deleteallfavs/"+me+'/'+$(this).data('type');			
13731 anikendra 356
		$.ajax({
357
			url: url,
358
			// The name of the callback parameter, as specified by the YQL service
359
			jsonp: "callback",
360
			// Tell jQuery we're expecting JSONP
361
			dataType: "jsonp",
362
			// Tell YQL what we want and that we want JSON
363
			data: {
364
				format: "json"
365
			},
366
			// Work with the response
367
			success: function( response ) {
368
				$('#loadingModal').modal('hide');
369
				if(response.success){			
370
					$('.deletefav').each(function(){
371
						$('#fav-'+$(this).data('id')).hide('slow');
372
					})					
373
				}
374
				$(that).hide();
375
			}
376
		});
377
		ga('send', 'event', 'favourites', 'removeall', me);
378
	});
13759 anikendra 379
	$('.revealbrands').on('click',function(){
380
		$(this).parent().find('.notfeatured').toggleClass('hidden');
381
		if($(this).html()=='Others'){
382
			$(this).html('Hide');
383
		}else{
384
			$(this).html('Others');
385
		}
386
	});
14068 anikendra 387
	$(document).on('click','.creditedcashbacks',function(){
388
		if($(this).find('.glyphicon-plus',0).length>0){
389
			$(this).find('.glyphicon-plus',0).removeClass('glyphicon-plus').addClass('glyphicon-minus');
390
		}else{
391
			$(this).find('.glyphicon-minus',0).removeClass('glyphicon-minus').addClass('glyphicon-plus');
392
		}
393
		$(this).next().toggleClass('hidden');
394
	});
395
	$(document).on('click','.panel-heading',function(){
396
		if($(this).find('.glyphicon-plus',0).length>0){
397
			$(this).find('.glyphicon-plus',0).removeClass('glyphicon-plus').addClass('glyphicon-minus');
398
		}else{
399
			$(this).find('.glyphicon-minus',0).removeClass('glyphicon-minus').addClass('glyphicon-plus');
400
		}
401
	});
14135 anikendra 402
	$(document).on('click','.prefcatselect',function(){
403
		$('.prefcatselect').removeClass('active')
404
		$(this).addClass('active');
405
		$('.categorypreferences').addClass('hidden');
406
		$('#cat-'+$(this).data('id')).toggleClass('hidden');
14150 anikendra 407
	});
408
	$(document).on('click','.refresh',function(){
409
		document.location.reload();
410
	});
14215 anikendra 411
	$(document).on('click','.hasmoretext',function(){
412
		$('#fulltext').html($(this).data('fulltext'));
413
		$('#fullTextModal').modal();
414
	});
14300 anikendra 415
	$(document).on('click','.favswitch',function(){
416
		$('.favswitch').removeClass('active')
417
		$(this).addClass('active');
418
		$('.clearfavs').addClass('hidden');
419
		$('.card').addClass('hidden');
420
		$('.'+$(this).data('type')).removeClass('hidden');
421
	});
14386 anikendra 422
	$(document).on('click','.brandpreferences .brands',function(){
423
		$(this).parents('.row').siblings('.controls').find('.editcategorypreferences',0).click();
424
	});
425
	$(document).on('click','.tryagainforliveprice',function(){		
426
		fetchLivePrice($(this).parent());
427
		$(this).parent().html('Getting Live Prices');
428
	});
14579 anikendra 429
	$(document).on('click','.alert > a',function(){		
430
		ga('send', 'event', 'notifications', 'click', $(this).html());
431
	});
432
	$(document).on('click','.banner',function(){		
433
		ga('send', 'event', 'banners', 'click', $(this).data('name'));
434
	});
13992 anikendra 435
});
14849 anikendra 436
function setCookie(cname, cvalue, days) {
437
    var d = new Date();
438
    d.setTime(d.getTime() + (days*24*60*60*1000));
439
    var expires = "expires="+d.toUTCString();
440
    document.cookie = cname + "=" + cvalue + "; " + expires;
441
}
442
 
443
function getCookie(cname) {
444
    var name = cname + "=";
445
    var ca = document.cookie.split(';');
446
    for(var i=0; i<ca.length; i++) {
447
        var c = ca[i];
448
        while (c.charAt(0)==' ') c = c.substring(1);
449
        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
450
    }
451
    return "";
452
}
453
function showpopup(id,count,interval){
14851 anikendra 454
	var cname = 'notif-count-'+me+'-'+id;
14849 anikendra 455
	var cookieval = getCookie(cname);
14851 anikendra 456
	var cname = 'notif-lastshown-'+me+'-'+id;
14849 anikendra 457
	var lastshown = getCookie(cname);
458
	if(cookieval==''){		
459
		incrementPopupCount(id,0);
460
		setLastShown(id);
461
		return true;
462
	} else{
463
		var d = new Date();
464
		var t = d.getTime();
465
		console.log(t-lastshown);
466
		console.log(interval*60*1000);
467
		if(t-lastshown>interval*60*1000){
468
			if(cookieval>=count){
469
				return false;
470
			}else{
471
				setLastShown(id);
472
				incrementPopupCount(id,cookieval);
473
				return true;	
474
			}
475
		}
476
	}
477
}
478
function setLastShown(id){
14851 anikendra 479
	var cname = 'notif-lastshown-'+me+'-'+id;
14849 anikendra 480
	var d = new Date();
481
	setCookie(cname, d.getTime(), 365);
482
}
483
function incrementPopupCount(id,currentCount) {
14851 anikendra 484
	var cname = 'notif-count-'+me+'-'+id;
14849 anikendra 485
	setCookie(cname, parseInt(currentCount)+1, 365);
14858 anikendra 486
}
487
var hidden, visibilityChange; 
488
function handleVisibilityChange() {
489
  if (document[hidden]) {
490
    console.log('mujhe dekho');
491
    document.title = "Mujhe Dekho Please";
492
    var tout = setTimeout(function(){ document.location.reload(); }, 1000*60);
493
  } else {
494
    console.log('active');
495
    clearTimeout(tout);
496
  }
497
}
498
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support 
499
  hidden = "hidden";
500
  visibilityChange = "visibilitychange";
501
} else if (typeof document.mozHidden !== "undefined") {
502
  hidden = "mozHidden";
503
  visibilityChange = "mozvisibilitychange";
504
} else if (typeof document.msHidden !== "undefined") {
505
  hidden = "msHidden";
506
  visibilityChange = "msvisibilitychange";
507
} else if (typeof document.webkitHidden !== "undefined") {
508
  hidden = "webkitHidden";
509
  visibilityChange = "webkitvisibilitychange";
510
}
511
if (typeof document.addEventListener === "undefined" || 
512
  typeof document[hidden] === "undefined") {
513
  alert("This feature requires a browser, such as Google Chrome or Firefox, that supports the Page Visibility API.");
514
} else {
515
  // Handle page visibility change   
516
  document.addEventListener(visibilityChange, handleVisibilityChange, false);
517
}    
14936 anikendra 518
$('.notificationok').on('click',function(e){
14932 anikendra 519
	e.preventDefault();
14931 anikendra 520
	$('.notificationmodal').modal('hide');
14935 anikendra 521
	setTimeout(function(){ $('.notificationmodal').modal('hide'); }, 1000);
14975 anikendra 522
	ga('send', 'event', 'popupnotification', 'ok', me);
14932 anikendra 523
	document.location = $(this).parent().prop('href');
15015 anikendra 524
});
525
$(document).on('click','.clearfilter',function(){	
526
	$('.filterbrand').each(function(){
527
		$(this).prop('checked',false);
528
	});	
529
});
530
$(document).on('click','.applyfilter',function(){	
531
	var brands = [];
15026 anikendra 532
	var brandnames = [];
15015 anikendra 533
	$('.filterbrand').each(function(){
534
		if($(this).prop('checked')){
15026 anikendra 535
			console.log($(this).parent().siblings('.brandname').html());
15015 anikendra 536
			brands.push($(this).val());
15026 anikendra 537
			brandnames.push($(this).parent().siblings('.brandname').html());
15015 anikendra 538
		}		
539
	});
540
	if(brands.length==0){
541
		$('#message').html('Please choose a few brands first').removeClass('hidden');
542
		setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
543
		return false;
544
	}else{
545
		var url = $('#brandselecter').prop('action');
15026 anikendra 546
		ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
15015 anikendra 547
		document.location = url+'&brands='+brands.join('^');
548
	}	
549
});
550
$(document).on('click','#showallbrands',function(){	
551
	$('.hidden').removeClass('hidden');
552
	$(this).hide();
15019 anikendra 553
});
554
$(document).on('input','#brandfilter',function(){	
555
	$('.brand').addClass('hidden');
556
	$('#showallbrands').hide();
557
	var that = $(this);
558
	$('li.brand').filter(function() { 
559
	  return $(this).data("brand").toLowerCase().indexOf($(that).val().toLowerCase()) != -1;
560
	}).removeClass('hidden','slow');
15015 anikendra 561
});