Subversion Repositories SmartDukaan

Rev

Rev 11850 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
538 rajveer 1
/* 
2
     Example:
3
     addResearch(refdivid,reqtype) refdivid=pane1, reqtype=single/multi
4
     Multiple request: onclick="javascript:addResearch('pane2','multi');"
5
     Single request: onclick="javascript:addResearch('','single');"
6
 
7
     addToCart(refdivid,reqtype) refdivid=pane1, reqtype=single/multi
8
     Multiple request: onclick="javascript:addToCart('pane2','multi');"
9
     Single request: onclick="javascript:addToCart('','single');"
10
 
11
     NOTE: incase reqtype=list then refdivid should be product id
12
*/
1922 varun.gupt 13
 
1829 varun.gupt 14
function trackEventWithGA(eventCategory, actionName, label)	{
12530 amit.gupta 15
	ga('send', 'event', eventCategory, actionName, label);
1829 varun.gupt 16
}
2110 vikas 17
 
18
function trackPageWithGA(page)	{
19
	if(typeof _gaq != "undefined" && _gaq != null)	{
20
		_gaq.push(['_trackPageview', page]);
21
	}
22
}
4786 varun.gupt 23
 
637 rajveer 24
$(function() {
11850 amit.gupta 25
	  $('.add-to-cart-icon,.add-to-cart-button').live('click', function() {
4934 amit.gupta 26
		clickedCatalogItem=$(this).closest('div.productDetails').find('a').html();
2762 rajveer 27
	    var items = this.id;
28
	    var itemsarray = items.split('-');
2811 rajveer 29
	    addToCart(itemsarray[1], itemsarray[0]);
4372 varun.gupt 30
	    trackEventWithGA('Home Page', 'Add to Cart Click', '');
2762 rajveer 31
	    return false;
32
	  });
33
 
4786 varun.gupt 34
	  $('.best-deals .title a, .best-deals .productImg a').click(function(){
35
		  trackEventWithGA('Home Page', 'Product Link Click', 'Best Deals');
36
	  });
37
	  $('.latest-arrivals .title a, .latest-arrivals .productImg a').click(function(){
38
		  trackEventWithGA('Home Page', 'Product Link Click', 'Latest Arrivals');
39
	  });
40
	  $('.best-sellers .title a, .best-sellers .productImg a').click(function(){
41
		  trackEventWithGA('Home Page', 'Product Link Click', 'Best Sellers');
42
	  });
43
 
11850 amit.gupta 44
	$("a.addtocart,a.addtocartbutton").live('click', function() {
4934 amit.gupta 45
		clickedCatalogItem=$(this).closest('div.productDetails').find('a').html();
637 rajveer 46
		var catalogid = $(this).attr('catalogid');
4934 amit.gupta 47
 
762 rajveer 48
		var radBtn = "";
49
		var param = "PARAMETERS_" + catalogid;
2762 rajveer 50
		radBtn += '<input type="hidden" id="selected_catalog_id" value=' + catalogid + ' />';
762 rajveer 51
		$.each(eval(param), function(val, text) {
52
			radBtn += '<label><input type="radio" name="radColorSel" value="' + val + '" /> <span>' + text + '</span></label>';
53
		});
54
 
55
		radBtn += '<div class="clearBoth"></div>';
56
		$(".colorSelLightBoxColor .content").html(radBtn);
637 rajveer 57
 
4372 varun.gupt 58
		$.fn.colorbox({
59
			inline:true, 
60
			href:".colorSelLightBoxColor", 
61
			open:true, 
62
			onComplete:function(){
63
				var posLeft = (document.documentElement.clientWidth / 2) - (parseInt($('#colorbox').css('width')) / 2);
64
				var posTop = (document.documentElement.clientHeight / 2) - (parseInt($('#colorbox').css('height')) / 2);
1189 varun.gupt 65
 
4372 varun.gupt 66
				$('#colorbox').css('top', posTop);
67
				$('#colorbox').css('left', posLeft);
68
			    trackEventWithGA('Home Page', 'Add to Cart Click', '');
69
			}
70
		});
637 rajveer 71
	});
762 rajveer 72
 
3080 rajveer 73
 
74
	$('#notify').live('click', function() {
75
		emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
76
		email=$('#emailId').val();
77
		if(!email.match(emailExp)){
78
			alert("Please enter valid email.");
79
			return false;
80
		}
81
		itemId=$('#itemId').val();
82
		emailId=$('#emailId').val();
83
		jQuery.ajax({
84
   		 type: "POST",
85
   		 url: "/product-notification",
86
   		 data: "emailId="+emailId+"&itemId="+itemId,
87
   		 success: function(msg){
3255 rajveer 88
   			$('#notificationBox').html("<h3>We will notify you once we get the stock.</h3>");	 
3080 rajveer 89
   		 }
90
   	 	});
91
	});
3283 rajveer 92
 
93
 
94
    $("#query").autocomplete({  autoFocus: true, minLength: 3,
95
    	source: "/auto-suggest",
96
    	select: function( event, ui ) {
97
    		this.value = ui.item.value;
3830 chandransh 98
			$('#formSearch').submit();
3283 rajveer 99
			return false;
100
		}
101
    });
102
 
637 rajveer 103
});
104
 
2811 rajveer 105
function addToCart(refdivid,reqtype){
2755 rajveer 106
     var seldata="";
107
     var tot=0;
108
     var saprt="";
109
     if(reqtype == "multi"){
110
          var containerdiv = "#" + refdivid;
111
          var par= containerdiv + " input[type=checkbox]:checked";
112
          var isMulti = false;
113
          $(par).each(function(){
114
 
115
	       	   var totalcolors = $(this).attr('totalcolors');
116
	           saprt = (tot>0)? "_":"";
117
               seldata += saprt+$(this).attr('itemid');
118
 
119
	           if(totalcolors != 1)	{
120
	        	   isMulti = true;
121
	       	   }
122
               tot++;
123
          });
124
          if(isMulti == true){
125
        	  alert("Some items are available in multiple colors. Please go to product page and select color you want.");
126
        	  return;
127
          } else	{
128
        	  var items = seldata.split('_');
129
        	  for(var i in items)	{
130
        		  trackEventWithGA('Order', 'Add to Cart', items[i]);
131
        	  }
132
          }
133
     }else if(reqtype == "single"){
134
          seldata = $("#item_id").val();
135
		  trackEventWithGA('Order', 'Add to Cart', seldata + '');
136
          tot=1;
137
     }else if(reqtype == "list"){
138
    	  var seldata=refdivid;
139
		  trackEventWithGA('Order', 'Add to Cart', seldata + '');
140
          tot=1;
141
     }
142
 
143
     if(tot > 0)	{
144
    	 jQuery.ajax({
145
    		 type: "POST",
146
    		 url: "/addtocart",
147
    		 data: "productid=" + seldata,
148
    		 success: function(msg){
149
    			 if(msg==""){
150
    				 window.location = "/cart";
151
    			 }else{
4934 amit.gupta 152
    				 trackEventWithGA('Order', 'OOS Lightbox', clickedCatalogItem);
2810 rajveer 153
    				 displayRelatedProducts(msg);
2755 rajveer 154
    			 }
155
    		 }
156
    	 });
157
     } else	{
158
    	 alert("Please select atleast one product");
159
     }
160
}
161
 
162
 
762 rajveer 163
function selectColor(){
164
	var selected = $(".colorSelLightBoxColor .content input[name='radColorSel']:checked");
165
	var itemid = selected.val();
2762 rajveer 166
 
1829 varun.gupt 167
	trackEventWithGA('Order', 'Select Product Color', itemid);
762 rajveer 168
 
1795 varun.gupt 169
	if(itemid == undefined)	{
762 rajveer 170
		alert('Please select a color.');
1795 varun.gupt 171
	} else	{
2811 rajveer 172
		addToCart(itemid,'list');
762 rajveer 173
	}
174
}
175
 
637 rajveer 176
 
2810 rajveer 177
function displayRelatedProducts(message){
178
	$.colorbox({
179
		html:message,
3255 rajveer 180
		maxWidth:"400px",
181
		maxHeight:"410px",
2810 rajveer 182
		width:"400px",
183
 
184
		onComplete: function(){
185
			$('#cartRecommendationBox').show().find('.widgetChkBox').hide();
186
		},
187
		onCleanup: function(){
188
			$('#cartRecommendationBox').hide();
2755 rajveer 189
		}
3255 rajveer 190
	});
191
 
2755 rajveer 192
}
193
 
194
 
195
 
1829 varun.gupt 196
function addResearch(refdivid, reqtype){
197
     var research_tot = $("#research_total").val();
198
     var seldata = [];
199
     var tot = 0;
5552 phani.kuma 200
     var fromsrc = "";
538 rajveer 201
 
1829 varun.gupt 202
     if(reqtype == "multi")	{
538 rajveer 203
          var containerdiv = "#" + refdivid;     
1829 varun.gupt 204
          var par = containerdiv + " input[type=checkbox]:checked";
538 rajveer 205
          $(par).each(function(){
1761 vikas 206
               seldata.unshift($(this).val());
1829 varun.gupt 207
               tot ++;
538 rajveer 208
          });
1829 varun.gupt 209
     }else if(reqtype == "single")	{
1761 vikas 210
    	  seldata.unshift($("#product_id").val());
2633 rajveer 211
          tot = 1;
5552 phani.kuma 212
          fromsrc = "product_page";
1829 varun.gupt 213
     }else if(reqtype == "list"){
1761 vikas 214
    	  seldata.unshift(refdivid);
2633 rajveer 215
          tot = 1;
5552 phani.kuma 216
          fromsrc = "other_pages";
538 rajveer 217
     }
1795 varun.gupt 218
 
219
     if(tot > 0)	{
538 rajveer 220
          jQuery.ajax({
221
               type: "POST",
1614 rajveer 222
                      url: "/addtoresearch",
5552 phani.kuma 223
                      data: "productid=[" + seldata +  "]&fromsrc=" + fromsrc,
1047 vikas 224
                      success: function(msg){
2759 varun.gupt 225
                           var postSuccessDOMProcessing = function(objValue)	{
226
                        	   trackEventWithGA('Research', 'Add to Research', objValue);
227
                        	   add_to_storage_set("resitems", objValue);
4922 varun.gupt 228
                        	   //Updating the count
5420 amit.gupta 229
                        	   var truncFields=function(){
230
                        		   var msgDom = $(msg);
231
                        		   $("#pane1").prepend(msgDom);
232
                        		   $(msgDom).find("a.truncate").truncate({addtitle: true});
233
                            	   $(msgDom).find("div.price").truncate({addtitle: true});
234
                            	   $(msgDom).find("div.text").truncate({addtitle: true});
235
                            	   $(msgDom).animate({ backgroundColor: "#fcffb3" }, 'slow');
236
                            	   $(msgDom).animate({ backgroundColor: "transparent" }, 'slow');
237
                            	   $('#research_compare_count').html($('#myresearch input[type="checkbox"]:checked').length);
238
                        	   };
239
                        	   if($('.common-widget-top-bar').data('is_colapsed')){
240
                        		   $("#myresearch").children(".common-widget-top-bar").trigger('click',[truncFields]);
241
                        	   }else {
242
                        		   truncFields();
4984 varun.gupt 243
                        	   }
2759 varun.gupt 244
                           };
1047 vikas 245
 
246
                           if(msg == 0){
3830 chandransh 247
                                alert( "Product is already in compare list" );
2759 varun.gupt 248
                           } else	{
1829 varun.gupt 249
                                var t = (research_tot * 1) + (tot * 1);
538 rajveer 250
                                $("#research_total").val(t);
2759 varun.gupt 251
                                if(t > 0)	{
538 rajveer 252
                                     $("#research_default").css("display","none");
253
                                }     
2759 varun.gupt 254
                                if(reqtype == "multi")	{
255
                                     jQuery.each(seldata,function(intIndex, objValue)	{
256
                                    	 postSuccessDOMProcessing(objValue);
538 rajveer 257
                                     });
258
 
2759 varun.gupt 259
                                } else if(reqtype == "single")	{
260
                                	postSuccessDOMProcessing(seldata);
261
 
262
                                } else if(reqtype == "list")	{
263
                                	postSuccessDOMProcessing(seldata);
264
                                }
538 rajveer 265
                           }
266
                      }
267
          });
2759 varun.gupt 268
     } else	{
538 rajveer 269
          alert("Please select atleast one product");
270
     }
271
}
272
 
273
 
1873 varun.gupt 274
 
275
 
1047 vikas 276
function scrollWinToTop(){
277
    $('html, body').animate({
278
      scrollTop: $("body").offset().top
279
    }, 0);
280
}
281
 
282
function changeShipAddress(id){
283
  addressId = id.substring(20);
284
   jQuery.ajax({
285
      type: "POST",
1919 rajveer 286
      url: "/shipping",
1047 vikas 287
      data: "action=change&addressid="+addressId,
288
      success: function(msg){
289
         $("#addressid").val(msg);
290
      }
291
   });
292
  document.getElementById('shipAddressContainer').innerHTML = document.getElementById(id).innerHTML;
293
	$(".proceed-bttn .yellow-image").removeClass('imgDisableButton').addClass('imgEnableButton');
294
	$(".proceed-bttn input[disabled='']").removeAttr('disabled');
2633 rajveer 295
 
296
	$('#newShipAdr').hide();
1047 vikas 297
	scrollWinToTop();
298
 
299
}
1053 vikas 300
 
1761 vikas 301
function merge_history_items(){
302
	params = $.Storage.get("histitems");
303
 
304
	jQuery.ajax({
305
		type: "POST",
306
		url: "/browse-history",
307
		data: "id="+params,
308
		cache: false,
309
		success: function(json) {
310
		    $.Storage.set("histitems", json);
311
		    load_history_widget();
312
	    }
313
	});
314
}
315
 
1623 rajveer 316
function load_history_widget() {
4276 varun.gupt 317
 
318
	var browseHistoryWidgetContainer = $("#browsehistory");
319
 
320
	if($(browseHistoryWidgetContainer).length == 0) {
2921 vikas 321
		return;
322
	}
3057 vikas 323
	var histitems = $.Storage.get("histitems");
324
	if (histitems == "[]") {
4276 varun.gupt 325
		$(browseHistoryWidgetContainer).find(".common-widget-content-area").html("");
326
		$(browseHistoryWidgetContainer).children('.common-widget-top-bar').trigger('click');
3057 vikas 327
		return;
328
	}
329
	var params = "/" + histitems;
1614 rajveer 330
 
1372 vikas 331
	jQuery.ajax({
332
		type: "GET",
1614 rajveer 333
		url: "/browse-history" + params,
3034 vikas 334
		cache: true,
1372 vikas 335
		success: function(html){
1761 vikas 336
		    $("#browsehistory").html(html);
1372 vikas 337
 
1761 vikas 338
		    // Product Title
339
		    $("#browsehistory table td div a").each(function(){
340
			    $(this).truncate({addtitle: true}); 
341
		    });
1372 vikas 342
 
1761 vikas 343
    		// Product Price
344
	    	$("#browsehistory table td div div.price").each(function(){
345
		    	$(this).truncate({addtitle: true});
346
		    });
1372 vikas 347
 
1761 vikas 348
		    // Product Details
349
		    $("#browsehistory table td div div.text").each(function(){
350
			    $(this).truncate({addtitle: true});
351
		    });
352
	    }
353
	});
354
}
355
 
356
function add_to_storage_set(key, id) {
357
	var set = eval($.Storage.get(key));
358
	if (set) {
359
		$.each(set, function(index, value) {
360
			if (value == id) {
361
				set.splice(index, 1);
362
			}
1372 vikas 363
		});
364
	}
1761 vikas 365
	set.unshift(id);
1964 vikas 366
	if (set.length>10)
367
	{
368
		set.splice(10, set.length-10);
369
	}
1761 vikas 370
	$.Storage.set(key, "[" + set.toString() + "]");
1372 vikas 371
}
372
 
1761 vikas 373
function delete_from_storage_set(key, id) {
374
	var set = eval($.Storage.get(key));
375
	if (set) {
376
		$.each(set, function(index, value) {
377
			if (value == id) {
378
				set.splice(index, 1);
379
			}
380
		});
381
	}
382
	$.Storage.set(key, "[" + set.toString() + "]");
1866 vikas 383
}
384
 
1868 vikas 385
function add_track_log(event, url, data) {
1999 vikas 386
	if ($.cookie("uafc")) {
1866 vikas 387
		jQuery.ajax( {
1919 rajveer 388
			url : "/tracking",
1866 vikas 389
			type : "POST",
390
			data : {
1868 vikas 391
				"event" : event,
1866 vikas 392
				"url" : url,
393
				"data" : data
394
			},
395
			cache : false
396
		});
397
	}
3037 rajveer 398
}
399
 
400
function load_accessories_widget(){
10198 amit.gupta 401
	var accessoriesContainer = $("#accessories");
4210 varun.gupt 402
 
10198 amit.gupta 403
	if(accessoriesContainer.length == 0) {
404
		return;
3037 rajveer 405
	}
10198 amit.gupta 406
 
407
	jQuery.ajax({
408
		type : "GET",
409
		url : "/related-accessories/" + $("#product_id").val(),
410
		cache: true,
411
		success : function(html) {
412
 
413
			if($.trim(html).length > 0)	{
414
	   		    $(accessoriesContainer).html(html);
415
 
416
	   		    var accessoryInfoContainer = $(accessoriesContainer).find("table td div");
417
			    // Product Title
418
			    $(accessoryInfoContainer).children("a").each(function() {
419
			    	$(this).truncate({addtitle : true});
420
			    });
421
 
422
			    // Product Price
423
			    $(accessoryInfoContainer).children("div.price").each(function() {
424
			    	$(this).truncate({addtitle : true});
425
				});
426
 
427
			    // Product Details
428
			    $(accessoryInfoContainer).children("div.text").each(function() {
429
			    	$(this).truncate( {addtitle : true});
430
				});
431
			} else	{
432
				$(accessoriesContainer).hide();
433
			}
434
	    }
435
	});
4210 varun.gupt 436
}