Subversion Repositories SmartDukaan

Rev

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