Subversion Repositories SmartDukaan

Rev

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