Subversion Repositories SmartDukaan

Rev

Rev 1623 | Rev 1761 | 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( "Product is already in my research" );
140
                           }else {
141
                                var t=(research_tot*1)+(tot*1);
538 rajveer 142
                                $("#research_total").val(t);
143
                                if(t > 0){
144
                                     $("#research_default").css("display","none");
145
                                }     
146
                                $("#pane1").prepend(msg);
1053 vikas 147
                                // $('#pane1').jScrollPane({showArrows:true, scrollbarWidth: 15, arrowSize: 16});
538 rajveer 148
 
149
                                if(reqtype == "multi"){
150
                                     var arrayprod_id=seldata.split("_");
151
                                     jQuery.each(arrayprod_id,function(intIndex, objValue){
152
                                          var tblid="#pane1 #"+objValue+ " td";
1242 vikas 153
                                          $(tblid + " div a").truncate({addtitle: true});
154
                                          $(tblid + " div div.price").truncate({addtitle: true});
155
                                          $(tblid + " div div.text").truncate({addtitle: true});
538 rajveer 156
                                          $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
1242 vikas 157
                                          $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');
538 rajveer 158
                                     });
159
 
160
                                }else if(reqtype == "single"){
161
                                     var tblid="#pane1 #"+seldata+ " td";
1242 vikas 162
                                     $(tblid + " div a").truncate({addtitle: true});
163
                                     $(tblid + " div div.price").truncate({addtitle: true});
164
                                     $(tblid + " div div.text").truncate({addtitle: true});
538 rajveer 165
                                     $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
166
                                     $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');  
167
                                }else if(reqtype == "list"){
168
                                     var tblid="#pane1 #"+seldata+ " td";
1242 vikas 169
                                     $(tblid + " div a").truncate({addtitle: true});
170
                                     $(tblid + " div div.price").truncate({addtitle: true});
171
                                     $(tblid + " div div.text").truncate({addtitle: true});
538 rajveer 172
                                     $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
173
                                     $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');     
174
                                }    
175
                           }
1372 vikas 176
                           $.Storage.set("research", $("#myresearch").html());
879 rajveer 177
                           //alert( "Data Saved: " + msg );
538 rajveer 178
                      }
179
          });
180
 
181
     }else{
182
          alert("Please select atleast one product");
183
     }
184
}
185
 
186
 
187
function addToCart(refdivid,reqtype){
188
     var seldata="";
189
     var tot=0;
190
     var saprt="";
191
     if(reqtype == "multi"){
192
          var containerdiv = "#" + refdivid;
193
          var par= containerdiv + " input[type=checkbox]:checked";
637 rajveer 194
          var isMulti = false;
538 rajveer 195
          $(par).each(function(){
809 rajveer 196
 
637 rajveer 197
	       	   var totalcolors = $(this).attr('totalcolors');
879 rajveer 198
	       	   //alert(totalcolors);
637 rajveer 199
	           if(totalcolors != 1){
200
	        	   isMulti = true; 
201
	       	   }
202
	           saprt = (tot>0)? "_":"";
203
               seldata += saprt+$(this).attr('itemid');
204
               tot++;
538 rajveer 205
          });
879 rajveer 206
          //alert("ismulti" + isMulti + " seldata " + seldata + "   refdiv is "+ refdivid + "  par "+ par);
637 rajveer 207
          if(isMulti == true){
208
        	  alert("Some items are available in multiple colors. Please go to product page and select color you want.");
209
        	  return;
210
          }
538 rajveer 211
     }else if(reqtype == "single"){
212
          seldata = $("#item_id").val();
213
          tot=1;
214
     }else if(reqtype == "list"){
637 rajveer 215
    	  var seldata=refdivid;
538 rajveer 216
          var tot=1;
217
     }
1614 rajveer 218
     /*
219
     var historyitems = "";
220
     if($.Storage.get("historyitems")){
221
    	 historyitems = "&historyitems=" +  $.Storage.get("historyitems");
222
    	 $.Storage.remove("historyitems");
223
     }
224
     +historyitems
225
     */
538 rajveer 226
 
227
     if(tot>0){
879 rajveer 228
          //alert("AJAX request to add products in Cart. Product ID: "+seldata+" and total: "+tot); 
538 rajveer 229
          jQuery.ajax({
230
               type: "POST",
1614 rajveer 231
                      url: "/addtocart",
538 rajveer 232
                      data: "productid="+seldata,
233
                      success: function(msg){
234
                           $("#cartItemCount").html(msg*1);
1410 rajveer 235
                           window.location="/cart";
879 rajveer 236
                           //alert( "Data Saved: " + msg );
538 rajveer 237
                      }
238
          });
239
     }else{
240
          alert("Please select atleast one product");
241
     }
242
 
637 rajveer 243
}
244
 
245
function selectProduct(itemId){
879 rajveer 246
	//alert("Selected item is "+ itemId);
1047 vikas 247
}
248
 
249
function scrollWinToTop(){
250
    $('html, body').animate({
251
      scrollTop: $("body").offset().top
252
    }, 0);
253
}
254
 
255
function resetShipForm(){
256
  $('#shipName').val("");
257
  $('#shipAddress1').val("");
258
  $('#shipAddress2').val("");
259
  $('#shipState').val("");
260
  $('#shipCity').val("");
261
  $('#shipPin').val("");
262
  $('#shipPhone').val("");
263
	$('#newShipAdr').hide();
264
	scrollWinToTop();
265
}
266
 
267
function changeShipAddress(id){
268
  addressId = id.substring(20);
269
 //alert("TODO AJAX request to change shipping address. " + addressId);
270
   jQuery.ajax({
271
      type: "POST",
272
      url: "./shipping",
273
      data: "action=change&addressid="+addressId,
274
      success: function(msg){
275
         //alert( "Data Saved: " + msg );
276
         $("#addressid").val(msg);
277
      }
278
   });
279
  //$("#addressid").val(addressId);
280
  document.getElementById('shipAddressContainer').innerHTML = document.getElementById(id).innerHTML;
281
	$(".proceed-bttn .yellow-image").removeClass('imgDisableButton').addClass('imgEnableButton');
282
	$(".proceed-bttn input[disabled='']").removeAttr('disabled');
283
 
284
  //document.getElementById('newShipAdr').style.display = 'none';
285
  $('#newShipAdr').hide();
286
	scrollWinToTop();
287
 
288
}
1053 vikas 289
 
1372 vikas 290
function load_research_widget(){
291
	jQuery.ajax( {
292
		type : "GET",
293
		url : "/myresearch",
1567 vikas 294
		cache: false,
1372 vikas 295
		success : function(html) {
296
		$("#myresearch").html(html);
297
 
298
		// Product Title
299
		$("#myresearch table td div a").each(
300
				function() {
301
					$(this).truncate( {
302
						addtitle : true
303
					});
304
				});
305
 
306
		// Product Price
307
		$("#myresearch table td div div.price").each(
308
				function() {
309
					$(this).truncate( {
310
						addtitle : true
311
					});
312
				});
313
 
314
		// Product Details
315
		$("#myresearch table td div div.text").each(
316
				function() {
317
					$(this).truncate( {
318
						addtitle : true
319
					});
320
				});
321
		$.Storage.set("research", $("#myresearch").html());		  
322
	}
323
	});
324
}
325
 
1614 rajveer 326
function update_browse_history(){
327
	if($.Storage.get("historyitems")){
328
		params = $.Storage.get("historyitems");
329
 
330
		jQuery.ajax({
331
			type: "POST",
332
			url: "/browse-history",
333
			data: "historyitems="+params,
334
			cache: false,
335
			success: function(html){
336
				//alert(html);
337
			}
338
		});
339
	}	
340
}
341
 
1623 rajveer 342
function load_history_widget() {
1614 rajveer 343
	var params = "";
1623 rajveer 344
	if(!($.cookie("uid"))){
1614 rajveer 345
		if($.Storage.get("historyitems")){
346
			params = "/" + $.Storage.get("historyitems");
347
		}
348
	}
349
 
1372 vikas 350
	jQuery.ajax({
351
		type: "GET",
1614 rajveer 352
		url: "/browse-history" + params,
1567 vikas 353
		cache: false,
1372 vikas 354
		success: function(html){
355
		$("#browsehistory").html(html);
356
 
357
		// Product Title
358
		$("#browsehistory table td div a").each(function(){
359
			$(this).truncate({addtitle: true}); 
360
		});
361
 
362
		// Product Price
363
		$("#browsehistory table td div div.price").each(function(){
364
			$(this).truncate({addtitle: true});
365
		});
366
 
367
		// Product Details
368
		$("#browsehistory table td div div.text").each(function(){
369
			$(this).truncate({addtitle: true});
370
		});
371
		$.Storage.set("history", $("#browsehistory").html());
372
	}
373
	});
374
}
375