Subversion Repositories SmartDukaan

Rev

Rev 19712 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7272 amit.gupta 1
$(function(){
7768 amit.gupta 2
 
3
	jQuery('.mk_videoclick').click(function(){
4
		var clicked = jQuery(this);
5
	    var scrollTo = jQuery("#recommendedvids");
6
	    if(currentVideoId!=currentVideoIds[clicked.attr("slidecounter")]){
7
	    	scrollTo.find('li[ytid=' + currentVideoIds[clicked.attr("slidecounter")] + ']').click();
8
	    }
9
		//trackEventWithGA('Product', 'VideoTabClicked',  $('title').text().split('|')[0].trim()  + "|" + clicked.attr("slidename"));
10
  		jQuery('html, body').animate({ scrollTop: scrollTo.offset().top }, 'medium');
11
    	return false;
12
	});
13
 
14
 
7272 amit.gupta 15
	$('#loopedSlider').loopedSlider();
16
 
17
	runEffect();
18
 
19
	$(".controls").tabs();
20
 
21
	$('#forgot_username_link').tipsy({gravity: 'w'});
22
 
23
	$("#zipcode").val($("#defaultpincode").val());
24
 
25
	if(typeof Entity != 'undefined'){
26
		var select = $("#colorSelector");
27
		if(Entity.orderedItems){
28
			$.each(Entity.orderedItems, function(index, sort) {
29
				select.find('option[value="' + sort + '"]').appendTo(select);
30
			});
31
			$("#item_id").val(Entity.orderedItems[0]);
32
			onColorSelectorChange(Entity.orderedItems[0]);
33
		}
34
		select.find("option:eq(0)").remove();
35
	}
36
 
37
    var prodid = $("#product_id").val();
38
 
39
 
40
 
41
    // Fix to always show first image's title on page load
42
    if ("undefined" != typeof(title_1)){
43
        $('.slides .modelName').html(title_1[0]);
44
    }
45
 
46
 
47
    function getSeletectedItemId(){
48
    	 return $("#item_id").val();
49
    }
50
 
51
 
52
    /**
53
     * Code to track user clicks on Product slides and 'Proceed to Payment' option
54
     */
55
	$('a.vt').click(function(){
56
		trackEventWithGA('Product', $(this).children('span').text(), $('title').text().split('|')[0].trim());
57
	});
58
 
59
	$('#computeShippingEstimate').click(function(){
60
		updateEstimate(getSeletectedItemId());
61
	});
62
 
63
    $("#addToCart").click(function(){
19710 amit.gupta 64
    	window.location = "/storewebsite/order-details?product_id=" + getSeletectedItemId() + "&price=" + $('#mrp').text();
7272 amit.gupta 65
	});
66
 
67
	$("#colorSelector").change(function(){
68
		var itemid = $("#colorSelector option:selected").val();
69
		onColorSelectorChange(itemid);
70
		return false;
71
	});
72
 
73
	$(".util_compare").click(function() {
74
		$.colorbox({
75
			inline:true, 
76
			href:"#compareLightBox",
77
    		width:"350px",
78
    		height:"230px",
79
 
80
    		onComplete: function(){
81
    			$('#compareLightBox').show();
82
    		},
83
    		onCleanup: function(){
84
    			$('#compareLightBox').hide();
85
    		}
86
    	});
87
	});
88
 
89
	$('.util_addnewresearch').click(function(){
90
		addResearch('', 'single');
91
	});
92
 
93
    $('#mobilename').keypress(function(e) {
94
    	if(e.keyCode == 13) {
95
    		return compareProducts($("#compare_continue").attr("producttype"));
96
        }
97
    });
98
 
99
 
100
    $("#compare_continue").click(function() {
101
    	return compareProducts($(this).attr("producttype"));
102
    });
103
 
104
    $('.tooltip').click(function() {
105
    	trackEventWithGA('Product', 'Helpdoc Click', $(this).attr('name'));
106
    });
107
 
108
    $('.tooltip').each(function(index) {
109
    	   $(this).qtip({
110
    		style: { width: 300, overflow: 'auto',
111
    			tip: { corner: 'topLeft' }, 
112
    			border: { width: 2, radius: 2, color: '#DDDDDD' } },
113
    		show: { when: { event: 'click' } },
114
    		content: { url: "/helpdocs/" + $(this).attr('name'), title: { text: ' ', button: 'Close'} },
115
    		hide: { when: { event: 'unfocus' } },
116
    		position: { adjust: {screen: true} }
117
    		});
118
    	});
119
 
120
 
121
    function compareProducts(productType){
122
		var hyphenatedProductType = productType.replace(/ +/g, '-').toLowerCase();
123
 
124
    	var productName = $("#mobilename").val();
125
		var hypenatedNameTwo = productName.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
126
 
127
		var productTwo = productIdNames[productType][productName];
128
		if(typeof productTwo == 'undefined'){
129
			alert("Please select a valid product");
130
			return false;
131
		}
132
		var productOne = $("#catalog_id").val();
133
		var prodDetail = $("#productDetail");
134
		var productNameOne = $(prodDetail).find("span.brand").html() + " " + $(prodDetail).find("span.product-name").html();  
135
		var hyphenateNameOne = productNameOne.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();  
136
		window.location = "/compare-" + hyphenatedProductType + "/" 
137
			+ hyphenateNameOne + "-vs-" + hypenatedNameTwo + "?p1="+productOne+"&p2="+productTwo+"&fromsrc=product_page";	
138
	}
139
 
140
    $("#accessories table td div a").live('click', function() {
141
    	var productId = $(this).parent().parent().parent().children().find('input[type=checkbox]').val();
142
    	trackEventWithGA('Widget', 'Accessory Click', productId);
143
    });
144
 
145
 
146
	$('.nextSlide-anchorLink').live('click', function() {
147
	    var nextSlideLink = $(this).attr('nextSlideId');
148
	    $('a[href="' + nextSlideLink +'"]').click();
149
	    return false;
150
	});
151
 
152
    $('a.compare-now').live('click', function(){
153
		var productType = $(this).attr('producttype');
154
		productType = productType.replace(/ +/g, '-').toLowerCase();
155
 
156
		var productOne = $("#catalog_id").val();
157
		var prodDetail = $("#productDetail");
158
		var productNameOne = $(prodDetail).find("span.brand").html() + " " + $(prodDetail).find("span.product-name").html();
159
		var hyphenateNameOne = productNameOne.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
160
 
161
		var productTwo = $(this).attr("value");
162
		var hypenatedNameTwo = $(this).attr("title").replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
163
 
164
		window.location = "/compare-" + productType + "/" + hyphenateNameOne + "-vs-" + hypenatedNameTwo + "?p1="+productOne+"&p2="+productTwo+"&fromsrc=most_compared_widget";
165
    });
7386 anupam.sin 166
    jQuery('div.bread-crumbs, div.compare-links, #social-plugins-div').remove();
7272 amit.gupta 167
});
168
 
169
function changeSignInClass(){
170
	if(document.getElementById("signinClass").className.indexOf("signin1") > -1)	{
171
		document.getElementById("signinClass").className = 'signin';
172
	} else	{
173
		document.getElementById("signinClass").className = 'signin1';
174
	}
175
}
176
 
177
 
178
function updateEstimate(itemId)	{
179
	itemId = itemId || $("#colorSelector option:selected").val();
180
	jQuery.ajax({
181
		type: "GET",
182
		url: "/storewebsite/estimate/" + $("#zipcode").val() + "_" + itemId,
183
		beforeSend: function()	{
184
			$("#shipping_time").show();
185
			$("#shipping_time_1").hide();
7332 anupam.sin 186
			$("#shipping_time .red").html("<img src='/storewebsite/images/loader_l.gif'>");
7272 amit.gupta 187
		},
188
		success: function(msg)	{
189
			var response = eval('(' + msg + ')');
7323 anupam.sin 190
			var deliveryEstimate = (response['delivery_estimate']);
7272 amit.gupta 191
			var isCODAvailableForLocation = (response['is_cod_available_for_location'] === 'true');
192
			var isOTG = (response['on_time_guarantee'] === 'true');
7426 anupam.sin 193
 
194
			var isActive = (response['is_active'] === 'true');
195
			var isActiveOnStore = (response['active_on_store'] === 'true');
7323 anupam.sin 196
			var selling_price = parseFloat(response['selling_price']).toFixed(2);
7358 anupam.sin 197
			var absoluteMinPrice = parseFloat(response['absolute_min_price']).toFixed(2);
7695 anupam.sin 198
 
199
			if(deliveryEstimate === '01 January 1970')	{
7272 amit.gupta 200
				$("#shipping_time").hide();
201
				$("#shipping_time_1").show();
202
			} else	{
7323 anupam.sin 203
				$("#shipping_time").html("Get this product on <label class='red'>" + deliveryEstimate + "</label>");
7272 amit.gupta 204
			}
7426 anupam.sin 205
 
206
			if(!isActiveOnStore) {
7427 anupam.sin 207
				$("#addToCart").text("NOT AVAILABLE");
208
				$("#addToCart").css("color", "black");
209
				$("#addToCart").unbind();
7432 rajveer 210
			} else if(!isActive) {
19705 amit.gupta 211
				$("#addToCart").text("NOT AVAILABLE");
7427 anupam.sin 212
				$("#addToCart").css("color", "black");
213
				$("#addToCart").unbind();
214
			} else {
215
				$("#addToCart").text("ADD TO CART");
216
				$("#addToCart").css("color", "white");
217
				$("#addToCart").unbind();
218
				$("#addToCart").bind('click', function(){
19713 amit.gupta 219
				$('<form action="/storewebsite/order-details" method="POST">' +
220
				    	'<input name="product_id" value="' + itemId +'"/>' +
19710 amit.gupta 221
				    	'<input name="price" value="' + $('#mrp').text() +'"/>' +
222
			      	'</form>').submit();
7427 anupam.sin 223
				});
7426 anupam.sin 224
			}
225
 
7695 anupam.sin 226
			if(selling_price == 0) {
227
				$("#addToCart").text("NOT AVAILABLE");
228
				$("#addToCart").css("color", "black");
229
				$("#addToCart").unbind();
230
 
231
				$('#sellingPriceBox').val('N/A');
232
				$('#mrp').html('N/A');
233
				$('#minPrice').html('N/A');
234
				$('#maxPrice').html('N/A');
235
				$('#absMin').val(0);
236
				$('#cod').hide();
237
				$('#otg').hide();
238
				$('#item_id').val(itemId);
239
 
240
				$('#editSellingPriceButton').hide();
241
				$("#shipping_time").html("<label class='red'>Error in getting price.Please refresh this page.</label>");
242
			} else {
243
				$('#editSellingPriceButton').show();
244
				$('.warranty').html(response['best_deal_text']);
245
				$('#mrp').html(selling_price);
246
				$('#minPrice').html(parseFloat(response['min_selling_price']).toFixed(2));
247
				$('#maxPrice').html(parseFloat(response['max_selling_price']).toFixed(2));
248
				$('#sellingPriceBox').val(selling_price);
249
				$('#absMin').val(absoluteMinPrice);
250
				$('#cod').hide();
251
				$('#otg').hide();
252
				$('#item_id').val(itemId);
253
			}
7272 amit.gupta 254
		}
255
	});
256
}
257
 
258
function load_most_compared_widget(){
259
	jQuery.ajax({
260
		type : "GET",
261
		url : "/most-compared-products/" + $("#product_id").val(),
262
		cache: false,
263
		success : function(html) {
264
   		    $("#mostcompared").html(html);
265
 
266
		    // Product Title
267
		    $("#mostcompared table td div a").each(function() {
268
		    		if($(this).attr('class') != "compare-now"){
269
		    			$(this).truncate({addtitle : true});
270
		    		}
271
		    });
272
 
273
		    // Product Price
274
		    $("#mostcompared table td div div.price").each(function() {
275
					$(this).truncate({addtitle : true});
276
			});
277
 
278
		    // Product Details
279
		    $("#mostcompared table td div div.text").each(function() {
280
					$(this).truncate( {addtitle : true});
281
			});
282
	    }
283
	});
284
}
285
function onColorSelectorChange(itemid){
286
	if($('#sp').length>0){
287
		$('#sp').html(PARAMETERS[itemid].SP);
288
		$('#mrp').html(PARAMETERS[itemid].MRP);
289
		$('#saving').html(PARAMETERS[itemid].SAVING);
290
		$("#item_id").val(itemid);
291
	}
292
	updateEstimate(itemid);
293
}