Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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