Subversion Repositories SmartDukaan

Rev

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