Subversion Repositories SmartDukaan

Rev

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