Subversion Repositories SmartDukaan

Rev

Go to most recent revision | 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);
7272 amit.gupta 185
 
186
			if(deliveryEstimate == -1)	{
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) {
194
				($"#addToCart").text("NOT AVAILABLE");
195
				($"#addToCart").css("color", "black");
196
				($"#addToCart").unbind();
197
			}
198
 
199
			if(!isActive) {
200
				($"#addToCart").text("OUT OF STOCK");
201
				($"#addToCart").css("color", "black");
202
				($"#addToCart").unbind();
203
			}
204
 
7323 anupam.sin 205
			$('.warranty').html(response['best_deal_text']);
206
			$('#mrp').html(selling_price);
207
			$('#minPrice').html(parseFloat(response['min_selling_price']).toFixed(2));
208
			$('#maxPrice').html(parseFloat(response['max_selling_price']).toFixed(2));
209
			$('#sellingPriceBox').val(selling_price);
7358 anupam.sin 210
			$('#absMin').val(absoluteMinPrice);
7323 anupam.sin 211
			$('#cod').hide();
212
			$('#otg').hide();
213
			$('#item_id').val(itemId);
7272 amit.gupta 214
		}
215
	});
216
}
217
 
218
function load_most_compared_widget(){
219
	jQuery.ajax({
220
		type : "GET",
221
		url : "/most-compared-products/" + $("#product_id").val(),
222
		cache: false,
223
		success : function(html) {
224
   		    $("#mostcompared").html(html);
225
 
226
		    // Product Title
227
		    $("#mostcompared table td div a").each(function() {
228
		    		if($(this).attr('class') != "compare-now"){
229
		    			$(this).truncate({addtitle : true});
230
		    		}
231
		    });
232
 
233
		    // Product Price
234
		    $("#mostcompared table td div div.price").each(function() {
235
					$(this).truncate({addtitle : true});
236
			});
237
 
238
		    // Product Details
239
		    $("#mostcompared table td div div.text").each(function() {
240
					$(this).truncate( {addtitle : true});
241
			});
242
	    }
243
	});
244
}
245
function onColorSelectorChange(itemid){
246
	if($('#sp').length>0){
247
		$('#sp').html(PARAMETERS[itemid].SP);
248
		$('#mrp').html(PARAMETERS[itemid].MRP);
249
		$('#saving').html(PARAMETERS[itemid].SAVING);
250
		$("#item_id").val(itemid);
251
	}
252
	updateEstimate(itemid);
253
}