Subversion Repositories SmartDukaan

Rev

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