Subversion Repositories SmartDukaan

Rev

Rev 7793 | Rev 7810 | 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
	});
12
 
1456 varun.gupt 13
	$('#loopedSlider').loopedSlider();
14
 
15
	runEffect();
16
 
17
	$(".controls").tabs();
18
 
19
	$('#forgot_username_link').tipsy({gravity: 'w'});
20
 
21
	$("#zipcode").val($("#defaultpincode").val());
4934 amit.gupta 22
 
23
	if(typeof Entity != 'undefined'){
24
		var select = $("#colorSelector");
5373 rajveer 25
		if(Entity.orderedItems){
5347 amit.gupta 26
			$.each(Entity.orderedItems, function(index, sort) {
27
				select.find('option[value="' + sort + '"]').appendTo(select);
28
			});
29
			$("#item_id").val(Entity.orderedItems[0]);
5889 amit.gupta 30
			onColorSelectorChange(Entity.orderedItems[0]);
5347 amit.gupta 31
		}
4934 amit.gupta 32
		select.find("option:eq(0)").remove();
33
	}
1456 varun.gupt 34
 
1761 vikas 35
    var prodid = $("#product_id").val();
36
 
37
	add_to_storage_set("histitems", prodid);
38
 
2652 rajveer 39
    load_accessories_widget();
3406 rajveer 40
 
41
    load_most_compared_widget();
2754 rajveer 42
 
2731 varun.gupt 43
 
4489 varun.gupt 44
    // Fix to always show first image's title on page load
4530 mandeep.dh 45
    if ("undefined" != typeof(title_1)){
46
        $('.slides .modelName').html(title_1[0]);
47
    }
4489 varun.gupt 48
 
4530 mandeep.dh 49
 
3830 chandransh 50
    function getSeletectedItemId(){
51
    	 return $("#item_id").val();
52
    }
53
 
54
 
1922 varun.gupt 55
    /**
56
     * Code to track user clicks on Product slides and 'Proceed to Payment' option
57
     */
58
	$('a.vt').click(function(){
59
		trackEventWithGA('Product', $(this).children('span').text(), $('title').text().split('|')[0].trim());
60
	});
61
 
3830 chandransh 62
	$('#computeShippingEstimate').click(function(){
63
		updateEstimate(getSeletectedItemId());
64
	});
65
 
66
    $("#addToCart").click(function(){
2811 rajveer 67
    	jQuery.ajax({
1456 varun.gupt 68
			type: "POST",
1614 rajveer 69
			url: "/addtocart",
3830 chandransh 70
			data: "productid=" + getSeletectedItemId(),
1456 varun.gupt 71
			success: function(msg)	{
4530 mandeep.dh 72
	   			 if(msg == "") {
3830 chandransh 73
	   				 trackEventWithGA('Order', 'Add to Cart', getSeletectedItemId() + '');
2036 rajveer 74
					 window.location = "/cart";
4530 mandeep.dh 75
				 } else {
4934 amit.gupta 76
					 var productDetail =  $("#productDetail");
77
    				 var prodInfo = $(productDetail).find("span.brand").html() + $(productDetail).find("span.product-name").html();
2810 rajveer 78
					 displayRelatedProducts(msg);
4934 amit.gupta 79
					 trackEventWithGA('Order', 'OOS Lightbox', prodInfo);
4530 mandeep.dh 80
				 }
2754 rajveer 81
	   		}
1456 varun.gupt 82
		});
83
	});
84
 
3830 chandransh 85
	$("#colorSelector").change(function(){
86
		var itemid = $("#colorSelector option:selected").val();
5889 amit.gupta 87
		onColorSelectorChange(itemid);
1456 varun.gupt 88
		return false;
89
	});
90
 
3830 chandransh 91
	$(".util_compare").click(function() {
2755 rajveer 92
		$.colorbox({
93
			inline:true, 
94
			href:"#compareLightBox",
95
    		width:"350px",
96
    		height:"230px",
97
 
98
    		onComplete: function(){
99
    			$('#compareLightBox').show();
100
    		},
101
    		onCleanup: function(){
102
    			$('#compareLightBox').hide();
103
    		}
104
    	});
2228 rajveer 105
	});
3830 chandransh 106
 
107
	$('.util_addnewresearch').click(function(){
108
		addResearch('', 'single');
109
	});
110
 
2236 rajveer 111
    $('#mobilename').keypress(function(e) {
112
    	if(e.keyCode == 13) {
5347 amit.gupta 113
    		return compareProducts($("#compare_continue").attr("producttype"));
2236 rajveer 114
        }
115
    });
116
 
117
 
2228 rajveer 118
    $("#compare_continue").click(function() {
5347 amit.gupta 119
    	return compareProducts($(this).attr("producttype"));
2228 rajveer 120
    });
2236 rajveer 121
 
3305 rajveer 122
    $('.tooltip').click(function() {
123
    	trackEventWithGA('Product', 'Helpdoc Click', $(this).attr('name'));
124
    });
125
 
2320 rajveer 126
    $('.tooltip').each(function(index) {
127
    	   $(this).qtip({
128
    		style: { width: 300, overflow: 'auto',
129
    			tip: { corner: 'topLeft' }, 
130
    			border: { width: 2, radius: 2, color: '#DDDDDD' } },
131
    		show: { when: { event: 'click' } },
132
    		content: { url: "/helpdocs/" + $(this).attr('name'), title: { text: ' ', button: 'Close'} },
133
    		hide: { when: { event: 'unfocus' } },
134
    		position: { adjust: {screen: true} }
135
    		});
136
    	});
137
 
138
 
5347 amit.gupta 139
    function compareProducts(productType){
140
		var hyphenatedProductType = productType.replace(/ +/g, '-').toLowerCase();
141
 
142
    	var productName = $("#mobilename").val();
5358 amit.gupta 143
		var hypenatedNameTwo = productName.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
4143 varun.gupt 144
 
5347 amit.gupta 145
		var productTwo = productIdNames[productType][productName];
2236 rajveer 146
		if(typeof productTwo == 'undefined'){
147
			alert("Please select a valid product");
148
			return false;
149
		}
2827 rajveer 150
		var productOne = $("#catalog_id").val();
5347 amit.gupta 151
		var prodDetail = $("#productDetail");
152
		var productNameOne = $(prodDetail).find("span.brand").html() + " " + $(prodDetail).find("span.product-name").html();  
5358 amit.gupta 153
		var hyphenateNameOne = productNameOne.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();  
5347 amit.gupta 154
		window.location = "/compare-" + hyphenatedProductType + "/" 
5552 phani.kuma 155
			+ hyphenateNameOne + "-vs-" + hypenatedNameTwo + "?p1="+productOne+"&p2="+productTwo+"&fromsrc=product_page";	
2236 rajveer 156
	}
2228 rajveer 157
 
2802 rajveer 158
    $("#accessories table td div a").live('click', function() {
159
    	var productId = $(this).parent().parent().parent().children().find('input[type=checkbox]').val();
160
    	trackEventWithGA('Widget', 'Accessory Click', productId);
161
    });
162
 
5862 amit.gupta 163
 
164
	$('.nextSlide-anchorLink').live('click', function() {
165
	    var nextSlideLink = $(this).attr('nextSlideId');
166
	    $('a[href="' + nextSlideLink +'"]').click();
167
	    return false;
168
	});
169
 
5552 phani.kuma 170
    $('a.compare-now').live('click', function(){
171
		var productType = $(this).attr('producttype');
172
		productType = productType.replace(/ +/g, '-').toLowerCase();
173
 
174
		var productOne = $("#catalog_id").val();
175
		var prodDetail = $("#productDetail");
176
		var productNameOne = $(prodDetail).find("span.brand").html() + " " + $(prodDetail).find("span.product-name").html();
177
		var hyphenateNameOne = productNameOne.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
178
 
179
		var productTwo = $(this).attr("value");
180
		var hypenatedNameTwo = $(this).attr("title").replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
181
 
182
		window.location = "/compare-" + productType + "/" + hyphenateNameOne + "-vs-" + hypenatedNameTwo + "?p1="+productOne+"&p2="+productTwo+"&fromsrc=most_compared_widget";
183
    });
184
 
1456 varun.gupt 185
});
186
 
187
function changeSignInClass(){
188
	if(document.getElementById("signinClass").className.indexOf("signin1") > -1)	{
189
		document.getElementById("signinClass").className = 'signin';
190
	} else	{
191
		document.getElementById("signinClass").className = 'signin1';
192
	}
193
}
194
 
2228 rajveer 195
 
1456 varun.gupt 196
function updateEstimate(itemId)	{
3830 chandransh 197
	itemId = itemId || $("#colorSelector option:selected").val();
1456 varun.gupt 198
 
199
	jQuery.ajax({
200
		type: "GET",
1919 rajveer 201
		url: "/estimate/" + $("#zipcode").val() + "_" + itemId,
1456 varun.gupt 202
		beforeSend: function()	{
5234 amit.gupta 203
			$("#shipping_time").show();
204
			$("#shipping_time_1").hide();
7791 rajveer 205
			$("#shipping_time .red").html("<img src='/images/loader_l.gif'>");
1456 varun.gupt 206
		},
207
		success: function(msg)	{
3830 chandransh 208
			var response = eval('(' + msg + ')');
7793 rajveer 209
			var deliveryEstimate = response['delivery_estimate'];
7809 rajveer 210
			var codDeliveryEstimate = response['cod_delivery_estimate'];
3830 chandransh 211
			var isCODAvailableForLocation = (response['is_cod_available_for_location'] === 'true');
6561 amit.gupta 212
			var isOTG = (response['on_time_guarantee'] === 'true');
7809 rajveer 213
			var systemDate = response['system_date'];
3830 chandransh 214
 
215
			if(deliveryEstimate == -1)	{
5234 amit.gupta 216
				$("#shipping_time").hide();
217
				$("#shipping_time_1").show();
3830 chandransh 218
			} else	{
7809 rajveer 219
				toDate = new Date(systemDate);
220
				myDate = new Date(deliveryEstimate);
221
				days = myDate.getDate() - toDate.getDate();
7791 rajveer 222
				if($("#shipping_time").html().indexOf('after arrival')>-1){
7809 rajveer 223
					$("#shipping_time .red").html(days + " Days");
7791 rajveer 224
				}else{
7809 rajveer 225
					if(isCODAvailableForLocation){
226
						codDate = new Date(codDeliveryEstimate);
227
						coddays = codDate.getDate() - myDate.getDate();
228
						if(days > 1){
229
							$('#cod_know_more').show();
230
							$("#shipping_time .cod").html(codDeliveryEstimate);
231
						}
232
					}
233
					if(days == 1){
234
						$("#shipping_time .red").html("Tomorrow, " + deliveryEstimate);
235
					}else{
236
						$("#shipping_time .red").html(deliveryEstimate);
237
					}
7791 rajveer 238
				}
3830 chandransh 239
			}
240
 
4869 rajveer 241
			if (isCODAvailableForLocation)	{
3830 chandransh 242
				$('#cod').show();
243
			} else {
244
				$('#cod').hide();
245
			}
6561 amit.gupta 246
 
247
			if (isOTG)	{
248
				$('#otg').show();
249
			} else {
250
				$('#otg').hide();
251
			}
1456 varun.gupt 252
		}
253
	});
2228 rajveer 254
}
255
 
3406 rajveer 256
function load_most_compared_widget(){
257
	jQuery.ajax({
258
		type : "GET",
259
		url : "/most-compared-products/" + $("#product_id").val(),
260
		cache: false,
261
		success : function(html) {
262
   		    $("#mostcompared").html(html);
263
 
264
		    // Product Title
265
		    $("#mostcompared table td div a").each(function() {
5552 phani.kuma 266
		    		if($(this).attr('class') != "compare-now"){
267
		    			$(this).truncate({addtitle : true});
268
		    		}
3406 rajveer 269
		    });
270
 
271
		    // Product Price
272
		    $("#mostcompared table td div div.price").each(function() {
273
					$(this).truncate({addtitle : true});
274
			});
275
 
276
		    // Product Details
277
		    $("#mostcompared table td div div.text").each(function() {
278
					$(this).truncate( {addtitle : true});
279
			});
280
	    }
281
	});
5889 amit.gupta 282
}
283
function onColorSelectorChange(itemid){
6021 amit.gupta 284
	if($('#sp').length>0){
285
		$('#sp').html(PARAMETERS[itemid].SP);
286
		$('#mrp').html(PARAMETERS[itemid].MRP);
287
		$('#saving').html(PARAMETERS[itemid].SAVING);
288
		$("#item_id").val(itemid);
289
	}
5889 amit.gupta 290
	updateEstimate(itemid);
3406 rajveer 291
}