Subversion Repositories SmartDukaan

Rev

Rev 1189 | Rev 1242 | 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
 
121
     if(tot>0){
879 rajveer 122
          //alert("AJAX request to add products in My research. Product ID: "+seldata+" and total: "+tot);
538 rajveer 123
          jQuery.ajax({
124
               type: "POST",
809 rajveer 125
                      url: "/myresearch",
538 rajveer 126
                      data: "productid="+seldata,
1047 vikas 127
                      success: function(msg){
128
 
129
                           if(msg == 0){
130
                                alert( "Please register/signin to use myresearch tool" );
131
                           }else if(msg == 1){
132
                                alert( "Product is already in my research" );
133
                           }else {
134
                                var t=(research_tot*1)+(tot*1);
538 rajveer 135
                                $("#research_total").val(t);
136
                                if(t > 0){
137
                                     $("#research_default").css("display","none");
138
                                }     
139
                                $("#pane1").prepend(msg);
1053 vikas 140
                                // $('#pane1').jScrollPane({showArrows:true, scrollbarWidth: 15, arrowSize: 16});
538 rajveer 141
 
142
                                if(reqtype == "multi"){
143
                                     var arrayprod_id=seldata.split("_");
144
                                     jQuery.each(arrayprod_id,function(intIndex, objValue){
145
                                          var tblid="#pane1 #"+objValue+ " td";
146
                                          $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
147
                                          $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');     
148
                                     });
149
 
150
                                }else if(reqtype == "single"){
151
                                     var tblid="#pane1 #"+seldata+ " td";
152
                                     $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
153
                                     $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');  
154
                                }else if(reqtype == "list"){
155
                                     var tblid="#pane1 #"+seldata+ " td";
156
                                     $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
157
                                     $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');     
158
                                }    
159
                           }
879 rajveer 160
                           //alert( "Data Saved: " + msg );
538 rajveer 161
                      }
162
          });
163
 
164
     }else{
165
          alert("Please select atleast one product");
166
     }
167
}
168
 
169
 
170
function addToCart(refdivid,reqtype){
171
     var seldata="";
172
     var tot=0;
173
     var saprt="";
174
     if(reqtype == "multi"){
175
          var containerdiv = "#" + refdivid;
176
          var par= containerdiv + " input[type=checkbox]:checked";
637 rajveer 177
          var isMulti = false;
538 rajveer 178
          $(par).each(function(){
809 rajveer 179
 
637 rajveer 180
	       	   var totalcolors = $(this).attr('totalcolors');
879 rajveer 181
	       	   //alert(totalcolors);
637 rajveer 182
	           if(totalcolors != 1){
183
	        	   isMulti = true; 
184
	       	   }
185
	           saprt = (tot>0)? "_":"";
186
               seldata += saprt+$(this).attr('itemid');
187
               tot++;
538 rajveer 188
          });
879 rajveer 189
          //alert("ismulti" + isMulti + " seldata " + seldata + "   refdiv is "+ refdivid + "  par "+ par);
637 rajveer 190
          if(isMulti == true){
191
        	  alert("Some items are available in multiple colors. Please go to product page and select color you want.");
192
        	  return;
193
          }
538 rajveer 194
     }else if(reqtype == "single"){
195
          seldata = $("#item_id").val();
196
          tot=1;
197
     }else if(reqtype == "list"){
637 rajveer 198
    	  var seldata=refdivid;
538 rajveer 199
          var tot=1;
200
     }
201
 
202
     if(tot>0){
879 rajveer 203
          //alert("AJAX request to add products in Cart. Product ID: "+seldata+" and total: "+tot); 
538 rajveer 204
          jQuery.ajax({
205
               type: "POST",
809 rajveer 206
                      url: "/cart",
538 rajveer 207
                      data: "productid="+seldata,
208
                      success: function(msg){
209
                           $("#cartItemCount").html(msg*1);
879 rajveer 210
                           //alert( "Data Saved: " + msg );
538 rajveer 211
                      }
212
          });
213
     }else{
214
          alert("Please select atleast one product");
215
     }
216
 
637 rajveer 217
}
218
 
219
function selectProduct(itemId){
879 rajveer 220
	//alert("Selected item is "+ itemId);
1047 vikas 221
}
222
 
223
function scrollWinToTop(){
224
    $('html, body').animate({
225
      scrollTop: $("body").offset().top
226
    }, 0);
227
}
228
 
229
function resetShipForm(){
230
  $('#shipName').val("");
231
  $('#shipAddress1').val("");
232
  $('#shipAddress2').val("");
233
  $('#shipState').val("");
234
  $('#shipCity').val("");
235
  $('#shipPin').val("");
236
  $('#shipPhone').val("");
237
	$('#newShipAdr').hide();
238
	scrollWinToTop();
239
}
240
 
241
function changeShipAddress(id){
242
  addressId = id.substring(20);
243
 //alert("TODO AJAX request to change shipping address. " + addressId);
244
   jQuery.ajax({
245
      type: "POST",
246
      url: "./shipping",
247
      data: "action=change&addressid="+addressId,
248
      success: function(msg){
249
         //alert( "Data Saved: " + msg );
250
         $("#addressid").val(msg);
251
      }
252
   });
253
  //$("#addressid").val(addressId);
254
  document.getElementById('shipAddressContainer').innerHTML = document.getElementById(id).innerHTML;
255
	$(".proceed-bttn .yellow-image").removeClass('imgDisableButton').addClass('imgEnableButton');
256
	$(".proceed-bttn input[disabled='']").removeAttr('disabled');
257
 
258
  //document.getElementById('newShipAdr').style.display = 'none';
259
  $('#newShipAdr').hide();
260
	scrollWinToTop();
261
 
262
}
1053 vikas 263
 
264
// Google analytics.
265
var _gaq = _gaq || [];
266
_gaq.push(['_setAccount', 'UA-21662919-1']);
267
_gaq.push(['_trackPageview']);
268
 
269
(function() {
270
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
271
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
272
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
273
})();