Subversion Repositories SmartDukaan

Rev

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