Subversion Repositories SmartDukaan

Rev

Rev 1199 | Rev 1372 | 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";
1242 vikas 146
                                          $(tblid + " div a").truncate({addtitle: true});
147
                                          $(tblid + " div div.price").truncate({addtitle: true});
148
                                          $(tblid + " div div.text").truncate({addtitle: true});
538 rajveer 149
                                          $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
1242 vikas 150
                                          $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');
538 rajveer 151
                                     });
152
 
153
                                }else if(reqtype == "single"){
154
                                     var tblid="#pane1 #"+seldata+ " 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');
159
                                     $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');  
160
                                }else if(reqtype == "list"){
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
                                }    
168
                           }
879 rajveer 169
                           //alert( "Data Saved: " + msg );
538 rajveer 170
                      }
171
          });
172
 
173
     }else{
174
          alert("Please select atleast one product");
175
     }
176
}
177
 
178
 
179
function addToCart(refdivid,reqtype){
180
     var seldata="";
181
     var tot=0;
182
     var saprt="";
183
     if(reqtype == "multi"){
184
          var containerdiv = "#" + refdivid;
185
          var par= containerdiv + " input[type=checkbox]:checked";
637 rajveer 186
          var isMulti = false;
538 rajveer 187
          $(par).each(function(){
809 rajveer 188
 
637 rajveer 189
	       	   var totalcolors = $(this).attr('totalcolors');
879 rajveer 190
	       	   //alert(totalcolors);
637 rajveer 191
	           if(totalcolors != 1){
192
	        	   isMulti = true; 
193
	       	   }
194
	           saprt = (tot>0)? "_":"";
195
               seldata += saprt+$(this).attr('itemid');
196
               tot++;
538 rajveer 197
          });
879 rajveer 198
          //alert("ismulti" + isMulti + " seldata " + seldata + "   refdiv is "+ refdivid + "  par "+ par);
637 rajveer 199
          if(isMulti == true){
200
        	  alert("Some items are available in multiple colors. Please go to product page and select color you want.");
201
        	  return;
202
          }
538 rajveer 203
     }else if(reqtype == "single"){
204
          seldata = $("#item_id").val();
205
          tot=1;
206
     }else if(reqtype == "list"){
637 rajveer 207
    	  var seldata=refdivid;
538 rajveer 208
          var tot=1;
209
     }
210
 
211
     if(tot>0){
879 rajveer 212
          //alert("AJAX request to add products in Cart. Product ID: "+seldata+" and total: "+tot); 
538 rajveer 213
          jQuery.ajax({
214
               type: "POST",
809 rajveer 215
                      url: "/cart",
538 rajveer 216
                      data: "productid="+seldata,
217
                      success: function(msg){
218
                           $("#cartItemCount").html(msg*1);
879 rajveer 219
                           //alert( "Data Saved: " + msg );
538 rajveer 220
                      }
221
          });
222
     }else{
223
          alert("Please select atleast one product");
224
     }
225
 
637 rajveer 226
}
227
 
228
function selectProduct(itemId){
879 rajveer 229
	//alert("Selected item is "+ itemId);
1047 vikas 230
}
231
 
232
function scrollWinToTop(){
233
    $('html, body').animate({
234
      scrollTop: $("body").offset().top
235
    }, 0);
236
}
237
 
238
function resetShipForm(){
239
  $('#shipName').val("");
240
  $('#shipAddress1').val("");
241
  $('#shipAddress2').val("");
242
  $('#shipState').val("");
243
  $('#shipCity').val("");
244
  $('#shipPin').val("");
245
  $('#shipPhone').val("");
246
	$('#newShipAdr').hide();
247
	scrollWinToTop();
248
}
249
 
250
function changeShipAddress(id){
251
  addressId = id.substring(20);
252
 //alert("TODO AJAX request to change shipping address. " + addressId);
253
   jQuery.ajax({
254
      type: "POST",
255
      url: "./shipping",
256
      data: "action=change&addressid="+addressId,
257
      success: function(msg){
258
         //alert( "Data Saved: " + msg );
259
         $("#addressid").val(msg);
260
      }
261
   });
262
  //$("#addressid").val(addressId);
263
  document.getElementById('shipAddressContainer').innerHTML = document.getElementById(id).innerHTML;
264
	$(".proceed-bttn .yellow-image").removeClass('imgDisableButton').addClass('imgEnableButton');
265
	$(".proceed-bttn input[disabled='']").removeAttr('disabled');
266
 
267
  //document.getElementById('newShipAdr').style.display = 'none';
268
  $('#newShipAdr').hide();
269
	scrollWinToTop();
270
 
271
}
1053 vikas 272
 
273
// Google analytics.
274
var _gaq = _gaq || [];
275
_gaq.push(['_setAccount', 'UA-21662919-1']);
276
_gaq.push(['_trackPageview']);
277
 
278
(function() {
279
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
280
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
281
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
282
})();