Subversion Repositories SmartDukaan

Rev

Rev 1614 | Rev 1643 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
538 rajveer 1
/* 
2
     Author: Binay Kumar
3
     Created on: 30.09.2010
4
 
5
     Example:
6
     addResearch(refdivid,reqtype) refdivid=pane1, reqtype=single/multi
7
     Multiple request: onclick="javascript:addResearch('pane2','multi');"
8
     Single request: onclick="javascript:addResearch('','single');"
9
 
10
     addToCart(refdivid,reqtype) refdivid=pane1, reqtype=single/multi
11
     Multiple request: onclick="javascript:addToCart('pane2','multi');"
12
     Single request: onclick="javascript:addToCart('','single');"
13
 
14
     NOTE: incase reqtype=list then refdivid should be product id
15
 
16
*/
17
 
637 rajveer 18
$(function() {
19
 
1199 vikas 20
	$("a.addtocart").live('click', function() {
637 rajveer 21
		var catalogid = $(this).attr('catalogid');
22
		//alert("clicked add to cart" + catalogid);
762 rajveer 23
 
24
		var radBtn = "";
25
		var param = "PARAMETERS_" + catalogid;
26
 
27
		$.each(eval(param), function(val, text) {
28
			radBtn += '<label><input type="radio" name="radColorSel" value="' + val + '" /> <span>' + text + '</span></label>';
29
		});
30
 
31
		radBtn += '<div class="clearBoth"></div>';
32
		$(".colorSelLightBoxColor .content").html(radBtn);
637 rajveer 33
 
1189 varun.gupt 34
		$.fn.colorbox({inline:true, href:".colorSelLightBoxColor", open:true, onComplete:function(){
35
			var posLeft = (document.documentElement.clientWidth / 2) - (parseInt($('#colorbox').css('width')) / 2);
36
			var posTop = (document.documentElement.clientHeight / 2) - (parseInt($('#colorbox').css('height')) / 2);
37
 
38
			$('#colorbox').css('top', posTop);
39
			$('#colorbox').css('left', posLeft);
40
		}});
762 rajveer 41
 
42
		/*
637 rajveer 43
		var select = $('#colorselector');
44
		var options = select.attr('options');
45
		$('option', select).remove();
46
		$.each(eval(param), function(val, text) {
47
		    options[options.length] = new Option(text, val);
48
		    //alert(val + ": " + text);
49
		});
50
		$( "#dialog-form" ).dialog( "open" );
762 rajveer 51
		*/
637 rajveer 52
	});
762 rajveer 53
 
54
	/*
637 rajveer 55
	$( "#dialog-form" ).dialog({
56
		autoOpen: false,
57
		height: 200,
58
		width: 250,
59
		modal: true,
60
		buttons: {
61
			Ok: function() {
62
				var bValid = true;
63
				var selected = $("#colorselector option:selected");
64
				var itemid = selected.val();
65
				addToCart(itemid,'list');
66
				$( this ).dialog( "close" );
67
				},
68
			Cancel: function() {
69
				$( this ).dialog( "close" );
70
				}
71
			},
72
			close: function() {
73
 
74
			}
75
		});
762 rajveer 76
 	*/
637 rajveer 77
});
78
 
79
 
762 rajveer 80
function selectColor(){
81
	var bValid = true;
82
	var selected = $(".colorSelLightBoxColor .content input[name='radColorSel']:checked");
83
	var itemid = selected.val();
84
 
85
	if(itemid == undefined){
86
		alert('Please select a color.');
87
	}else{
88
		addToCart(itemid,'list');
89
		$.colorbox.close();
90
	}
91
}
92
 
637 rajveer 93
function onSelectChange(itemid){
879 rajveer 94
	//alert("selected color is"+itemid);
637 rajveer 95
}
96
 
97
 
538 rajveer 98
function addResearch(refdivid,reqtype){
99
     var research_tot=$("#research_total").val();
100
     var seldata="";
101
     var tot=0;
102
     var saprt="";
103
 
104
     if(reqtype=="multi"){
105
          var containerdiv = "#" + refdivid;     
106
          var par= containerdiv + " input[type=checkbox]:checked";
107
          $(par).each(function(){
108
               saprt = (tot>0)? "_":"";
109
               seldata += saprt+$(this).val();
637 rajveer 110
               tot++;
538 rajveer 111
          });
112
     }else if(reqtype=="single"){
809 rajveer 113
          var seldata=$("#product_id").val();
538 rajveer 114
          var tot=1;
115
     }else if(reqtype=="list"){
116
 
117
          var seldata=refdivid;
118
          var tot=1;
119
     }
120
 
1614 rajveer 121
/*
122
     var historyitems = "";
123
     if($.Storage.get("historyitems")){
124
    	 historyitems = "&historyitems=" +  $.Storage.get("historyitems");
125
    	 $.Storage.remove("historyitems");
126
     }
127
     +historyitems
128
     */
129
 
538 rajveer 130
     if(tot>0){
879 rajveer 131
          //alert("AJAX request to add products in My research. Product ID: "+seldata+" and total: "+tot);
538 rajveer 132
          jQuery.ajax({
133
               type: "POST",
1614 rajveer 134
                      url: "/addtoresearch",
538 rajveer 135
                      data: "productid="+seldata,
1047 vikas 136
                      success: function(msg){
137
 
138
                           if(msg == 0){
139
                                alert( "Please register/signin to use myresearch tool" );
140
                           }else if(msg == 1){
141
                                alert( "Product is already in my research" );
142
                           }else {
143
                                var t=(research_tot*1)+(tot*1);
538 rajveer 144
                                $("#research_total").val(t);
145
                                if(t > 0){
146
                                     $("#research_default").css("display","none");
147
                                }     
148
                                $("#pane1").prepend(msg);
1053 vikas 149
                                // $('#pane1').jScrollPane({showArrows:true, scrollbarWidth: 15, arrowSize: 16});
538 rajveer 150
 
151
                                if(reqtype == "multi"){
152
                                     var arrayprod_id=seldata.split("_");
153
                                     jQuery.each(arrayprod_id,function(intIndex, objValue){
154
                                          var tblid="#pane1 #"+objValue+ " td";
1242 vikas 155
                                          $(tblid + " div a").truncate({addtitle: true});
156
                                          $(tblid + " div div.price").truncate({addtitle: true});
157
                                          $(tblid + " div div.text").truncate({addtitle: true});
538 rajveer 158
                                          $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
1242 vikas 159
                                          $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');
538 rajveer 160
                                     });
161
 
162
                                }else if(reqtype == "single"){
163
                                     var tblid="#pane1 #"+seldata+ " td";
1242 vikas 164
                                     $(tblid + " div a").truncate({addtitle: true});
165
                                     $(tblid + " div div.price").truncate({addtitle: true});
166
                                     $(tblid + " div div.text").truncate({addtitle: true});
538 rajveer 167
                                     $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
168
                                     $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');  
169
                                }else if(reqtype == "list"){
170
                                     var tblid="#pane1 #"+seldata+ " td";
1242 vikas 171
                                     $(tblid + " div a").truncate({addtitle: true});
172
                                     $(tblid + " div div.price").truncate({addtitle: true});
173
                                     $(tblid + " div div.text").truncate({addtitle: true});
538 rajveer 174
                                     $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
175
                                     $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');     
176
                                }    
177
                           }
1372 vikas 178
                           $.Storage.set("research", $("#myresearch").html());
879 rajveer 179
                           //alert( "Data Saved: " + msg );
538 rajveer 180
                      }
181
          });
182
 
183
     }else{
184
          alert("Please select atleast one product");
185
     }
186
}
187
 
188
 
189
function addToCart(refdivid,reqtype){
190
     var seldata="";
191
     var tot=0;
192
     var saprt="";
193
     if(reqtype == "multi"){
194
          var containerdiv = "#" + refdivid;
195
          var par= containerdiv + " input[type=checkbox]:checked";
637 rajveer 196
          var isMulti = false;
538 rajveer 197
          $(par).each(function(){
809 rajveer 198
 
637 rajveer 199
	       	   var totalcolors = $(this).attr('totalcolors');
879 rajveer 200
	       	   //alert(totalcolors);
637 rajveer 201
	           if(totalcolors != 1){
202
	        	   isMulti = true; 
203
	       	   }
204
	           saprt = (tot>0)? "_":"";
205
               seldata += saprt+$(this).attr('itemid');
206
               tot++;
538 rajveer 207
          });
879 rajveer 208
          //alert("ismulti" + isMulti + " seldata " + seldata + "   refdiv is "+ refdivid + "  par "+ par);
637 rajveer 209
          if(isMulti == true){
210
        	  alert("Some items are available in multiple colors. Please go to product page and select color you want.");
211
        	  return;
212
          }
538 rajveer 213
     }else if(reqtype == "single"){
214
          seldata = $("#item_id").val();
215
          tot=1;
216
     }else if(reqtype == "list"){
637 rajveer 217
    	  var seldata=refdivid;
538 rajveer 218
          var tot=1;
219
     }
1614 rajveer 220
     /*
221
     var historyitems = "";
222
     if($.Storage.get("historyitems")){
223
    	 historyitems = "&historyitems=" +  $.Storage.get("historyitems");
224
    	 $.Storage.remove("historyitems");
225
     }
226
     +historyitems
227
     */
538 rajveer 228
 
229
     if(tot>0){
879 rajveer 230
          //alert("AJAX request to add products in Cart. Product ID: "+seldata+" and total: "+tot); 
538 rajveer 231
          jQuery.ajax({
232
               type: "POST",
1614 rajveer 233
                      url: "/addtocart",
538 rajveer 234
                      data: "productid="+seldata,
235
                      success: function(msg){
236
                           $("#cartItemCount").html(msg*1);
1410 rajveer 237
                           window.location="/cart";
879 rajveer 238
                           //alert( "Data Saved: " + msg );
538 rajveer 239
                      }
240
          });
241
     }else{
242
          alert("Please select atleast one product");
243
     }
244
 
637 rajveer 245
}
246
 
247
function selectProduct(itemId){
879 rajveer 248
	//alert("Selected item is "+ itemId);
1047 vikas 249
}
250
 
251
function scrollWinToTop(){
252
    $('html, body').animate({
253
      scrollTop: $("body").offset().top
254
    }, 0);
255
}
256
 
257
function resetShipForm(){
258
  $('#shipName').val("");
259
  $('#shipAddress1').val("");
260
  $('#shipAddress2').val("");
261
  $('#shipState').val("");
262
  $('#shipCity').val("");
263
  $('#shipPin').val("");
264
  $('#shipPhone').val("");
265
	$('#newShipAdr').hide();
266
	scrollWinToTop();
267
}
268
 
269
function changeShipAddress(id){
270
  addressId = id.substring(20);
271
 //alert("TODO AJAX request to change shipping address. " + addressId);
272
   jQuery.ajax({
273
      type: "POST",
274
      url: "./shipping",
275
      data: "action=change&addressid="+addressId,
276
      success: function(msg){
277
         //alert( "Data Saved: " + msg );
278
         $("#addressid").val(msg);
279
      }
280
   });
281
  //$("#addressid").val(addressId);
282
  document.getElementById('shipAddressContainer').innerHTML = document.getElementById(id).innerHTML;
283
	$(".proceed-bttn .yellow-image").removeClass('imgDisableButton').addClass('imgEnableButton');
284
	$(".proceed-bttn input[disabled='']").removeAttr('disabled');
285
 
286
  //document.getElementById('newShipAdr').style.display = 'none';
287
  $('#newShipAdr').hide();
288
	scrollWinToTop();
289
 
290
}
1053 vikas 291
 
1372 vikas 292
function load_research_widget(){
293
	jQuery.ajax( {
294
		type : "GET",
295
		url : "/myresearch",
1567 vikas 296
		cache: false,
1372 vikas 297
		success : function(html) {
298
		$("#myresearch").html(html);
299
 
300
		// Product Title
301
		$("#myresearch table td div a").each(
302
				function() {
303
					$(this).truncate( {
304
						addtitle : true
305
					});
306
				});
307
 
308
		// Product Price
309
		$("#myresearch table td div div.price").each(
310
				function() {
311
					$(this).truncate( {
312
						addtitle : true
313
					});
314
				});
315
 
316
		// Product Details
317
		$("#myresearch table td div div.text").each(
318
				function() {
319
					$(this).truncate( {
320
						addtitle : true
321
					});
322
				});
323
		$.Storage.set("research", $("#myresearch").html());		  
324
	}
325
	});
326
}
327
 
1614 rajveer 328
function update_browse_history(){
329
	if($.Storage.get("historyitems")){
330
		params = $.Storage.get("historyitems");
331
 
332
		jQuery.ajax({
333
			type: "POST",
334
			url: "/browse-history",
335
			data: "historyitems="+params,
336
			cache: false,
337
			success: function(html){
338
				//alert(html);
339
			}
340
		});
341
	}	
342
}
343
 
1623 rajveer 344
function load_history_widget() {
1614 rajveer 345
	var params = "";
1623 rajveer 346
	if(!($.cookie("uid"))){
1614 rajveer 347
		if($.Storage.get("historyitems")){
348
			params = "/" + $.Storage.get("historyitems");
349
		}
350
	}
351
 
1372 vikas 352
	jQuery.ajax({
353
		type: "GET",
1614 rajveer 354
		url: "/browse-history" + params,
1567 vikas 355
		cache: false,
1372 vikas 356
		success: function(html){
357
		$("#browsehistory").html(html);
358
 
359
		// Product Title
360
		$("#browsehistory table td div a").each(function(){
361
			$(this).truncate({addtitle: true}); 
362
		});
363
 
364
		// Product Price
365
		$("#browsehistory table td div div.price").each(function(){
366
			$(this).truncate({addtitle: true});
367
		});
368
 
369
		// Product Details
370
		$("#browsehistory table td div div.text").each(function(){
371
			$(this).truncate({addtitle: true});
372
		});
373
		$.Storage.set("history", $("#browsehistory").html());
374
	}
375
	});
376
}
377