Subversion Repositories SmartDukaan

Rev

Rev 18177 | Rev 18190 | 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') {
18177 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'){
18119 amit.gupta 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
    $(document).on('click','.dislikeit',function(e){            
13583 anikendra 476
		var that = $(this);
17766 manish.sha 477
		if($(that).find('span.dislikedeal').hasClass('active')){
13583 anikendra 478
			//User has already liked it,so remove like
479
			var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/dislike";	
480
		}else{
13682 anikendra 481
			$('#myModal').find('#productToHide',0).val($(this).data('id'));
13583 anikendra 482
			var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/dislike";
483
		}
484
		$.ajax({
485
			url: url,
486
			// The name of the callback parameter, as specified by the YQL service
487
			jsonp: "callback",
488
			// Tell jQuery we're expecting JSONP
489
			dataType: "jsonp",
490
			// Tell YQL what we want and that we want JSON
491
			data: {
492
				format: "json"
493
			},
494
			// Work with the response
495
			success: function( response ) {
496
				if(response.success){
17766 manish.sha 497
					that.find('span.dislikedeal').toggleClass('active');
498
					$(".img-overlay div[name='likediv_"+that.data('id')+"']").find('span.likedeal').removeClass('active');
13583 anikendra 499
				}
500
			}
501
		});
13686 anikendra 502
		ga('send', 'event', 'product', 'dislike', $(this).data('id'));
15550 anikendra 503
		var properties = {};
504
		properties.sku = String($(this).data('id'));
505
		pma.send('products','favourites','dislike',me,properties);
13583 anikendra 506
	});
13731 anikendra 507
	$('.deletefav').on('click',function(){
508
		var that = $(this);
509
		$('#loadingModal').modal();
510
		var url = apihost+"/user_actions/deletefav/"+me+"/"+$(this).data('id');			
511
		$.ajax({
512
			url: url,
513
			// The name of the callback parameter, as specified by the YQL service
514
			jsonp: "callback",
515
			// Tell jQuery we're expecting JSONP
516
			dataType: "jsonp",
517
			// Tell YQL what we want and that we want JSON
518
			data: {
519
				format: "json"
520
			},
521
			// Work with the response
522
			success: function( response ) {
523
				$('#loadingModal').modal('hide');
524
				if(response.success){			
525
					$('#fav-'+$(that).data('id')).hide('slow');
526
				}
527
			}
528
		});
529
		ga('send', 'event', 'favourites', 'remove', $(this).data('id'));
15550 anikendra 530
		var properties = {};
531
		properties.sku = String($(this).data('id'));
532
		pma.send('products','favourites','remove',me,properties);
13731 anikendra 533
	});
534
	$('.clearfavs').on('click',function(){
535
		var that = $(this);
536
		$('#loadingModal').modal();
14300 anikendra 537
		var url = apihost+"/user_actions/deleteallfavs/"+me+'/'+$(this).data('type');			
13731 anikendra 538
		$.ajax({
539
			url: url,
540
			// The name of the callback parameter, as specified by the YQL service
541
			jsonp: "callback",
542
			// Tell jQuery we're expecting JSONP
543
			dataType: "jsonp",
544
			// Tell YQL what we want and that we want JSON
545
			data: {
546
				format: "json"
547
			},
548
			// Work with the response
549
			success: function( response ) {
550
				$('#loadingModal').modal('hide');
551
				if(response.success){			
552
					$('.deletefav').each(function(){
553
						$('#fav-'+$(this).data('id')).hide('slow');
554
					})					
555
				}
556
				$(that).hide();
557
			}
558
		});
559
		ga('send', 'event', 'favourites', 'removeall', me);
15550 anikendra 560
		pma.send('products','favourites','removeall',me);
13731 anikendra 561
	});
13759 anikendra 562
	$('.revealbrands').on('click',function(){
563
		$(this).parent().find('.notfeatured').toggleClass('hidden');
564
		if($(this).html()=='Others'){
565
			$(this).html('Hide');
566
		}else{
567
			$(this).html('Others');
568
		}
569
	});
17129 anikendra 570
	$(document).on('click','.showtips',function(){
571
		$('.apptips').toggleClass('hidden');
572
	});
14068 anikendra 573
	$(document).on('click','.creditedcashbacks',function(){
574
		if($(this).find('.glyphicon-plus',0).length>0){
575
			$(this).find('.glyphicon-plus',0).removeClass('glyphicon-plus').addClass('glyphicon-minus');
576
		}else{
577
			$(this).find('.glyphicon-minus',0).removeClass('glyphicon-minus').addClass('glyphicon-plus');
578
		}
579
		$(this).next().toggleClass('hidden');
580
	});
16858 naman 581
	$(document).on('click','.panel-heading a',function(){
14068 anikendra 582
		if($(this).find('.glyphicon-plus',0).length>0){
583
			$(this).find('.glyphicon-plus',0).removeClass('glyphicon-plus').addClass('glyphicon-minus');
584
		}else{
585
			$(this).find('.glyphicon-minus',0).removeClass('glyphicon-minus').addClass('glyphicon-plus');
586
		}
587
	});
14135 anikendra 588
	$(document).on('click','.prefcatselect',function(){
589
		$('.prefcatselect').removeClass('active')
590
		$(this).addClass('active');
591
		$('.categorypreferences').addClass('hidden');
592
		$('#cat-'+$(this).data('id')).toggleClass('hidden');
14150 anikendra 593
	});
594
	$(document).on('click','.refresh',function(){
595
		document.location.reload();
596
	});
14215 anikendra 597
	$(document).on('click','.hasmoretext',function(){
598
		$('#fulltext').html($(this).data('fulltext'));
599
		$('#fullTextModal').modal();
600
	});
14300 anikendra 601
	$(document).on('click','.favswitch',function(){
602
		$('.favswitch').removeClass('active')
603
		$(this).addClass('active');
604
		$('.clearfavs').addClass('hidden');
605
		$('.card').addClass('hidden');
606
		$('.'+$(this).data('type')).removeClass('hidden');
607
	});
14386 anikendra 608
	$(document).on('click','.brandpreferences .brands',function(){
609
		$(this).parents('.row').siblings('.controls').find('.editcategorypreferences',0).click();
610
	});
611
	$(document).on('click','.tryagainforliveprice',function(){		
612
		fetchLivePrice($(this).parent());
613
		$(this).parent().html('Getting Live Prices');
614
	});
14579 anikendra 615
	$(document).on('click','.alert > a',function(){		
616
		ga('send', 'event', 'notifications', 'click', $(this).html());
15550 anikendra 617
		pma.send('notifications','click',$(this).html(),me);
14579 anikendra 618
	});
619
	$(document).on('click','.banner',function(){		
620
		ga('send', 'event', 'banners', 'click', $(this).data('name'));
15550 anikendra 621
		pma.send('banners','click',$(this).data('name'),me);
14579 anikendra 622
	});
13992 anikendra 623
});
15310 anikendra 624
function setCookie(cname, cvalue, days, forceCookie) {
625
	if(typeof(Storage) !== "undefined" && !forceCookie) {
626
		localStorage.setItem(cname, cvalue);
627
	} else{
628
		var d = new Date();
629
	    d.setTime(d.getTime() + (days*24*60*60*1000));
630
	    var expires = "expires="+d.toUTCString();
631
	    document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
632
	}    
14849 anikendra 633
}
634
 
15310 anikendra 635
function getCookie(cname,forceCookie) {
636
	if(typeof(Storage) !== "undefined" && !forceCookie) {
637
	    return localStorage.getItem(cname);
638
	} else {	   
639
	    var name = cname + "=";
640
	    var ca = document.cookie.split(';');
641
	    for(var i=0; i<ca.length; i++) {
642
	        var c = ca[i];
643
	        while (c.charAt(0)==' ') c = c.substring(1);
644
	        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
645
	    }
646
	    return "";
647
	}
14849 anikendra 648
}
15310 anikendra 649
 
16495 anikendra 650
function needToDisplayPaytmPopup(me){
651
	var id = 'tip'
652
	var cname = 'paytm-help-count-'+me+'-'+id;
653
	var cookieval = getCookie(cname,1);
654
	if(!cookieval || cookieval == 'NaN' || cookieval==''){		
655
		incrementPopupCount(id,0,'paytm-help-count-');
656
		return true;
657
	} else if(cookieval < 5) {
658
		incrementPopupCount(id,cookieval,'paytm-help-count-');
659
		return true;
660
	} else{
661
		return false;
662
	}
663
};
664
 
14849 anikendra 665
function showpopup(id,count,interval){
14851 anikendra 666
	var cname = 'notif-count-'+me+'-'+id;
15797 anikendra 667
	var cookieval = getCookie(cname,1);
14851 anikendra 668
	var cname = 'notif-lastshown-'+me+'-'+id;
15797 anikendra 669
	var lastshown = getCookie(cname,1);
15310 anikendra 670
	if(!cookieval || cookieval == 'NaN' || cookieval==''){		
15077 anikendra 671
		incrementPopupCount(id,0,'notif-count-');
672
		setLastShown(id,'notif-lastshown-');
14849 anikendra 673
		return true;
674
	} else{
675
		var d = new Date();
676
		var t = d.getTime();
677
		if(t-lastshown>interval*60*1000){
678
			if(cookieval>=count){
679
				return false;
680
			}else{
15077 anikendra 681
				setLastShown(id,'notif-lastshown-');
682
				incrementPopupCount(id,cookieval,'notif-count-');
14849 anikendra 683
				return true;	
684
			}
685
		}
686
	}
687
}
15077 anikendra 688
function setLastShown(id,cookiename){
689
	var cname = cookiename+me+'-'+id;
14849 anikendra 690
	var d = new Date();
15721 anikendra 691
	setCookie(cname, d.getTime(), 365, 1);
14849 anikendra 692
}
15077 anikendra 693
function incrementPopupCount(id,currentCount,cookiename) {
694
	var cname = cookiename+me+'-'+id;
15721 anikendra 695
	setCookie(cname, parseInt(currentCount)+1, 365, 1);
14858 anikendra 696
}
697
var hidden, visibilityChange; 
698
function handleVisibilityChange() {
699
  if (document[hidden]) {
15058 anikendra 700
  	// pagetitle = document.title;
14858 anikendra 701
  } else {
15058 anikendra 702
  	// document.title = pagetitle;
14858 anikendra 703
  }
704
}
705
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support 
706
  hidden = "hidden";
707
  visibilityChange = "visibilitychange";
708
} else if (typeof document.mozHidden !== "undefined") {
709
  hidden = "mozHidden";
710
  visibilityChange = "mozvisibilitychange";
711
} else if (typeof document.msHidden !== "undefined") {
712
  hidden = "msHidden";
713
  visibilityChange = "msvisibilitychange";
714
} else if (typeof document.webkitHidden !== "undefined") {
715
  hidden = "webkitHidden";
716
  visibilityChange = "webkitvisibilitychange";
717
}
718
if (typeof document.addEventListener === "undefined" || 
719
  typeof document[hidden] === "undefined") {
18119 amit.gupta 720
  //console.log("This feature requires a browser, such as Google Chrome or Firefox, that supports the Page Visibility API.");
14858 anikendra 721
} else {
722
  // Handle page visibility change   
723
  document.addEventListener(visibilityChange, handleVisibilityChange, false);
724
}    
14936 anikendra 725
$('.notificationok').on('click',function(e){
14932 anikendra 726
	e.preventDefault();
14931 anikendra 727
	$('.notificationmodal').modal('hide');
15159 anikendra 728
	// setTimeout(function(){ $('.notificationmodal').modal('hide'); }, 1000);
16133 anikendra 729
	ga('send', 'event', 'popupnotification-'+$(this).parent().data('id'), 'ok', me);
730
	var properties = {};
731
	properties.id = String($(this).parent().data('id'));
732
	pma.send('popupnotification','click','ok',me,properties);
14932 anikendra 733
	document.location = $(this).parent().prop('href');
15015 anikendra 734
});
735
$(document).on('click','.clearfilter',function(){	
736
	$('.filterbrand').each(function(){
737
		$(this).prop('checked',false);
738
	});	
15550 anikendra 739
	ga('send', 'event', 'filter', 'brand', 'reset');
740
	pma.send('filters','brands','reset',me);
15015 anikendra 741
});
17691 naman 742
 
743
$(document).on('click','.clearfiltersubcategory',function(){	
744
	$('.filtersubcategory').each(function(){
745
		$(this).prop('checked',false);
746
	});	
747
	ga('send', 'event', 'filter', 'subcategory', 'reset');
748
	pma.send('filters','subcategory','reset',me);
749
});
15015 anikendra 750
$(document).on('click','.applyfilter',function(){	
15584 anikendra 751
	$(this).prop('disabled',true);
752
	$('#loadingModal').modal();
15015 anikendra 753
	var brands = [];
15026 anikendra 754
	var brandnames = [];
17691 naman 755
	var subcategories = [];
756
	var subcatnames = [];
15015 anikendra 757
	$('.filterbrand').each(function(){
758
		if($(this).prop('checked')){
759
			brands.push($(this).val());
15026 anikendra 760
			brandnames.push($(this).parent().siblings('.brandname').html());
15015 anikendra 761
		}		
762
	});
17691 naman 763
 
764
	$('.filtersubcategory').each(function(){
765
		if($(this).prop('checked')){
766
			subcategories.push($(this).val());
767
			subcatnames.push($(this).parent().siblings('.subcategoryname').html());
768
		}
769
	});
770
 
771
	if(brands.length==0 && subcategories.length==0){
15721 anikendra 772
		$('#loadingModal').modal('hide');
17691 naman 773
		$('#message').html('Please choose a few brands/subcategories first').removeClass('hidden');
774
		setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
775
		$(this).prop('disabled',false);
776
		return false;
777
	}else if(brands.length==0 && subcategories.length>0 ){
778
		setCookie('subcategorieschosen', subcategories, 0.25, true);
779
		var url = $('#subcategoryselecter').prop('action');
780
		ga('send', 'event', 'filter', 'subcategory', subcatnames.join('|'));
781
		properties = {};
782
		for(var i in subcatnames){
783
			properties['subcategories_'+i] = subcatnames[i];
784
		}
785
		pma.send('filters','subcategories','addfilter',me,properties);
786
		var postdata = {'user_id':me,'type':'subcategory','filters':subcatnames.join('|')};
787
		$.post( "/user_filters/add", postdata, function( data ) {
788
			$('#loadingModal').modal('hide');
789
			$(this).prop('disabled',false);
790
	  		document.location = url+'&subcategories='+subcategories.join('^');
791
		});	
792
	}else if(brands.length>0 && subcategories.length==0 ){
793
		setCookie('brandschosen', brands, 0.25, true);
794
		var url = $('#brandselecter').prop('action');
795
		ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
796
		properties = {};
797
		for(var i in brandnames){
798
			properties['brand_'+i] = brandnames[i];
799
		}
800
		pma.send('filters','brands','addfilter',me,properties);
801
		var postdata = {'user_id':me,'type':'brand','filters':brandnames.join('|')};
802
		$.post( "/user_filters/add", postdata, function( data ) {
803
			$('#loadingModal').modal('hide');
804
			$(this).prop('disabled',false);
805
	  		document.location = url+'&brands='+brands.join('^');
806
		});		
807
	}else if(brands.length>0 && subcategories.length>0 ){
808
		setCookie('brandschosen', brands, 0.25, true);
809
		setCookie('subcategorieschosen', subcategories, 0.25, true);
810
		var url = $('#brandselecter').prop('action');
811
		ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
812
		ga('send', 'event', 'filter', 'subcategory', subcatnames.join('|'));
813
		properties = {};
814
		for(var i in brandnames){
815
			properties['brand_'+i] = brandnames[i];
816
		}
817
		for(var i in subcatnames){
818
			properties['subcategory_'+i] = subcatnames[i];
819
		}
820
		pma.send('filters','brandsnsubcategories','addfilter',me,properties);
821
		var dataStr = brandnames.join('|');
822
		dataStr = dataStr + subcatnames.join('|');
823
		var postdata = {'user_id':me,'type':'brandnsubcategory','filters':dataStr};
824
		$.post( "/user_filters/add", postdata, function( data ) {
825
			$('#loadingModal').modal('hide');
826
			$(this).prop('disabled',false);
827
	  		document.location = url+'&brands='+brands.join('^')+"&subcategories="+subcategories.join("^");
828
		});
829
	}
830
 
831
	/*if(brands.length==0){
832
		$('#loadingModal').modal('hide');
15015 anikendra 833
		$('#message').html('Please choose a few brands first').removeClass('hidden');
834
		setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
15722 anikendra 835
		$(this).prop('disabled',false);
15015 anikendra 836
		return false;
837
	}else{
16240 anikendra 838
		setCookie('brandschosen', brands, 0.25, true);
15015 anikendra 839
		var url = $('#brandselecter').prop('action');
15026 anikendra 840
		ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
15550 anikendra 841
		properties = {};
842
		for(var i in brandnames){
843
			properties['brand_'+i] = brandnames[i];
844
		}
845
		pma.send('filters','brands','addfilter',me,properties);
15085 anikendra 846
		var postdata = {'user_id':me,'type':'brand','filters':brandnames.join('|')};
847
		$.post( "/user_filters/add", postdata, function( data ) {
15584 anikendra 848
			$('#loadingModal').modal('hide');
15722 anikendra 849
			$(this).prop('disabled',false);
15584 anikendra 850
	  		document.location = url+'&brands='+brands.join('^');
15085 anikendra 851
		});		
17691 naman 852
	}
853
 
854
	if(subcategories.length==0){
855
		$('#loadingModal').modal('hide');
856
		$('#message').html('Please choose a few Sub-categories first').removeClass('hidden');
857
		setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
858
		$(this).prop('disabled',false);
859
		return false;
860
	}else{
861
		setCookie('subcategorieschosen', subcategories, 0.25, true);
862
		var url = $('#subcategoryselecter').prop('action');
863
		ga('send', 'event', 'filter', 'subcategory', brandnames.join('|'));
864
		properties = {};
865
		for(var i in brandnames){
866
			properties['brand_'+i] = brandnames[i];
867
		}
868
		pma.send('filters','subcategories','addfilter',me,properties);
869
		var postdata = {'user_id':me,'type':'subcategory','filters':subcatnames.join('|')};
870
		$.post( "/user_filters/add", postdata, function( data ) {
871
			$('#loadingModal').modal('hide');
872
			$(this).prop('disabled',false);
873
	  		document.location = url+'&brands='+brands.join('^');
874
		});		
875
	}*/	
15015 anikendra 876
});
18066 naman 877
 
878
 
15015 anikendra 879
$(document).on('click','#showallbrands',function(){	
18066 naman 880
	$('.brand').removeClass('hidden');
881
    $('.subcategory').removeClass('hidden');
15015 anikendra 882
	$(this).hide();
15019 anikendra 883
});
884
$(document).on('input','#brandfilter',function(){	
885
	$('.brand').addClass('hidden');
886
	$('#showallbrands').hide();
887
	var that = $(this);
888
	$('li.brand').filter(function() { 
889
	  return $(this).data("brand").toLowerCase().indexOf($(that).val().toLowerCase()) != -1;
890
	}).removeClass('hidden','slow');
15042 anikendra 891
});
17707 naman 892
 
893
$(document).on('input','#subcatfilter',function(){	
894
	$('.subcategory').addClass('hidden');
895
	$('#showallbrands').hide();
896
	var that = $(this);
897
	$('li.subcategory').filter(function() { 
898
	  return $(this).data("brand").toLowerCase().indexOf($(that).val().toLowerCase()) != -1;
899
	}).removeClass('hidden','slow');
900
});
901
 
902
 
15077 anikendra 903
$(document).on('click','.filterbrand',function(){
904
	var clicked = $(this).parent().parent();
15042 anikendra 905
	// all the LIs above the clicked one
906
	var previousAll = clicked.prevAll();
907
 
908
	// only proceed if it's not already on top (no previous siblings)
909
	if(previousAll.length > 0) {
910
	// top LI
911
	var top = $(previousAll[previousAll.length - 1]);
912
 
913
	// immediately previous LI
914
	var previous = $(previousAll[0]);
915
 
916
	// how far up do we need to move the clicked LI?
917
	var moveUp = clicked.attr('offsetTop') - top.attr('offsetTop');
918
 
919
	// how far down do we need to move the previous siblings?
920
	var moveDown = (clicked.offset().top + clicked.outerHeight()) - (previous.offset().top + previous.outerHeight());
921
 
922
	// let's move stuff
923
	clicked.css('position', 'relative');
924
	previousAll.css('position', 'relative');
925
	clicked.animate({'top': -moveUp});
926
	previousAll.animate({'top': moveDown}, {complete: function() {
927
	  // rearrange the DOM and restore positioning when we're done moving
928
	  clicked.parent().prepend(clicked);
929
	  clicked.css({'position': 'static', 'top': 0});
930
	  previousAll.css({'position': 'static', 'top': 0}); 
931
	}});
932
	}
933
})
17691 naman 934
$(document).on('click','.filtersubcategory',function(){
935
	var clicked = $(this).parent().parent();
936
	// all the LIs above the clicked one
937
	var previousAll = clicked.prevAll();
938
 
939
	// only proceed if it's not already on top (no previous siblings)
940
	if(previousAll.length > 0) {
941
	// top LI
942
	var top = $(previousAll[previousAll.length - 1]);
943
 
944
	// immediately previous LI
945
	var previous = $(previousAll[0]);
946
 
947
	// how far up do we need to move the clicked LI?
948
	var moveUp = clicked.attr('offsetTop') - top.attr('offsetTop');
949
 
950
	// how far down do we need to move the previous siblings?
951
	var moveDown = (clicked.offset().top + clicked.outerHeight()) - (previous.offset().top + previous.outerHeight());
952
 
953
	// let's move stuff
954
	clicked.css('position', 'relative');
955
	previousAll.css('position', 'relative');
956
	clicked.animate({'top': -moveUp});
957
	previousAll.animate({'top': moveDown}, {complete: function() {
958
	  // rearrange the DOM and restore positioning when we're done moving
959
	  clicked.parent().prepend(clicked);
960
	  clicked.css({'position': 'static', 'top': 0});
961
	  previousAll.css({'position': 'static', 'top': 0}); 
962
	}});
963
	}
964
})
15042 anikendra 965
$(document).on('click','.clearfilters',function(){
15310 anikendra 966
	setCookie('brandschosen', '', -1, true);
17691 naman 967
	setCookie('subcategorieschosen','',-1, true);
15058 anikendra 968
	ga('send', 'event', 'filter', 'brand', 'clearfilters');
17691 naman 969
	ga('send', 'event', 'filter', 'subcategory', 'clearfilters');
15550 anikendra 970
	pma.send('filters','brands','clearfilters',me);
17691 naman 971
	pma.send('filters','subcategory','clearfilters',me);
15085 anikendra 972
	var postdata = {'user_id':me,'type':'clear'};
16240 anikendra 973
	$('#loadingModal').modal('show');
974
	$.post("/user_filters/add", postdata, function( data ) {		
17635 naman 975
	  	// document.location.reload();
976
	  	window.location.replace(window.location.href.split('?')[0]);
15085 anikendra 977
	});	
15042 anikendra 978
});
979
function selectChosenBrands(){
16261 anikendra 980
	var brandschosen = decodeURIComponent(getCookie('brandschosen',true));
17691 naman 981
	var subcategorieschosen = decodeURIComponent(getCookie('subcategorieschosen',true));
15042 anikendra 982
	if(brandschosen && brandschosen.length>0){
983
		var brands = brandschosen.split(',');
984
		for(var i in brands){
985
			$('.brand').filter(function() { 
986
			  	return $(this).data("brandid") == brands[i];
15077 anikendra 987
			}).removeClass('hidden').find('.filterbrand',0).trigger( "click" );
15042 anikendra 988
		}
989
	}
17691 naman 990
	if(subcategorieschosen && subcategorieschosen.length>0){
991
		var subcategories = subcategorieschosen.split(',');
992
		for(var i in subcategories){
993
			$('.subcategory').filter(function() { 
994
			  	return $(this).data("brandid") == subcategories[i];
995
			}).removeClass('hidden').find('.filtersubcategory',0).trigger( "click" );
996
		}
997
	}
15065 anikendra 998
}
15585 anikendra 999
function showPosition(position) {
15586 anikendra 1000
    setCookie('latitude',position.coords.latitude,1,true); 
1001
    setCookie('longitude',position.coords.longitude,1,true);	
15585 anikendra 1002
}
15065 anikendra 1003
$(function () {
18115 amit.gupta 1004
	$("#popovertrigger5").popover('hide').remove();
18033 amit.gupta 1005
	$('.data-up:first').append('<a id="popovertrigger5"  data-container="body" data-toggle="popover" data-placement="left" data-content="Quick buy multiple items together"></a>');
18176 amit.gupta 1006
	setPopOver("popovertrigger5", ".plusqtybutton", 'click', 5000);
18023 amit.gupta 1007
	callBackFunction = function(){
1008
		return document.location.pathname=="/category/6";		
1009
	};
18033 amit.gupta 1010
	setPopOver("popovertrigger4", callBackFunction);
18115 amit.gupta 1011
	//$('[data-toggle="popover"]#'+id).popover('show');
18023 amit.gupta 1012
	if (navigator.geolocation) {
1013
        navigator.geolocation.getCurrentPosition(showPosition);
1014
    } 
1015
});
1016
 
18176 amit.gupta 1017
function setPopOver(poid, callBack1, eventString, fadeAfter){
15310 anikendra 1018
	var cname = 'popover-count-'+me+'-'+poid;
15721 anikendra 1019
	var cookieval = getCookie(cname,1);
18023 amit.gupta 1020
	if(typeof callBack1=="function"){
1021
		if (callBack1()){
1022
			var cname = 'popover-count-'+me+'-'+poid;
1023
			var cookieval = getCookie(cname,1);
1024
			$('#' + poid).popover('hide');
1025
			if(!cookieval || cookieval == 'NaN' || cookieval == ''){
1026
				incrementPopupCount(poid,0,'popover-count-');
1027
			} else if(cookieval > 0) {
1028
				incrementPopupCount(poid, cookieval, 'popover-count-');
1029
			}
1030
			setLastShown(poid,'popover-lastshown-');
15310 anikendra 1031
		}
18023 amit.gupta 1032
	} else {
1033
		$('div.content').on(eventString, callBack1, function(){
1034
			var cname = 'popover-count-'+me+'-'+poid;
1035
			var cookieval = getCookie(cname,1);
1036
			$('#' + poid).popover('hide');
1037
			if(!cookieval || cookieval == 'NaN' || cookieval == ''){
1038
				incrementPopupCount(poid,0,'popover-count-');
1039
			} else if(cookieval > 0) {
1040
				incrementPopupCount(poid, cookieval, 'popover-count-');
1041
			}
1042
			setLastShown(poid,'popover-lastshown-');
1043
		}); 
18008 amit.gupta 1044
	}
18176 amit.gupta 1045
 
1046
	if(typeof fadeAfter!="undefined"){
18181 amit.gupta 1047
		var s = setInterval(function(){
1048
			if($('#' + poid +':in-viewport').length>0) {
1049
				setTimeout(function(){
1050
					$('#' + poid).popover('hide');
1051
				}, fadeAfter);
1052
				clearInterval(s);
1053
			}
1054
		}, 2000);
18176 amit.gupta 1055
	}
15310 anikendra 1056
 
15077 anikendra 1057
	var cname = 'popover-lastshown-'+me+'-'+poid;
15721 anikendra 1058
	var lastshown = getCookie(cname,1);
15310 anikendra 1059
	if(cookieval=='' || cookieval == 'NaN' || !cookieval){				
15077 anikendra 1060
		showpopover(poid);
15521 anikendra 1061
	} 
1062
	//Donot show popover anymore as long as we don't find a suitable solution
15721 anikendra 1063
	else{
15077 anikendra 1064
		var d = new Date();
1065
		var t = d.getTime();
15085 anikendra 1066
		if(t-lastshown>18*3600*1000){
15310 anikendra 1067
			if(cookieval>=2){
15077 anikendra 1068
				return false;
1069
			}else{
15310 anikendra 1070
				showpopover(poid);				
15077 anikendra 1071
			}
1072
		}
15721 anikendra 1073
	}
15583 anikendra 1074
	ga('send', 'event', 'popover', me, cookieval);
18023 amit.gupta 1075
}
16656 anikendra 1076
$('.getapp').on('click',function(){
17102 anikendra 1077
	/*var that = $(this);
16656 anikendra 1078
	var req = $.ajax({
1079
		url: 'http://104.200.25.40:8057/appAffiliates/generateRedirectUrl/'+me+'/'+$(that).data('id'),
1080
		// Tell jQuery we're expecting JSONP
1081
		dataType: "jsonp",
1082
		// Tell YQL what we want and that we want JSON			
1083
		method: 'get',
1084
		// timeout: 30000,
1085
		// Work with the response
1086
		success: function( response ) {
1087
			console.log(response);
1088
		}
17102 anikendra 1089
	});*/
1090
	$('#loadingModal').modal('show');
1091
	document.location = '/abouts/apphint';
16656 anikendra 1092
});
15077 anikendra 1093
function showpopover(id){
18036 amit.gupta 1094
	try {
1095
		$('[data-toggle="popover"]#'+id).popover({html:true,viewport:{container:'body'}, trigger:'manual'});
1096
		$('[data-toggle="popover"]#'+id).popover('show');		
1097
	}catch(err){
1098
		//
1099
	}
15085 anikendra 1100
}
1101
$(document).on('click','.nodeals',function(){
1102
	document.location = $(this).data('href');
16018 anikendra 1103
});
1104
$(document).on('click','.selectbrand',function(e){
1105
	e.preventDefault();
1106
	var brands = $(this).data('id');
1107
	var brandname = $(this).html();
18119 amit.gupta 1108
	//console.log(brandname);
17703 naman 1109
 
16018 anikendra 1110
	setCookie('brandschosen', brands, 1, true);
1111
	var url = $(this).data('href');
1112
	ga('send', 'event', 'selectbrand', 'brand', brandname);
1113
	properties = {};
1114
	properties['brand'] = brandname;
1115
	pma.send('filters','brands','selectbrand',me,properties);
1116
	var postdata = {'user_id':me,'type':'brand','filters':brandname};
1117
	$.post( "/user_filters/add", postdata, function( data ) {
1118
		$('#loadingModal').modal('hide');
1119
		$(this).addClass('activebrand');
1120
  		document.location = url+'&brands='+brands;
1121
	});
1122
});
17703 naman 1123
 
1124
$(document).on('click','.selectsubcat',function(e){
1125
	e.preventDefault();
17707 naman 1126
	$('.clearfilters').click();
17703 naman 1127
	var brands = $(this).data('id');
1128
	var brandname = $(this).html();
18119 amit.gupta 1129
	//console.log(brandname);
17703 naman 1130
 
1131
	setCookie('subcategorieschosen', brands, 1, true);
1132
	var url = $(this).data('href');
1133
	// alert(url);
1134
	// ga('send', 'event', 'subcategorieschosen', 'brand', brandname);
1135
	document.location = url;
1136
	// properties = {};
1137
	// properties['brand'] = brandname;
1138
	// pma.send('filters','brands','selectbrand',me,properties);
1139
	// // var postdata = {'user_id':me,'type':'brand','filters':brandname};
1140
	// $.post( "/user_filters/add", postdata, function( data ) {
1141
	// 	$('#loadingModal').modal('hide');
1142
	// 	$(this).addClass('activebrand');
1143
 //  		document.location = url+'&brands='+brands;
1144
	// });
1145
});
1146
 
16495 anikendra 1147
$(document).on('click','.shownexttip',function(e){
1148
	$(this).addClass('hidden').remove();
1149
	$('#firsttip').addClass('hidden').remove();
1150
	$('#secondtip').removeClass('hidden');
1151
	$('.gotit').removeClass('hidden');
1152
});
15128 anikendra 1153
var Base64 = {
1154
    _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
1155
    encode: function(input) {
1156
        var output = "";
1157
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
1158
        var i = 0;
1159
        input = Base64._utf8_encode(input);
1160
        while (i < input.length) {
1161
            chr1 = input.charCodeAt(i++);
1162
            chr2 = input.charCodeAt(i++);
1163
            chr3 = input.charCodeAt(i++);
1164
 
1165
            enc1 = chr1 >> 2;
1166
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
1167
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
1168
            enc4 = chr3 & 63;
1169
            if (isNaN(chr2)) {
1170
                enc3 = enc4 = 64;
1171
            } else if (isNaN(chr3)) {
1172
                enc4 = 64;
1173
            }
1174
            output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
1175
        }
1176
        return output;
1177
    },
1178
 
1179
 
1180
    decode: function(input) {
1181
        var output = "";
1182
        var chr1, chr2, chr3;
1183
        var enc1, enc2, enc3, enc4;
1184
        var i = 0;
1185
        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
1186
        while (i < input.length) {
1187
            enc1 = this._keyStr.indexOf(input.charAt(i++));
1188
            enc2 = this._keyStr.indexOf(input.charAt(i++));
1189
            enc3 = this._keyStr.indexOf(input.charAt(i++));
1190
            enc4 = this._keyStr.indexOf(input.charAt(i++));
1191
            chr1 = (enc1 << 2) | (enc2 >> 4);
1192
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
1193
            chr3 = ((enc3 & 3) << 6) | enc4;
1194
            output = output + String.fromCharCode(chr1);
1195
            if (enc3 != 64) {
1196
                output = output + String.fromCharCode(chr2);
1197
            }
1198
            if (enc4 != 64) {
1199
                output = output + String.fromCharCode(chr3);
1200
            }
1201
        }
1202
        output = Base64._utf8_decode(output);
1203
        return output;
1204
    },
1205
 
1206
    _utf8_encode: function(string) {
1207
        string = string.replace(/\r\n/g, "\n");
1208
        var utftext = "";
1209
        for (var n = 0; n < string.length; n++) {
1210
            var c = string.charCodeAt(n);
1211
            if (c < 128) {
1212
                utftext += String.fromCharCode(c);
1213
            }
1214
            else if ((c > 127) && (c < 2048)) {
1215
                utftext += String.fromCharCode((c >> 6) | 192);
1216
                utftext += String.fromCharCode((c & 63) | 128);
1217
            }
1218
            else {
1219
                utftext += String.fromCharCode((c >> 12) | 224);
1220
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
1221
                utftext += String.fromCharCode((c & 63) | 128);
1222
            }
1223
        }
1224
        return utftext;
1225
    },
1226
 
1227
    _utf8_decode: function(utftext) {
1228
        var string = "";
1229
        var i = 0;
1230
        var c = c1 = c2 = 0;
1231
        while (i < utftext.length) {
1232
            c = utftext.charCodeAt(i);
1233
            if (c < 128) {
1234
                string += String.fromCharCode(c);
1235
                i++;
1236
            }
1237
            else if ((c > 191) && (c < 224)) {
1238
                c2 = utftext.charCodeAt(i + 1);
1239
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
1240
                i += 2;
1241
            }
1242
            else {
1243
                c2 = utftext.charCodeAt(i + 1);
1244
                c3 = utftext.charCodeAt(i + 2);
1245
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
1246
                i += 3;
1247
            }
1248
        }
1249
        return string;
1250
    }
15550 anikendra 1251
}
1252
 
1253
 
1254
var pma = new function() {
15584 anikendra 1255
    this.apiurl = "http://45.33.50.227:8081/";
15550 anikendra 1256
    this.endpoints = {'identify':'identify','profile':'profile','track':'track'};
1257
 
1258
    this.send = function (category,action,label,user_id,properties) {
15585 anikendra 1259
    	if(!properties){
1260
    		properties = {};
1261
    	}
1262
    	properties.location = window.location.href;
1263
    	// properties.appCodeName = navigator.appCodeName;
1264
    	// properties.appName = navigator.appName;
1265
    	// properties.appVersion = navigator.appVersion;
1266
    	properties.cookieEnabled = String(navigator.cookieEnabled);
1267
    	properties.platform = navigator.platform;
1268
    	properties.userAgent = navigator.userAgent;
1269
    	properties.ip = ip;
1270
	  	if (navigator.geolocation) {
15586 anikendra 1271
	  		if(getCookie('latitude',true)){
1272
	  			properties.latitude = getCookie('latitude');
1273
	  		}	  		
1274
	  		if(getCookie('longitude',true)){
1275
		  		properties.longitude = getCookie('longitude');
1276
		  	}
15585 anikendra 1277
	  	}
1278
	  	properties.screenHeight = String(screen.height);
1279
	  	properties.screenWidth = String(screen.width);
1280
    	// console.log(properties);
15550 anikendra 1281
 		$.ajax({
1282
			url: this.apiurl + this.endpoints.track,
1283
			data: {'category':category,'action':action,'label':label,'user_id':user_id,'properties':cassandraMAP.stringify(properties)},
1284
			// Tell jQuery we're expecting JSONP
1285
			dataType: "json",
1286
			// Tell YQL what we want and that we want JSON			
1287
			method: 'post',
1288
			// Work with the response
1289
			success: function( response ) {
1290
				//Well, well, well :)
1291
			}
1292
		});       
1293
    };
1294
 
1295
    this.formDataToObject = function(formdata){
1296
    	var properties = {};
1297
    	var keys = [];
1298
		var formdata = JSON.parse(JSON.stringify(formdata));
1299
		for (var i in formdata) {
1300
			var key = formdata[i].name;
1301
			if(index = keys.indexOf(key)==-1){
1302
				properties[key] = formdata[i].value;
1303
			}else{
1304
				properties[key+'_'+i] = formdata[i].value;
1305
			}
1306
			keys.push(key);
1307
		};
1308
		return properties;
1309
	}
16704 anikendra 1310
}
1311
//App page
1312
$.fn.stars = function() {
1313
    return $(this).each(function() {
1314
        // Get the value
1315
        var val = parseFloat($(this).html());
1316
        // Make sure that the value is in 0 - 5 range, multiply to get width
1317
        val = Math.round(val * 2) / 2;
1318
        var size = Math.max(0, (Math.min(5, val))) * 16;
1319
        // Create stars holder
1320
        var $span = $('<span />').width(size);
1321
        // Replace the numerical value with stars
1322
        $(this).html($span);
1323
    });
1324
}
1325
$(function() {
1326
    $('span.stars').stars();	
18023 amit.gupta 1327
});
1328
 
1329
function sendCartChangeEvent(){
1330
	var cart_details_old = localStorage.getItem('cart_details_old');
1331
	var cart_details = localStorage.getItem('cart_details');
1332
	if (cart_details_old == cart_details){
1333
		return;
1334
	} else if(cart_details!=null){
1335
		JSON.parse(cart_details);
1336
 
1337
	}
1338
}
1339
 
1340
//setInterval(30000, )