Subversion Repositories SmartDukaan

Rev

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