Subversion Repositories SmartDukaan

Rev

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