Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
11888 anikendra 1
window.onload=function(){
2
	var pheight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
3
	if(document.getElementsByClassName('cart-cont')[0] != undefined){
4
 
5
	    document.getElementsByClassName('cart-cont')[0].style.minHeight = pheight - 235 +'px';  
6
	}
7
};
8
 
9
function clearmsg() {
10
  if (document.getElementById("coupon-msg").style.display == "block") {
11
    document.getElementById("coupon-msg").style.display = "none";
12
  }
13
}
14
 
15
function applycoupon() {
16
  var coupon = document.getElementById("couponcode").value;
17
  if (coupon.length <= 0) {
18
    if (document.getElementById("error").style.display == "block") {
19
      document.getElementById("error").style.display = "none";
20
    }
21
    var bRed = document.getElementById("couponcode");
22
    bRed.style.border = "red solid 1px";
23
    bRed.style.color = "red";
24
    bRed.value = "Please enter the coupon code!";
25
    setTimeout(function() {
26
      bRed.style.border = "";
27
      bRed.style.color = "";
28
      bRed.value = "";
29
    }, 3000);
30
    return false;
31
  } else {
32
    if (document.getElementById("error").style.display == "block") {
33
      document.getElementById("error").style.display = "none";
34
    }
35
    var url = base_url + "cart/coupon/" + coupon;
36
    microAjax(url, function(res) {
37
      var data = JSON.parse(res);
38
      var message = data.message;
39
        document.getElementById("addCoupon").style.display = "block";
40
      document.getElementById("coupon-msg").style.display = "block";
41
      if (message.length > 0) {
42
        document.getElementById("coupon-msg").innerHTML = message;
43
      }
44
      //if (data.discountedPrice != undefined && parseInt(data.discountedPrice) >= 0) {
45
      if (data.couponCode != undefined && data.couponCode.length > 0) {
46
	var dealtextdivs = document.getElementsByClassName('dealdiv');
47
	for(var i in dealtextdivs){
48
 		if(dealtextdivs[i].innerHTML===undefined)continue;
49
		var item_id = dealtextdivs[i].getAttribute('id');
50
		dealtextdivs[i].innerHTML = data.dealTextArray[item_id];
51
		if(data.dealTextArray[item_id]==''){
52
			dealtextdivs[i].style.display='none';
53
		}
54
	}
55
        //document.getElementById("addCoupon").style.display = "none";
56
        document.getElementById("removeCoupon").style.display = "block";
57
        if (data.couponCode.length > 0) {
58
          document.getElementById("removeCoupon").innerHTML = "Remove Coupon: " + data.couponCode;
12524 anikendra 59
          /*if ( typeof _gaq != "undefined" && _gaq != null) {
11888 anikendra 60
            _gaq.push(["_trackEvent", "COUPON", "Coupon Applied", data.couponCode]);
12524 anikendra 61
          }*/
62
	ga('send', 'event', 'Coupon', 'Coupon Applied',data.couponCode);
11888 anikendra 63
	      }else{
64
          document.getElementById("removeCoupon").innerHTML = "Remove Coupon";
65
        }
66
        document.getElementById("discount").style.display = "block";
67
        var discount = parseInt(data.totalPrice) - parseInt(data.discountedPrice);
68
        document.getElementById("discountAmt").innerHTML = discount;
69
        document.getElementById("discountPrice").style.display = "block";
70
        document.getElementById("discountedPrice").innerHTML = parseInt(document.getElementById("total").innerHTML) - discount;
71
      } else {
72
        document.getElementById("discount").style.display = "none";
73
        document.getElementById("discountPrice").style.display = "none";
74
      }
75
    });
76
  }
77
}
78
 
79
function clearcoupon(code) {
80
  var url = base_url + "cart/couponClear/" + code;
81
  microAjax(url, function(res) {
12524 anikendra 82
    /*if ( typeof _gaq != "undefined" && _gaq != null) {
11888 anikendra 83
      _gaq.push(["_trackEvent", "COUPON", "Coupon Removed", document.getElementById("couponcode").value]);
12524 anikendra 84
    }*/
85
	ga('send', 'event', 'Coupon', 'Coupon Removed',document.getElementById("couponcode").value);
11888 anikendra 86
    var data = JSON.parse(res);
87
    var message = data.message;
88
    var total = data.totalPrice;
89
    document.getElementById("addCoupon").style.display = "block";
90
    document.getElementById("removeCoupon").style.display = "none";
91
    document.getElementById("discount").style.display = "none";
92
    document.getElementById("discountPrice").style.display = "none";
93
    document.getElementById("coupon-msg").style.display = "none";
94
    document.getElementById("couponcode").value = "";
95
    var finalinsurance = 0;
96
    if (insuredItems.length > 0) {
97
      for ( j = 0; j < insuredItems.length; j++) {
98
        var insurance = insuredItems[j] + "theft";
99
        var cost = document.getElementById(insurance).innerHTML;
100
        finalinsurance = finalinsurance + parseInt(cost);
101
      }
102
    }
103
    if (parseInt(finalinsurance) > 0) {
104
      total = parseInt(total) + parseInt(finalinsurance);
105
      document.getElementById("total").innerHTML = total;
106
    }
107
  });
108
}
109
 
110
function updateQty(e) {
111
  var oldValue = e.currentTarget.getAttribute("data-value");
112
  var newvalue = e.currentTarget.value;
113
  if (parseInt(newvalue) != parseInt(oldValue)) {
114
    var url = base_url + "cart/update/" + e.currentTarget.id + "/" + newvalue;
115
    window.location.href = url;
116
  }
117
}
118
 
15933 manish.sha 119
function updateQuantity(itemId, oldValue){
120
	var newvalue = document.getElementById("qty_"+itemId).value;
16035 manish.sha 121
	if(parseInt(newvalue)>20){
16041 manish.sha 122
		document.getElementById("max-quantity-msg").text="You can not order more than 20 units of the same product";
16040 manish.sha 123
		document.getElementById("max-quantity-msg").style.display="block";
16035 manish.sha 124
		document.getElementById("qty_"+itemId).value=1;
125
		return;
126
	}
15933 manish.sha 127
	if (parseInt(newvalue) != parseInt(oldValue)) {
128
	    var url = base_url + "cart/update/" + itemId + "/" + newvalue;
16035 manish.sha 129
	    microAjax(url, function(res) {
130
	    	if (res != "") {
131
		    	var data = JSON.parse(res);
132
		    	message = data.response.updatecart[0].message
133
		    	if(message ==""){
134
 
135
		    	}
136
	    	}
137
	    });
15933 manish.sha 138
	}
139
}
140
 
11888 anikendra 141
function removeItem(itemId) {
142
  var url = base_url + "cart/delete/" + itemId;
143
  window.location.href = url;
144
}
145
 
15933 manish.sha 146
function showQtyConfirmButton(itemId){
15952 manish.sha 147
	document.getElementById("confirmQty_"+itemId).style.display = "block";
15933 manish.sha 148
}
149
 
11888 anikendra 150
var insuredItems = new Array();
151
function teftinsure(e) {
152
  var key = e.currentTarget.getAttribute("data-key");
153
  if (key == "ins") {
154
    if (document.getElementById("error").style.display == "block") {
155
      document.getElementById("error").style.display = "none";
156
    }
157
    var id = e.currentTarget.id;
158
    var insure = document.getElementById(id).checked;
159
    var itemId = e.currentTarget.getAttribute("data-value");
160
    var tnc = itemId + "tnc";
161
    var tc = itemId + "tc";
162
    tncChkd = document.getElementById(tnc).checked;
163
    var theft = itemId + "theft";
164
    var theft = document.getElementById(theft).innerHTML;
165
    theft = parseInt(theft);
166
    var total = document.getElementById("total").innerHTML;
167
    total = parseInt(total);
168
    if (insure == true) {
169
      insuredItems.push(itemId);
12524 anikendra 170
      /*if ( typeof _gaq != "undefined" && _gaq != null) {
11888 anikendra 171
        _gaq.push(["_trackEvent", "insurance", "Want Insurance", itemId]);
12524 anikendra 172
      }*/
173
	ga('send', 'event', 'Insurance', 'Want Insurance',itemId);
11888 anikendra 174
      if (document.getElementById("discountPrice").style.display == "block") {
175
        var discountPrice = document.getElementById("discountedPrice").innerHTML;
176
        discountPrice = parseInt(discountPrice);
177
        document.getElementById("discountedPrice").innerHTML = discountPrice + theft;
178
      } else {
179
        document.getElementById("total").innerHTML = total + theft;
180
      }
181
    }
182
    if (insure == false) {
183
      if (document.getElementById("error").style.display == "block") {
184
        document.getElementById("error").style.display = "none";
185
      }
186
      if (document.getElementById(tc).style.display == "block") {
187
        document.getElementById(tc).style.display = "none";
188
      }
189
      var ind = insuredItems.indexOf(itemId);
190
      insuredItems.splice(ind, 1);
191
      if (document.getElementById("discountPrice").style.display == "block") {
192
        var discountPrice = document.getElementById("discountedPrice").innerHTML;
193
        discountPrice = parseInt(discountPrice);
194
        document.getElementById("discountedPrice").innerHTML = discountPrice - theft;
195
      } else {
196
        document.getElementById("total").innerHTML = total - theft;
197
      }
198
    }
199
  }
200
  if (key == "tnc") {
201
    if (document.getElementById("error").style.display == "block") {
202
      document.getElementById("error").style.display = "none";
203
    }
204
    var id = e.currentTarget.id;
205
    var tncChkd = document.getElementById(id).checked;
206
    var itemId = e.currentTarget.getAttribute("data-value");
207
    var insurance = itemId + "insurance";
208
    var tc = itemId + "tc";
209
    var insure = document.getElementById(insurance).checked;
210
  }
211
  if (insure == true && tncChkd == false) {
212
    if (document.getElementById("error").style.display == "block") {
213
      document.getElementById("error").style.display = "none";
214
    }
215
    if (document.getElementById(tc).style.display == "block") {
216
      var url = base_url + "cart/insure/" + itemId + "/" + tncChkd + "/1";
217
      microAjax(url, function(res) {
218
        var data = JSON.parse(res);
219
        data = data.status;
220
        if (data == true) {
221
        }
222
        if (data == false) {
223
          alert(data);
224
        }
225
      });
226
    } else {
227
      document.getElementById(tc).style.display = "block";
228
    }
229
  } else {
230
    if (insure == true && tncChkd == true) {
12524 anikendra 231
      /*if ( typeof _gaq != "undefined" && _gaq != null) {
11888 anikendra 232
        _gaq.push(["_trackEvent", "Insurance", "Agreed to Terms", itemId]);
12524 anikendra 233
      }*/
234
	ga('send', 'event', 'Insurance', 'Agreed to Terms',itemId);
11888 anikendra 235
      var url = base_url + "cart/insure/" + itemId + "/" + insure + "/1";
236
      microAjax(url, function(res) {
237
        var data = JSON.parse(res);
238
        data = data.status;
239
        if (data == true) {
240
        }
241
        if (data == false) {
242
          alert(data);
243
        }
244
      });
245
    } else {
246
      if (insure == false && tncChkd == true) {
247
        var url = base_url + "cart/insure/" + itemId + "/" + insure + "/1";
248
        microAjax(url, function(res) {
249
          var data = JSON.parse(res);
250
          data = data.status;
251
          if (data == true) {
252
            document.getElementById(tnc).checked = false;
253
            document.getElementById(tc).style.display = "none";
254
          }
255
          if (data == false) {
256
            alert(data);
257
          }
258
        });
259
      } else {
260
        if (insure == false && tncChkd == true) {
261
          var url = base_url + "cart/insure/" + itemId + "/" + insure + "/1";
262
          microAjax(url, function(res) {
263
            var data = JSON.parse(res);
264
            data = data.status;
265
            if (data == true) {
266
              document.getElementById(tnc).checked = false;
267
              document.getElementById(tc).style.display = "none";
268
            }
269
            if (data == false) {
270
              alert(data);
271
            }
272
          });
273
        }
274
      }
275
    }
276
  }
277
}
278
 
279
function dataprotection(e) {
280
  var id = e.currentTarget.id;
281
  var protection = document.getElementById(id).checked;
282
  var itemId = e.currentTarget.getAttribute("data-value");
283
  var url = base_url + "cart/insure/" + itemId + "/" + protection + "/2";
284
  microAjax(url, function(res) {
285
    var data = JSON.parse(res);
286
    data = data.status;
287
    if (data == true) {
288
    }
289
    if (data == false) {
290
    }
291
  });
292
}
293
 
294
function checkout() {
295
  var chx = document.getElementsByClassName("checkbox");
296
  for (var i = 0; i < chx.length; i++) {
297
    if (chx[i].type == "checkbox" && chx[i].checked) {
298
      var id = chx[i].getAttribute("data-value");
299
      var tnc = id + "tnc";
300
      if (document.getElementById(tnc).checked == false) {
12524 anikendra 301
        /*if ( typeof _gaq != "undefined" && _gaq != null) {
11888 anikendra 302
          _gaq.push(["_trackEvent", "Insurance", "Alert for tnc"]);
12524 anikendra 303
        }*/
304
	ga('send', 'event', 'Insurance', 'Alert for tnc');
11888 anikendra 305
        document.getElementById("error").style.display = "block";
306
        document.getElementById("error").innerHTML = "Please agree to the terms and conditions to get insurance";
307
        window.scrollTo(0, 0);
308
        return false;
309
        break;
310
      }
311
    }
312
  }
313
  if (locationServicable == false) {
314
    var pincode = document.getElementById("pincode").value;
12524 anikendra 315
    /*if ( typeof _gaq != "undefined" && _gaq != null) {
11888 anikendra 316
      _gaq.push(["_trackEvent", "Cart", "Location not serviceable", pincode]);
12524 anikendra 317
    }*/
318
	ga('send', 'event', 'Cart', 'Location not serviceable',pincode);
11888 anikendra 319
    document.getElementById("error").style.display = "block";
320
    if (itemsNotServicable == items.length) {
321
      document.getElementById("error").innerHTML = "Location not serviceable. Please try a different pincode";
322
    } else {
323
      if (itemsNotServicable != items.length) {
324
        document.getElementById("error").innerHTML = "Location not serviceable for one of the products. Please try a different pincode or try removing the product";
325
      }
326
    }
327
    window.scrollTo(0, 0);
328
    return false;
329
  }
330
  if ((notServiceableLocation != undefined) && (notServiceableLocation != 0)) {
331
    var pincode = document.getElementById("pincode").value;
12524 anikendra 332
    /*if ( typeof _gaq != "undefined" && _gaq != null) {
11888 anikendra 333
      _gaq.push(["_trackEvent", "Cart", "Location not serviceable", pincode]);
12524 anikendra 334
    }*/
335
	ga('send', 'event', 'Cart', 'Location not serviceable',pincode);
11888 anikendra 336
    document.getElementById("error").style.display = "block";
337
    if (notServiceableLocation == items.length) {
338
      document.getElementById("error").innerHTML = "Location not serviceable. Please try a different pincode";
339
    } else {
340
      if (notServiceableLocation != items.length) {
341
        document.getElementById("error").innerHTML = "Location not serviceable for one of the products. Please try a different pincode or try removing the product";
342
      }
343
    }
344
    window.scrollTo(0, 0);
345
    return false;
346
  }
347
  window.location.href = base_url + "shipping";
348
}
349
 
350
var j = 0;
351
var locationServicable;
352
var itemsNotServicable = 0;
353
function checkShipping() {
354
  if (j != 0) {
355
    j = 0;
356
  }
357
  if (itemsNotServicable != 0) {
358
    itemsNotServicable = 0;
359
  }
360
  var pincode = document.getElementById("pincode").value;
361
  pincode = pincode.trim();
362
  if (/^\d+$/.test(pincode) && pincode.length == 6) {
363
    if (document.getElementById("error")) {
364
      document.getElementById("error").style.display = "none";
365
    }
366
    for ( i = 0; i < items.length; i++) {
367
      itemId = items[i].id;
368
      var url = base_url + "productinfo/getDeliveryDetails/" + itemId + "/" + pincode;
369
      j = i;
370
      microAjax(url, function(res) {
371
        if (res != "") {
372
          data = JSON.parse(res);
373
          days = data.business_days;
374
          if (days >= 0) {
375
            locationServicable = true;
376
            var service = items[j].id + "service";
377
            document.getElementById(service).style.display = "none";
378
            var delivery = items[j].id + "delivery";
379
            if (document.getElementById(delivery)) {
380
              document.getElementById(delivery).style.display = "block";
381
              var del = items[j].id + "del";
382
              document.getElementById(del).innerHTML = data.delivery_estimate;
383
            }
384
            if (data.is_cod_available_for_location == true) {
385
              var cod = items[j].id + "cod";
386
              if (document.getElementById(cod).style.display == "none") {
387
                document.getElementById(cod).style.display = "block";
388
              }
389
            }
390
            if (data.on_time_guarantee == true) {
391
              var otg = items[j].id + "otg";
392
              if (document.getElementById(otg).style.display == "none") {
393
                document.getElementById(otg).style.display = "block";
394
              }
395
            }
396
          } else {
397
            var del = items[j].id + "delivery";
398
            document.getElementById(del).style.display = "none";
399
            var cod = items[j].id + "cod";
400
            document.getElementById(cod).style.display = "none";
401
            var otg = items[j].id + "otg";
402
            document.getElementById(otg).style.display = "none";
403
            var service = items[j].id + "service";
404
            document.getElementById(service).style.display = "block";
405
            document.getElementById(service).innerHTML = "Location is not serviceable";
406
            locationServicable = false;
407
            itemsNotServicable++;
408
          }
409
          j--;
410
        }
411
      });
412
    }
413
  } else {
414
    document.getElementById("error").style.display = "block";
415
    document.getElementById("error").innerHTML = "Invalid pincode!";
416
  }
417
}
418
 
419
function shomoreredirect() {
420
  window.location.href = base_url;
421
}