Subversion Repositories SmartDukaan

Rev

Rev 17006 | Rev 17026 | 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);
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
						}
17017 naman 366
				  	} else if(store == 7 ) {
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
17017 naman 379
				  	  else if(store == 6)
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
	});
14068 anikendra 564
	$(document).on('click','.creditedcashbacks',function(){
565
		if($(this).find('.glyphicon-plus',0).length>0){
566
			$(this).find('.glyphicon-plus',0).removeClass('glyphicon-plus').addClass('glyphicon-minus');
567
		}else{
568
			$(this).find('.glyphicon-minus',0).removeClass('glyphicon-minus').addClass('glyphicon-plus');
569
		}
570
		$(this).next().toggleClass('hidden');
571
	});
16858 naman 572
	$(document).on('click','.panel-heading a',function(){
14068 anikendra 573
		if($(this).find('.glyphicon-plus',0).length>0){
574
			$(this).find('.glyphicon-plus',0).removeClass('glyphicon-plus').addClass('glyphicon-minus');
575
		}else{
576
			$(this).find('.glyphicon-minus',0).removeClass('glyphicon-minus').addClass('glyphicon-plus');
577
		}
578
	});
14135 anikendra 579
	$(document).on('click','.prefcatselect',function(){
580
		$('.prefcatselect').removeClass('active')
581
		$(this).addClass('active');
582
		$('.categorypreferences').addClass('hidden');
583
		$('#cat-'+$(this).data('id')).toggleClass('hidden');
14150 anikendra 584
	});
585
	$(document).on('click','.refresh',function(){
586
		document.location.reload();
587
	});
14215 anikendra 588
	$(document).on('click','.hasmoretext',function(){
589
		$('#fulltext').html($(this).data('fulltext'));
590
		$('#fullTextModal').modal();
591
	});
14300 anikendra 592
	$(document).on('click','.favswitch',function(){
593
		$('.favswitch').removeClass('active')
594
		$(this).addClass('active');
595
		$('.clearfavs').addClass('hidden');
596
		$('.card').addClass('hidden');
597
		$('.'+$(this).data('type')).removeClass('hidden');
598
	});
14386 anikendra 599
	$(document).on('click','.brandpreferences .brands',function(){
600
		$(this).parents('.row').siblings('.controls').find('.editcategorypreferences',0).click();
601
	});
602
	$(document).on('click','.tryagainforliveprice',function(){		
603
		fetchLivePrice($(this).parent());
604
		$(this).parent().html('Getting Live Prices');
605
	});
14579 anikendra 606
	$(document).on('click','.alert > a',function(){		
607
		ga('send', 'event', 'notifications', 'click', $(this).html());
15550 anikendra 608
		pma.send('notifications','click',$(this).html(),me);
14579 anikendra 609
	});
610
	$(document).on('click','.banner',function(){		
611
		ga('send', 'event', 'banners', 'click', $(this).data('name'));
15550 anikendra 612
		pma.send('banners','click',$(this).data('name'),me);
14579 anikendra 613
	});
13992 anikendra 614
});
15310 anikendra 615
function setCookie(cname, cvalue, days, forceCookie) {
616
	if(typeof(Storage) !== "undefined" && !forceCookie) {
617
		localStorage.setItem(cname, cvalue);
618
	} else{
619
		var d = new Date();
620
	    d.setTime(d.getTime() + (days*24*60*60*1000));
621
	    var expires = "expires="+d.toUTCString();
622
	    document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
623
	}    
14849 anikendra 624
}
625
 
15310 anikendra 626
function getCookie(cname,forceCookie) {
627
	if(typeof(Storage) !== "undefined" && !forceCookie) {
628
	    return localStorage.getItem(cname);
629
	} else {	   
630
	    var name = cname + "=";
631
	    var ca = document.cookie.split(';');
632
	    for(var i=0; i<ca.length; i++) {
633
	        var c = ca[i];
634
	        while (c.charAt(0)==' ') c = c.substring(1);
635
	        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
636
	    }
637
	    return "";
638
	}
14849 anikendra 639
}
15310 anikendra 640
 
16495 anikendra 641
function needToDisplayPaytmPopup(me){
642
	var id = 'tip'
643
	var cname = 'paytm-help-count-'+me+'-'+id;
644
	var cookieval = getCookie(cname,1);
645
	if(!cookieval || cookieval == 'NaN' || cookieval==''){		
646
		incrementPopupCount(id,0,'paytm-help-count-');
647
		return true;
648
	} else if(cookieval < 5) {
649
		incrementPopupCount(id,cookieval,'paytm-help-count-');
650
		return true;
651
	} else{
652
		return false;
653
	}
654
};
655
 
14849 anikendra 656
function showpopup(id,count,interval){
14851 anikendra 657
	var cname = 'notif-count-'+me+'-'+id;
15797 anikendra 658
	var cookieval = getCookie(cname,1);
14851 anikendra 659
	var cname = 'notif-lastshown-'+me+'-'+id;
15797 anikendra 660
	var lastshown = getCookie(cname,1);
15310 anikendra 661
	if(!cookieval || cookieval == 'NaN' || cookieval==''){		
15077 anikendra 662
		incrementPopupCount(id,0,'notif-count-');
663
		setLastShown(id,'notif-lastshown-');
14849 anikendra 664
		return true;
665
	} else{
666
		var d = new Date();
667
		var t = d.getTime();
668
		if(t-lastshown>interval*60*1000){
669
			if(cookieval>=count){
670
				return false;
671
			}else{
15077 anikendra 672
				setLastShown(id,'notif-lastshown-');
673
				incrementPopupCount(id,cookieval,'notif-count-');
14849 anikendra 674
				return true;	
675
			}
676
		}
677
	}
678
}
15077 anikendra 679
function setLastShown(id,cookiename){
680
	var cname = cookiename+me+'-'+id;
14849 anikendra 681
	var d = new Date();
15721 anikendra 682
	setCookie(cname, d.getTime(), 365, 1);
14849 anikendra 683
}
15077 anikendra 684
function incrementPopupCount(id,currentCount,cookiename) {
685
	var cname = cookiename+me+'-'+id;
15721 anikendra 686
	setCookie(cname, parseInt(currentCount)+1, 365, 1);
14858 anikendra 687
}
688
var hidden, visibilityChange; 
689
function handleVisibilityChange() {
690
  if (document[hidden]) {
15058 anikendra 691
  	// pagetitle = document.title;
14858 anikendra 692
  } else {
15058 anikendra 693
  	// document.title = pagetitle;
14858 anikendra 694
  }
695
}
696
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support 
697
  hidden = "hidden";
698
  visibilityChange = "visibilitychange";
699
} else if (typeof document.mozHidden !== "undefined") {
700
  hidden = "mozHidden";
701
  visibilityChange = "mozvisibilitychange";
702
} else if (typeof document.msHidden !== "undefined") {
703
  hidden = "msHidden";
704
  visibilityChange = "msvisibilitychange";
705
} else if (typeof document.webkitHidden !== "undefined") {
706
  hidden = "webkitHidden";
707
  visibilityChange = "webkitvisibilitychange";
708
}
709
if (typeof document.addEventListener === "undefined" || 
710
  typeof document[hidden] === "undefined") {
15077 anikendra 711
  console.log("This feature requires a browser, such as Google Chrome or Firefox, that supports the Page Visibility API.");
14858 anikendra 712
} else {
713
  // Handle page visibility change   
714
  document.addEventListener(visibilityChange, handleVisibilityChange, false);
715
}    
14936 anikendra 716
$('.notificationok').on('click',function(e){
14932 anikendra 717
	e.preventDefault();
14931 anikendra 718
	$('.notificationmodal').modal('hide');
15159 anikendra 719
	// setTimeout(function(){ $('.notificationmodal').modal('hide'); }, 1000);
16133 anikendra 720
	ga('send', 'event', 'popupnotification-'+$(this).parent().data('id'), 'ok', me);
721
	var properties = {};
722
	properties.id = String($(this).parent().data('id'));
723
	pma.send('popupnotification','click','ok',me,properties);
14932 anikendra 724
	document.location = $(this).parent().prop('href');
15015 anikendra 725
});
726
$(document).on('click','.clearfilter',function(){	
727
	$('.filterbrand').each(function(){
728
		$(this).prop('checked',false);
729
	});	
15550 anikendra 730
	ga('send', 'event', 'filter', 'brand', 'reset');
731
	pma.send('filters','brands','reset',me);
15015 anikendra 732
});
733
$(document).on('click','.applyfilter',function(){	
15584 anikendra 734
	$(this).prop('disabled',true);
735
	$('#loadingModal').modal();
15015 anikendra 736
	var brands = [];
15026 anikendra 737
	var brandnames = [];
15015 anikendra 738
	$('.filterbrand').each(function(){
739
		if($(this).prop('checked')){
740
			brands.push($(this).val());
15026 anikendra 741
			brandnames.push($(this).parent().siblings('.brandname').html());
15015 anikendra 742
		}		
743
	});
744
	if(brands.length==0){
15721 anikendra 745
		$('#loadingModal').modal('hide');
15015 anikendra 746
		$('#message').html('Please choose a few brands first').removeClass('hidden');
747
		setTimeout(function(){ $('#message').addClass('hidden'); }, 3000);
15722 anikendra 748
		$(this).prop('disabled',false);
15015 anikendra 749
		return false;
750
	}else{
16240 anikendra 751
		setCookie('brandschosen', brands, 0.25, true);
15015 anikendra 752
		var url = $('#brandselecter').prop('action');
15026 anikendra 753
		ga('send', 'event', 'filter', 'brand', brandnames.join('|'));
15550 anikendra 754
		properties = {};
755
		for(var i in brandnames){
756
			properties['brand_'+i] = brandnames[i];
757
		}
758
		pma.send('filters','brands','addfilter',me,properties);
15085 anikendra 759
		var postdata = {'user_id':me,'type':'brand','filters':brandnames.join('|')};
760
		$.post( "/user_filters/add", postdata, function( data ) {
15584 anikendra 761
			$('#loadingModal').modal('hide');
15722 anikendra 762
			$(this).prop('disabled',false);
15584 anikendra 763
	  		document.location = url+'&brands='+brands.join('^');
15085 anikendra 764
		});		
15015 anikendra 765
	}	
766
});
767
$(document).on('click','#showallbrands',function(){	
768
	$('.hidden').removeClass('hidden');
769
	$(this).hide();
15019 anikendra 770
});
771
$(document).on('input','#brandfilter',function(){	
772
	$('.brand').addClass('hidden');
773
	$('#showallbrands').hide();
774
	var that = $(this);
775
	$('li.brand').filter(function() { 
776
	  return $(this).data("brand").toLowerCase().indexOf($(that).val().toLowerCase()) != -1;
777
	}).removeClass('hidden','slow');
15042 anikendra 778
});
15077 anikendra 779
$(document).on('click','.filterbrand',function(){
780
	var clicked = $(this).parent().parent();
15042 anikendra 781
	// all the LIs above the clicked one
782
	var previousAll = clicked.prevAll();
783
 
784
	// only proceed if it's not already on top (no previous siblings)
785
	if(previousAll.length > 0) {
786
	// top LI
787
	var top = $(previousAll[previousAll.length - 1]);
788
 
789
	// immediately previous LI
790
	var previous = $(previousAll[0]);
791
 
792
	// how far up do we need to move the clicked LI?
793
	var moveUp = clicked.attr('offsetTop') - top.attr('offsetTop');
794
 
795
	// how far down do we need to move the previous siblings?
796
	var moveDown = (clicked.offset().top + clicked.outerHeight()) - (previous.offset().top + previous.outerHeight());
797
 
798
	// let's move stuff
799
	clicked.css('position', 'relative');
800
	previousAll.css('position', 'relative');
801
	clicked.animate({'top': -moveUp});
802
	previousAll.animate({'top': moveDown}, {complete: function() {
803
	  // rearrange the DOM and restore positioning when we're done moving
804
	  clicked.parent().prepend(clicked);
805
	  clicked.css({'position': 'static', 'top': 0});
806
	  previousAll.css({'position': 'static', 'top': 0}); 
807
	}});
808
	}
809
})
810
$(document).on('click','.clearfilters',function(){
15310 anikendra 811
	setCookie('brandschosen', '', -1, true);
15058 anikendra 812
	ga('send', 'event', 'filter', 'brand', 'clearfilters');
15550 anikendra 813
	pma.send('filters','brands','clearfilters',me);
15085 anikendra 814
	var postdata = {'user_id':me,'type':'clear'};
16240 anikendra 815
	$('#loadingModal').modal('show');
816
	$.post("/user_filters/add", postdata, function( data ) {		
817
	  	document.location.reload();
15085 anikendra 818
	});	
15042 anikendra 819
});
820
function selectChosenBrands(){
16261 anikendra 821
	var brandschosen = decodeURIComponent(getCookie('brandschosen',true));
15042 anikendra 822
	if(brandschosen && brandschosen.length>0){
823
		var brands = brandschosen.split(',');
824
		for(var i in brands){
825
			$('.brand').filter(function() { 
826
			  	return $(this).data("brandid") == brands[i];
15077 anikendra 827
			}).removeClass('hidden').find('.filterbrand',0).trigger( "click" );
15042 anikendra 828
		}
829
	}
15065 anikendra 830
}
15585 anikendra 831
function showPosition(position) {
15586 anikendra 832
    setCookie('latitude',position.coords.latitude,1,true); 
833
    setCookie('longitude',position.coords.longitude,1,true);	
15585 anikendra 834
}
15065 anikendra 835
$(function () {
15077 anikendra 836
	var poid = 'popovertrigger';
15310 anikendra 837
	var cname = 'popover-count-'+me+'-'+poid;
15721 anikendra 838
	var cookieval = getCookie(cname,1);
15310 anikendra 839
	$('#dropdownMenu1').on('click',function(){
840
		var cname = 'popover-count-'+me+'-'+poid;
15721 anikendra 841
		var cookieval = getCookie(cname,1);
15310 anikendra 842
		$('#popovertrigger').popover('hide');
843
		if(!cookieval || cookieval == 'NaN' || cookieval == ''){
844
			incrementPopupCount(poid,0,'popover-count-');
15526 anikendra 845
		} else if(cookieval > 0) {
15310 anikendra 846
			incrementPopupCount(poid, cookieval, 'popover-count-');
847
		}
848
		setLastShown(poid,'popover-lastshown-');
849
	})
850
 
15077 anikendra 851
	var cname = 'popover-lastshown-'+me+'-'+poid;
15721 anikendra 852
	var lastshown = getCookie(cname,1);
15310 anikendra 853
	if(cookieval=='' || cookieval == 'NaN' || !cookieval){				
15077 anikendra 854
		showpopover(poid);
15521 anikendra 855
	} 
856
	//Donot show popover anymore as long as we don't find a suitable solution
15721 anikendra 857
	else{
15077 anikendra 858
		var d = new Date();
859
		var t = d.getTime();
15085 anikendra 860
		if(t-lastshown>18*3600*1000){
15310 anikendra 861
			if(cookieval>=2){
15077 anikendra 862
				return false;
863
			}else{
15310 anikendra 864
				showpopover(poid);				
15077 anikendra 865
			}
866
		}
15721 anikendra 867
	}
15583 anikendra 868
	ga('send', 'event', 'popover', me, cookieval);
15585 anikendra 869
	if (navigator.geolocation) {
870
        navigator.geolocation.getCurrentPosition(showPosition);
871
    } 
15077 anikendra 872
});
16656 anikendra 873
$('.getapp').on('click',function(){
874
	var that = $(this);
875
	var req = $.ajax({
876
		url: 'http://104.200.25.40:8057/appAffiliates/generateRedirectUrl/'+me+'/'+$(that).data('id'),
877
		// Tell jQuery we're expecting JSONP
878
		dataType: "jsonp",
879
		// Tell YQL what we want and that we want JSON			
880
		method: 'get',
881
		// timeout: 30000,
882
		// Work with the response
883
		success: function( response ) {
884
			console.log(response);
885
		}
886
	});
887
});
15077 anikendra 888
function showpopover(id){
889
	$('[data-toggle="popover"]#'+id).popover({'html':true});
890
	$('[data-toggle="popover"]#'+id).trigger('click');		
15085 anikendra 891
}
892
$(document).on('click','.nodeals',function(){
893
	document.location = $(this).data('href');
16018 anikendra 894
});
895
$(document).on('click','.selectbrand',function(e){
896
	e.preventDefault();
897
	var brands = $(this).data('id');
898
	var brandname = $(this).html();
899
	console.log(brandname);
900
	setCookie('brandschosen', brands, 1, true);
901
	var url = $(this).data('href');
902
	ga('send', 'event', 'selectbrand', 'brand', brandname);
903
	properties = {};
904
	properties['brand'] = brandname;
905
	pma.send('filters','brands','selectbrand',me,properties);
906
	var postdata = {'user_id':me,'type':'brand','filters':brandname};
907
	$.post( "/user_filters/add", postdata, function( data ) {
908
		$('#loadingModal').modal('hide');
909
		$(this).addClass('activebrand');
910
  		document.location = url+'&brands='+brands;
911
	});
912
});
16495 anikendra 913
$(document).on('click','.shownexttip',function(e){
914
	$(this).addClass('hidden').remove();
915
	$('#firsttip').addClass('hidden').remove();
916
	$('#secondtip').removeClass('hidden');
917
	$('.gotit').removeClass('hidden');
918
});
15128 anikendra 919
var Base64 = {
920
    _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
921
    encode: function(input) {
922
        var output = "";
923
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
924
        var i = 0;
925
        input = Base64._utf8_encode(input);
926
        while (i < input.length) {
927
            chr1 = input.charCodeAt(i++);
928
            chr2 = input.charCodeAt(i++);
929
            chr3 = input.charCodeAt(i++);
930
 
931
            enc1 = chr1 >> 2;
932
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
933
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
934
            enc4 = chr3 & 63;
935
            if (isNaN(chr2)) {
936
                enc3 = enc4 = 64;
937
            } else if (isNaN(chr3)) {
938
                enc4 = 64;
939
            }
940
            output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
941
        }
942
        return output;
943
    },
944
 
945
 
946
    decode: function(input) {
947
        var output = "";
948
        var chr1, chr2, chr3;
949
        var enc1, enc2, enc3, enc4;
950
        var i = 0;
951
        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
952
        while (i < input.length) {
953
            enc1 = this._keyStr.indexOf(input.charAt(i++));
954
            enc2 = this._keyStr.indexOf(input.charAt(i++));
955
            enc3 = this._keyStr.indexOf(input.charAt(i++));
956
            enc4 = this._keyStr.indexOf(input.charAt(i++));
957
            chr1 = (enc1 << 2) | (enc2 >> 4);
958
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
959
            chr3 = ((enc3 & 3) << 6) | enc4;
960
            output = output + String.fromCharCode(chr1);
961
            if (enc3 != 64) {
962
                output = output + String.fromCharCode(chr2);
963
            }
964
            if (enc4 != 64) {
965
                output = output + String.fromCharCode(chr3);
966
            }
967
        }
968
        output = Base64._utf8_decode(output);
969
        return output;
970
    },
971
 
972
    _utf8_encode: function(string) {
973
        string = string.replace(/\r\n/g, "\n");
974
        var utftext = "";
975
        for (var n = 0; n < string.length; n++) {
976
            var c = string.charCodeAt(n);
977
            if (c < 128) {
978
                utftext += String.fromCharCode(c);
979
            }
980
            else if ((c > 127) && (c < 2048)) {
981
                utftext += String.fromCharCode((c >> 6) | 192);
982
                utftext += String.fromCharCode((c & 63) | 128);
983
            }
984
            else {
985
                utftext += String.fromCharCode((c >> 12) | 224);
986
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
987
                utftext += String.fromCharCode((c & 63) | 128);
988
            }
989
        }
990
        return utftext;
991
    },
992
 
993
    _utf8_decode: function(utftext) {
994
        var string = "";
995
        var i = 0;
996
        var c = c1 = c2 = 0;
997
        while (i < utftext.length) {
998
            c = utftext.charCodeAt(i);
999
            if (c < 128) {
1000
                string += String.fromCharCode(c);
1001
                i++;
1002
            }
1003
            else if ((c > 191) && (c < 224)) {
1004
                c2 = utftext.charCodeAt(i + 1);
1005
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
1006
                i += 2;
1007
            }
1008
            else {
1009
                c2 = utftext.charCodeAt(i + 1);
1010
                c3 = utftext.charCodeAt(i + 2);
1011
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
1012
                i += 3;
1013
            }
1014
        }
1015
        return string;
1016
    }
15550 anikendra 1017
}
1018
 
1019
 
1020
var pma = new function() {
15584 anikendra 1021
    this.apiurl = "http://45.33.50.227:8081/";
15550 anikendra 1022
    this.endpoints = {'identify':'identify','profile':'profile','track':'track'};
1023
 
1024
    this.send = function (category,action,label,user_id,properties) {
15585 anikendra 1025
    	if(!properties){
1026
    		properties = {};
1027
    	}
1028
    	properties.location = window.location.href;
1029
    	// properties.appCodeName = navigator.appCodeName;
1030
    	// properties.appName = navigator.appName;
1031
    	// properties.appVersion = navigator.appVersion;
1032
    	properties.cookieEnabled = String(navigator.cookieEnabled);
1033
    	properties.platform = navigator.platform;
1034
    	properties.userAgent = navigator.userAgent;
1035
    	properties.ip = ip;
1036
	  	if (navigator.geolocation) {
15586 anikendra 1037
	  		if(getCookie('latitude',true)){
1038
	  			properties.latitude = getCookie('latitude');
1039
	  		}	  		
1040
	  		if(getCookie('longitude',true)){
1041
		  		properties.longitude = getCookie('longitude');
1042
		  	}
15585 anikendra 1043
	  	}
1044
	  	properties.screenHeight = String(screen.height);
1045
	  	properties.screenWidth = String(screen.width);
1046
    	// console.log(properties);
15550 anikendra 1047
 		$.ajax({
1048
			url: this.apiurl + this.endpoints.track,
1049
			data: {'category':category,'action':action,'label':label,'user_id':user_id,'properties':cassandraMAP.stringify(properties)},
1050
			// Tell jQuery we're expecting JSONP
1051
			dataType: "json",
1052
			// Tell YQL what we want and that we want JSON			
1053
			method: 'post',
1054
			// Work with the response
1055
			success: function( response ) {
1056
				//Well, well, well :)
1057
			}
1058
		});       
1059
    };
1060
 
1061
    this.formDataToObject = function(formdata){
1062
    	var properties = {};
1063
    	var keys = [];
1064
		var formdata = JSON.parse(JSON.stringify(formdata));
1065
		for (var i in formdata) {
1066
			var key = formdata[i].name;
1067
			if(index = keys.indexOf(key)==-1){
1068
				properties[key] = formdata[i].value;
1069
			}else{
1070
				properties[key+'_'+i] = formdata[i].value;
1071
			}
1072
			keys.push(key);
1073
		};
1074
		return properties;
1075
	}
16704 anikendra 1076
}
1077
//App page
1078
$.fn.stars = function() {
1079
    return $(this).each(function() {
1080
        // Get the value
1081
        var val = parseFloat($(this).html());
1082
        // Make sure that the value is in 0 - 5 range, multiply to get width
1083
        val = Math.round(val * 2) / 2;
1084
        var size = Math.max(0, (Math.min(5, val))) * 16;
1085
        // Create stars holder
1086
        var $span = $('<span />').width(size);
1087
        // Replace the numerical value with stars
1088
        $(this).html($span);
1089
    });
1090
}
1091
$(function() {
1092
    $('span.stars').stars();	
1093
});