Subversion Repositories SmartDukaan

Rev

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