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(){
51
    	jQuery.ajax({
52
			type: "POST",
53
			url: "/addtocart",
54
			data: "productid=" + getSeletectedItemId(),
55
			success: function(msg)	{
56
	   			 if(msg == "") {
57
	   				 trackEventWithGA('Order', 'Add to Cart', getSeletectedItemId() + '');
58
					 window.location = "/cart";
59
				 } else {
60
					 var productDetail =  $("#productDetail");
61
    				 var prodInfo = $(productDetail).find("span.brand").html() + $(productDetail).find("span.product-name").html();
62
					 displayRelatedProducts(msg);
63
					 trackEventWithGA('Order', 'OOS Lightbox', prodInfo);
64
				 }
65
	   		}
66
		});
67
	});
68
 
69
	$("#colorSelector").change(function(){
70
		var itemid = $("#colorSelector option:selected").val();
71
		onColorSelectorChange(itemid);
72
		return false;
73
	});
74
 
75
	$(".util_compare").click(function() {
76
		$.colorbox({
77
			inline:true, 
78
			href:"#compareLightBox",
79
    		width:"350px",
80
    		height:"230px",
81
 
82
    		onComplete: function(){
83
    			$('#compareLightBox').show();
84
    		},
85
    		onCleanup: function(){
86
    			$('#compareLightBox').hide();
87
    		}
88
    	});
89
	});
90
 
91
	$('.util_addnewresearch').click(function(){
92
		addResearch('', 'single');
93
	});
94
 
95
    $('#mobilename').keypress(function(e) {
96
    	if(e.keyCode == 13) {
97
    		return compareProducts($("#compare_continue").attr("producttype"));
98
        }
99
    });
100
 
101
 
102
    $("#compare_continue").click(function() {
103
    	return compareProducts($(this).attr("producttype"));
104
    });
105
 
106
    $('.tooltip').click(function() {
107
    	trackEventWithGA('Product', 'Helpdoc Click', $(this).attr('name'));
108
    });
109
 
110
    $('.tooltip').each(function(index) {
111
    	   $(this).qtip({
112
    		style: { width: 300, overflow: 'auto',
113
    			tip: { corner: 'topLeft' }, 
114
    			border: { width: 2, radius: 2, color: '#DDDDDD' } },
115
    		show: { when: { event: 'click' } },
116
    		content: { url: "/helpdocs/" + $(this).attr('name'), title: { text: ' ', button: 'Close'} },
117
    		hide: { when: { event: 'unfocus' } },
118
    		position: { adjust: {screen: true} }
119
    		});
120
    	});
121
 
122
 
123
    function compareProducts(productType){
124
		var hyphenatedProductType = productType.replace(/ +/g, '-').toLowerCase();
125
 
126
    	var productName = $("#mobilename").val();
127
		var hypenatedNameTwo = productName.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
128
 
129
		var productTwo = productIdNames[productType][productName];
130
		if(typeof productTwo == 'undefined'){
131
			alert("Please select a valid product");
132
			return false;
133
		}
134
		var productOne = $("#catalog_id").val();
135
		var prodDetail = $("#productDetail");
136
		var productNameOne = $(prodDetail).find("span.brand").html() + " " + $(prodDetail).find("span.product-name").html();  
137
		var hyphenateNameOne = productNameOne.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();  
138
		window.location = "/compare-" + hyphenatedProductType + "/" 
139
			+ hyphenateNameOne + "-vs-" + hypenatedNameTwo + "?p1="+productOne+"&p2="+productTwo+"&fromsrc=product_page";	
140
	}
141
 
142
    $("#accessories table td div a").live('click', function() {
143
    	var productId = $(this).parent().parent().parent().children().find('input[type=checkbox]').val();
144
    	trackEventWithGA('Widget', 'Accessory Click', productId);
145
    });
146
 
147
 
148
	$('.nextSlide-anchorLink').live('click', function() {
149
	    var nextSlideLink = $(this).attr('nextSlideId');
150
	    $('a[href="' + nextSlideLink +'"]').click();
151
	    return false;
152
	});
153
 
154
    $('a.compare-now').live('click', function(){
155
		var productType = $(this).attr('producttype');
156
		productType = productType.replace(/ +/g, '-').toLowerCase();
157
 
158
		var productOne = $("#catalog_id").val();
159
		var prodDetail = $("#productDetail");
160
		var productNameOne = $(prodDetail).find("span.brand").html() + " " + $(prodDetail).find("span.product-name").html();
161
		var hyphenateNameOne = productNameOne.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
162
 
163
		var productTwo = $(this).attr("value");
164
		var hypenatedNameTwo = $(this).attr("title").replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
165
 
166
		window.location = "/compare-" + productType + "/" + hyphenateNameOne + "-vs-" + hypenatedNameTwo + "?p1="+productOne+"&p2="+productTwo+"&fromsrc=most_compared_widget";
167
    });
168
    jQuery('div.bread-crumbs, div.compare-links').remove();
169
});
170
 
171
function changeSignInClass(){
172
	if(document.getElementById("signinClass").className.indexOf("signin1") > -1)	{
173
		document.getElementById("signinClass").className = 'signin';
174
	} else	{
175
		document.getElementById("signinClass").className = 'signin1';
176
	}
177
}
178
 
179
 
180
function updateEstimate(itemId)	{
181
	itemId = itemId || $("#colorSelector option:selected").val();
182
 
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();
189
			$("#shipping_time .red").html("<img src='/images/loader_l.gif'> business days");
190
		},
191
		success: function(msg)	{
192
			var response = eval('(' + msg + ')');
193
			var deliveryEstimate = parseInt(response['delivery_estimate']);
194
			var isCODAvailableForLocation = (response['is_cod_available_for_location'] === 'true');
195
			var isOTG = (response['on_time_guarantee'] === 'true');
196
 
197
			if(deliveryEstimate == -1)	{
198
				$("#shipping_time").hide();
199
				$("#shipping_time_1").show();
200
			} else	{
201
				$("#shipping_time .red").html(deliveryEstimate + ' Business Days');
202
			}
203
 
204
			if (isCODAvailableForLocation)	{
205
				$('#cod').show();
206
			} else {
207
				$('#cod').hide();
208
			}
209
 
210
			if (isOTG)	{
211
				$('#otg').show();
212
			} else {
213
				$('#otg').hide();
214
			}
215
		}
216
	});
217
}
218
 
219
function load_most_compared_widget(){
220
	jQuery.ajax({
221
		type : "GET",
222
		url : "/most-compared-products/" + $("#product_id").val(),
223
		cache: false,
224
		success : function(html) {
225
   		    $("#mostcompared").html(html);
226
 
227
		    // Product Title
228
		    $("#mostcompared table td div a").each(function() {
229
		    		if($(this).attr('class') != "compare-now"){
230
		    			$(this).truncate({addtitle : true});
231
		    		}
232
		    });
233
 
234
		    // Product Price
235
		    $("#mostcompared table td div div.price").each(function() {
236
					$(this).truncate({addtitle : true});
237
			});
238
 
239
		    // Product Details
240
		    $("#mostcompared table td div div.text").each(function() {
241
					$(this).truncate( {addtitle : true});
242
			});
243
	    }
244
	});
245
}
246
function onColorSelectorChange(itemid){
247
	if($('#sp').length>0){
248
		$('#sp').html(PARAMETERS[itemid].SP);
249
		$('#mrp').html(PARAMETERS[itemid].MRP);
250
		$('#saving').html(PARAMETERS[itemid].SAVING);
251
		$("#item_id").val(itemid);
252
	}
253
	updateEstimate(itemid);
254
}