Subversion Repositories SmartDukaan

Rev

Rev 16122 | Rev 17475 | 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() {
16123 manish.sha 10
  if (document.getElementById("cart-quantity-msg") !=null){
11
	document.getElementById("cart-quantity-msg").innerHTML = '';
12
	document.getElementById("cart-quantity-msg").style.display = 'none';
13
  }
11888 anikendra 14
  if (document.getElementById("coupon-msg").style.display == "block") {
15
    document.getElementById("coupon-msg").style.display = "none";
16
  }
17
}
18
 
19
function applycoupon() {
20
  var coupon = document.getElementById("couponcode").value;
21
  if (coupon.length <= 0) {
22
    if (document.getElementById("error").style.display == "block") {
23
      document.getElementById("error").style.display = "none";
24
    }
25
    var bRed = document.getElementById("couponcode");
26
    bRed.style.border = "red solid 1px";
27
    bRed.style.color = "red";
28
    bRed.value = "Please enter the coupon code!";
29
    setTimeout(function() {
30
      bRed.style.border = "";
31
      bRed.style.color = "";
32
      bRed.value = "";
33
    }, 3000);
34
    return false;
35
  } else {
36
    if (document.getElementById("error").style.display == "block") {
37
      document.getElementById("error").style.display = "none";
38
    }
39
    var url = base_url + "cart/coupon/" + coupon;
40
    microAjax(url, function(res) {
41
      var data = JSON.parse(res);
42
      var message = data.message;
43
        document.getElementById("addCoupon").style.display = "block";
44
      document.getElementById("coupon-msg").style.display = "block";
45
      if (message.length > 0) {
46
        document.getElementById("coupon-msg").innerHTML = message;
47
      }
48
      //if (data.discountedPrice != undefined && parseInt(data.discountedPrice) >= 0) {
49
      if (data.couponCode != undefined && data.couponCode.length > 0) {
50
	var dealtextdivs = document.getElementsByClassName('dealdiv');
51
	for(var i in dealtextdivs){
52
 		if(dealtextdivs[i].innerHTML===undefined)continue;
53
		var item_id = dealtextdivs[i].getAttribute('id');
54
		dealtextdivs[i].innerHTML = data.dealTextArray[item_id];
55
		if(data.dealTextArray[item_id]==''){
56
			dealtextdivs[i].style.display='none';
57
		}
58
	}
59
        //document.getElementById("addCoupon").style.display = "none";
60
        document.getElementById("removeCoupon").style.display = "block";
61
        if (data.couponCode.length > 0) {
62
          document.getElementById("removeCoupon").innerHTML = "Remove Coupon: " + data.couponCode;
12524 anikendra 63
          /*if ( typeof _gaq != "undefined" && _gaq != null) {
11888 anikendra 64
            _gaq.push(["_trackEvent", "COUPON", "Coupon Applied", data.couponCode]);
12524 anikendra 65
          }*/
66
	ga('send', 'event', 'Coupon', 'Coupon Applied',data.couponCode);
11888 anikendra 67
	      }else{
68
          document.getElementById("removeCoupon").innerHTML = "Remove Coupon";
69
        }
70
        document.getElementById("discount").style.display = "block";
71
        var discount = parseInt(data.totalPrice) - parseInt(data.discountedPrice);
72
        document.getElementById("discountAmt").innerHTML = discount;
73
        document.getElementById("discountPrice").style.display = "block";
74
        document.getElementById("discountedPrice").innerHTML = parseInt(document.getElementById("total").innerHTML) - discount;
75
      } else {
76
        document.getElementById("discount").style.display = "none";
77
        document.getElementById("discountPrice").style.display = "none";
78
      }
79
    });
16113 manish.sha 80
    Pace.stop();
11888 anikendra 81
  }
82
}
83
 
84
function clearcoupon(code) {
85
  var url = base_url + "cart/couponClear/" + code;
86
  microAjax(url, function(res) {
12524 anikendra 87
    /*if ( typeof _gaq != "undefined" && _gaq != null) {
11888 anikendra 88
      _gaq.push(["_trackEvent", "COUPON", "Coupon Removed", document.getElementById("couponcode").value]);
12524 anikendra 89
    }*/
90
	ga('send', 'event', 'Coupon', 'Coupon Removed',document.getElementById("couponcode").value);
11888 anikendra 91
    var data = JSON.parse(res);
92
    var message = data.message;
93
    var total = data.totalPrice;
94
    document.getElementById("addCoupon").style.display = "block";
95
    document.getElementById("removeCoupon").style.display = "none";
96
    document.getElementById("discount").style.display = "none";
97
    document.getElementById("discountPrice").style.display = "none";
98
    document.getElementById("coupon-msg").style.display = "none";
99
    document.getElementById("couponcode").value = "";
100
    var finalinsurance = 0;
101
    if (insuredItems.length > 0) {
102
      for ( j = 0; j < insuredItems.length; j++) {
103
        var insurance = insuredItems[j] + "theft";
104
        var cost = document.getElementById(insurance).innerHTML;
105
        finalinsurance = finalinsurance + parseInt(cost);
106
      }
107
    }
108
    if (parseInt(finalinsurance) > 0) {
109
      total = parseInt(total) + parseInt(finalinsurance);
110
      document.getElementById("total").innerHTML = total;
111
    }
112
  });
16113 manish.sha 113
  Pace.stop();
11888 anikendra 114
}
115
 
116
function updateQty(e) {
117
  var oldValue = e.currentTarget.getAttribute("data-value");
118
  var newvalue = e.currentTarget.value;
119
  if (parseInt(newvalue) != parseInt(oldValue)) {
120
    var url = base_url + "cart/update/" + e.currentTarget.id + "/" + newvalue;
121
    window.location.href = url;
122
  }
123
}
124
 
15933 manish.sha 125
function updateQuantity(itemId, oldValue){
126
	var newvalue = document.getElementById("qty_"+itemId).value;
16035 manish.sha 127
	if(parseInt(newvalue)>20){
16040 manish.sha 128
		document.getElementById("max-quantity-msg").style.display="block";
16064 manish.sha 129
		document.getElementById("qty_"+itemId).value=parseInt(oldValue);
16063 manish.sha 130
		document.getElementById('cart-quantity-msg').innerHTML = '';
131
		document.getElementById('cart-quantity-msg').style.display = 'none';
16035 manish.sha 132
		return;
133
	}
15933 manish.sha 134
	if (parseInt(newvalue) != parseInt(oldValue)) {
135
	    var url = base_url + "cart/update/" + itemId + "/" + newvalue;
16048 manish.sha 136
	    Pace.start();
137
	    window.location.href = url;
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
}