Subversion Repositories SmartDukaan

Rev

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