Subversion Repositories SmartDukaan

Rev

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