Subversion Repositories SmartDukaan

Rev

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