Subversion Repositories SmartDukaan

Rev

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