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
    });
153
    jQuery('div.bread-crumbs, div.compare-links').remove();
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();
7329 anupam.sin 173
			$("#shipping_time .red").html("<img src='/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');
7323 anupam.sin 180
			var selling_price = parseFloat(response['selling_price']).toFixed(2);
7272 amit.gupta 181
 
182
			if(deliveryEstimate == -1)	{
183
				$("#shipping_time").hide();
184
				$("#shipping_time_1").show();
185
			} else	{
7323 anupam.sin 186
				$("#shipping_time").html("Get this product on <label class='red'>" + deliveryEstimate + "</label>");
7272 amit.gupta 187
			}
7323 anupam.sin 188
			$('.warranty').html(response['best_deal_text']);
189
			$('#mrp').html(selling_price);
190
			$('#minPrice').html(parseFloat(response['min_selling_price']).toFixed(2));
191
			$('#maxPrice').html(parseFloat(response['max_selling_price']).toFixed(2));
192
			$('#sellingPriceBox').val(selling_price);
193
			$('#cod').hide();
194
			$('#otg').hide();
195
			$('#item_id').val(itemId);
7272 amit.gupta 196
		}
197
	});
198
}
199
 
200
function load_most_compared_widget(){
201
	jQuery.ajax({
202
		type : "GET",
203
		url : "/most-compared-products/" + $("#product_id").val(),
204
		cache: false,
205
		success : function(html) {
206
   		    $("#mostcompared").html(html);
207
 
208
		    // Product Title
209
		    $("#mostcompared table td div a").each(function() {
210
		    		if($(this).attr('class') != "compare-now"){
211
		    			$(this).truncate({addtitle : true});
212
		    		}
213
		    });
214
 
215
		    // Product Price
216
		    $("#mostcompared table td div div.price").each(function() {
217
					$(this).truncate({addtitle : true});
218
			});
219
 
220
		    // Product Details
221
		    $("#mostcompared table td div div.text").each(function() {
222
					$(this).truncate( {addtitle : true});
223
			});
224
	    }
225
	});
226
}
227
function onColorSelectorChange(itemid){
228
	if($('#sp').length>0){
229
		$('#sp').html(PARAMETERS[itemid].SP);
230
		$('#mrp').html(PARAMETERS[itemid].MRP);
231
		$('#saving').html(PARAMETERS[itemid].SAVING);
232
		$("#item_id").val(itemid);
233
	}
234
	updateEstimate(itemid);
235
}