Subversion Repositories SmartDukaan

Rev

Rev 19706 | Rev 19710 | 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();
7272 amit.gupta 68
	});
69
 
70
	$("#colorSelector").change(function(){
71
		var itemid = $("#colorSelector option:selected").val();
72
		onColorSelectorChange(itemid);
73
		return false;
74
	});
75
 
76
	$(".util_compare").click(function() {
77
		$.colorbox({
78
			inline:true, 
79
			href:"#compareLightBox",
80
    		width:"350px",
81
    		height:"230px",
82
 
83
    		onComplete: function(){
84
    			$('#compareLightBox').show();
85
    		},
86
    		onCleanup: function(){
87
    			$('#compareLightBox').hide();
88
    		}
89
    	});
90
	});
91
 
92
	$('.util_addnewresearch').click(function(){
93
		addResearch('', 'single');
94
	});
95
 
96
    $('#mobilename').keypress(function(e) {
97
    	if(e.keyCode == 13) {
98
    		return compareProducts($("#compare_continue").attr("producttype"));
99
        }
100
    });
101
 
102
 
103
    $("#compare_continue").click(function() {
104
    	return compareProducts($(this).attr("producttype"));
105
    });
106
 
107
    $('.tooltip').click(function() {
108
    	trackEventWithGA('Product', 'Helpdoc Click', $(this).attr('name'));
109
    });
110
 
111
    $('.tooltip').each(function(index) {
112
    	   $(this).qtip({
113
    		style: { width: 300, overflow: 'auto',
114
    			tip: { corner: 'topLeft' }, 
115
    			border: { width: 2, radius: 2, color: '#DDDDDD' } },
116
    		show: { when: { event: 'click' } },
117
    		content: { url: "/helpdocs/" + $(this).attr('name'), title: { text: '&nbsp;', button: 'Close'} },
118
    		hide: { when: { event: 'unfocus' } },
119
    		position: { adjust: {screen: true} }
120
    		});
121
    	});
122
 
123
 
124
    function compareProducts(productType){
125
		var hyphenatedProductType = productType.replace(/ +/g, '-').toLowerCase();
126
 
127
    	var productName = $("#mobilename").val();
128
		var hypenatedNameTwo = productName.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
129
 
130
		var productTwo = productIdNames[productType][productName];
131
		if(typeof productTwo == 'undefined'){
132
			alert("Please select a valid product");
133
			return false;
134
		}
135
		var productOne = $("#catalog_id").val();
136
		var prodDetail = $("#productDetail");
137
		var productNameOne = $(prodDetail).find("span.brand").html() + " " + $(prodDetail).find("span.product-name").html();  
138
		var hyphenateNameOne = productNameOne.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();  
139
		window.location = "/compare-" + hyphenatedProductType + "/" 
140
			+ hyphenateNameOne + "-vs-" + hypenatedNameTwo + "?p1="+productOne+"&p2="+productTwo+"&fromsrc=product_page";	
141
	}
142
 
143
    $("#accessories table td div a").live('click', function() {
144
    	var productId = $(this).parent().parent().parent().children().find('input[type=checkbox]').val();
145
    	trackEventWithGA('Widget', 'Accessory Click', productId);
146
    });
147
 
148
 
149
	$('.nextSlide-anchorLink').live('click', function() {
150
	    var nextSlideLink = $(this).attr('nextSlideId');
151
	    $('a[href="' + nextSlideLink +'"]').click();
152
	    return false;
153
	});
154
 
155
    $('a.compare-now').live('click', function(){
156
		var productType = $(this).attr('producttype');
157
		productType = productType.replace(/ +/g, '-').toLowerCase();
158
 
159
		var productOne = $("#catalog_id").val();
160
		var prodDetail = $("#productDetail");
161
		var productNameOne = $(prodDetail).find("span.brand").html() + " " + $(prodDetail).find("span.product-name").html();
162
		var hyphenateNameOne = productNameOne.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
163
 
164
		var productTwo = $(this).attr("value");
165
		var hypenatedNameTwo = $(this).attr("title").replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
166
 
167
		window.location = "/compare-" + productType + "/" + hyphenateNameOne + "-vs-" + hypenatedNameTwo + "?p1="+productOne+"&p2="+productTwo+"&fromsrc=most_compared_widget";
168
    });
7386 anupam.sin 169
    jQuery('div.bread-crumbs, div.compare-links, #social-plugins-div').remove();
7272 amit.gupta 170
});
171
 
172
function changeSignInClass(){
173
	if(document.getElementById("signinClass").className.indexOf("signin1") > -1)	{
174
		document.getElementById("signinClass").className = 'signin';
175
	} else	{
176
		document.getElementById("signinClass").className = 'signin1';
177
	}
178
}
179
 
180
 
181
function updateEstimate(itemId)	{
182
	itemId = itemId || $("#colorSelector option:selected").val();
183
	jQuery.ajax({
184
		type: "GET",
185
		url: "/storewebsite/estimate/" + $("#zipcode").val() + "_" + itemId,
186
		beforeSend: function()	{
187
			$("#shipping_time").show();
188
			$("#shipping_time_1").hide();
7332 anupam.sin 189
			$("#shipping_time .red").html("<img src='/storewebsite/images/loader_l.gif'>");
7272 amit.gupta 190
		},
191
		success: function(msg)	{
192
			var response = eval('(' + msg + ')');
7323 anupam.sin 193
			var deliveryEstimate = (response['delivery_estimate']);
7272 amit.gupta 194
			var isCODAvailableForLocation = (response['is_cod_available_for_location'] === 'true');
195
			var isOTG = (response['on_time_guarantee'] === 'true');
7426 anupam.sin 196
 
197
			var isActive = (response['is_active'] === 'true');
198
			var isActiveOnStore = (response['active_on_store'] === 'true');
7323 anupam.sin 199
			var selling_price = parseFloat(response['selling_price']).toFixed(2);
7358 anupam.sin 200
			var absoluteMinPrice = parseFloat(response['absolute_min_price']).toFixed(2);
7695 anupam.sin 201
 
202
			if(deliveryEstimate === '01 January 1970')	{
7272 amit.gupta 203
				$("#shipping_time").hide();
204
				$("#shipping_time_1").show();
205
			} else	{
7323 anupam.sin 206
				$("#shipping_time").html("Get this product on <label class='red'>" + deliveryEstimate + "</label>");
7272 amit.gupta 207
			}
7426 anupam.sin 208
 
209
			if(!isActiveOnStore) {
7427 anupam.sin 210
				$("#addToCart").text("NOT AVAILABLE");
211
				$("#addToCart").css("color", "black");
212
				$("#addToCart").unbind();
7432 rajveer 213
			} else if(!isActive) {
19705 amit.gupta 214
				$("#addToCart").text("NOT AVAILABLE");
7427 anupam.sin 215
				$("#addToCart").css("color", "black");
216
				$("#addToCart").unbind();
217
			} else {
218
				$("#addToCart").text("ADD TO CART");
219
				$("#addToCart").css("color", "white");
220
				$("#addToCart").unbind();
221
				$("#addToCart").bind('click', function(){
222
			    	window.location = "/storewebsite/order-details?product_id=" + itemId + "&price=" + $('#mrp').text();
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
}