Subversion Repositories SmartDukaan

Rev

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