Subversion Repositories SmartDukaan

Rev

Rev 18115 | Rev 18119 | 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) {
4
	if(value==0){
5
		return '';
6
	}
7
	if(type==2){
14789 anikendra 8
		return ' +'+value+' Cashback';
14773 anikendra 9
	}else if(type==1){
14789 anikendra 10
		return ' +'+value+'% Cashback';
14773 anikendra 11
	}else{
12
		return '';
13
	}
15926 anikendra 14
};
15
function showShopcluesPopup(url){
16
	$('#shopcluesUrl').prop('href',url);
17
	$('#shopcluesModal').modal('show');
18
	return;
19
};
16397 anikendra 20
function showPaytmPopup(url){
21
	$('#paytmUrl').prop('href',url);
22
	$('#paytmModal').modal('show');
23
	return;
24
};
16485 anikendra 25
function showPaytmHelpPopup() {
26
	$('#loadingModal').modal('hide');
27
	$('#paytmHelpModal').modal('show');
28
}
29
function redirectToPaytm(url){
16679 anikendra 30
	url = 'http://mobilehotindia.com/r.html?'+Base64.encode(url);
16485 anikendra 31
	$('#paytmHelpModal').modal('hide');
32
	//check if paytm is active or not
33
	var paytmactive = getCookie('paytmActive',1);
16679 anikendra 34
	if(paytmactive && paytmactive == 'true'){		
16485 anikendra 35
		document.location = url;	
36
		pma.send('apk','paytm','active',me,null);
37
	}else{
38
		pma.send('apk','paytm','inactive',me,null);
39
		$('#loadingModal').modal('hide');
40
		showPaytmPopup(url);
41
	}
42
}
17006 naman 43
 
44
function redirectTohomeShop18(url){
45
	url = 'http://mobilehotindia.com/r.html?'+Base64.encode(url);
46
	//check if paytm is active or not
17017 naman 47
	var homeShop18active = getCookie('homeshop18',1);
48
	if(homeShop18active && homeShop18active == 'true'){		
17006 naman 49
		document.location = url;	
50
		pma.send('apk','homeShop18','active',me,null);
17635 naman 51
	}else{	
17006 naman 52
		pma.send('apk','homeShop18','inactive',me,null);
53
		$('#loadingModal').modal('hide');
54
		showhomeShop18Popup(url);
55
	}
56
}
57
 
58
function showhomeShop18Popup(url){
59
	$('#homeShop18Url').prop('href',url);
60
	$('#homeShop18Modal').modal('show');
61
	return;
62
};
63
 
13984 anikendra 64
$(function(){	
18115 amit.gupta 65
	if($('.scrollselector > .card').length>0) {
14969 anikendra 66
		setTimeout(function(){ document.location.reload(); }, 1000*15*60);
16395 anikendra 67
		if(typeof noscrolling == 'undefined') {
18115 amit.gupta 68
			$('.scrollselector').jscroll({
16368 anikendra 69
				loadingHtml: '<center><img src="/img/ajax-loader.gif" alt="Loading" /></center>',
70
			    autoTriggerUntil: 3,
71
			    padding: 20,
17804 manish.sha 72
			    callback:loadCartDetails
16368 anikendra 73
			});
74
		}
13820 anikendra 75
	}
13901 anikendra 76
	if($('.storeminprice').length>0) {
77
		var globalminprice = 9999999;
14773 anikendra 78
		var globalminsku;
79
		var globalmincashback = '';		
16124 anikendra 80
		var globalminoffer = '';		
14345 anikendra 81
		var calls = [];
13901 anikendra 82
		$('.storeminprice').each(function(){
14345 anikendra 83
			var temp = {'sort':$(this).data('searchorder'),'val':$(this)};
84
			calls.push(temp);
85
		});
86
		calls = sortByKey(calls,'sort');		
87
		for(var i in calls){
88
			fetchLivePrice(calls[i]['val'])
14969 anikendra 89
		}				
14345 anikendra 90
	};
91
	function sortByKey(array, key) {
92
	    return array.sort(function(a, b) {
93
	        var x = a[key]; var y = b[key];
94
	        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
95
	    });
15926 anikendra 96
	};		
15923 anikendra 97
	function getCouponText(coupon){
98
		return "<span class='red'>"+coupon+"</span>";
15926 anikendra 99
	};
16467 anikendra 100
	function getGrossPriceText(gross_price,available_price){
16656 anikendra 101
		if(gross_price == available_price)
102
			return "";
103
		return "Paytm cashback - "+(gross_price-available_price)+"<br>Net Price = <span class='red text-bigger'>"+available_price+"</span>"
16467 anikendra 104
	}
14432 anikendra 105
	function fetchLivePrice(obj){		
15607 anikendra 106
		ga('send', 'event', 'liveprice', 'fetch',$('#bestpriceproductname').html());
15550 anikendra 107
		var properties = {};
108
		properties.bundle_id = String($(obj).data('bundle_id'));
15607 anikendra 109
		properties.product_name = String($('#bestpriceproductname').html());
15585 anikendra 110
		pma.send('products','livesprice','fetch',me,properties);
14432 anikendra 111
		var that = obj;	
112
		var inStock = false;		
16495 anikendra 113
		var priceToCompare = 0;
14386 anikendra 114
		var req = $.ajax({
14345 anikendra 115
			url: '/store_products/getliveprice/'+$(that).data('bundle_id')+'/'+$(that).data('id'),
116
			// Tell jQuery we're expecting JSONP
117
			dataType: "json",
118
			// Tell YQL what we want and that we want JSON			
119
			method: 'get',
14430 anikendra 120
			// timeout: 30000,
14345 anikendra 121
			// Work with the response
122
			success: function( response ) {
123
				if(response.success){
124
					var i = 0;	
17006 naman 125
					var minpriceindex = 0;		
14797 anikendra 126
					if(response.products[i].in_stock == 1) {
16219 anikendra 127
						inStock = true;
16495 anikendra 128
						var minprice = 9999999;//Math.round(response.products[i]['available_price']);
14797 anikendra 129
						var minpriceurl = response.products[i]['marketPlaceUrl'];
130
					}
14345 anikendra 131
					if(response.products.length>0){
132
						//More than one products in store
133
						var variants = [];
16124 anikendra 134
						var j = 0;
135
						for(var i in response.products){								
14685 anikendra 136
							if(response.products[i].in_stock == 1){
16495 anikendra 137
								if(response.products[i].gross_price && response.products[i].gross_price > response.products[i].available_price) {
138
									priceToCompare = response.products[i].gross_price;
139
								}else{
140
									priceToCompare = response.products[i].available_price;
141
								}
15923 anikendra 142
								inStock = true;								
16495 anikendra 143
								if(priceToCompare && priceToCompare < globalminprice) {
144
									globalminprice = Math.round(priceToCompare);
14685 anikendra 145
									globalminsku = response.products[i]._id;
146
									var globalminsource = response.products[i].source_id;
14773 anikendra 147
									var globalminurl = response.products[i].marketPlaceUrl;
16124 anikendra 148
									var globalminoffer = response.products[i].offer;
14773 anikendra 149
									var globalmincashback = getcashbackstring(response.products[i].cash_back_type,response.products[i].cash_back);
14685 anikendra 150
								}
16495 anikendra 151
								if(typeof minprice == 'undefined' || priceToCompare < minprice) {
152
									minprice = Math.round(priceToCompare);
16219 anikendra 153
									minpriceindex = j;
16124 anikendra 154
								}								
16234 anikendra 155
								if(response.products[i].tagline && response.products[i].tagline.length>0 && $('#productoneliner').html().length==0) { 
16124 anikendra 156
									$('#productoneliner').html(response.products[i].tagline).removeClass('hidden').show();									
157
								}								
16467 anikendra 158
								variants.push({'name' : response.products[i].source_product_name, 'source_id' : response.products[i].source_id, 'available_price' : Math.round(response.products[i].available_price), 'url' : response.products[i].marketPlaceUrl,'source_product_name' : response.products[i].source_product_name,'id' : response.products[i]._id,'cash_back_type' : response.products[i].cash_back_type,'cash_back' : response.products[i].cash_back,'coupon': response.products[i].coupon,'codAvailable' : response.products[i].codAvailable,'offer' : response.products[i].offer,'gross_price' : response.products[i].gross_price});
16124 anikendra 159
							}					
16219 anikendra 160
							j++;
13901 anikendra 161
						}
16219 anikendra 162
						if(variants.length>1){
16124 anikendra 163
							variants.splice(minpriceindex,1);							
14713 anikendra 164
							var variantslink = $('<span class="variants"> '+(variants.length+1)+' Options</span>');
165
							$(that).parent().parent().find('.pull-left',0).append(variantslink);							
14799 anikendra 166
							$(variantslink).data('variants',variants).data('minprice',minprice);
13948 anikendra 167
						}
14345 anikendra 168
					}
169
					if(inStock){
14797 anikendra 170
						$(that).html(minprice).siblings('.cashbackamount').html(getcashbackstring(response.products[minpriceindex].cash_back_type,response.products[minpriceindex].cash_back)).parent().addClass('viewproduct');
14689 anikendra 171
						$('#name-'+$(that).data('id')).html(response.products[minpriceindex]['source_product_name']);
16039 anikendra 172
						if(response.products[minpriceindex]['coupon'] && response.products[minpriceindex]['coupon'].length>0){
15923 anikendra 173
							$('#couponcode-'+$(that).data('id')).show().find('span.red',0).html(getCouponText(response.products[minpriceindex]['coupon']));
16013 anikendra 174
						}			
175
						if(!response.products[minpriceindex]['codAvailable']){
16124 anikendra 176
							$('#codstatus-'+$(that).data('id')).show().removeClass('codstatus');
15923 anikendra 177
						}
16467 anikendra 178
						if(response.products[minpriceindex]['gross_price'] && response.products[minpriceindex]['gross_price'] > 0){
179
							$('#gross_price-'+$(that).data('id')).show().removeClass('gross_price').html(getGrossPriceText(response.products[minpriceindex]['gross_price'],response.products[minpriceindex]['available_price']));
180
						}
16124 anikendra 181
						if(response.products[minpriceindex]['offer'].length>0){
182
							$('#itemoffer-'+$(that).data('id')).show().html(response.products[minpriceindex]['offer']);
183
						}
14685 anikendra 184
						$('#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');
14345 anikendra 185
						if(globalminprice != 9999999) {
16124 anikendra 186
							$('#bestprice').html(globalminprice).siblings('.cashbackamount').html(globalmincashback).siblings('.productoffer').html(globalminoffer);
14685 anikendra 187
							$('#beststorelink').data('id',globalminsku).data('source',globalminsource).data('price',globalminprice).data('url',globalminurl).removeClass('hidden');
14345 anikendra 188
							$('#bestpricecontainer').removeClass('hidden');
14432 anikendra 189
						} 
14386 anikendra 190
					} else{
15607 anikendra 191
						ga('send', 'event', 'liveprice', 'outofstock', $('#bestpriceproductname').html());
15550 anikendra 192
						var properties = {};
193
						properties.sku = String(response.products[0]._id);
15607 anikendra 194
						properties.source = String(response.products[0].source_id);
195
						properties.product_name = String($('#bestpriceproductname').html());
15767 anikendra 196
						pma.send('products','liveprice','outofstock',me,properties);
14432 anikendra 197
						outOfStockCount++;
14345 anikendra 198
						$(that).parent().parent().remove();	
13901 anikendra 199
					}
14345 anikendra 200
					if(!response.products[0].available_price){
14434 anikendra 201
						// outOfStockCount++;
202
						// $(that).parent().parent().remove();	
203
						var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
204
						$(that).html(btn);
15585 anikendra 205
						// ga('send', 'event', 'liveprice', 'failed', response.products[0]._id);
206
						// console.log('failed for '+ response);
207
						// properties = {};
208
						// properties.sku = String(response.products[0]._id); 
209
						// pma.send('products','liveprice','failed',me,properties);
14969 anikendra 210
					}					
14386 anikendra 211
				} else{
14434 anikendra 212
					// outOfStockCount++;
213
					// $(that).parent().parent().remove();
214
					var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
215
					$(that).html(btn);
14969 anikendra 216
					ga('send', 'event', 'liveprice', 'failure', response.products[0]._id);
15550 anikendra 217
					properties = {};
218
					properties.sku = String(response.products[0]._id); 
219
					pma.send('products','liveprice','failure',me,properties);
13901 anikendra 220
				}
14432 anikendra 221
				checkForOutStocks(outOfStockCount);
14345 anikendra 222
			},
15310 anikendra 223
			error: function(request, status, err) {            	
224
        		var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
225
				$(that).html(btn);
226
				try{
227
					if(response){
228
						ga('send', 'event', 'liveprice', 'error', response.products[0]._id);
15550 anikendra 229
						var properties = {};
230
						properties.sku = String(response.products[0]._id);
231
						pma.send('products','livescore','error',me,properties);
15310 anikendra 232
					}						
233
				} catch(e){}
14345 anikendra 234
			}
13901 anikendra 235
		});
14386 anikendra 236
		livePriceCalls.push(req);
14357 anikendra 237
	};
14432 anikendra 238
	function checkForOutStocks(count){
239
		if(count>=livePriceCalls.length){
240
			$('#bestpricecontainer').html('<h4>Out of stock</h4>').removeClass('hidden');	
14969 anikendra 241
		}		
14432 anikendra 242
	};
14687 anikendra 243
	$(document).on('click','.showless',function(){
244
		$(this).addClass('hidden').siblings('.varnts').hide();
245
		$(this).parent().find('.variants',0).removeClass('hidden').addClass('justshow');
246
	});
13901 anikendra 247
	$(document).on('click','.variants',function(){
248
		$('.storeproductinfo').empty();
16219 anikendra 249
		var variants = $(this).data('variants');		
14799 anikendra 250
		var minprice = $(this).data('minprice');
14026 anikendra 251
		$('#variantscount').html(variants.length);
13901 anikendra 252
		for(var i in variants){
16495 anikendra 253
			if(variants[i].gross_price && variants[i].gross_price > variants[i].available_price) {
254
				var priceToDisplay = variants[i].gross_price;
255
			}else{
256
				var priceToDisplay = variants[i].available_price;
257
			}
258
			if(minprice == priceToDisplay) {
259
				var html = '<div class="clearfix varnts"></div><div class="col-xs-6 varnts text-small">'+variants[i].name+'</div><div class="col-xs-6 varnts viewproduct" data-source="'+variants[i].source_id+'" data-price="'+priceToDisplay+'" data-url="'+variants[i].url+'" data-id="'+variants[i].id+'"><span class="cashbackrupee varnts text-right" ></span> <span class="storeminprice">'+priceToDisplay+'</span><span class="cashbackamount">'+getcashbackstring(variants[i].cash_back_type,variants[i].cash_back)+'</span><span class="pull-right arrowright"></span>';
14849 anikendra 260
			} else {
16656 anikendra 261
				var html = '<div class="clearfix varnts"></div><div class="col-xs-6 varnts text-small">'+variants[i].name+'</div><div class="col-xs-6 varnts viewproduct" data-source="'+variants[i].source_id+'" data-price="'+priceToDisplay+'" data-url="'+variants[i].url+'" data-id="'+variants[i].id+'"><span class="cashbackrupee varnts text-right" ></span> <span class="text-small">'+priceToDisplay+'</span><span class="cashbackamount">'+getcashbackstring(variants[i].cash_back_type,variants[i].cash_back)+'</span><span class="pull-right arrowright"></span>';
16124 anikendra 262
			}
16467 anikendra 263
			if(variants[i].gross_price && variants[i].gross_price>0){
264
				html += '<p class="text-small">'+getGrossPriceText(variants[i].gross_price,variants[i].available_price)+'</p>';
265
			}	
16124 anikendra 266
			if(variants[i].offer.length>0){
267
				html += '<p class="text-small">'+variants[i].offer+'</p>';
16013 anikendra 268
			}	
16039 anikendra 269
			if(variants[i].coupon && variants[i].coupon.length>0){
16013 anikendra 270
				html += '<p class="text-small">Use Coupon <span class="red">'+variants[i].coupon+'</span></p>';
271
			}
272
			if(!variants[i].codAvailable){
16124 anikendra 273
				html += '<p class="text-small">COD not available</p>';
274
			}			
16013 anikendra 275
			html += '</div></div>';
276
			var row = $(html);			
14687 anikendra 277
			$(this).parent().parent().append(row);			
13901 anikendra 278
		}
14713 anikendra 279
		var showless = $('<div class="showless col-xs-9 text-right">Less <i class="glyphicon glyphicon-chevron-up"></i></span>');
14687 anikendra 280
		$(this).parent().parent().append(showless);
281
		$(this).addClass('hidden');
13901 anikendra 282
	});
13695 anikendra 283
	$('.categorytab').on('click','.categorytabcontrol.active',function(){
284
		$(this).toggleClass('active');
285
		$('#preferences-'+$(this).data('id')).addClass('hidden');
286
		$(this).parent().parent().children().find('.savecategorypreferences',0).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');
287
	});
13759 anikendra 288
	$('.categorytab').on('click','.categorytabcontrol:not(.active)',function(){
289
		$(this).parent().parent().find('.btn',0).click();
290
	});
13695 anikendra 291
	$('.categorytab').on('click','.editcategorypreferences',function(e){
292
		var that = $(this);
293
		$(that).removeClass('editcategorypreferences').addClass('savecategorypreferences').html('Done').addClass('btn-success');
294
		$('#togglepreferences-'+$(that).data('id')).toggleClass('active');
295
		$('#preferences-'+$(that).data('id')).removeClass('hidden');
296
		$('.brandselector').each(function(){
297
			if($(this).data('catid')==$(that).data('id')){
298
				$(this).addClass('active');
299
			}
17691 naman 300
		});
301
		$('.subcategoryselector').each(function(){
302
			if($(this).data('catid')==$(that).data('id')){
303
				$(this).addClass('active');
304
			}
16066 anikendra 305
		});		
13695 anikendra 306
	});
307
	$('.categorytab').on('click','.savecategorypreferences',function(e){
308
		var that = $(this);
309
		$(that).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');
310
		$('#togglepreferences-'+$(that).data('id')).toggleClass('active');
311
		$.ajax({
312
			url: $('#categorypreference-'+$(that).data('id')).attr('action'),
313
			data: $('#categorypreference-'+$(that).data('id')).serialize(),
314
			// Tell jQuery we're expecting JSONP
315
			dataType: "json",
316
			// Tell YQL what we want and that we want JSON			
317
			method: 'post',
318
			// Work with the response
319
			success: function( response ) {
320
				if(response.success){
321
					$('#preferences-'+$(that).data('id')).addClass('hidden');
322
				}
323
			}
324
		});
16066 anikendra 325
		active = getCookie('shopcluesActive',1);
16068 anikendra 326
		if(active && active == 'true'){
16066 anikendra 327
			$('.firsttimemsg').removeClass('hidden').show();
328
		}		
13695 anikendra 329
		ga('send', 'event', 'preferences', 'update', me);
15550 anikendra 330
		properties = pma.formDataToObject($('#categorypreference-'+$(this).data('id')).serializeArray());
331
		pma.send('preferences', 'update', 'set', me, properties);
13695 anikendra 332
	});
15767 anikendra 333
	$(document).on('click','.viewproduct',function(e){		
14386 anikendra 334
		if(typeof livePriceCalls != undefined) {
335
	    	for(var i in livePriceCalls){
336
	    		livePriceCalls[i].abort();
337
	    	}
338
	    }
13686 anikendra 339
		$('#loadingModal').modal();
14952 anikendra 340
		if($(this).data('source')==2){
341
			//in case of flipkart, close popup after 5 seconds
15311 anikendra 342
			setTimeout(function(){ $('#loadingModal').modal('hide');$('#customMessageModal').modal('hide'); }, 1000*10);			
14952 anikendra 343
		}
15159 anikendra 344
		var store = $(this).data('source');
14345 anikendra 345
		var url = apihost+"clicks/add/"+me+"/"+$(this).data('id')+'/'+$(this).data('source')+'/?url='+encodeURIComponent($(this).data('url'))+'&price='+$(this).data('price');
13579 anikendra 346
		$.ajax({
347
			url: url,
348
			// The name of the callback parameter, as specified by the YQL service
349
			jsonp: "callback",
350
			// Tell jQuery we're expecting JSONP
351
			dataType: "jsonp",
352
			// Tell YQL what we want and that we want JSON
353
			data: {
354
				format: "json"
355
			},
356
			// Work with the response
357
			success: function( response ) {
358
				if(response.success && response.type=='redirect'){
16495 anikendra 359
					console.log(store);
15920 anikendra 360
					if(store == 5) {
361
						//check if shopclues is active or not
362
						active = getCookie('shopcluesActive',1);
16679 anikendra 363
						response.url = 'http://mobilehotindia.com/r.html?'+Base64.encode(response.url);
364
						if(active && active == 'true'){							
15920 anikendra 365
							document.location = response.url;	
366
							pma.send('apk','shopclues','active',me,null);
367
						}else{
368
							pma.send('apk','shopclues','inactive',me,null);
369
							$('#loadingModal').modal('hide');
370
							showShopcluesPopup(response.url);
371
						}
17026 naman 372
				  	} else if(store == 6 ) {
16485 anikendra 373
				  		//display paytm help
16495 anikendra 374
				  		if(needToDisplayPaytmPopup(me)){
375
				  			showPaytmHelpPopup();
376
					  		$('#oktatabyebye').on('click',function(){
377
					  			redirectToPaytm(response.url);	
378
					  		});	
379
				  		}else{
380
				  			redirectToPaytm(response.url);	
381
				  		}
17006 naman 382
 
383
					} 
384
					  //for homeshop 18
17026 naman 385
				  	  else if(store == 7)
17006 naman 386
				  	  {
17017 naman 387
				  			redirectTohomeShop18(response.url);	
17006 naman 388
 
389
				  	  }
390
					  else if (store == 3 || store == 2) {
15310 anikendra 391
						if (store == 2){
392
							response.url = 'http://mobilehotindia.com/r.html?'+Base64.encode(response.url);
393
						}
16940 anikendra 394
						if (store == 3){
395
							response.url = '/r.html?'+Base64.encode(response.url);
396
						}
15188 anikendra 397
						if(response.showmessage == 1) {
398
							$('#loadingModal').modal('hide');
399
							$('#customMessage').html(response.message);
15310 anikendra 400
							$('#customMessageModal').modal('show');							
15311 anikendra 401
							setTimeout(function(){ document.location = response.url;}, 1000*3);			
15310 anikendra 402
						} else{
15206 anikendra 403
							document.location = response.url;	
15188 anikendra 404
						}
15203 anikendra 405
					} else {
16940 anikendra 406
						response.url = '/r.html?'+Base64.encode(response.url);
15128 anikendra 407
						document.location = response.url;
408
					}										
13579 anikendra 409
				}
15310 anikendra 410
			},
411
			error: function() {
412
				document.location = url;
13579 anikendra 413
			}
414
		});
14432 anikendra 415
		ga('send', 'event', 'product', 'click', $(this).data('url'));
15550 anikendra 416
		var properties = {};
417
		properties.sku = String($(this).data('id'));
418
		properties.source = String($(this).data('source'));
419
		properties.url = encodeURIComponent($(this).data('url'));
420
		properties.price = String($(this).data('price'));
421
		pma.send('products','url','click',me,properties);
13583 anikendra 422
	});
18066 naman 423
	$(document).on('click','.likeit',function(e){	
13583 anikendra 424
		var that = $(this);
17766 manish.sha 425
		if($(that).find('span.likedeal').hasClass('active')){
13583 anikendra 426
			//User has already liked it,so remove like
427
			var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/like";	
428
		}else{
429
			var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/like";
430
		}
431
		$.ajax({
432
			url: url,
433
			// The name of the callback parameter, as specified by the YQL service
434
			jsonp: "callback",
435
			// Tell jQuery we're expecting JSONP
436
			dataType: "jsonp",
437
			// Tell YQL what we want and that we want JSON
438
			data: {
439
				format: "json"
440
			},
441
			// Work with the response
442
			success: function( response ) {
443
				if(response.success){
17766 manish.sha 444
					that.find('span.likedeal').toggleClass('active');
445
					$(".img-overlay div[name='dislikediv_"+that.data('id')+"']").find('span.dislikedeal').removeClass('active');
13583 anikendra 446
				}
447
			}
448
		});
13686 anikendra 449
		ga('send', 'event', 'product', 'like', $(this).data('id'));
15550 anikendra 450
		var properties = {};
451
		properties.sku = String($(this).data('id'));
452
		pma.send('products','favourites','like',me,properties);
13583 anikendra 453
	});
13688 anikendra 454
	$('#myModal').on('click','#unlikebtn',function(e){
13682 anikendra 455
		e.preventDefault();
456
		var url = $('#unlikeproductform').attr('action')+'?'+$('#unlikeproductform').serialize()
457
		$.ajax({
458
			url: url,
459
			// The name of the callback parameter, as specified by the YQL service
460
			jsonp: "callback",
461
			// Tell jQuery we're expecting JSONP
462
			dataType: "jsonp",
463
			// Tell YQL what we want and that we want JSON
464
			data: {
465
				format: "json"
466
			},
467
			// Work with the response
468
			success: function( response ) {
469
			}
470
		});
471
		$('#myModal').modal('hide');
13686 anikendra 472
		ga('send', 'event', 'brand', 'hide', $('#myModal').find('#productToHide',0).val());
15550 anikendra 473
		pma.send('brands','hide',$('#myModal').find('#productToHide',0).val(),me);
13682 anikendra 474
	})
18066 naman 475
	// $('.jscroll-inner').on('click','.dislikeit',function(e){			
476
    $(document).on('click','.dislikeit',function(e){            
13583 anikendra 477
		var that = $(this);
17766 manish.sha 478
		if($(that).find('span.dislikedeal').hasClass('active')){
13583 anikendra 479
			//User has already liked it,so remove like
480
			var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/dislike";	
481
		}else{
13682 anikendra 482
			$('#myModal').find('#productToHide',0).val($(this).data('id'));
13583 anikendra 483
			var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/dislike";
484
		}
485
		$.ajax({
486
			url: url,
487
			// The name of the callback parameter, as specified by the YQL service
488
			jsonp: "callback",
489
			// Tell jQuery we're expecting JSONP
490
			dataType: "jsonp",
491
			// Tell YQL what we want and that we want JSON
492
			data: {
493
				format: "json"
494
			},
495
			// Work with the response
496
			success: function( response ) {
497
				if(response.success){
17766 manish.sha 498
					that.find('span.dislikedeal').toggleClass('active');
499
					$(".img-overlay div[name='likediv_"+that.data('id')+"']").find('span.likedeal').removeClass('active');
13583 anikendra 500
				}
501
			}
502
		});
13686 anikendra 503
		ga('send', 'event', 'product', 'dislike', $(this).data('id'));
15550 anikendra 504
		var properties = {};
505
		properties.sku = String($(this).data('id'));
506
		pma.send('products','favourites','dislike',me,properties);
13583 anikendra 507
	});
13731 anikendra 508
	$('.deletefav').on('click',function(){
509
		var that = $(this);
510
		$('#loadingModal').modal();
511
		var url = apihost+"/user_actions/deletefav/"+me+"/"+$(this).data('id');			
512
		$.ajax({
513
			url: url,
514
			// The name of the callback parameter, as specified by the YQL service
515
			jsonp: "callback",
516
			// Tell jQuery we're expecting JSONP
517
			dataType: "jsonp",
518
			// Tell YQL what we want and that we want JSON
519
			data: {
520
				format: "json"
521
			},
522
			// Work with the response
523
			success: function( response ) {
524
				$('#loadingModal').modal('hide');
525
				if(response.success){			
526
					$('#fav-'+$(that).data('id')).hide('slow');
527
				}
528
			}
529
		});
530
		ga('send', 'event', 'favourites', 'remove', $(this).data('id'));
15550 anikendra 531
		var properties = {};
532
		properties.sku = String($(this).data('id'));
533
		pma.send('products','favourites','remove',me,properties);
13731 anikendra 534
	});
535
	$('.clearfavs').on('click',function(){
536
		var that = $(this);
537
		$('#loadingModal').modal();
14300 anikendra 538
		var url = apihost+"/user_actions/deleteallfavs/"+me+'/'+$(this).data('type');			
13731 anikendra 539
		$.ajax({
540
			url: url,
541
			// The name of the callback parameter, as specified by the YQL service
542
			jsonp: "callback",
543
			// Tell jQuery we're expecting JSONP
544
			dataType: "jsonp",
545
			// Tell YQL what we want and that we want JSON
546
			data: {
547
				format: "json"
548
			},
549
			// Work with the response
550
			success: function( response ) {
551
				$('#loadingModal').modal('hide');
552
				if(response.success){			
553
					$('.deletefav').each(function(){
554
						$('#fav-'+$(this).data('id')).hide('slow');
555
					})					
556
				}
557
				$(that).hide();
558
			}
559
		});
560
		ga('send', 'event', 'favourites', 'removeall', me);
15550 anikendra 561
		pma.send('products','favourites','removeall',me);
13731 anikendra 562
	});
13759 anikendra 563
	$('.revealbrands').on('click',function(){
564
		$(this).parent().find('.notfeatured').toggleClass('hidden');
565
		if($(this).html()=='Others'){
566
			$(this).html('Hide');
567
		}else{
568
			$(this).html('Others');
569
		}
570
	});
17129 anikendra 571
	$(document).on('click','.showtips',function(){
572
		$('.apptips').toggleClass('hidden');
573
	});
14068 anikendra 574
	$(document).on('click','.creditedcashbacks',function(){
575
		if($(this).find('.glyphicon-plus',0).length>0){
576
			$(this).find('.glyphicon-plus',0).removeClass('glyphicon-plus').addClass('glyphicon-minus');
577
		}else{
578
			$(this).find('.glyphicon-minus',0).removeClass('glyphicon-minus').addClass('glyphicon-plus');
579
		}
580
		$(this).next().toggleClass('hidden');
581
	});
16858 naman 582
	$(document).on('click','.panel-heading a',function(){
14068 anikendra 583
		if($(this).find('.glyphicon-plus',0).length>0){
584
			$(this).find('.glyphicon-plus',0).removeClass('glyphicon-plus').addClass('glyphicon-minus');
585
		}else{
586
			$(this).find('.glyphicon-minus',0).removeClass('glyphicon-minus').addClass('glyphicon-plus');
587
		}
588
	});
14135 anikendra 589
	$(document).on('click','.prefcatselect',function(){
590
		$('.prefcatselect').removeClass('active')
591
		$(this).addClass('active');
592
		$('.categorypreferences').addClass('hidden');
593
		$('#cat-'+$(this).data('id')).toggleClass('hidden');
14150 anikendra 594
	});
595
	$(document).on('click','.refresh',function(){
596
		document.location.reload();
597
	});
14215 anikendra 598
	$(document).on('click','.hasmoretext',function(){
599
		$('#fulltext').html($(this).data('fulltext'));
600
		$('#fullTextModal').modal();
601
	});
14300 anikendra 602
	$(document).on('click','.favswitch',function(){
603
		$('.favswitch').removeClass('active')
604
		$(this).addClass('active');
605
		$('.clearfavs').addClass('hidden');
606
		$('.card').addClass('hidden');
607
		$('.'+$(this).data('type')).removeClass('hidden');
608
	});
14386 anikendra 609
	$(document).on('click','.brandpreferences .brands',function(){
610
		$(this).parents('.row').siblings('.controls').find('.editcategorypreferences',0).click();
611
	});
612
	$(document).on('click','.tryagainforliveprice',function(){		
613
		fetchLivePrice($(this).parent());
614
		$(this).parent().html('Getting Live Prices');
615
	});
14579 anikendra 616
	$(document).on('click','.alert > a',function(){		
617
		ga('send', 'event', 'notifications', 'click', $(this).html());
15550 anikendra 618
		pma.send('notifications','click',$(this).html(),me);
14579 anikendra 619
	});
620
	$(document).on('click','.banner',function(){		
621
		ga('send', 'event', 'banners', 'click', $(this).data('name'));
15550 anikendra 622
		pma.send('banners','click',$(this).data('name'),me);
14579 anikendra 623
	});
13992 anikendra 624
});
15310 anikendra 625
function setCookie(cname, cvalue, days, forceCookie) {
626
	if(typeof(Storage) !== "undefined" && !forceCookie) {
627
		localStorage.setItem(cname, cvalue);
628
	} else{
629
		var d = new Date();
630
	    d.setTime(d.getTime() + (days*24*60*60*1000));
631
	    var expires = "expires="+d.toUTCString();
632
	    document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
633
	}    
14849 anikendra 634
}
635
 
15310 anikendra 636
function getCookie(cname,forceCookie) {
637
	if(typeof(Storage) !== "undefined" && !forceCookie) {
638
	    return localStorage.getItem(cname);
639
	} else {	   
640
	    var name = cname + "=";
641
	    var ca = document.cookie.split(';');
642
	    for(var i=0; i<ca.length; i++) {
643
	        var c = ca[i];
644
	        while (c.charAt(0)==' ') c = c.substring(1);
645
	        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
646
	    }
647
	    return "";
648
	}
14849 anikendra 649
}
15310 anikendra 650
 
16495 anikendra 651
function needToDisplayPaytmPopup(me){
652
	var id = 'tip'
653
	var cname = 'paytm-help-count-'+me+'-'+id;
654
	var cookieval = getCookie(cname,1);
655
	if(!cookieval || cookieval == 'NaN' || cookieval==''){		
656
		incrementPopupCount(id,0,'paytm-help-count-');
657
		return true;
658
	} else if(cookieval < 5) {
659
		incrementPopupCount(id,cookieval,'paytm-help-count-');
660
		return true;
661
	} else{
662
		return false;
663
	}
664
};
665
 
14849 anikendra 666
function showpopup(id,count,interval){
14851 anikendra 667
	var cname = 'notif-count-'+me+'-'+id;
15797 anikendra 668
	var cookieval = getCookie(cname,1);
14851 anikendra 669
	var cname = 'notif-lastshown-'+me+'-'+id;
15797 anikendra 670
	var lastshown = getCookie(cname,1);
15310 anikendra 671
	if(!cookieval || cookieval == 'NaN' || cookieval==''){		
15077 anikendra 672
		incrementPopupCount(id,0,'notif-count-');
673
		setLastShown(id,'notif-lastshown-');
14849 anikendra 674
		return true;
675
	} else{
676
		var d = new Date();
677
		var t = d.getTime();
678
		if(t-lastshown>interval*60*1000){
679
			if(cookieval>=count){
680
				return false;
681
			}else{
15077 anikendra 682
				setLastShown(id,'notif-lastshown-');
683
				incrementPopupCount(id,cookieval,'notif-count-');
14849 anikendra 684
				return true;	
685
			}
686
		}
687
	}
688
}
15077 anikendra 689
function setLastShown(id,cookiename){
690
	var cname = cookiename+me+'-'+id;
14849 anikendra 691
	var d = new Date();
15721 anikendra 692
	setCookie(cname, d.getTime(), 365, 1);
14849 anikendra 693
}
15077 anikendra 694
function incrementPopupCount(id,currentCount,cookiename) {
695
	var cname = cookiename+me+'-'+id;
15721 anikendra 696
	setCookie(cname, parseInt(currentCount)+1, 365, 1);
14858 anikendra 697
}
698
var hidden, visibilityChange; 
699
function handleVisibilityChange() {
700
  if (document[hidden]) {
15058 anikendra 701
  	// pagetitle = document.title;
14858 anikendra 702
  } else {
15058 anikendra 703
  	// document.title = pagetitle;
14858 anikendra 704
  }
705
}
706
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support 
707
  hidden = "hidden";
708
  visibilityChange = "visibilitychange";
709
} else if (typeof document.mozHidden !== "undefined") {
710
  hidden = "mozHidden";
711
  visibilityChange = "mozvisibilitychange";
712
} else if (typeof document.msHidden !== "undefined") {
713
  hidden = "msHidden";
714
  visibilityChange = "msvisibilitychange";
715
} else if (typeof document.webkitHidden !== "undefined") {
716
  hidden = "webkitHidden";
717
  visibilityChange = "webkitvisibilitychange";
718
}
719
if (typeof document.addEventListener === "undefined" || 
720
  typeof document[hidden] === "undefined") {
15077 anikendra 721
  console.log("This feature requires a browser, such as Google Chrome or Firefox, that supports the Page Visibility API.");
14858 anikendra 722
} else {
723
  // Handle page visibility change   
724
  document.addEventListener(visibilityChange, handleVisibilityChange, false);
725
}    
14936 anikendra 726
$('.notificationok').on('click',function(e){
14932 anikendra 727
	e.preventDefault();
14931 anikendra 728
	$('.notificationmodal').modal('hide');
15159 anikendra 729
	// setTimeout(function(){ $('.notificationmodal').modal('hide'); }, 1000);
16133 anikendra 730
	ga('send', 'event', 'popupnotification-'+$(this).parent().data('id'), 'ok', me);
731
	var properties = {};
732
	properties.id = String($(this).parent().data('id'));
733
	pma.send('popupnotification','click','ok',me,properties);
14932 anikendra 734
	document.location = $(this).parent().prop('href');
15015 anikendra 735
});
736
$(document).on('click','.clearfilter',function(){	
737
	$('.filterbrand').each(function(){
738
		$(this).prop('checked',false);
739
	});	
15550 anikendra 740
	ga('send', 'event', 'filter', 'brand', 'reset');
741
	pma.send('filters','brands','reset',me);
15015 anikendra 742
});
17691 naman 743
 
744
$(document).on('click','.clearfiltersubcategory',function(){	
745
	$('.filtersubcategory').each(function(){
746
		$(this).prop('checked',false);
747
	});	
748
	ga('send', 'event', 'filter', 'subcategory', 'reset');
749
	pma.send('filters','subcategory','reset',me);
750
});
15015 anikendra 751
$(document).on('click','.applyfilter',function(){	
15584 anikendra 752
	$(this).prop('disabled',true);
753
	$('#loadingModal').modal();
15015 anikendra 754
	var brands = [];
15026 anikendra 755
	var brandnames = [];
17691 naman 756
	var subcategories = [];
757
	var subcatnames = [];
15015 anikendra 758
	$('.filterbrand').each(function(){
759
		if($(this).prop('checked')){
760
			brands.push($(this).val());
15026 anikendra 761
			brandnames.push($(this).parent().siblings('.brandname').html());
15015 anikendra 762
		}		
763
	});
17691 naman 764
 
765
	$('.filtersubcategory').each(function(){
766
		if($(this).prop('checked')){
767
			subcategories.push($(this).val());
768
			subcatnames.push($(this).parent().siblings('.subcategoryname').html());
769
		}
770
	});
771
 
772
	if(brands.length==0 && subcategories.length==0){
15721 anikendra 773
		$('#loadingModal').modal('hide');
17691 naman 774
		$('#message').html('Please choose a few brands/subcategories first').removeClass('hidden');
775
		setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
776
		$(this).prop('disabled',false);
777
		return false;
778
	}else if(brands.length==0 && subcategories.length>0 ){
779
		setCookie('subcategorieschosen', subcategories, 0.25, true);
780
		var url = $('#subcategoryselecter').prop('action');
781
		ga('send', 'event', 'filter', 'subcategory', subcatnames.join('|'));
782
		properties = {};
783
		for(var i in subcatnames){
784
			properties['subcategories_'+i] = subcatnames[i];
785
		}
786
		pma.send('filters','subcategories','addfilter',me,properties);
787
		var postdata = {'user_id':me,'type':'subcategory','filters':subcatnames.join('|')};
788
		$.post( "/user_filters/add", postdata, function( data ) {
789
			$('#loadingModal').modal('hide');
790
			$(this).prop('disabled',false);
791
	  		document.location = url+'&subcategories='+subcategories.join('^');
792
		});	
793
	}else if(brands.length>0 && subcategories.length==0 ){
794
		setCookie('brandschosen', brands, 0.25, true);
795
		var url = $('#brandselecter').prop('action');
796
		ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
797
		properties = {};
798
		for(var i in brandnames){
799
			properties['brand_'+i] = brandnames[i];
800
		}
801
		pma.send('filters','brands','addfilter',me,properties);
802
		var postdata = {'user_id':me,'type':'brand','filters':brandnames.join('|')};
803
		$.post( "/user_filters/add", postdata, function( data ) {
804
			$('#loadingModal').modal('hide');
805
			$(this).prop('disabled',false);
806
	  		document.location = url+'&brands='+brands.join('^');
807
		});		
808
	}else if(brands.length>0 && subcategories.length>0 ){
809
		setCookie('brandschosen', brands, 0.25, true);
810
		setCookie('subcategorieschosen', subcategories, 0.25, true);
811
		var url = $('#brandselecter').prop('action');
812
		ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
813
		ga('send', 'event', 'filter', 'subcategory', subcatnames.join('|'));
814
		properties = {};
815
		for(var i in brandnames){
816
			properties['brand_'+i] = brandnames[i];
817
		}
818
		for(var i in subcatnames){
819
			properties['subcategory_'+i] = subcatnames[i];
820
		}
821
		pma.send('filters','brandsnsubcategories','addfilter',me,properties);
822
		var dataStr = brandnames.join('|');
823
		dataStr = dataStr + subcatnames.join('|');
824
		var postdata = {'user_id':me,'type':'brandnsubcategory','filters':dataStr};
825
		$.post( "/user_filters/add", postdata, function( data ) {
826
			$('#loadingModal').modal('hide');
827
			$(this).prop('disabled',false);
828
	  		document.location = url+'&brands='+brands.join('^')+"&subcategories="+subcategories.join("^");
829
		});
830
	}
831
 
832
	/*if(brands.length==0){
833
		$('#loadingModal').modal('hide');
15015 anikendra 834
		$('#message').html('Please choose a few brands first').removeClass('hidden');
835
		setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
15722 anikendra 836
		$(this).prop('disabled',false);
15015 anikendra 837
		return false;
838
	}else{
16240 anikendra 839
		setCookie('brandschosen', brands, 0.25, true);
15015 anikendra 840
		var url = $('#brandselecter').prop('action');
15026 anikendra 841
		ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
15550 anikendra 842
		properties = {};
843
		for(var i in brandnames){
844
			properties['brand_'+i] = brandnames[i];
845
		}
846
		pma.send('filters','brands','addfilter',me,properties);
15085 anikendra 847
		var postdata = {'user_id':me,'type':'brand','filters':brandnames.join('|')};
848
		$.post( "/user_filters/add", postdata, function( data ) {
15584 anikendra 849
			$('#loadingModal').modal('hide');
15722 anikendra 850
			$(this).prop('disabled',false);
15584 anikendra 851
	  		document.location = url+'&brands='+brands.join('^');
15085 anikendra 852
		});		
17691 naman 853
	}
854
 
855
	if(subcategories.length==0){
856
		$('#loadingModal').modal('hide');
857
		$('#message').html('Please choose a few Sub-categories first').removeClass('hidden');
858
		setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
859
		$(this).prop('disabled',false);
860
		return false;
861
	}else{
862
		setCookie('subcategorieschosen', subcategories, 0.25, true);
863
		var url = $('#subcategoryselecter').prop('action');
864
		ga('send', 'event', 'filter', 'subcategory', brandnames.join('|'));
865
		properties = {};
866
		for(var i in brandnames){
867
			properties['brand_'+i] = brandnames[i];
868
		}
869
		pma.send('filters','subcategories','addfilter',me,properties);
870
		var postdata = {'user_id':me,'type':'subcategory','filters':subcatnames.join('|')};
871
		$.post( "/user_filters/add", postdata, function( data ) {
872
			$('#loadingModal').modal('hide');
873
			$(this).prop('disabled',false);
874
	  		document.location = url+'&brands='+brands.join('^');
875
		});		
876
	}*/	
15015 anikendra 877
});
18066 naman 878
 
879
 
15015 anikendra 880
$(document).on('click','#showallbrands',function(){	
18066 naman 881
	$('.brand').removeClass('hidden');
882
    $('.subcategory').removeClass('hidden');
15015 anikendra 883
	$(this).hide();
15019 anikendra 884
});
885
$(document).on('input','#brandfilter',function(){	
886
	$('.brand').addClass('hidden');
887
	$('#showallbrands').hide();
888
	var that = $(this);
889
	$('li.brand').filter(function() { 
890
	  return $(this).data("brand").toLowerCase().indexOf($(that).val().toLowerCase()) != -1;
891
	}).removeClass('hidden','slow');
15042 anikendra 892
});
17707 naman 893
 
894
$(document).on('input','#subcatfilter',function(){	
895
	$('.subcategory').addClass('hidden');
896
	$('#showallbrands').hide();
897
	var that = $(this);
898
	$('li.subcategory').filter(function() { 
899
	  return $(this).data("brand").toLowerCase().indexOf($(that).val().toLowerCase()) != -1;
900
	}).removeClass('hidden','slow');
901
});
902
 
903
 
15077 anikendra 904
$(document).on('click','.filterbrand',function(){
905
	var clicked = $(this).parent().parent();
15042 anikendra 906
	// all the LIs above the clicked one
907
	var previousAll = clicked.prevAll();
908
 
909
	// only proceed if it's not already on top (no previous siblings)
910
	if(previousAll.length > 0) {
911
	// top LI
912
	var top = $(previousAll[previousAll.length - 1]);
913
 
914
	// immediately previous LI
915
	var previous = $(previousAll[0]);
916
 
917
	// how far up do we need to move the clicked LI?
918
	var moveUp = clicked.attr('offsetTop') - top.attr('offsetTop');
919
 
920
	// how far down do we need to move the previous siblings?
921
	var moveDown = (clicked.offset().top + clicked.outerHeight()) - (previous.offset().top + previous.outerHeight());
922
 
923
	// let's move stuff
924
	clicked.css('position', 'relative');
925
	previousAll.css('position', 'relative');
926
	clicked.animate({'top': -moveUp});
927
	previousAll.animate({'top': moveDown}, {complete: function() {
928
	  // rearrange the DOM and restore positioning when we're done moving
929
	  clicked.parent().prepend(clicked);
930
	  clicked.css({'position': 'static', 'top': 0});
931
	  previousAll.css({'position': 'static', 'top': 0}); 
932
	}});
933
	}
934
})
17691 naman 935
$(document).on('click','.filtersubcategory',function(){
936
	var clicked = $(this).parent().parent();
937
	// all the LIs above the clicked one
938
	var previousAll = clicked.prevAll();
939
 
940
	// only proceed if it's not already on top (no previous siblings)
941
	if(previousAll.length > 0) {
942
	// top LI
943
	var top = $(previousAll[previousAll.length - 1]);
944
 
945
	// immediately previous LI
946
	var previous = $(previousAll[0]);
947
 
948
	// how far up do we need to move the clicked LI?
949
	var moveUp = clicked.attr('offsetTop') - top.attr('offsetTop');
950
 
951
	// how far down do we need to move the previous siblings?
952
	var moveDown = (clicked.offset().top + clicked.outerHeight()) - (previous.offset().top + previous.outerHeight());
953
 
954
	// let's move stuff
955
	clicked.css('position', 'relative');
956
	previousAll.css('position', 'relative');
957
	clicked.animate({'top': -moveUp});
958
	previousAll.animate({'top': moveDown}, {complete: function() {
959
	  // rearrange the DOM and restore positioning when we're done moving
960
	  clicked.parent().prepend(clicked);
961
	  clicked.css({'position': 'static', 'top': 0});
962
	  previousAll.css({'position': 'static', 'top': 0}); 
963
	}});
964
	}
965
})
15042 anikendra 966
$(document).on('click','.clearfilters',function(){
15310 anikendra 967
	setCookie('brandschosen', '', -1, true);
17691 naman 968
	setCookie('subcategorieschosen','',-1, true);
15058 anikendra 969
	ga('send', 'event', 'filter', 'brand', 'clearfilters');
17691 naman 970
	ga('send', 'event', 'filter', 'subcategory', 'clearfilters');
15550 anikendra 971
	pma.send('filters','brands','clearfilters',me);
17691 naman 972
	pma.send('filters','subcategory','clearfilters',me);
15085 anikendra 973
	var postdata = {'user_id':me,'type':'clear'};
16240 anikendra 974
	$('#loadingModal').modal('show');
975
	$.post("/user_filters/add", postdata, function( data ) {		
17635 naman 976
	  	// document.location.reload();
977
	  	window.location.replace(window.location.href.split('?')[0]);
15085 anikendra 978
	});	
15042 anikendra 979
});
980
function selectChosenBrands(){
16261 anikendra 981
	var brandschosen = decodeURIComponent(getCookie('brandschosen',true));
17691 naman 982
	var subcategorieschosen = decodeURIComponent(getCookie('subcategorieschosen',true));
15042 anikendra 983
	if(brandschosen && brandschosen.length>0){
984
		var brands = brandschosen.split(',');
985
		for(var i in brands){
986
			$('.brand').filter(function() { 
987
			  	return $(this).data("brandid") == brands[i];
15077 anikendra 988
			}).removeClass('hidden').find('.filterbrand',0).trigger( "click" );
15042 anikendra 989
		}
990
	}
17691 naman 991
	if(subcategorieschosen && subcategorieschosen.length>0){
992
		var subcategories = subcategorieschosen.split(',');
993
		for(var i in subcategories){
994
			$('.subcategory').filter(function() { 
995
			  	return $(this).data("brandid") == subcategories[i];
996
			}).removeClass('hidden').find('.filtersubcategory',0).trigger( "click" );
997
		}
998
	}
15065 anikendra 999
}
15585 anikendra 1000
function showPosition(position) {
15586 anikendra 1001
    setCookie('latitude',position.coords.latitude,1,true); 
1002
    setCookie('longitude',position.coords.longitude,1,true);	
15585 anikendra 1003
}
15065 anikendra 1004
$(function () {
18115 amit.gupta 1005
	$("#popovertrigger5").popover('hide').remove();
18033 amit.gupta 1006
	$('.data-up:first').append('<a id="popovertrigger5"  data-container="body" data-toggle="popover" data-placement="left" data-content="Quick buy multiple items together"></a>');
18115 amit.gupta 1007
	setPopOver("popovertrigger5", ".plusqtybutton", 'click');
18023 amit.gupta 1008
	callBackFunction = function(){
1009
		return document.location.pathname=="/category/6";		
1010
	};
18033 amit.gupta 1011
	setPopOver("popovertrigger4", callBackFunction);
18115 amit.gupta 1012
	//$('[data-toggle="popover"]#'+id).popover('show');
18023 amit.gupta 1013
	if (navigator.geolocation) {
1014
        navigator.geolocation.getCurrentPosition(showPosition);
1015
    } 
1016
});
1017
 
1018
function setPopOver(poid, callBack1, eventString){
15310 anikendra 1019
	var cname = 'popover-count-'+me+'-'+poid;
15721 anikendra 1020
	var cookieval = getCookie(cname,1);
18023 amit.gupta 1021
	if(typeof callBack1=="function"){
1022
		if (callBack1()){
1023
			var cname = 'popover-count-'+me+'-'+poid;
1024
			var cookieval = getCookie(cname,1);
1025
			$('#' + poid).popover('hide');
1026
			if(!cookieval || cookieval == 'NaN' || cookieval == ''){
1027
				incrementPopupCount(poid,0,'popover-count-');
1028
			} else if(cookieval > 0) {
1029
				incrementPopupCount(poid, cookieval, 'popover-count-');
1030
			}
1031
			setLastShown(poid,'popover-lastshown-');
15310 anikendra 1032
		}
18023 amit.gupta 1033
	} else {
1034
		$('div.content').on(eventString, callBack1, function(){
1035
			var cname = 'popover-count-'+me+'-'+poid;
1036
			var cookieval = getCookie(cname,1);
1037
			$('#' + poid).popover('hide');
1038
			if(!cookieval || cookieval == 'NaN' || cookieval == ''){
1039
				incrementPopupCount(poid,0,'popover-count-');
1040
			} else if(cookieval > 0) {
1041
				incrementPopupCount(poid, cookieval, 'popover-count-');
1042
			}
1043
			setLastShown(poid,'popover-lastshown-');
1044
		}); 
18008 amit.gupta 1045
	}
15310 anikendra 1046
 
15077 anikendra 1047
	var cname = 'popover-lastshown-'+me+'-'+poid;
15721 anikendra 1048
	var lastshown = getCookie(cname,1);
15310 anikendra 1049
	if(cookieval=='' || cookieval == 'NaN' || !cookieval){				
15077 anikendra 1050
		showpopover(poid);
15521 anikendra 1051
	} 
1052
	//Donot show popover anymore as long as we don't find a suitable solution
15721 anikendra 1053
	else{
15077 anikendra 1054
		var d = new Date();
1055
		var t = d.getTime();
15085 anikendra 1056
		if(t-lastshown>18*3600*1000){
15310 anikendra 1057
			if(cookieval>=2){
15077 anikendra 1058
				return false;
1059
			}else{
15310 anikendra 1060
				showpopover(poid);				
15077 anikendra 1061
			}
1062
		}
15721 anikendra 1063
	}
15583 anikendra 1064
	ga('send', 'event', 'popover', me, cookieval);
18023 amit.gupta 1065
}
16656 anikendra 1066
$('.getapp').on('click',function(){
17102 anikendra 1067
	/*var that = $(this);
16656 anikendra 1068
	var req = $.ajax({
1069
		url: 'http://104.200.25.40:8057/appAffiliates/generateRedirectUrl/'+me+'/'+$(that).data('id'),
1070
		// Tell jQuery we're expecting JSONP
1071
		dataType: "jsonp",
1072
		// Tell YQL what we want and that we want JSON			
1073
		method: 'get',
1074
		// timeout: 30000,
1075
		// Work with the response
1076
		success: function( response ) {
1077
			console.log(response);
1078
		}
17102 anikendra 1079
	});*/
1080
	$('#loadingModal').modal('show');
1081
	document.location = '/abouts/apphint';
16656 anikendra 1082
});
15077 anikendra 1083
function showpopover(id){
18036 amit.gupta 1084
	try {
1085
		$('[data-toggle="popover"]#'+id).popover({html:true,viewport:{container:'body'}, trigger:'manual'});
1086
		$('[data-toggle="popover"]#'+id).popover('show');		
1087
	}catch(err){
1088
		//
1089
	}
15085 anikendra 1090
}
1091
$(document).on('click','.nodeals',function(){
1092
	document.location = $(this).data('href');
16018 anikendra 1093
});
1094
$(document).on('click','.selectbrand',function(e){
1095
	e.preventDefault();
1096
	var brands = $(this).data('id');
1097
	var brandname = $(this).html();
1098
	console.log(brandname);
17703 naman 1099
 
16018 anikendra 1100
	setCookie('brandschosen', brands, 1, true);
1101
	var url = $(this).data('href');
1102
	ga('send', 'event', 'selectbrand', 'brand', brandname);
1103
	properties = {};
1104
	properties['brand'] = brandname;
1105
	pma.send('filters','brands','selectbrand',me,properties);
1106
	var postdata = {'user_id':me,'type':'brand','filters':brandname};
1107
	$.post( "/user_filters/add", postdata, function( data ) {
1108
		$('#loadingModal').modal('hide');
1109
		$(this).addClass('activebrand');
1110
  		document.location = url+'&brands='+brands;
1111
	});
1112
});
17703 naman 1113
 
1114
$(document).on('click','.selectsubcat',function(e){
1115
	e.preventDefault();
17707 naman 1116
	$('.clearfilters').click();
17703 naman 1117
	var brands = $(this).data('id');
1118
	var brandname = $(this).html();
1119
	console.log(brandname);
1120
 
1121
	setCookie('subcategorieschosen', brands, 1, true);
1122
	var url = $(this).data('href');
1123
	// alert(url);
1124
	// ga('send', 'event', 'subcategorieschosen', 'brand', brandname);
1125
	document.location = url;
1126
	// properties = {};
1127
	// properties['brand'] = brandname;
1128
	// pma.send('filters','brands','selectbrand',me,properties);
1129
	// // var postdata = {'user_id':me,'type':'brand','filters':brandname};
1130
	// $.post( "/user_filters/add", postdata, function( data ) {
1131
	// 	$('#loadingModal').modal('hide');
1132
	// 	$(this).addClass('activebrand');
1133
 //  		document.location = url+'&brands='+brands;
1134
	// });
1135
});
1136
 
16495 anikendra 1137
$(document).on('click','.shownexttip',function(e){
1138
	$(this).addClass('hidden').remove();
1139
	$('#firsttip').addClass('hidden').remove();
1140
	$('#secondtip').removeClass('hidden');
1141
	$('.gotit').removeClass('hidden');
1142
});
15128 anikendra 1143
var Base64 = {
1144
    _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
1145
    encode: function(input) {
1146
        var output = "";
1147
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
1148
        var i = 0;
1149
        input = Base64._utf8_encode(input);
1150
        while (i < input.length) {
1151
            chr1 = input.charCodeAt(i++);
1152
            chr2 = input.charCodeAt(i++);
1153
            chr3 = input.charCodeAt(i++);
1154
 
1155
            enc1 = chr1 >> 2;
1156
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
1157
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
1158
            enc4 = chr3 & 63;
1159
            if (isNaN(chr2)) {
1160
                enc3 = enc4 = 64;
1161
            } else if (isNaN(chr3)) {
1162
                enc4 = 64;
1163
            }
1164
            output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
1165
        }
1166
        return output;
1167
    },
1168
 
1169
 
1170
    decode: function(input) {
1171
        var output = "";
1172
        var chr1, chr2, chr3;
1173
        var enc1, enc2, enc3, enc4;
1174
        var i = 0;
1175
        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
1176
        while (i < input.length) {
1177
            enc1 = this._keyStr.indexOf(input.charAt(i++));
1178
            enc2 = this._keyStr.indexOf(input.charAt(i++));
1179
            enc3 = this._keyStr.indexOf(input.charAt(i++));
1180
            enc4 = this._keyStr.indexOf(input.charAt(i++));
1181
            chr1 = (enc1 << 2) | (enc2 >> 4);
1182
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
1183
            chr3 = ((enc3 & 3) << 6) | enc4;
1184
            output = output + String.fromCharCode(chr1);
1185
            if (enc3 != 64) {
1186
                output = output + String.fromCharCode(chr2);
1187
            }
1188
            if (enc4 != 64) {
1189
                output = output + String.fromCharCode(chr3);
1190
            }
1191
        }
1192
        output = Base64._utf8_decode(output);
1193
        return output;
1194
    },
1195
 
1196
    _utf8_encode: function(string) {
1197
        string = string.replace(/\r\n/g, "\n");
1198
        var utftext = "";
1199
        for (var n = 0; n < string.length; n++) {
1200
            var c = string.charCodeAt(n);
1201
            if (c < 128) {
1202
                utftext += String.fromCharCode(c);
1203
            }
1204
            else if ((c > 127) && (c < 2048)) {
1205
                utftext += String.fromCharCode((c >> 6) | 192);
1206
                utftext += String.fromCharCode((c & 63) | 128);
1207
            }
1208
            else {
1209
                utftext += String.fromCharCode((c >> 12) | 224);
1210
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
1211
                utftext += String.fromCharCode((c & 63) | 128);
1212
            }
1213
        }
1214
        return utftext;
1215
    },
1216
 
1217
    _utf8_decode: function(utftext) {
1218
        var string = "";
1219
        var i = 0;
1220
        var c = c1 = c2 = 0;
1221
        while (i < utftext.length) {
1222
            c = utftext.charCodeAt(i);
1223
            if (c < 128) {
1224
                string += String.fromCharCode(c);
1225
                i++;
1226
            }
1227
            else if ((c > 191) && (c < 224)) {
1228
                c2 = utftext.charCodeAt(i + 1);
1229
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
1230
                i += 2;
1231
            }
1232
            else {
1233
                c2 = utftext.charCodeAt(i + 1);
1234
                c3 = utftext.charCodeAt(i + 2);
1235
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
1236
                i += 3;
1237
            }
1238
        }
1239
        return string;
1240
    }
15550 anikendra 1241
}
1242
 
1243
 
1244
var pma = new function() {
15584 anikendra 1245
    this.apiurl = "http://45.33.50.227:8081/";
15550 anikendra 1246
    this.endpoints = {'identify':'identify','profile':'profile','track':'track'};
1247
 
1248
    this.send = function (category,action,label,user_id,properties) {
15585 anikendra 1249
    	if(!properties){
1250
    		properties = {};
1251
    	}
1252
    	properties.location = window.location.href;
1253
    	// properties.appCodeName = navigator.appCodeName;
1254
    	// properties.appName = navigator.appName;
1255
    	// properties.appVersion = navigator.appVersion;
1256
    	properties.cookieEnabled = String(navigator.cookieEnabled);
1257
    	properties.platform = navigator.platform;
1258
    	properties.userAgent = navigator.userAgent;
1259
    	properties.ip = ip;
1260
	  	if (navigator.geolocation) {
15586 anikendra 1261
	  		if(getCookie('latitude',true)){
1262
	  			properties.latitude = getCookie('latitude');
1263
	  		}	  		
1264
	  		if(getCookie('longitude',true)){
1265
		  		properties.longitude = getCookie('longitude');
1266
		  	}
15585 anikendra 1267
	  	}
1268
	  	properties.screenHeight = String(screen.height);
1269
	  	properties.screenWidth = String(screen.width);
1270
    	// console.log(properties);
15550 anikendra 1271
 		$.ajax({
1272
			url: this.apiurl + this.endpoints.track,
1273
			data: {'category':category,'action':action,'label':label,'user_id':user_id,'properties':cassandraMAP.stringify(properties)},
1274
			// Tell jQuery we're expecting JSONP
1275
			dataType: "json",
1276
			// Tell YQL what we want and that we want JSON			
1277
			method: 'post',
1278
			// Work with the response
1279
			success: function( response ) {
1280
				//Well, well, well :)
1281
			}
1282
		});       
1283
    };
1284
 
1285
    this.formDataToObject = function(formdata){
1286
    	var properties = {};
1287
    	var keys = [];
1288
		var formdata = JSON.parse(JSON.stringify(formdata));
1289
		for (var i in formdata) {
1290
			var key = formdata[i].name;
1291
			if(index = keys.indexOf(key)==-1){
1292
				properties[key] = formdata[i].value;
1293
			}else{
1294
				properties[key+'_'+i] = formdata[i].value;
1295
			}
1296
			keys.push(key);
1297
		};
1298
		return properties;
1299
	}
16704 anikendra 1300
}
1301
//App page
1302
$.fn.stars = function() {
1303
    return $(this).each(function() {
1304
        // Get the value
1305
        var val = parseFloat($(this).html());
1306
        // Make sure that the value is in 0 - 5 range, multiply to get width
1307
        val = Math.round(val * 2) / 2;
1308
        var size = Math.max(0, (Math.min(5, val))) * 16;
1309
        // Create stars holder
1310
        var $span = $('<span />').width(size);
1311
        // Replace the numerical value with stars
1312
        $(this).html($span);
1313
    });
1314
}
1315
$(function() {
1316
    $('span.stars').stars();	
18023 amit.gupta 1317
});
1318
 
1319
function sendCartChangeEvent(){
1320
	var cart_details_old = localStorage.getItem('cart_details_old');
1321
	var cart_details = localStorage.getItem('cart_details');
1322
	if (cart_details_old == cart_details){
1323
		return;
1324
	} else if(cart_details!=null){
1325
		JSON.parse(cart_details);
1326
 
1327
	}
1328
}
1329
 
1330
//setInterval(30000, )