Subversion Repositories SmartDukaan

Rev

Rev 4786 | Rev 4874 | 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() {
28
	    var items = this.id;
29
	    var itemsarray = items.split('-');
2811 rajveer 30
	    addToCart(itemsarray[1], itemsarray[0]);
4372 varun.gupt 31
	    trackEventWithGA('Home Page', 'Add to Cart Click', '');
2762 rajveer 32
	    return false;
33
	  });
34
 
4786 varun.gupt 35
	  $('.best-deals .title a, .best-deals .productImg a').click(function(){
36
		  trackEventWithGA('Home Page', 'Product Link Click', 'Best Deals');
37
	  });
38
	  $('.latest-arrivals .title a, .latest-arrivals .productImg a').click(function(){
39
		  trackEventWithGA('Home Page', 'Product Link Click', 'Latest Arrivals');
40
	  });
41
	  $('.best-sellers .title a, .best-sellers .productImg a').click(function(){
42
		  trackEventWithGA('Home Page', 'Product Link Click', 'Best Sellers');
43
	  });
44
 
1199 vikas 45
	$("a.addtocart").live('click', function() {
637 rajveer 46
		var catalogid = $(this).attr('catalogid');
1795 varun.gupt 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{
4740 amit.gupta 152
    				 trackEventWithGA('Order', 'OOS Lightbox', seldata + '');
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;
538 rajveer 200
 
1829 varun.gupt 201
     if(reqtype == "multi")	{
538 rajveer 202
          var containerdiv = "#" + refdivid;     
1829 varun.gupt 203
          var par = containerdiv + " input[type=checkbox]:checked";
538 rajveer 204
          $(par).each(function(){
1761 vikas 205
               seldata.unshift($(this).val());
1829 varun.gupt 206
               tot ++;
538 rajveer 207
          });
1829 varun.gupt 208
     }else if(reqtype == "single")	{
1761 vikas 209
    	  seldata.unshift($("#product_id").val());
2633 rajveer 210
          tot = 1;
1829 varun.gupt 211
     }else if(reqtype == "list"){
1761 vikas 212
    	  seldata.unshift(refdivid);
2633 rajveer 213
          tot = 1;
538 rajveer 214
     }
1795 varun.gupt 215
 
216
     if(tot > 0)	{
879 rajveer 217
          //alert("AJAX request to add products in My research. Product ID: "+seldata+" and total: "+tot);
538 rajveer 218
          jQuery.ajax({
219
               type: "POST",
1614 rajveer 220
                      url: "/addtoresearch",
1829 varun.gupt 221
                      data: "productid=[" + seldata +  "]",
1047 vikas 222
                      success: function(msg){
2759 varun.gupt 223
                           var postSuccessDOMProcessing = function(objValue)	{
224
                        	   trackEventWithGA('Research', 'Add to Research', objValue);
225
                        	   add_to_storage_set("resitems", objValue);
226
                        	   var tblid = "#pane1 #" + objValue + " td";
227
                        	   $(tblid + " div a.truncate").truncate({addtitle: true});
228
                        	   $(tblid + " div div.price").truncate({addtitle: true});
229
                        	   $(tblid + " div div.text").truncate({addtitle: true});
230
                        	   $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
231
                        	   $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');
232
                           };
1047 vikas 233
 
234
                           if(msg == 0){
3830 chandransh 235
                                alert( "Product is already in compare list" );
2759 varun.gupt 236
                           } else	{
1829 varun.gupt 237
                                var t = (research_tot * 1) + (tot * 1);
538 rajveer 238
                                $("#research_total").val(t);
2759 varun.gupt 239
                                if(t > 0)	{
538 rajveer 240
                                     $("#research_default").css("display","none");
241
                                }     
242
                                $("#pane1").prepend(msg);
243
 
2759 varun.gupt 244
                                if(reqtype == "multi")	{
245
                                     jQuery.each(seldata,function(intIndex, objValue)	{
246
                                    	 postSuccessDOMProcessing(objValue);
538 rajveer 247
                                     });
248
 
2759 varun.gupt 249
                                } else if(reqtype == "single")	{
250
                                	postSuccessDOMProcessing(seldata);
251
 
252
                                } else if(reqtype == "list")	{
253
                                	postSuccessDOMProcessing(seldata);
254
                                }
538 rajveer 255
                           }
256
                      }
257
          });
2759 varun.gupt 258
     } else	{
538 rajveer 259
          alert("Please select atleast one product");
260
     }
261
}
262
 
263
 
1873 varun.gupt 264
 
265
 
1047 vikas 266
function scrollWinToTop(){
267
    $('html, body').animate({
268
      scrollTop: $("body").offset().top
269
    }, 0);
270
}
271
 
272
function changeShipAddress(id){
273
  addressId = id.substring(20);
274
 //alert("TODO AJAX request to change shipping address. " + addressId);
275
   jQuery.ajax({
276
      type: "POST",
1919 rajveer 277
      url: "/shipping",
1047 vikas 278
      data: "action=change&addressid="+addressId,
279
      success: function(msg){
280
         $("#addressid").val(msg);
281
      }
282
   });
283
  document.getElementById('shipAddressContainer').innerHTML = document.getElementById(id).innerHTML;
284
	$(".proceed-bttn .yellow-image").removeClass('imgDisableButton').addClass('imgEnableButton');
285
	$(".proceed-bttn input[disabled='']").removeAttr('disabled');
2633 rajveer 286
 
287
	$('#newShipAdr').hide();
1047 vikas 288
	scrollWinToTop();
289
 
290
}
1053 vikas 291
 
1761 vikas 292
function merge_history_items(){
293
	params = $.Storage.get("histitems");
294
 
295
	jQuery.ajax({
296
		type: "POST",
297
		url: "/browse-history",
298
		data: "id="+params,
299
		cache: false,
300
		success: function(json) {
301
		    $.Storage.set("histitems", json);
302
		    load_history_widget();
303
	    }
304
	});
305
}
306
 
1623 rajveer 307
function load_history_widget() {
4276 varun.gupt 308
 
309
	var browseHistoryWidgetContainer = $("#browsehistory");
310
 
311
	if($(browseHistoryWidgetContainer).length == 0) {
2921 vikas 312
		return;
313
	}
3057 vikas 314
	var histitems = $.Storage.get("histitems");
315
	if (histitems == "[]") {
4276 varun.gupt 316
		$(browseHistoryWidgetContainer).find(".common-widget-content-area").html("");
317
		$(browseHistoryWidgetContainer).children('.common-widget-top-bar').trigger('click');
3057 vikas 318
		return;
319
	}
320
	var params = "/" + histitems;
1614 rajveer 321
 
1372 vikas 322
	jQuery.ajax({
323
		type: "GET",
1614 rajveer 324
		url: "/browse-history" + params,
3034 vikas 325
		cache: true,
1372 vikas 326
		success: function(html){
1761 vikas 327
		    $("#browsehistory").html(html);
1372 vikas 328
 
1761 vikas 329
		    // Product Title
330
		    $("#browsehistory table td div a").each(function(){
331
			    $(this).truncate({addtitle: true}); 
332
		    });
1372 vikas 333
 
1761 vikas 334
    		// Product Price
335
	    	$("#browsehistory table td div div.price").each(function(){
336
		    	$(this).truncate({addtitle: true});
337
		    });
1372 vikas 338
 
1761 vikas 339
		    // Product Details
340
		    $("#browsehistory table td div div.text").each(function(){
341
			    $(this).truncate({addtitle: true});
342
		    });
343
	    }
344
	});
345
}
346
 
347
function add_to_storage_set(key, id) {
348
	var set = eval($.Storage.get(key));
349
	if (set) {
350
		$.each(set, function(index, value) {
351
			if (value == id) {
352
				set.splice(index, 1);
353
			}
1372 vikas 354
		});
355
	}
1761 vikas 356
	set.unshift(id);
1964 vikas 357
	if (set.length>10)
358
	{
359
		set.splice(10, set.length-10);
360
	}
1761 vikas 361
	$.Storage.set(key, "[" + set.toString() + "]");
1372 vikas 362
}
363
 
1761 vikas 364
function delete_from_storage_set(key, id) {
365
	var set = eval($.Storage.get(key));
366
	if (set) {
367
		$.each(set, function(index, value) {
368
			if (value == id) {
369
				set.splice(index, 1);
370
			}
371
		});
372
	}
373
	$.Storage.set(key, "[" + set.toString() + "]");
1866 vikas 374
}
375
 
1868 vikas 376
function add_track_log(event, url, data) {
1999 vikas 377
	if ($.cookie("uafc")) {
1866 vikas 378
		jQuery.ajax( {
1919 rajveer 379
			url : "/tracking",
1866 vikas 380
			type : "POST",
381
			data : {
1868 vikas 382
				"event" : event,
1866 vikas 383
				"url" : url,
384
				"data" : data
385
			},
386
			cache : false
387
		});
388
	}
3037 rajveer 389
}
390
 
391
function load_accessories_widget(){
4210 varun.gupt 392
	var accessoriesContainer = $("#accessories");
393
 
394
	if(accessoriesContainer.length == 0) {
3037 rajveer 395
		return;
396
	}
4210 varun.gupt 397
 
3037 rajveer 398
	jQuery.ajax({
399
		type : "GET",
400
		url : "/related-accessories/" + $("#product_id").val(),
3040 rajveer 401
		cache: true,
3037 rajveer 402
		success : function(html) {
4210 varun.gupt 403
 
404
			if($.trim(html).length > 0)	{
405
	   		    $(accessoriesContainer).html(html);
406
 
407
	   		    var accessoryInfoContainer = $(accessoriesContainer).find("table td div");
408
			    // Product Title
409
			    $(accessoryInfoContainer).children("a").each(function() {
410
			    	$(this).truncate({addtitle : true});
411
			    });
3037 rajveer 412
 
4210 varun.gupt 413
			    // Product Price
414
			    $(accessoryInfoContainer).children("div.price").each(function() {
415
			    	$(this).truncate({addtitle : true});
416
				});
3037 rajveer 417
 
4210 varun.gupt 418
			    // Product Details
419
			    $(accessoryInfoContainer).children("div.text").each(function() {
420
			    	$(this).truncate( {addtitle : true});
421
				});
422
			} else	{
423
				$(accessoriesContainer).hide();
424
			}
3037 rajveer 425
	    }
426
	});
4210 varun.gupt 427
}