Subversion Repositories SmartDukaan

Rev

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