Subversion Repositories SmartDukaan

Rev

Rev 4984 | Rev 5420 | 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);
227
                        	   var tblid = "#pane1 #" + objValue + " td";
228
                        	   $(tblid + " div a.truncate").truncate({addtitle: true});
229
                        	   $(tblid + " div div.price").truncate({addtitle: true});
230
                        	   $(tblid + " div div.text").truncate({addtitle: true});
231
                        	   $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
232
                        	   $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');
4922 varun.gupt 233
                        	   //Updating the count
234
                        	   $('#research_compare_count').html($('#myresearch input[type="checkbox"]:checked').length);
4984 varun.gupt 235
 
236
                        	   if($('#myresearch input[type="checkbox"]').length == 1)	{
237
                        		   $("#myresearch").children(".common-widget-top-bar").trigger('click');
238
                        	   }
2759 varun.gupt 239
                           };
1047 vikas 240
 
241
                           if(msg == 0){
3830 chandransh 242
                                alert( "Product is already in compare list" );
2759 varun.gupt 243
                           } else	{
1829 varun.gupt 244
                                var t = (research_tot * 1) + (tot * 1);
538 rajveer 245
                                $("#research_total").val(t);
2759 varun.gupt 246
                                if(t > 0)	{
538 rajveer 247
                                     $("#research_default").css("display","none");
248
                                }     
249
                                $("#pane1").prepend(msg);
250
 
2759 varun.gupt 251
                                if(reqtype == "multi")	{
252
                                     jQuery.each(seldata,function(intIndex, objValue)	{
253
                                    	 postSuccessDOMProcessing(objValue);
538 rajveer 254
                                     });
255
 
2759 varun.gupt 256
                                } else if(reqtype == "single")	{
257
                                	postSuccessDOMProcessing(seldata);
258
 
259
                                } else if(reqtype == "list")	{
260
                                	postSuccessDOMProcessing(seldata);
261
                                }
538 rajveer 262
                           }
263
                      }
264
          });
2759 varun.gupt 265
     } else	{
538 rajveer 266
          alert("Please select atleast one product");
267
     }
268
}
269
 
270
 
1873 varun.gupt 271
 
272
 
1047 vikas 273
function scrollWinToTop(){
274
    $('html, body').animate({
275
      scrollTop: $("body").offset().top
276
    }, 0);
277
}
278
 
279
function changeShipAddress(id){
280
  addressId = id.substring(20);
281
   jQuery.ajax({
282
      type: "POST",
1919 rajveer 283
      url: "/shipping",
1047 vikas 284
      data: "action=change&addressid="+addressId,
285
      success: function(msg){
286
         $("#addressid").val(msg);
287
      }
288
   });
289
  document.getElementById('shipAddressContainer').innerHTML = document.getElementById(id).innerHTML;
290
	$(".proceed-bttn .yellow-image").removeClass('imgDisableButton').addClass('imgEnableButton');
291
	$(".proceed-bttn input[disabled='']").removeAttr('disabled');
2633 rajveer 292
 
293
	$('#newShipAdr').hide();
1047 vikas 294
	scrollWinToTop();
295
 
296
}
1053 vikas 297
 
1761 vikas 298
function merge_history_items(){
299
	params = $.Storage.get("histitems");
300
 
301
	jQuery.ajax({
302
		type: "POST",
303
		url: "/browse-history",
304
		data: "id="+params,
305
		cache: false,
306
		success: function(json) {
307
		    $.Storage.set("histitems", json);
308
		    load_history_widget();
309
	    }
310
	});
311
}
312
 
1623 rajveer 313
function load_history_widget() {
4276 varun.gupt 314
 
315
	var browseHistoryWidgetContainer = $("#browsehistory");
316
 
317
	if($(browseHistoryWidgetContainer).length == 0) {
2921 vikas 318
		return;
319
	}
3057 vikas 320
	var histitems = $.Storage.get("histitems");
321
	if (histitems == "[]") {
4276 varun.gupt 322
		$(browseHistoryWidgetContainer).find(".common-widget-content-area").html("");
323
		$(browseHistoryWidgetContainer).children('.common-widget-top-bar').trigger('click');
3057 vikas 324
		return;
325
	}
326
	var params = "/" + histitems;
1614 rajveer 327
 
1372 vikas 328
	jQuery.ajax({
329
		type: "GET",
1614 rajveer 330
		url: "/browse-history" + params,
3034 vikas 331
		cache: true,
1372 vikas 332
		success: function(html){
1761 vikas 333
		    $("#browsehistory").html(html);
1372 vikas 334
 
1761 vikas 335
		    // Product Title
336
		    $("#browsehistory table td div a").each(function(){
337
			    $(this).truncate({addtitle: true}); 
338
		    });
1372 vikas 339
 
1761 vikas 340
    		// Product Price
341
	    	$("#browsehistory table td div div.price").each(function(){
342
		    	$(this).truncate({addtitle: true});
343
		    });
1372 vikas 344
 
1761 vikas 345
		    // Product Details
346
		    $("#browsehistory table td div div.text").each(function(){
347
			    $(this).truncate({addtitle: true});
348
		    });
349
	    }
350
	});
351
}
352
 
353
function add_to_storage_set(key, id) {
354
	var set = eval($.Storage.get(key));
355
	if (set) {
356
		$.each(set, function(index, value) {
357
			if (value == id) {
358
				set.splice(index, 1);
359
			}
1372 vikas 360
		});
361
	}
1761 vikas 362
	set.unshift(id);
1964 vikas 363
	if (set.length>10)
364
	{
365
		set.splice(10, set.length-10);
366
	}
1761 vikas 367
	$.Storage.set(key, "[" + set.toString() + "]");
1372 vikas 368
}
369
 
1761 vikas 370
function delete_from_storage_set(key, id) {
371
	var set = eval($.Storage.get(key));
372
	if (set) {
373
		$.each(set, function(index, value) {
374
			if (value == id) {
375
				set.splice(index, 1);
376
			}
377
		});
378
	}
379
	$.Storage.set(key, "[" + set.toString() + "]");
1866 vikas 380
}
381
 
1868 vikas 382
function add_track_log(event, url, data) {
1999 vikas 383
	if ($.cookie("uafc")) {
1866 vikas 384
		jQuery.ajax( {
1919 rajveer 385
			url : "/tracking",
1866 vikas 386
			type : "POST",
387
			data : {
1868 vikas 388
				"event" : event,
1866 vikas 389
				"url" : url,
390
				"data" : data
391
			},
392
			cache : false
393
		});
394
	}
3037 rajveer 395
}
396
 
397
function load_accessories_widget(){
4210 varun.gupt 398
	var accessoriesContainer = $("#accessories");
399
 
400
	if(accessoriesContainer.length == 0) {
3037 rajveer 401
		return;
402
	}
4210 varun.gupt 403
 
3037 rajveer 404
	jQuery.ajax({
405
		type : "GET",
406
		url : "/related-accessories/" + $("#product_id").val(),
3040 rajveer 407
		cache: true,
3037 rajveer 408
		success : function(html) {
4210 varun.gupt 409
 
410
			if($.trim(html).length > 0)	{
411
	   		    $(accessoriesContainer).html(html);
412
 
413
	   		    var accessoryInfoContainer = $(accessoriesContainer).find("table td div");
414
			    // Product Title
415
			    $(accessoryInfoContainer).children("a").each(function() {
416
			    	$(this).truncate({addtitle : true});
417
			    });
3037 rajveer 418
 
4210 varun.gupt 419
			    // Product Price
420
			    $(accessoryInfoContainer).children("div.price").each(function() {
421
			    	$(this).truncate({addtitle : true});
422
				});
3037 rajveer 423
 
4210 varun.gupt 424
			    // Product Details
425
			    $(accessoryInfoContainer).children("div.text").each(function() {
426
			    	$(this).truncate( {addtitle : true});
427
				});
428
			} else	{
429
				$(accessoriesContainer).hide();
430
			}
3037 rajveer 431
	    }
432
	});
4210 varun.gupt 433
}