Subversion Repositories SmartDukaan

Rev

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