Subversion Repositories SmartDukaan

Rev

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