Subversion Repositories SmartDukaan

Rev

Rev 12034 | Rev 12036 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1456 varun.gupt 1
$(function(){
7744 amit.gupta 2
	jQuery('.mk_videoclick').click(function(){
3
		var clicked = jQuery(this);
4
	    var scrollTo = jQuery("#recommendedvids");
5
	    if(currentVideoId!=currentVideoIds[clicked.attr("slidecounter")]){
6
	    	scrollTo.find('li[ytid=' + currentVideoIds[clicked.attr("slidecounter")] + ']').click();
7
	    }
8
		trackEventWithGA('Product', 'VideoTabClicked',  $('title').text().split('|')[0].trim()  + "|" + clicked.attr("slidename"));
9
  		jQuery('html, body').animate({ scrollTop: scrollTo.offset().top }, 'medium');
10
    	return false;
11
	});
7853 amit.gupta 12
 
13
	var bankEle = jQuery("#bank-name");
14
	var first = true;
15
	var allBankImgs = {
16
		1:"/images/hdfc-icon.png",
17
		2:"/images/axis-icon.png",
18
	 	3:"/images/icici-icon.png",
19
	 	4:"/images/indusind-icon.png",
20
	 	5:"/images/citi-icon.png",
21
	 	6:"/images/std-chartered-icon.png",
22
	 	7:"/images/hsbc-icon.png",
23
	 	8:"/images/kotak-icon.png",
24
	 	9:"/images/sbi-icon.png",
25
	};
7744 amit.gupta 26
 
7853 amit.gupta 27
 
28
	var minEmi = 999999;
9149 amit.gupta 29
	if(typeof EMI === "undefined"){
30
		EMI={};
31
	}
32
	EMI.lowestEmiBank = 0;
7853 amit.gupta 33
	jQuery.each(emiObj, function(index, opt) {
34
		if(sellingPrice >= opt.minAmount){ 
35
			if(typeof banks[opt.bankId] == "undefined") {
36
				banks[opt.bankId] = {};
37
				banks[opt.bankId].name =  opt.bankName;
38
				banks[opt.bankId].emis =  {};
39
				banks[opt.bankId].active =  true;
40
				banks[opt.bankId].img = allBankImgs[opt.bankId];
41
			}
42
			var bank = banks[opt.bankId];
43
			var bankTenure = {};
44
			bankTenure.tenureDescription = opt.tenureDescription;
8950 amit.gupta 45
			var r = opt.interestRate/12/100;
12031 amit.gupta 46
			var installment = sellingPrice*r*Math.pow(1+r,opt.tenure)/(Math.pow(1+r,opt.tenure) - 1);
8950 amit.gupta 47
			bankTenure.monthlyEmi =  (Math.round(installment*100)/100).toFixed(2);
48
			bankTenure.interestRate = opt.interestRate;
9149 amit.gupta 49
			if(minEmi > installment){
50
				minEmi = installment;
12026 amit.gupta 51
				EMI.interestRate = r;
52
				EMI.tenure = opt.tenure; 
9149 amit.gupta 53
				EMI.lowestEmiBank = opt.bankId;
7853 amit.gupta 54
			}
55
			bank.emis[opt.id] = bankTenure;
56
		}
57
	});
58
	jQuery.each(banks, function(index, bank){
59
		var style = ' style="background: url(\'' + bank.img + '\') no-repeat right"';
60
		if(first){
61
			bankEle.append('<li title="' + bank.name + '"' + style +'><input type="radio" id="' + index +'" value="' + index +'" name="bankselected"' + (bank.active ? '""' : 'disabled="disabled"') + ' checked="checked"/></li>');
62
			first = false;
63
		}else {
64
			bankEle.append('<li title="' + bank.name +'"' + style +'><input type="radio" id="' + index +'" value="' + index +'" name="bankselected"' + (bank.active ? '""' : 'disabled="disabled"') + ' /></li>');
65
		}
66
	});
67
 
68
	bankEle.find("input[type='radio']").click(onBankClicked);
69
 
12026 amit.gupta 70
	jQuery("#emi_more,#emi_more1").click(function(){
7853 amit.gupta 71
 
72
		$.colorbox({
73
			inline:true, 
74
			href:"#emiLightBox",
75
    		width:"600px",
76
    		height:"410px",
77
 
78
    		onComplete: function(){
79
    			$('#emiLightBox').show();
9149 amit.gupta 80
    			if(EMI.lowestEmiBank == 0) {
81
    				bankEle.find("input[type='radio']:first").trigger('click');
82
    			}
83
    			else {
9153 amit.gupta 84
    				bankEle.find("#" + EMI.lowestEmiBank).trigger('click');
9149 amit.gupta 85
    			}
7853 amit.gupta 86
    		},
87
    		onCleanup: function(){
88
    			$('#emiLightBox').hide();
89
    		}
90
    	});
91
    	trackEventWithGA('Product', 'Emi Know More Clicked',  $('title').text().split('|')[0].trim());
92
	});
93
 
1456 varun.gupt 94
	$('#loopedSlider').loopedSlider();
95
 
96
	runEffect();
97
 
98
	$(".controls").tabs();
99
 
100
	$('#forgot_username_link').tipsy({gravity: 'w'});
101
 
102
	$("#zipcode").val($("#defaultpincode").val());
4934 amit.gupta 103
 
104
	if(typeof Entity != 'undefined'){
105
		var select = $("#colorSelector");
5373 rajveer 106
		if(Entity.orderedItems){
5347 amit.gupta 107
			$.each(Entity.orderedItems, function(index, sort) {
108
				select.find('option[value="' + sort + '"]').appendTo(select);
109
			});
110
			$("#item_id").val(Entity.orderedItems[0]);
5889 amit.gupta 111
			onColorSelectorChange(Entity.orderedItems[0]);
11672 anikendra 112
			if(typeof deliveryEstimate != 'undefined') {
113
				$("#shipping_time").show();
114
				$("#shipping_time_1").hide();
115
				//$("#shipping_time .red").html("<img src='/images/loader_l.gif'>");
116
				populateEstimate(deliveryEstimate);
117
			}else{
118
				updateEstimate(Entity.orderedItems[0]);
119
			}
5347 amit.gupta 120
		}
4934 amit.gupta 121
		select.find("option:eq(0)").remove();
122
	}
1456 varun.gupt 123
 
1761 vikas 124
    var prodid = $("#product_id").val();
125
 
126
	add_to_storage_set("histitems", prodid);
127
 
2652 rajveer 128
    load_accessories_widget();
3406 rajveer 129
 
130
    load_most_compared_widget();
2754 rajveer 131
 
2731 varun.gupt 132
 
4489 varun.gupt 133
    // Fix to always show first image's title on page load
4530 mandeep.dh 134
    if ("undefined" != typeof(title_1)){
135
        $('.slides .modelName').html(title_1[0]);
136
    }
4489 varun.gupt 137
 
4530 mandeep.dh 138
 
3830 chandransh 139
    function getSeletectedItemId(){
140
    	 return $("#item_id").val();
141
    }
142
 
143
 
1922 varun.gupt 144
    /**
145
     * Code to track user clicks on Product slides and 'Proceed to Payment' option
146
     */
147
	$('a.vt').click(function(){
148
		trackEventWithGA('Product', $(this).children('span').text(), $('title').text().split('|')[0].trim());
149
	});
150
 
3830 chandransh 151
	$('#computeShippingEstimate').click(function(){
152
		updateEstimate(getSeletectedItemId());
153
	});
154
 
155
    $("#addToCart").click(function(){
2811 rajveer 156
    	jQuery.ajax({
1456 varun.gupt 157
			type: "POST",
1614 rajveer 158
			url: "/addtocart",
3830 chandransh 159
			data: "productid=" + getSeletectedItemId(),
1456 varun.gupt 160
			success: function(msg)	{
4530 mandeep.dh 161
	   			 if(msg == "") {
3830 chandransh 162
	   				 trackEventWithGA('Order', 'Add to Cart', getSeletectedItemId() + '');
2036 rajveer 163
					 window.location = "/cart";
4530 mandeep.dh 164
				 } else {
4934 amit.gupta 165
					 var productDetail =  $("#productDetail");
166
    				 var prodInfo = $(productDetail).find("span.brand").html() + $(productDetail).find("span.product-name").html();
2810 rajveer 167
					 displayRelatedProducts(msg);
4934 amit.gupta 168
					 trackEventWithGA('Order', 'OOS Lightbox', prodInfo);
4530 mandeep.dh 169
				 }
2754 rajveer 170
	   		}
1456 varun.gupt 171
		});
172
	});
173
 
3830 chandransh 174
	$("#colorSelector").change(function(){
175
		var itemid = $("#colorSelector option:selected").val();
5889 amit.gupta 176
		onColorSelectorChange(itemid);
11672 anikendra 177
		updateEstimate(itemid);
1456 varun.gupt 178
		return false;
179
	});
180
 
3830 chandransh 181
	$(".util_compare").click(function() {
2755 rajveer 182
		$.colorbox({
183
			inline:true, 
184
			href:"#compareLightBox",
185
    		width:"350px",
186
    		height:"230px",
187
 
188
    		onComplete: function(){
189
    			$('#compareLightBox').show();
190
    		},
191
    		onCleanup: function(){
192
    			$('#compareLightBox').hide();
193
    		}
194
    	});
2228 rajveer 195
	});
3830 chandransh 196
 
197
	$('.util_addnewresearch').click(function(){
198
		addResearch('', 'single');
199
	});
200
 
2236 rajveer 201
    $('#mobilename').keypress(function(e) {
202
    	if(e.keyCode == 13) {
5347 amit.gupta 203
    		return compareProducts($("#compare_continue").attr("producttype"));
2236 rajveer 204
        }
205
    });
206
 
207
 
2228 rajveer 208
    $("#compare_continue").click(function() {
5347 amit.gupta 209
    	return compareProducts($(this).attr("producttype"));
2228 rajveer 210
    });
2236 rajveer 211
 
3305 rajveer 212
    $('.tooltip').click(function() {
213
    	trackEventWithGA('Product', 'Helpdoc Click', $(this).attr('name'));
214
    });
215
 
2320 rajveer 216
    $('.tooltip').each(function(index) {
217
    	   $(this).qtip({
218
    		style: { width: 300, overflow: 'auto',
219
    			tip: { corner: 'topLeft' }, 
220
    			border: { width: 2, radius: 2, color: '#DDDDDD' } },
221
    		show: { when: { event: 'click' } },
222
    		content: { url: "/helpdocs/" + $(this).attr('name'), title: { text: '&nbsp;', button: 'Close'} },
223
    		hide: { when: { event: 'unfocus' } },
224
    		position: { adjust: {screen: true} }
225
    		});
226
    	});
227
 
228
 
5347 amit.gupta 229
    function compareProducts(productType){
230
		var hyphenatedProductType = productType.replace(/ +/g, '-').toLowerCase();
231
 
232
    	var productName = $("#mobilename").val();
5358 amit.gupta 233
		var hypenatedNameTwo = productName.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
4143 varun.gupt 234
 
5347 amit.gupta 235
		var productTwo = productIdNames[productType][productName];
2236 rajveer 236
		if(typeof productTwo == 'undefined'){
237
			alert("Please select a valid product");
238
			return false;
239
		}
2827 rajveer 240
		var productOne = $("#catalog_id").val();
5347 amit.gupta 241
		var prodDetail = $("#productDetail");
242
		var productNameOne = $(prodDetail).find("span.brand").html() + " " + $(prodDetail).find("span.product-name").html();  
5358 amit.gupta 243
		var hyphenateNameOne = productNameOne.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();  
5347 amit.gupta 244
		window.location = "/compare-" + hyphenatedProductType + "/" 
5552 phani.kuma 245
			+ hyphenateNameOne + "-vs-" + hypenatedNameTwo + "?p1="+productOne+"&p2="+productTwo+"&fromsrc=product_page";	
2236 rajveer 246
	}
2228 rajveer 247
 
2802 rajveer 248
    $("#accessories table td div a").live('click', function() {
10537 amit.gupta 249
    	var productId = $(this).attr('title');
2802 rajveer 250
    	trackEventWithGA('Widget', 'Accessory Click', productId);
251
    });
252
 
5862 amit.gupta 253
 
254
	$('.nextSlide-anchorLink').live('click', function() {
255
	    var nextSlideLink = $(this).attr('nextSlideId');
256
	    $('a[href="' + nextSlideLink +'"]').click();
257
	    return false;
258
	});
259
 
5552 phani.kuma 260
    $('a.compare-now').live('click', function(){
261
		var productType = $(this).attr('producttype');
262
		productType = productType.replace(/ +/g, '-').toLowerCase();
263
 
264
		var productOne = $("#catalog_id").val();
265
		var prodDetail = $("#productDetail");
266
		var productNameOne = $(prodDetail).find("span.brand").html() + " " + $(prodDetail).find("span.product-name").html();
267
		var hyphenateNameOne = productNameOne.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
268
 
269
		var productTwo = $(this).attr("value");
270
		var hypenatedNameTwo = $(this).attr("title").replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
271
 
272
		window.location = "/compare-" + productType + "/" + hyphenateNameOne + "-vs-" + hypenatedNameTwo + "?p1="+productOne+"&p2="+productTwo+"&fromsrc=most_compared_widget";
273
    });
274
 
1456 varun.gupt 275
});
276
 
277
function changeSignInClass(){
278
	if(document.getElementById("signinClass").className.indexOf("signin1") > -1)	{
279
		document.getElementById("signinClass").className = 'signin';
280
	} else	{
281
		document.getElementById("signinClass").className = 'signin1';
282
	}
283
}
284
 
11672 anikendra 285
function populateEstimate(msg) {
286
	var response = eval('(' + msg + ')');
287
	var deliveryEstimate = response['delivery_estimate'];
288
	var codDeliveryEstimate = response['cod_delivery_estimate'];
289
	var isCODAvailableForLocation = (response['is_cod_available_for_location'] === 'true');
290
	var isOTG = (response['on_time_guarantee'] === 'true');
291
	var businessDays = response['business_days'];
292
 
293
	if(deliveryEstimate == -1)	{
294
		$("#shipping_time").hide();
295
		$("#shipping_time_1").show();
296
		$('#cod_know_more').hide();
297
	} else	{
298
		$('#cod_know_more').hide();
299
		if($("#shipping_time").html().indexOf('after arrival')>-1){
300
			$("#shipping_time .red").html(businessDays + " Days");
301
		}else{
302
			if(isCODAvailableForLocation && (codDeliveryEstimate != deliveryEstimate)){
303
				$("#shipping_time .cod").html("Cash On Delivery orders is " + codDeliveryEstimate);
304
				$('#cod_know_more').show();
305
			}
306
			$("#shipping_time .red").html(deliveryEstimate);
307
		}
308
	}
309
 
310
	if (isCODAvailableForLocation)	{
311
		$('#cod').show();
312
	} else {
313
		$('#cod').hide();
314
	}
315
 
316
	if (isOTG)	{
317
		$('#otg').show();
318
	} else {
319
		$('#otg').hide();
320
	}
321
}
2228 rajveer 322
 
1456 varun.gupt 323
function updateEstimate(itemId)	{
3830 chandransh 324
	itemId = itemId || $("#colorSelector option:selected").val();
1456 varun.gupt 325
 
326
	jQuery.ajax({
327
		type: "GET",
1919 rajveer 328
		url: "/estimate/" + $("#zipcode").val() + "_" + itemId,
1456 varun.gupt 329
		beforeSend: function()	{
5234 amit.gupta 330
			$("#shipping_time").show();
331
			$("#shipping_time_1").hide();
7893 rajveer 332
			$("#shipping_time .red").html("<img src='/images/loader_l.gif'>");
1456 varun.gupt 333
		},
334
		success: function(msg)	{
11672 anikendra 335
			populateEstimate(msg);
1456 varun.gupt 336
		}
337
	});
2228 rajveer 338
}
339
 
3406 rajveer 340
function load_most_compared_widget(){
10198 amit.gupta 341
	if(Entity.isComparable) {
342
		jQuery.ajax({
343
			type : "GET",
344
			url : "/most-compared-products/" + $("#product_id").val(),
345
			cache: false,
346
			success : function(html) {
347
	   		    $("#mostcompared").html(html);
348
 
349
			    // Product Title
350
			    $("#mostcompared table td div a").each(function() {
351
			    		if($(this).attr('class') != "compare-now"){
352
			    			$(this).truncate({addtitle : true});
353
			    		}
354
			    });
355
 
356
			    // Product Price
357
			    $("#mostcompared table td div div.price").each(function() {
358
						$(this).truncate({addtitle : true});
359
				});
360
 
361
			    // Product Details
362
			    $("#mostcompared table td div div.text").each(function() {
363
						$(this).truncate( {addtitle : true});
364
				});
365
		    }
366
		});
367
	}
5889 amit.gupta 368
}
369
function onColorSelectorChange(itemid){
12026 amit.gupta 370
	if(typeof privateDeals[itemid]== "undefined") {
371
		sellingPrice = Number(PARAMETERS[itemid].SP); 
372
		if($('#sp').length>0){
373
			$('#sp').html(PARAMETERS[itemid].SP);
374
			$('#mrp').html(PARAMETERS[itemid].MRP);
375
			$('#saving').html(PARAMETERS[itemid].SAVING);
376
			$("#item_id").val(itemid);
377
		}
12032 amit.gupta 378
		$('div.mk_deal').fadeOut('fast');
12026 amit.gupta 379
		$('div.mk_nodeal').show();
380
	} else {
381
		var itemp = privateDeals[itemid];
382
		sellingPrice = itemp.dealPojo.dealPrice;
12031 amit.gupta 383
		var installment = sellingPrice*EMI.interestRate*Math.pow(1+EMI.interestRate,EMI.tenure)/(Math.pow(1+EMI.interestRate,EMI.tenure) - 1);
12027 amit.gupta 384
		if(typeof itemp.mrp == "undefined" || itemp.mrp =="") itemp.mrp = itemp.sellingPrice
12026 amit.gupta 385
		var percentoff = Math.round((1-itemp.dealPojo.dealPrice/itemp.mrp)*100);
386
		var dealLeft = '';
387
		var dealRight = '';
388
		if(itemp.dealPojo.dealTextOption==0){
389
			dealRight = itemp.bestDealText;
390
		}else if(itemp.dealPojo.dealTextOption==1){
391
			dealLeft=itemp.bestDealText;
392
		}else {
393
			dealRight=itemp.bestDealText;
394
			dealLeft = itemp.dealPojo.dealText
395
		}
396
 
397
		var html = [];
398
		html.push('<div style="color:yellow;padding:3px">');
399
		html.push('<div class="left"><div><b>Only for You: </b><spap class="red">Rs.' + itemp.selling + '</span> (' + percentoff + '% Off) </div>');
400
		if(dealLeft != ''){
401
			html.push('<div class="red" style="font-weight:bold;padding-bottom:6px">' + dealLeft +'</div>');
402
		}
403
		html.push('<div class="red" style="font-weight:bold;padding-bottom:6px">Use Coupon: saholicdeals</div>');
404
		html.push('</div>');
12035 amit.gupta 405
		html.push('<div class="price right">');
12026 amit.gupta 406
		html.push('<div class="left rupeeimage"></div><span class="mrp bold">'+ itemp.mrp +'</span>');
407
		if(itemp.mrp!=itemp.sellingPrice) {
408
			html.push('<span class="mrp bold">'+ itemp.sellingPrice +'</span>');
409
		}
410
		if(dealRight != ''){
411
			html.push('<div style="font-weight:bold;padding-bottom:6px;text-decoration:line-through">' + dealRight +'</div>');
412
		}
12035 amit.gupta 413
		html.push('<div><span class="mk_emi" style="font-size: 14px;">EMIs from <span class="red">Rs.' + (Math.round(installment*100)/100).toFixed(2) +'</span> per month<a style="padding-left:2px" href="javascript:void(0)" id="emi_more1"><img style="vertical-align: middle;" src="/unversioned/images/quesmark.png"></a></span></div>')
12026 amit.gupta 414
		html.push('</div>');
415
		html.push('</div>');
12032 amit.gupta 416
		$('div.mk_nodeal').fadeOut('fast');
12034 amit.gupta 417
		$('div.mk_deal').html(html.join('')).show();
6021 amit.gupta 418
	}
7853 amit.gupta 419
}
420
 
421
banks = {};
422
var first = true;
423
for (obj in PARAMETERS) {
424
   sellingPrice = Number(PARAMETERS[obj].SP);
425
   break;
426
}
427
 
428
function onBankClicked(){
429
	var bankId = jQuery(this).val();
430
	var bank = banks[bankId];
431
	var emiTableEle = jQuery("#emi_options");
432
	var tdHtml=[];
433
	var tenureHtml=[];
8948 amit.gupta 434
	var percentHtml=[];
9145 rajveer 435
	tdHtml.push("<td><b>Installment<br>(Including Interest)</b></td>");
8960 rajveer 436
	percentHtml.push("<td><b>Interest Rate<br>(Annualized)</b></td>");
7853 amit.gupta 437
	jQuery.each(bank.emis, function(key,val){
438
		tdHtml.push('<td><span style="font-size:11px" class="rupee-icon"><b>' + val.monthlyEmi+ '</b></span></td>');
439
		tenureHtml.push('<td><span style="font-size:11px"><b>' + val.tenureDescription + '</b></span></td>');
8948 amit.gupta 440
		percentHtml.push('<td><span style="font-size:11px"><b>' + val.interestRate + '%</b></span></td>');
7853 amit.gupta 441
	});
8948 amit.gupta 442
	emiTableEle.find("td.mk_bankname").html(bank.name);
7853 amit.gupta 443
	emiTableEle.find("td.mk_emioptions").attr("colspan", count(bank.emis));
444
	emiTableEle.find("tr.emirow").html(tdHtml.join(""));
445
	emiTableEle.find("tr.mk_tenure").html(tenureHtml.join(""));	
8948 amit.gupta 446
	emiTableEle.find("tr.mk_percent").html(percentHtml.join(""));	
7853 amit.gupta 447
}
448
 
449
function count(obj) {
450
   var count=0;
451
   for(var prop in obj) {
452
      if (obj.hasOwnProperty(prop)) {
453
         ++count;
454
      }
455
   }
456
   return count;
11970 amit.gupta 457
}
12026 amit.gupta 458
privateDeals={};
11970 amit.gupta 459
if(typeof prodJson!="undefined"){
460
	for(i in prodJson.response.itemPojos){
461
		var deal = prodJson.response.itemPojos[i].dealPojo;
462
		if (typeof deal != "undefined"){
12029 amit.gupta 463
			privateDeals[prodJson.response.itemPojos[i].id] = prodJson.response.itemPojos[i];
11970 amit.gupta 464
		}
465
	}
12026 amit.gupta 466
}
467
 
468
function highlightDeal(){
469
 
3406 rajveer 470
}