Subversion Repositories SmartDukaan

Rev

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