Subversion Repositories SmartDukaan

Rev

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