Subversion Repositories SmartDukaan

Rev

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