Subversion Repositories SmartDukaan

Rev

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