Subversion Repositories SmartDukaan

Rev

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