Subversion Repositories SmartDukaan

Rev

Rev 16940 | Rev 17017 | 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
47
	var paytmactive = getCookie('homeShop18',1);
48
	if(paytmactive && paytmactive == 'true'){		
49
		document.location = url;	
50
		pma.send('apk','homeShop18','active',me,null);
51
	}else{
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
						}
16397 anikendra 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
379
				  	  else if(store == 7)
380
				  	  {
381
 
382
				  			redirectTohomeshop18(response.url);	
383
 
384
				  	  }
385
					  else if (store == 3 || store == 2) {
15310 anikendra 386
						if (store == 2){
387
							response.url = 'http://mobilehotindia.com/r.html?'+Base64.encode(response.url);
388
						}
16940 anikendra 389
						if (store == 3){
390
							response.url = '/r.html?'+Base64.encode(response.url);
391
						}
15188 anikendra 392
						if(response.showmessage == 1) {
393
							$('#loadingModal').modal('hide');
394
							$('#customMessage').html(response.message);
15310 anikendra 395
							$('#customMessageModal').modal('show');							
15311 anikendra 396
							setTimeout(function(){ document.location = response.url;}, 1000*3);			
15310 anikendra 397
						} else{
15206 anikendra 398
							document.location = response.url;	
15188 anikendra 399
						}
15203 anikendra 400
					} else {
16940 anikendra 401
						response.url = '/r.html?'+Base64.encode(response.url);
15128 anikendra 402
						document.location = response.url;
403
					}										
13579 anikendra 404
				}
15310 anikendra 405
			},
406
			error: function() {
407
				document.location = url;
13579 anikendra 408
			}
409
		});
14432 anikendra 410
		ga('send', 'event', 'product', 'click', $(this).data('url'));
15550 anikendra 411
		var properties = {};
412
		properties.sku = String($(this).data('id'));
413
		properties.source = String($(this).data('source'));
414
		properties.url = encodeURIComponent($(this).data('url'));
415
		properties.price = String($(this).data('price'));
416
		pma.send('products','url','click',me,properties);
13583 anikendra 417
	});
13719 anikendra 418
	$('.jscroll-inner').on('click','.likedeal',function(e){	
13583 anikendra 419
		var that = $(this);
13682 anikendra 420
		if($(that).hasClass('active')){
13583 anikendra 421
			//User has already liked it,so remove like
422
			var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/like";	
423
		}else{
424
			var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/like";
425
		}
426
		$.ajax({
427
			url: url,
428
			// The name of the callback parameter, as specified by the YQL service
429
			jsonp: "callback",
430
			// Tell jQuery we're expecting JSONP
431
			dataType: "jsonp",
432
			// Tell YQL what we want and that we want JSON
433
			data: {
434
				format: "json"
435
			},
436
			// Work with the response
437
			success: function( response ) {
438
				if(response.success){
13672 anikendra 439
					$(that).toggleClass('active');
440
					$(that).parent().find('li.dislikedeal',0).removeClass('active');
13583 anikendra 441
				}
442
			}
443
		});
13686 anikendra 444
		ga('send', 'event', 'product', 'like', $(this).data('id'));
15550 anikendra 445
		var properties = {};
446
		properties.sku = String($(this).data('id'));
447
		pma.send('products','favourites','like',me,properties);
13583 anikendra 448
	});
13688 anikendra 449
	$('#myModal').on('click','#unlikebtn',function(e){
13682 anikendra 450
		e.preventDefault();
451
		var url = $('#unlikeproductform').attr('action')+'?'+$('#unlikeproductform').serialize()
452
		$.ajax({
453
			url: url,
454
			// The name of the callback parameter, as specified by the YQL service
455
			jsonp: "callback",
456
			// Tell jQuery we're expecting JSONP
457
			dataType: "jsonp",
458
			// Tell YQL what we want and that we want JSON
459
			data: {
460
				format: "json"
461
			},
462
			// Work with the response
463
			success: function( response ) {
464
			}
465
		});
466
		$('#myModal').modal('hide');
13686 anikendra 467
		ga('send', 'event', 'brand', 'hide', $('#myModal').find('#productToHide',0).val());
15550 anikendra 468
		pma.send('brands','hide',$('#myModal').find('#productToHide',0).val(),me);
13682 anikendra 469
	})
13719 anikendra 470
	$('.jscroll-inner').on('click','.dislikedeal',function(e){			
13583 anikendra 471
		var that = $(this);
13682 anikendra 472
		if($(that).hasClass('active')){
13583 anikendra 473
			//User has already liked it,so remove like
474
			var url = apihost+"/user_actions/rem/"+me+"/"+$(this).data('id')+"/dislike";	
475
		}else{
13682 anikendra 476
			$('#myModal').find('#productToHide',0).val($(this).data('id'));
13583 anikendra 477
			var url = apihost+"/user_actions/update/"+me+"/"+$(this).data('id')+"/dislike";
478
		}
479
		$.ajax({
480
			url: url,
481
			// The name of the callback parameter, as specified by the YQL service
482
			jsonp: "callback",
483
			// Tell jQuery we're expecting JSONP
484
			dataType: "jsonp",
485
			// Tell YQL what we want and that we want JSON
486
			data: {
487
				format: "json"
488
			},
489
			// Work with the response
490
			success: function( response ) {
491
				if(response.success){
13672 anikendra 492
					$(that).toggleClass('active');
493
					$(that).parent().find('li.likedeal',0).removeClass('active');
13583 anikendra 494
				}
495
			}
496
		});
13686 anikendra 497
		ga('send', 'event', 'product', 'dislike', $(this).data('id'));
15550 anikendra 498
		var properties = {};
499
		properties.sku = String($(this).data('id'));
500
		pma.send('products','favourites','dislike',me,properties);
13583 anikendra 501
	});
13731 anikendra 502
	$('.deletefav').on('click',function(){
503
		var that = $(this);
504
		$('#loadingModal').modal();
505
		var url = apihost+"/user_actions/deletefav/"+me+"/"+$(this).data('id');			
506
		$.ajax({
507
			url: url,
508
			// The name of the callback parameter, as specified by the YQL service
509
			jsonp: "callback",
510
			// Tell jQuery we're expecting JSONP
511
			dataType: "jsonp",
512
			// Tell YQL what we want and that we want JSON
513
			data: {
514
				format: "json"
515
			},
516
			// Work with the response
517
			success: function( response ) {
518
				$('#loadingModal').modal('hide');
519
				if(response.success){			
520
					$('#fav-'+$(that).data('id')).hide('slow');
521
				}
522
			}
523
		});
524
		ga('send', 'event', 'favourites', 'remove', $(this).data('id'));
15550 anikendra 525
		var properties = {};
526
		properties.sku = String($(this).data('id'));
527
		pma.send('products','favourites','remove',me,properties);
13731 anikendra 528
	});
529
	$('.clearfavs').on('click',function(){
530
		var that = $(this);
531
		$('#loadingModal').modal();
14300 anikendra 532
		var url = apihost+"/user_actions/deleteallfavs/"+me+'/'+$(this).data('type');			
13731 anikendra 533
		$.ajax({
534
			url: url,
535
			// The name of the callback parameter, as specified by the YQL service
536
			jsonp: "callback",
537
			// Tell jQuery we're expecting JSONP
538
			dataType: "jsonp",
539
			// Tell YQL what we want and that we want JSON
540
			data: {
541
				format: "json"
542
			},
543
			// Work with the response
544
			success: function( response ) {
545
				$('#loadingModal').modal('hide');
546
				if(response.success){			
547
					$('.deletefav').each(function(){
548
						$('#fav-'+$(this).data('id')).hide('slow');
549
					})					
550
				}
551
				$(that).hide();
552
			}
553
		});
554
		ga('send', 'event', 'favourites', 'removeall', me);
15550 anikendra 555
		pma.send('products','favourites','removeall',me);
13731 anikendra 556
	});
13759 anikendra 557
	$('.revealbrands').on('click',function(){
558
		$(this).parent().find('.notfeatured').toggleClass('hidden');
559
		if($(this).html()=='Others'){
560
			$(this).html('Hide');
561
		}else{
562
			$(this).html('Others');
563
		}
564
	});
14068 anikendra 565
	$(document).on('click','.creditedcashbacks',function(){
566
		if($(this).find('.glyphicon-plus',0).length>0){
567
			$(this).find('.glyphicon-plus',0).removeClass('glyphicon-plus').addClass('glyphicon-minus');
568
		}else{
569
			$(this).find('.glyphicon-minus',0).removeClass('glyphicon-minus').addClass('glyphicon-plus');
570
		}
571
		$(this).next().toggleClass('hidden');
572
	});
16858 naman 573
	$(document).on('click','.panel-heading a',function(){
14068 anikendra 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
	});
14135 anikendra 580
	$(document).on('click','.prefcatselect',function(){
581
		$('.prefcatselect').removeClass('active')
582
		$(this).addClass('active');
583
		$('.categorypreferences').addClass('hidden');
584
		$('#cat-'+$(this).data('id')).toggleClass('hidden');
14150 anikendra 585
	});
586
	$(document).on('click','.refresh',function(){
587
		document.location.reload();
588
	});
14215 anikendra 589
	$(document).on('click','.hasmoretext',function(){
590
		$('#fulltext').html($(this).data('fulltext'));
591
		$('#fullTextModal').modal();
592
	});
14300 anikendra 593
	$(document).on('click','.favswitch',function(){
594
		$('.favswitch').removeClass('active')
595
		$(this).addClass('active');
596
		$('.clearfavs').addClass('hidden');
597
		$('.card').addClass('hidden');
598
		$('.'+$(this).data('type')).removeClass('hidden');
599
	});
14386 anikendra 600
	$(document).on('click','.brandpreferences .brands',function(){
601
		$(this).parents('.row').siblings('.controls').find('.editcategorypreferences',0).click();
602
	});
603
	$(document).on('click','.tryagainforliveprice',function(){		
604
		fetchLivePrice($(this).parent());
605
		$(this).parent().html('Getting Live Prices');
606
	});
14579 anikendra 607
	$(document).on('click','.alert > a',function(){		
608
		ga('send', 'event', 'notifications', 'click', $(this).html());
15550 anikendra 609
		pma.send('notifications','click',$(this).html(),me);
14579 anikendra 610
	});
611
	$(document).on('click','.banner',function(){		
612
		ga('send', 'event', 'banners', 'click', $(this).data('name'));
15550 anikendra 613
		pma.send('banners','click',$(this).data('name'),me);
14579 anikendra 614
	});
13992 anikendra 615
});
15310 anikendra 616
function setCookie(cname, cvalue, days, forceCookie) {
617
	if(typeof(Storage) !== "undefined" && !forceCookie) {
618
		localStorage.setItem(cname, cvalue);
619
	} else{
620
		var d = new Date();
621
	    d.setTime(d.getTime() + (days*24*60*60*1000));
622
	    var expires = "expires="+d.toUTCString();
623
	    document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
624
	}    
14849 anikendra 625
}
626
 
15310 anikendra 627
function getCookie(cname,forceCookie) {
628
	if(typeof(Storage) !== "undefined" && !forceCookie) {
629
	    return localStorage.getItem(cname);
630
	} else {	   
631
	    var name = cname + "=";
632
	    var ca = document.cookie.split(';');
633
	    for(var i=0; i<ca.length; i++) {
634
	        var c = ca[i];
635
	        while (c.charAt(0)==' ') c = c.substring(1);
636
	        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
637
	    }
638
	    return "";
639
	}
14849 anikendra 640
}
15310 anikendra 641
 
16495 anikendra 642
function needToDisplayPaytmPopup(me){
643
	var id = 'tip'
644
	var cname = 'paytm-help-count-'+me+'-'+id;
645
	var cookieval = getCookie(cname,1);
646
	if(!cookieval || cookieval == 'NaN' || cookieval==''){		
647
		incrementPopupCount(id,0,'paytm-help-count-');
648
		return true;
649
	} else if(cookieval < 5) {
650
		incrementPopupCount(id,cookieval,'paytm-help-count-');
651
		return true;
652
	} else{
653
		return false;
654
	}
655
};
656
 
14849 anikendra 657
function showpopup(id,count,interval){
14851 anikendra 658
	var cname = 'notif-count-'+me+'-'+id;
15797 anikendra 659
	var cookieval = getCookie(cname,1);
14851 anikendra 660
	var cname = 'notif-lastshown-'+me+'-'+id;
15797 anikendra 661
	var lastshown = getCookie(cname,1);
15310 anikendra 662
	if(!cookieval || cookieval == 'NaN' || cookieval==''){		
15077 anikendra 663
		incrementPopupCount(id,0,'notif-count-');
664
		setLastShown(id,'notif-lastshown-');
14849 anikendra 665
		return true;
666
	} else{
667
		var d = new Date();
668
		var t = d.getTime();
669
		if(t-lastshown>interval*60*1000){
670
			if(cookieval>=count){
671
				return false;
672
			}else{
15077 anikendra 673
				setLastShown(id,'notif-lastshown-');
674
				incrementPopupCount(id,cookieval,'notif-count-');
14849 anikendra 675
				return true;	
676
			}
677
		}
678
	}
679
}
15077 anikendra 680
function setLastShown(id,cookiename){
681
	var cname = cookiename+me+'-'+id;
14849 anikendra 682
	var d = new Date();
15721 anikendra 683
	setCookie(cname, d.getTime(), 365, 1);
14849 anikendra 684
}
15077 anikendra 685
function incrementPopupCount(id,currentCount,cookiename) {
686
	var cname = cookiename+me+'-'+id;
15721 anikendra 687
	setCookie(cname, parseInt(currentCount)+1, 365, 1);
14858 anikendra 688
}
689
var hidden, visibilityChange; 
690
function handleVisibilityChange() {
691
  if (document[hidden]) {
15058 anikendra 692
  	// pagetitle = document.title;
14858 anikendra 693
  } else {
15058 anikendra 694
  	// document.title = pagetitle;
14858 anikendra 695
  }
696
}
697
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support 
698
  hidden = "hidden";
699
  visibilityChange = "visibilitychange";
700
} else if (typeof document.mozHidden !== "undefined") {
701
  hidden = "mozHidden";
702
  visibilityChange = "mozvisibilitychange";
703
} else if (typeof document.msHidden !== "undefined") {
704
  hidden = "msHidden";
705
  visibilityChange = "msvisibilitychange";
706
} else if (typeof document.webkitHidden !== "undefined") {
707
  hidden = "webkitHidden";
708
  visibilityChange = "webkitvisibilitychange";
709
}
710
if (typeof document.addEventListener === "undefined" || 
711
  typeof document[hidden] === "undefined") {
15077 anikendra 712
  console.log("This feature requires a browser, such as Google Chrome or Firefox, that supports the Page Visibility API.");
14858 anikendra 713
} else {
714
  // Handle page visibility change   
715
  document.addEventListener(visibilityChange, handleVisibilityChange, false);
716
}    
14936 anikendra 717
$('.notificationok').on('click',function(e){
14932 anikendra 718
	e.preventDefault();
14931 anikendra 719
	$('.notificationmodal').modal('hide');
15159 anikendra 720
	// setTimeout(function(){ $('.notificationmodal').modal('hide'); }, 1000);
16133 anikendra 721
	ga('send', 'event', 'popupnotification-'+$(this).parent().data('id'), 'ok', me);
722
	var properties = {};
723
	properties.id = String($(this).parent().data('id'));
724
	pma.send('popupnotification','click','ok',me,properties);
14932 anikendra 725
	document.location = $(this).parent().prop('href');
15015 anikendra 726
});
727
$(document).on('click','.clearfilter',function(){	
728
	$('.filterbrand').each(function(){
729
		$(this).prop('checked',false);
730
	});	
15550 anikendra 731
	ga('send', 'event', 'filter', 'brand', 'reset');
732
	pma.send('filters','brands','reset',me);
15015 anikendra 733
});
734
$(document).on('click','.applyfilter',function(){	
15584 anikendra 735
	$(this).prop('disabled',true);
736
	$('#loadingModal').modal();
15015 anikendra 737
	var brands = [];
15026 anikendra 738
	var brandnames = [];
15015 anikendra 739
	$('.filterbrand').each(function(){
740
		if($(this).prop('checked')){
741
			brands.push($(this).val());
15026 anikendra 742
			brandnames.push($(this).parent().siblings('.brandname').html());
15015 anikendra 743
		}		
744
	});
745
	if(brands.length==0){
15721 anikendra 746
		$('#loadingModal').modal('hide');
15015 anikendra 747
		$('#message').html('Please choose a few brands first').removeClass('hidden');
748
		setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
15722 anikendra 749
		$(this).prop('disabled',false);
15015 anikendra 750
		return false;
751
	}else{
16240 anikendra 752
		setCookie('brandschosen', brands, 0.25, true);
15015 anikendra 753
		var url = $('#brandselecter').prop('action');
15026 anikendra 754
		ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
15550 anikendra 755
		properties = {};
756
		for(var i in brandnames){
757
			properties['brand_'+i] = brandnames[i];
758
		}
759
		pma.send('filters','brands','addfilter',me,properties);
15085 anikendra 760
		var postdata = {'user_id':me,'type':'brand','filters':brandnames.join('|')};
761
		$.post( "/user_filters/add", postdata, function( data ) {
15584 anikendra 762
			$('#loadingModal').modal('hide');
15722 anikendra 763
			$(this).prop('disabled',false);
15584 anikendra 764
	  		document.location = url+'&brands='+brands.join('^');
15085 anikendra 765
		});		
15015 anikendra 766
	}	
767
});
768
$(document).on('click','#showallbrands',function(){	
769
	$('.hidden').removeClass('hidden');
770
	$(this).hide();
15019 anikendra 771
});
772
$(document).on('input','#brandfilter',function(){	
773
	$('.brand').addClass('hidden');
774
	$('#showallbrands').hide();
775
	var that = $(this);
776
	$('li.brand').filter(function() { 
777
	  return $(this).data("brand").toLowerCase().indexOf($(that).val().toLowerCase()) != -1;
778
	}).removeClass('hidden','slow');
15042 anikendra 779
});
15077 anikendra 780
$(document).on('click','.filterbrand',function(){
781
	var clicked = $(this).parent().parent();
15042 anikendra 782
	// all the LIs above the clicked one
783
	var previousAll = clicked.prevAll();
784
 
785
	// only proceed if it's not already on top (no previous siblings)
786
	if(previousAll.length > 0) {
787
	// top LI
788
	var top = $(previousAll[previousAll.length - 1]);
789
 
790
	// immediately previous LI
791
	var previous = $(previousAll[0]);
792
 
793
	// how far up do we need to move the clicked LI?
794
	var moveUp = clicked.attr('offsetTop') - top.attr('offsetTop');
795
 
796
	// how far down do we need to move the previous siblings?
797
	var moveDown = (clicked.offset().top + clicked.outerHeight()) - (previous.offset().top + previous.outerHeight());
798
 
799
	// let's move stuff
800
	clicked.css('position', 'relative');
801
	previousAll.css('position', 'relative');
802
	clicked.animate({'top': -moveUp});
803
	previousAll.animate({'top': moveDown}, {complete: function() {
804
	  // rearrange the DOM and restore positioning when we're done moving
805
	  clicked.parent().prepend(clicked);
806
	  clicked.css({'position': 'static', 'top': 0});
807
	  previousAll.css({'position': 'static', 'top': 0}); 
808
	}});
809
	}
810
})
811
$(document).on('click','.clearfilters',function(){
15310 anikendra 812
	setCookie('brandschosen', '', -1, true);
15058 anikendra 813
	ga('send', 'event', 'filter', 'brand', 'clearfilters');
15550 anikendra 814
	pma.send('filters','brands','clearfilters',me);
15085 anikendra 815
	var postdata = {'user_id':me,'type':'clear'};
16240 anikendra 816
	$('#loadingModal').modal('show');
817
	$.post("/user_filters/add", postdata, function( data ) {		
818
	  	document.location.reload();
15085 anikendra 819
	});	
15042 anikendra 820
});
821
function selectChosenBrands(){
16261 anikendra 822
	var brandschosen = decodeURIComponent(getCookie('brandschosen',true));
15042 anikendra 823
	if(brandschosen && brandschosen.length>0){
824
		var brands = brandschosen.split(',');
825
		for(var i in brands){
826
			$('.brand').filter(function() { 
827
			  	return $(this).data("brandid") == brands[i];
15077 anikendra 828
			}).removeClass('hidden').find('.filterbrand',0).trigger( "click" );
15042 anikendra 829
		}
830
	}
15065 anikendra 831
}
15585 anikendra 832
function showPosition(position) {
15586 anikendra 833
    setCookie('latitude',position.coords.latitude,1,true); 
834
    setCookie('longitude',position.coords.longitude,1,true);	
15585 anikendra 835
}
15065 anikendra 836
$(function () {
15077 anikendra 837
	var poid = 'popovertrigger';
15310 anikendra 838
	var cname = 'popover-count-'+me+'-'+poid;
15721 anikendra 839
	var cookieval = getCookie(cname,1);
15310 anikendra 840
	$('#dropdownMenu1').on('click',function(){
841
		var cname = 'popover-count-'+me+'-'+poid;
15721 anikendra 842
		var cookieval = getCookie(cname,1);
15310 anikendra 843
		$('#popovertrigger').popover('hide');
844
		if(!cookieval || cookieval == 'NaN' || cookieval == ''){
845
			incrementPopupCount(poid,0,'popover-count-');
15526 anikendra 846
		} else if(cookieval > 0) {
15310 anikendra 847
			incrementPopupCount(poid, cookieval, 'popover-count-');
848
		}
849
		setLastShown(poid,'popover-lastshown-');
850
	})
851
 
15077 anikendra 852
	var cname = 'popover-lastshown-'+me+'-'+poid;
15721 anikendra 853
	var lastshown = getCookie(cname,1);
15310 anikendra 854
	if(cookieval=='' || cookieval == 'NaN' || !cookieval){				
15077 anikendra 855
		showpopover(poid);
15521 anikendra 856
	} 
857
	//Donot show popover anymore as long as we don't find a suitable solution
15721 anikendra 858
	else{
15077 anikendra 859
		var d = new Date();
860
		var t = d.getTime();
15085 anikendra 861
		if(t-lastshown>18*3600*1000){
15310 anikendra 862
			if(cookieval>=2){
15077 anikendra 863
				return false;
864
			}else{
15310 anikendra 865
				showpopover(poid);				
15077 anikendra 866
			}
867
		}
15721 anikendra 868
	}
15583 anikendra 869
	ga('send', 'event', 'popover', me, cookieval);
15585 anikendra 870
	if (navigator.geolocation) {
871
        navigator.geolocation.getCurrentPosition(showPosition);
872
    } 
15077 anikendra 873
});
16656 anikendra 874
$('.getapp').on('click',function(){
875
	var that = $(this);
876
	var req = $.ajax({
877
		url: 'http://104.200.25.40:8057/appAffiliates/generateRedirectUrl/'+me+'/'+$(that).data('id'),
878
		// Tell jQuery we're expecting JSONP
879
		dataType: "jsonp",
880
		// Tell YQL what we want and that we want JSON			
881
		method: 'get',
882
		// timeout: 30000,
883
		// Work with the response
884
		success: function( response ) {
885
			console.log(response);
886
		}
887
	});
888
});
15077 anikendra 889
function showpopover(id){
890
	$('[data-toggle="popover"]#'+id).popover({'html':true});
891
	$('[data-toggle="popover"]#'+id).trigger('click');		
15085 anikendra 892
}
893
$(document).on('click','.nodeals',function(){
894
	document.location = $(this).data('href');
16018 anikendra 895
});
896
$(document).on('click','.selectbrand',function(e){
897
	e.preventDefault();
898
	var brands = $(this).data('id');
899
	var brandname = $(this).html();
900
	console.log(brandname);
901
	setCookie('brandschosen', brands, 1, true);
902
	var url = $(this).data('href');
903
	ga('send', 'event', 'selectbrand', 'brand', brandname);
904
	properties = {};
905
	properties['brand'] = brandname;
906
	pma.send('filters','brands','selectbrand',me,properties);
907
	var postdata = {'user_id':me,'type':'brand','filters':brandname};
908
	$.post( "/user_filters/add", postdata, function( data ) {
909
		$('#loadingModal').modal('hide');
910
		$(this).addClass('activebrand');
911
  		document.location = url+'&brands='+brands;
912
	});
913
});
16495 anikendra 914
$(document).on('click','.shownexttip',function(e){
915
	$(this).addClass('hidden').remove();
916
	$('#firsttip').addClass('hidden').remove();
917
	$('#secondtip').removeClass('hidden');
918
	$('.gotit').removeClass('hidden');
919
});
15128 anikendra 920
var Base64 = {
921
    _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
922
    encode: function(input) {
923
        var output = "";
924
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
925
        var i = 0;
926
        input = Base64._utf8_encode(input);
927
        while (i < input.length) {
928
            chr1 = input.charCodeAt(i++);
929
            chr2 = input.charCodeAt(i++);
930
            chr3 = input.charCodeAt(i++);
931
 
932
            enc1 = chr1 >> 2;
933
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
934
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
935
            enc4 = chr3 & 63;
936
            if (isNaN(chr2)) {
937
                enc3 = enc4 = 64;
938
            } else if (isNaN(chr3)) {
939
                enc4 = 64;
940
            }
941
            output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
942
        }
943
        return output;
944
    },
945
 
946
 
947
    decode: function(input) {
948
        var output = "";
949
        var chr1, chr2, chr3;
950
        var enc1, enc2, enc3, enc4;
951
        var i = 0;
952
        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
953
        while (i < input.length) {
954
            enc1 = this._keyStr.indexOf(input.charAt(i++));
955
            enc2 = this._keyStr.indexOf(input.charAt(i++));
956
            enc3 = this._keyStr.indexOf(input.charAt(i++));
957
            enc4 = this._keyStr.indexOf(input.charAt(i++));
958
            chr1 = (enc1 << 2) | (enc2 >> 4);
959
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
960
            chr3 = ((enc3 & 3) << 6) | enc4;
961
            output = output + String.fromCharCode(chr1);
962
            if (enc3 != 64) {
963
                output = output + String.fromCharCode(chr2);
964
            }
965
            if (enc4 != 64) {
966
                output = output + String.fromCharCode(chr3);
967
            }
968
        }
969
        output = Base64._utf8_decode(output);
970
        return output;
971
    },
972
 
973
    _utf8_encode: function(string) {
974
        string = string.replace(/\r\n/g, "\n");
975
        var utftext = "";
976
        for (var n = 0; n < string.length; n++) {
977
            var c = string.charCodeAt(n);
978
            if (c < 128) {
979
                utftext += String.fromCharCode(c);
980
            }
981
            else if ((c > 127) && (c < 2048)) {
982
                utftext += String.fromCharCode((c >> 6) | 192);
983
                utftext += String.fromCharCode((c & 63) | 128);
984
            }
985
            else {
986
                utftext += String.fromCharCode((c >> 12) | 224);
987
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
988
                utftext += String.fromCharCode((c & 63) | 128);
989
            }
990
        }
991
        return utftext;
992
    },
993
 
994
    _utf8_decode: function(utftext) {
995
        var string = "";
996
        var i = 0;
997
        var c = c1 = c2 = 0;
998
        while (i < utftext.length) {
999
            c = utftext.charCodeAt(i);
1000
            if (c < 128) {
1001
                string += String.fromCharCode(c);
1002
                i++;
1003
            }
1004
            else if ((c > 191) && (c < 224)) {
1005
                c2 = utftext.charCodeAt(i + 1);
1006
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
1007
                i += 2;
1008
            }
1009
            else {
1010
                c2 = utftext.charCodeAt(i + 1);
1011
                c3 = utftext.charCodeAt(i + 2);
1012
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
1013
                i += 3;
1014
            }
1015
        }
1016
        return string;
1017
    }
15550 anikendra 1018
}
1019
 
1020
 
1021
var pma = new function() {
15584 anikendra 1022
    this.apiurl = "http://45.33.50.227:8081/";
15550 anikendra 1023
    this.endpoints = {'identify':'identify','profile':'profile','track':'track'};
1024
 
1025
    this.send = function (category,action,label,user_id,properties) {
15585 anikendra 1026
    	if(!properties){
1027
    		properties = {};
1028
    	}
1029
    	properties.location = window.location.href;
1030
    	// properties.appCodeName = navigator.appCodeName;
1031
    	// properties.appName = navigator.appName;
1032
    	// properties.appVersion = navigator.appVersion;
1033
    	properties.cookieEnabled = String(navigator.cookieEnabled);
1034
    	properties.platform = navigator.platform;
1035
    	properties.userAgent = navigator.userAgent;
1036
    	properties.ip = ip;
1037
	  	if (navigator.geolocation) {
15586 anikendra 1038
	  		if(getCookie('latitude',true)){
1039
	  			properties.latitude = getCookie('latitude');
1040
	  		}	  		
1041
	  		if(getCookie('longitude',true)){
1042
		  		properties.longitude = getCookie('longitude');
1043
		  	}
15585 anikendra 1044
	  	}
1045
	  	properties.screenHeight = String(screen.height);
1046
	  	properties.screenWidth = String(screen.width);
1047
    	// console.log(properties);
15550 anikendra 1048
 		$.ajax({
1049
			url: this.apiurl + this.endpoints.track,
1050
			data: {'category':category,'action':action,'label':label,'user_id':user_id,'properties':cassandraMAP.stringify(properties)},
1051
			// Tell jQuery we're expecting JSONP
1052
			dataType: "json",
1053
			// Tell YQL what we want and that we want JSON			
1054
			method: 'post',
1055
			// Work with the response
1056
			success: function( response ) {
1057
				//Well, well, well :)
1058
			}
1059
		});       
1060
    };
1061
 
1062
    this.formDataToObject = function(formdata){
1063
    	var properties = {};
1064
    	var keys = [];
1065
		var formdata = JSON.parse(JSON.stringify(formdata));
1066
		for (var i in formdata) {
1067
			var key = formdata[i].name;
1068
			if(index = keys.indexOf(key)==-1){
1069
				properties[key] = formdata[i].value;
1070
			}else{
1071
				properties[key+'_'+i] = formdata[i].value;
1072
			}
1073
			keys.push(key);
1074
		};
1075
		return properties;
1076
	}
16704 anikendra 1077
}
1078
//App page
1079
$.fn.stars = function() {
1080
    return $(this).each(function() {
1081
        // Get the value
1082
        var val = parseFloat($(this).html());
1083
        // Make sure that the value is in 0 - 5 range, multiply to get width
1084
        val = Math.round(val * 2) / 2;
1085
        var size = Math.max(0, (Math.min(5, val))) * 16;
1086
        // Create stars holder
1087
        var $span = $('<span />').width(size);
1088
        // Replace the numerical value with stars
1089
        $(this).html($span);
1090
    });
1091
}
1092
$(function() {
1093
    $('span.stars').stars();	
1094
});