Subversion Repositories SmartDukaan

Rev

Rev 6303 | Rev 6480 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4126 varun.gupt 1
$(function(){
4984 varun.gupt 2
	function CollapsibleWidget(container)	{
3
 
4
		this.widgetContainer = container;
5
		this.collapsbiles = $(container).children('.common-widget-control-bar, .common-widget-content-area');
6
		this.isCollapsed = null;
7
 
8
		this.collapse = function()	{
9
			$(this.collapsbiles).each(function()	{
10
				$(this).slideUp();
11
			});
12
			this.isCollapsed = true;
13
		};
14
 
15
		this.open = function()	{
16
			$(this.collapsbiles).each(function()	{
17
				$(this).slideDown();
18
			});
19
			this.isCollapsed = false;
20
		};
21
 
22
		this.test = function()	{
23
		};
24
	}
4798 varun.gupt 25
 
4984 varun.gupt 26
	ResearchWidget.prototype = new CollapsibleWidget();
27
	ResearchWidget.prototype.constructor = CollapsibleWidget;
28
 
29
	function ResearchWidget(container)	{
30
		CollapsibleWidget.call(this, container);
31
	}
32
 
4798 varun.gupt 33
	function updateCompareCount()	{
34
		$('#research_compare_count').html($('#myresearch input[type="checkbox"]:checked').length);
35
	}
36
 
4126 varun.gupt 37
	/** Sidebar Widgets **/
4237 varun.gupt 38
 
39
	$('#shoppingExpInfo').click(function(){
40
		$.colorbox({
4284 varun.gupt 41
    		width: "550px",
42
    		height: "320px",
4237 varun.gupt 43
    		inline: true,
44
    		href: "<h3>Shopping with Saholic.com is completely safe</h3><br />" +
4284 varun.gupt 45
		"<b>1.</b> We are part of Spice Group - India's # 1 Mobile retailer.<br /><br />" +
46
		"<b>2.</b> We procure directly from the Manufacturers - Hence we only sell genuine products with full Manufacturer Warranty.<br /><br />" +
47
		"<b>3.</b> We provide free Next Day Delivery to most locations - You can check the delivery time to your location by entering your pin code on the product page.<br /><br />" +
6173 kshitij.so 48
		"<b>4.</b> We use the best Internet Security technology - Your payment is 100% secure.<br />",
4372 varun.gupt 49
			onComplete: function(){
6261 amit.gupta 50
				trackEventWithGA('Widget', 'Safe shopping sticky banner is clicked', '');
4372 varun.gupt 51
			}
4237 varun.gupt 52
    	});
53
	});
6245 kshitij.so 54
 
6453 kshitij.so 55
	$('#emiInfo').click(function(){
56
		$.colorbox({
57
    		width: "550px",
58
    		height: "400px",
59
    		inline: true,
60
    		href: "<h3>EMI Details</h3><br />" +
61
    		"<ul style = 'list-style : disc inside none'>"+
62
		"<li>All Inclusive Processing Fee is as follows</li><br />" +
63
		"<table width='46%' cellspacing='0' cellpadding='0' border='0' id='emiwidget' style='padding-top: 2px; padding-bottom: 2px; border-top-width: 0px; border-left-width: 0px;margin-left: 13px'>" +
64
		"<thead>"+
65
		"<tr>"+
66
		"<th width='50%' style='border-left: 1px solid gray; border-top: 1px solid gray;border-bottom: 1px solid gray;text-align: center;'>Months</th>"+
67
		"<th width='50%' style='border:1px solid gray;text-align: center;'>Processing Fee*</th>"+
68
		"</tr>"+
69
		"</thead>"+
70
		"<tbody>"+
71
		"<tr>"+
72
		"<td style='border-bottom: 1px solid gray; border-left: 1px solid gray; text-align: center;'>3</td>"+
73
		"<td style='border-right: 1px solid gray; border-bottom: 1px solid gray; border-left: 1px solid gray;text-align: center;'>0</td>"+
74
		"</tr>"+
75
		"<tr>"+
76
		"<td style='border-bottom: 1px solid gray; border-left: 1px solid gray; text-align: center;'>6</td>"+
77
		"<td style='border-right: 1px solid gray; border-bottom: 1px solid gray; border-left: 1px solid gray;text-align: center;'>4.05%</td>"+		"</tr>"+
78
		"<tr>"+
79
		"<td style='border-bottom: 1px solid gray; border-left: 1px solid gray; text-align: center;'>9</td>"+
80
		"<td style='border-right: 1px solid gray; border-bottom: 1px solid gray; border-left: 1px solid gray;text-align: center;'>6.57%</td>"+
81
		"</tr>"+
82
		"<tr>"+
83
		"<td style='border-bottom: 1px solid gray; border-left: 1px solid gray; text-align: center;'>12</td>"+
84
		"<td style='border-right: 1px solid gray; border-bottom: 1px solid gray; border-left: 1px solid gray;text-align: center;'>8.82%</td>"+
85
		"</tr>"+
86
		"</tbody>"+
87
		"</table>"+
88
		"<span style='padding-left:13px'>*Inclusive of service tax.<br/></span>"+
89
		"<br />"+
90
		"<li> Select EMI on Make Payment Page to see Monthly EMI and Total Amount Paid.</li><br />" +
91
		"<li> Minimum purchase of Rs. 200</li><br />"+
92
		"<li> For HDFC Credit Card Holders, other Banks Coming Soon.</li>"+
93
		"</ul>",
94
			onComplete: function(){
95
				trackEventWithGA('Widget', 'Emi info widget is clicked', '');
96
			}
97
    	});
98
	});
6245 kshitij.so 99
 
6453 kshitij.so 100
 
6245 kshitij.so 101
	$('#pickupstoreInfo').click(function(){
102
		$.colorbox({
103
    		width: "550px",
104
    		height: "370px",
105
    		inline: true,
106
    		href: "<h3>Frequently Asked Questions</h3><br />" +
107
		"<b>Q)</b> What is 'Buy Online & Pickup in Store' ?<br /><br />" +
108
		"<b>A)</b> Buy Online from Saholic.Com and pickup your product from the nearest Spice Hotspot Retail Store.<br /><br />" +
109
		"<b>Q)</b> How do i avail this facility ?<br /><br />" +
110
		"<b>A)</b> Simply select Pickup In Store On the Shipping Page and select your nearest store. Please note this facility is available only in Delhi/NCR.</a><br /><br />"+
111
		"<b>Q)</b> When will the product be available for pickup ?<br /><br />" +
112
		"<b>A)</b> You can enter your pin code on the Product Page to find estimated time to deliver. After placing the order we will also give you the estimated date for pickup.</a><br /><br />",
113
 
114
			onComplete: function(){
6262 amit.gupta 115
				var ev = "Product Page";
6303 amit.gupta 116
				var label = window.location.pathname;
6264 amit.gupta 117
				if (label=="" || label=="#")
6261 amit.gupta 118
				{
6303 amit.gupta 119
					label = "";
6262 amit.gupta 120
					ev = "Home Page";
6261 amit.gupta 121
				}
6262 amit.gupta 122
				else if (label.indexOf("shipping") != -1){
123
					ev = "Shipping Page";
124
					var blkstr = [];
6263 amit.gupta 125
					jQuery("#cartDetail").find("span.cart-item-name").each(function(key,str){
6262 amit.gupta 126
						blkstr.push(str);
127
					});
6303 amit.gupta 128
					label = blkstr.join(", ");
129
				} else if (label.substr(label.lastIndexOf('/') + 1).length==5 && typeof label.substr(label.lastIndexOf('/') + 1) =="number") {
130
					ev = "Category Page";
131
				} else if (label.substr(label.lastIndexOf('-') + 1).length==7  && typeof label.substr(label.lastIndexOf('-') + 1) =="number") {
132
					ev = "Product Page";
6262 amit.gupta 133
				}
6261 amit.gupta 134
				trackEventWithGA('Pickup in Store LightBox', ev, label);
6245 kshitij.so 135
			}
136
    	});
137
	});
4126 varun.gupt 138
 
5420 amit.gupta 139
	$('.common-widget-top-bar').live('click', function(e, callback){
4126 varun.gupt 140
		var isColapsed = $(this).data('is_colapsed') == true ? true : false;
141
		var widgetBox = $(this).siblings('.common-widget-content-area');
142
		var controlBox = $(this).siblings('.common-widget-control-bar');
143
		var controlBoxArrowImg = $(this).find('img');
4210 varun.gupt 144
 
4126 varun.gupt 145
		if (isColapsed)	{
146
			if(controlBox.length > 0)	{
147
				$(controlBox).slideDown('fast', function(){
5420 amit.gupta 148
					$(widgetBox).slideDown('fast', callback);
4126 varun.gupt 149
					$(controlBoxArrowImg).attr('src', '/images/IconDownArrow_UnselectedTab.png');
150
				});
151
			} else	{
152
				$(widgetBox).slideDown();
153
				$(controlBoxArrowImg).attr('src', '/images/IconDownArrow_UnselectedTab.png');
154
			}
155
		} else	{
156
			$(widgetBox).slideUp(function(){
157
				$(controlBox).slideUp('fast');
158
				$(controlBoxArrowImg).attr('src', '/images/IconRightArrow_UnselectedTab.png');
159
			});
160
		}
161
		$(this).data('is_colapsed', !isColapsed);
162
	});
163
 
164
	/**
165
	 * Update count of products checked for comparison
166
	 **/
167
	$('#myresearch input[type="checkbox"]').live('click', function(){
4798 varun.gupt 168
		updateCompareCount();
4126 varun.gupt 169
	});
170
 
171
	$("#research_compare").live('click', function(){
172
		var seldata = "";
5322 amit.gupta 173
		var prodnames = "";
4126 varun.gupt 174
		var tot = 1;
175
		var saprt = "";
176
		var par = $('#myresearch').find('input[type=checkbox]:checked');
4926 varun.gupt 177
		var haveSameProductType = true;
178
		var productType = null;
179
 
4126 varun.gupt 180
		$(par).each(function(){
4926 varun.gupt 181
 
182
			if(productType != null && productType != $(this).attr('producttype'))	{
183
				haveSameProductType = false;
184
			}
185
			productType = $(this).attr('producttype');
186
 
4126 varun.gupt 187
			if(tot == 1)	{
5358 amit.gupta 188
				prodnames += $(this).attr("title").replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
4126 varun.gupt 189
				seldata += "p" + tot + "=" + $(this).val();
190
			} else	{
191
				seldata += "&p" + tot + "=" + $(this).val();
5358 amit.gupta 192
				prodnames += "-vs-" + $(this).attr("title").replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
4126 varun.gupt 193
			}
194
			tot ++;
195
		});
4984 varun.gupt 196
 
4926 varun.gupt 197
		if(! haveSameProductType)	{
198
			alert("Only products of same category can be compared");
199
		} else if(tot > 6)	{
4126 varun.gupt 200
			alert("Can compare upto five products only.");
201
		} else if(tot > 2)	{
5552 phani.kuma 202
			window.location = "/compare-" + productType.replace(/ +/g, '-').toLowerCase() + "/" + prodnames + "?" + seldata+"&fromsrc=comparison_widget";
4126 varun.gupt 203
		} else	{
204
			alert("Please select atleast two products");
205
		}
206
	});
207
 
208
	$("#research_delete").live('click', function(){
209
		var research_tot = $("#research_total").val();
210
		var seldata = [];
211
		var tot = 0;
212
		var saprt = "";
213
		var par = $('#myresearch').find('input[type=checkbox]:checked');
214
 
215
		$(par).each(function(){
216
			seldata.unshift($(this).val());
217
			tot ++;
218
		});
219
 
220
		if(tot > 0)	{
221
			var t = (research_tot * 1) - (tot * 1);
222
			$("#research_total").val(t);
223
 
224
			jQuery.ajax({
225
				type: "GET",
226
				url: "/deletefromresearch/[" + seldata + "]?_method=delete",
227
				success: function(msg)	{
228
					jQuery.each(seldata, function(intIndex, objValue){
229
						delete_from_storage_set("resitems", objValue);
230
						$("#myresearch").find("#" + objValue).fadeOut('slow', function() {
231
							$(this).remove();
232
							if(t === 0)	{
233
								$("#research_default").css("display", "block");
234
							}
235
						});
236
					});
4984 varun.gupt 237
 
4922 varun.gupt 238
					//Updating the count
239
					$('#research_compare_count').html($('#myresearch input[type="checkbox"]:checked').length - seldata.length);
4984 varun.gupt 240
 
241
					if ($('#myresearch input[type="checkbox"]').length - seldata.length <= 0)	{
242
						$("#myresearch").children(".common-widget-top-bar").trigger('click');
243
					}
4126 varun.gupt 244
				}
245
			});
246
		} else	{
247
			alert("Please select atleast one product");
248
		}
249
	});
250
 
251
	// No uid cookie
252
	if (!$.cookie("uid"))	{
253
		// No uid in storage
254
		if (!$.Storage.get("uid"))	{
255
			if (!$.Storage.get("resitems"))	{
256
				$.Storage.set("resitems", "[]");
257
			}
258
			if (!$.Storage.get("histitems"))	{
259
				$.Storage.set("histitems", "[]");
260
			}
261
		}
262
		else	{			// uid in storage : logout
263
			$.Storage.remove("uid");
264
			$.Storage.set("resitems", "[]");
265
			$.Storage.set("histitems", "[]");
266
		}
267
		load_research_widget();
268
		load_history_widget();
269
	}
270
	else	{				// With uid cookie
271
		var cookie = $.cookie("uid");
272
		// Just logged in merge storage items
273
		if (!$.Storage.get("uid"))	{
274
			$.Storage.set("uid", cookie);
275
			merge_history_items();
276
			load_research_items();
277
		}
278
		else	{
279
			// UID changed
280
			if ( cookie != $.Storage.get("uid"))	{
281
				$.Storage.set("uid", cookie);
282
				$.Storage.set("resitems", "[]");
283
				$.Storage.set("histitems", "[]");
284
				merge_history_items();
285
				load_research_items();
286
			}
287
			else	{		// Uid is same
288
				if (!$.Storage.get("resitems"))	{
289
					$.Storage.set("resitems", "[]");
290
					load_research_items();
291
				}
292
				else	{
293
					load_research_widget();
294
				}
295
 
296
				if (!$.Storage.get("histitems"))	{
297
					$.Storage.set("histitems", "[]");
298
					merge_history_items();
299
				}
300
				else	{
301
					load_history_widget();
302
				}
303
			}
304
		}
305
	}
4798 varun.gupt 306
 
307
	function load_research_items(){
308
		jQuery.ajax({
309
			type: "GET",
310
			url: "/myresearch",
311
			cache: false,
312
			success: function(json) {
313
			    $.Storage.set("resitems", json);
314
			    load_research_widget();
315
		    }
316
		});
317
	}
318
 
319
	function load_research_widget(){
320
		var myResearchWidgetContainer = $("#myresearch");
321
 
322
		if($(myResearchWidgetContainer).length == 0) {
323
			return;
324
		}
325
		var resitems = $.Storage.get("resitems");
326
 
327
		if (resitems == "[]") {
328
			var emptyResWidgetHtml = '<table border="0" width="100%" cellspacing="1" cellpadding="0" id="research_default">\
329
		      <tbody>\
330
		        <tr><td align="center"><b>Add items to compare list</b></td></tr>\
331
		       </tbody>\
332
		      </table>';
333
			$(myResearchWidgetContainer).find(".common-widget-content-area").html(emptyResWidgetHtml);
334
			$(myResearchWidgetContainer).children(".common-widget-top-bar").trigger('click');
335
			return;
336
		}
337
		var params = "/" + resitems;
338
 
339
		jQuery.ajax({
340
			type : "GET",
341
			url : "/myresearch" + params,
342
			cache: true,
343
			success : function(html) {
344
	   		    $("#myresearch").html(html);
345
	   			updateCompareCount();
346
 
347
			    // Product Title
348
			    $("#myresearch table td div a.truncate").each(function() {
349
						$(this).truncate({addtitle : true});
350
			    });
351
 
352
			    // Product Price
353
			    $("#myresearch table td div div.price").each(function() {
354
						$(this).truncate({addtitle : true});
355
				});
356
 
357
			    // Product Details
358
			    $("#myresearch table td div div.text").each(function() {
359
						$(this).truncate( {addtitle : true});
360
				});
361
		    }
362
		});
363
	}
4126 varun.gupt 364
});