Subversion Repositories SmartDukaan

Rev

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