Subversion Repositories SmartDukaan

Rev

Rev 7791 | Rev 7809 | 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'];
3830 chandransh 210
			var isCODAvailableForLocation = (response['is_cod_available_for_location'] === 'true');
6561 amit.gupta 211
			var isOTG = (response['on_time_guarantee'] === 'true');
3830 chandransh 212
 
213
			if(deliveryEstimate == -1)	{
5234 amit.gupta 214
				$("#shipping_time").hide();
215
				$("#shipping_time_1").show();
3830 chandransh 216
			} else	{
7791 rajveer 217
				if($("#shipping_time").html().indexOf('after arrival')>-1){
218
					myDate = new Date(deliveryEstimate);
219
					toDate = new Date();
220
					days = parseInt((myDate - toDate) / (1000 * 60 * 60 * 24));
221
					$("#shipping_time .red").html(days + " Business Days");
222
				}else{
223
					$("#shipping_time .red").html(deliveryEstimate);
224
				}
3830 chandransh 225
			}
226
 
4869 rajveer 227
			if (isCODAvailableForLocation)	{
3830 chandransh 228
				$('#cod').show();
229
			} else {
230
				$('#cod').hide();
231
			}
6561 amit.gupta 232
 
233
			if (isOTG)	{
234
				$('#otg').show();
235
			} else {
236
				$('#otg').hide();
237
			}
1456 varun.gupt 238
		}
239
	});
2228 rajveer 240
}
241
 
3406 rajveer 242
function load_most_compared_widget(){
243
	jQuery.ajax({
244
		type : "GET",
245
		url : "/most-compared-products/" + $("#product_id").val(),
246
		cache: false,
247
		success : function(html) {
248
   		    $("#mostcompared").html(html);
249
 
250
		    // Product Title
251
		    $("#mostcompared table td div a").each(function() {
5552 phani.kuma 252
		    		if($(this).attr('class') != "compare-now"){
253
		    			$(this).truncate({addtitle : true});
254
		    		}
3406 rajveer 255
		    });
256
 
257
		    // Product Price
258
		    $("#mostcompared table td div div.price").each(function() {
259
					$(this).truncate({addtitle : true});
260
			});
261
 
262
		    // Product Details
263
		    $("#mostcompared table td div div.text").each(function() {
264
					$(this).truncate( {addtitle : true});
265
			});
266
	    }
267
	});
5889 amit.gupta 268
}
269
function onColorSelectorChange(itemid){
6021 amit.gupta 270
	if($('#sp').length>0){
271
		$('#sp').html(PARAMETERS[itemid].SP);
272
		$('#mrp').html(PARAMETERS[itemid].MRP);
273
		$('#saving').html(PARAMETERS[itemid].SAVING);
274
		$("#item_id").val(itemid);
275
	}
5889 amit.gupta 276
	updateEstimate(itemid);
3406 rajveer 277
}