Subversion Repositories SmartDukaan

Rev

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