Subversion Repositories SmartDukaan

Rev

Rev 11845 | Rev 11885 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
11517 lgm 1
window.onload=function(){
2
	var pheight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
3
	if(document.getElementsByClassName('cart-cont')[0] != undefined){
11094 lgm 4
 
11517 lgm 5
	    document.getElementsByClassName('cart-cont')[0].style.minHeight = pheight - 235 +'px';  
6
	}
7
};
8
 
11558 lgm 9
function clearmsg() {
10
  if (document.getElementById("coupon-msg").style.display == "block") {
11
    document.getElementById("coupon-msg").style.display = "none";
12
  }
10582 lgm 13
}
11558 lgm 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;
11852 anikendra 39
        document.getElementById("addCoupon").style.display = "block";
11834 anikendra 40
      document.getElementById("coupon-msg").style.display = "block";
11558 lgm 41
      if (message.length > 0) {
42
        document.getElementById("coupon-msg").innerHTML = message;
43
      }
11852 anikendra 44
      //if (data.discountedPrice != undefined && parseInt(data.discountedPrice) >= 0) {
45
      if (data.couponCode != undefined && data.couponCode.length > 0) {
46
        //document.getElementById("addCoupon").style.display = "none";
11558 lgm 47
        document.getElementById("removeCoupon").style.display = "block";
48
        if (data.couponCode.length > 0) {
49
          document.getElementById("removeCoupon").innerHTML = "Remove Coupon: " + data.couponCode;
11845 anikendra 50
          if ( typeof _gaq != "undefined" && _gaq != null) {
51
            _gaq.push(["_trackEvent", "COUPON", "Coupon Applied", data.couponCode, itemString]);
52
          }
53
	      }else{
11835 anikendra 54
          document.getElementById("removeCoupon").innerHTML = "Remove Coupon";
11558 lgm 55
        }
56
        document.getElementById("discount").style.display = "block";
57
        var discount = parseInt(data.totalPrice) - parseInt(data.discountedPrice);
58
        document.getElementById("discountAmt").innerHTML = discount;
59
        document.getElementById("discountPrice").style.display = "block";
60
        document.getElementById("discountedPrice").innerHTML = parseInt(document.getElementById("total").innerHTML) - discount;
11852 anikendra 61
      } else {
62
        document.getElementById("discount").style.display = "none";
63
        document.getElementById("discountPrice").style.display = "none";
11558 lgm 64
      }
65
    });
66
  }
10582 lgm 67
}
11558 lgm 68
 
69
function clearcoupon(code) {
70
  var url = base_url + "cart/couponClear/" + code;
71
  microAjax(url, function(res) {
11845 anikendra 72
    if ( typeof _gaq != "undefined" && _gaq != null) {
73
      _gaq.push(["_trackEvent", "COUPON", "Coupon Removed", code]);
74
    }
11558 lgm 75
    var data = JSON.parse(res);
76
    var message = data.message;
77
    var total = data.totalPrice;
78
    document.getElementById("addCoupon").style.display = "block";
79
    document.getElementById("removeCoupon").style.display = "none";
80
    document.getElementById("discount").style.display = "none";
81
    document.getElementById("discountPrice").style.display = "none";
82
    document.getElementById("coupon-msg").style.display = "none";
83
    document.getElementById("couponcode").value = "";
84
    var finalinsurance = 0;
85
    if (insuredItems.length > 0) {
86
      for ( j = 0; j < insuredItems.length; j++) {
87
        var insurance = insuredItems[j] + "theft";
88
        var cost = document.getElementById(insurance).innerHTML;
89
        finalinsurance = finalinsurance + parseInt(cost);
90
      }
91
    }
92
    if (parseInt(finalinsurance) > 0) {
93
      total = parseInt(total) + parseInt(finalinsurance);
94
      document.getElementById("total").innerHTML = total;
95
    }
96
  });
10582 lgm 97
}
11558 lgm 98
 
99
function updateQty(e) {
100
  var oldValue = e.currentTarget.getAttribute("data-value");
101
  var newvalue = e.currentTarget.value;
102
  if (parseInt(newvalue) != parseInt(oldValue)) {
103
    var url = base_url + "cart/update/" + e.currentTarget.id + "/" + newvalue;
104
    window.location.href = url;
105
  }
10582 lgm 106
}
107
 
11558 lgm 108
function removeItem(itemId) {
109
  var url = base_url + "cart/delete/" + itemId;
110
  window.location.href = url;
10582 lgm 111
}
11558 lgm 112
 
10582 lgm 113
var insuredItems = new Array();
11558 lgm 114
function teftinsure(e) {
115
  var key = e.currentTarget.getAttribute("data-key");
116
  if (key == "ins") {
117
    if (document.getElementById("error").style.display == "block") {
118
      document.getElementById("error").style.display = "none";
119
    }
120
    var id = e.currentTarget.id;
121
    var insure = document.getElementById(id).checked;
122
    var itemId = e.currentTarget.getAttribute("data-value");
123
    var tnc = itemId + "tnc";
124
    var tc = itemId + "tc";
125
    tncChkd = document.getElementById(tnc).checked;
126
    var theft = itemId + "theft";
127
    var theft = document.getElementById(theft).innerHTML;
128
    theft = parseInt(theft);
129
    var total = document.getElementById("total").innerHTML;
130
    total = parseInt(total);
131
    if (insure == true) {
132
      insuredItems.push(itemId);
133
      if ( typeof _gaq != "undefined" && _gaq != null) {
134
        _gaq.push(["_trackEvent", "insurance", "Want Insurance", itemId]);
135
      }
136
      if (document.getElementById("discountPrice").style.display == "block") {
137
        var discountPrice = document.getElementById("discountedPrice").innerHTML;
138
        discountPrice = parseInt(discountPrice);
139
        document.getElementById("discountedPrice").innerHTML = discountPrice + theft;
140
      } else {
141
        document.getElementById("total").innerHTML = total + theft;
142
      }
143
    }
144
    if (insure == false) {
145
      if (document.getElementById("error").style.display == "block") {
146
        document.getElementById("error").style.display = "none";
147
      }
148
      if (document.getElementById(tc).style.display == "block") {
149
        document.getElementById(tc).style.display = "none";
150
      }
151
      var ind = insuredItems.indexOf(itemId);
152
      insuredItems.splice(ind, 1);
153
      if (document.getElementById("discountPrice").style.display == "block") {
154
        var discountPrice = document.getElementById("discountedPrice").innerHTML;
155
        discountPrice = parseInt(discountPrice);
156
        document.getElementById("discountedPrice").innerHTML = discountPrice - theft;
157
      } else {
158
        document.getElementById("total").innerHTML = total - theft;
159
      }
160
    }
161
  }
162
  if (key == "tnc") {
163
    if (document.getElementById("error").style.display == "block") {
164
      document.getElementById("error").style.display = "none";
165
    }
166
    var id = e.currentTarget.id;
167
    var tncChkd = document.getElementById(id).checked;
168
    var itemId = e.currentTarget.getAttribute("data-value");
169
    var insurance = itemId + "insurance";
170
    var tc = itemId + "tc";
171
    var insure = document.getElementById(insurance).checked;
172
  }
173
  if (insure == true && tncChkd == false) {
174
    if (document.getElementById("error").style.display == "block") {
175
      document.getElementById("error").style.display = "none";
176
    }
177
    if (document.getElementById(tc).style.display == "block") {
178
      var url = base_url + "cart/insure/" + itemId + "/" + tncChkd + "/1";
179
      microAjax(url, function(res) {
180
        var data = JSON.parse(res);
181
        data = data.status;
182
        if (data == true) {
183
        }
184
        if (data == false) {
185
          alert(data);
186
        }
187
      });
188
    } else {
189
      document.getElementById(tc).style.display = "block";
190
    }
191
  } else {
192
    if (insure == true && tncChkd == true) {
193
      if ( typeof _gaq != "undefined" && _gaq != null) {
194
        _gaq.push(["_trackEvent", "Insurance", "Agreed to Terms", itemId]);
195
      }
196
      var url = base_url + "cart/insure/" + itemId + "/" + insure + "/1";
197
      microAjax(url, function(res) {
198
        var data = JSON.parse(res);
199
        data = data.status;
200
        if (data == true) {
201
        }
202
        if (data == false) {
203
          alert(data);
204
        }
205
      });
206
    } else {
207
      if (insure == false && tncChkd == true) {
208
        var url = base_url + "cart/insure/" + itemId + "/" + insure + "/1";
209
        microAjax(url, function(res) {
210
          var data = JSON.parse(res);
211
          data = data.status;
212
          if (data == true) {
213
            document.getElementById(tnc).checked = false;
214
            document.getElementById(tc).style.display = "none";
215
          }
216
          if (data == false) {
217
            alert(data);
218
          }
219
        });
220
      } else {
221
        if (insure == false && tncChkd == true) {
222
          var url = base_url + "cart/insure/" + itemId + "/" + insure + "/1";
223
          microAjax(url, function(res) {
224
            var data = JSON.parse(res);
225
            data = data.status;
226
            if (data == true) {
227
              document.getElementById(tnc).checked = false;
228
              document.getElementById(tc).style.display = "none";
229
            }
230
            if (data == false) {
231
              alert(data);
232
            }
233
          });
234
        }
235
      }
236
    }
237
  }
238
}
10582 lgm 239
 
11558 lgm 240
function dataprotection(e) {
241
  var id = e.currentTarget.id;
242
  var protection = document.getElementById(id).checked;
243
  var itemId = e.currentTarget.getAttribute("data-value");
244
  var url = base_url + "cart/insure/" + itemId + "/" + protection + "/2";
245
  microAjax(url, function(res) {
246
    var data = JSON.parse(res);
247
    data = data.status;
248
    if (data == true) {
249
    }
250
    if (data == false) {
251
    }
252
  });
10582 lgm 253
}
254
 
11558 lgm 255
function checkout() {
256
  var chx = document.getElementsByClassName("checkbox");
257
  for (var i = 0; i < chx.length; i++) {
258
    if (chx[i].type == "checkbox" && chx[i].checked) {
259
      var id = chx[i].getAttribute("data-value");
260
      var tnc = id + "tnc";
261
      if (document.getElementById(tnc).checked == false) {
262
        if ( typeof _gaq != "undefined" && _gaq != null) {
263
          _gaq.push(["_trackEvent", "Insurance", "Alert for tnc"]);
264
        }
265
        document.getElementById("error").style.display = "block";
266
        document.getElementById("error").innerHTML = "Please agree to the terms and conditions to get insurance";
267
        window.scrollTo(0, 0);
268
        return false;
269
        break;
270
      }
271
    }
272
  }
273
  if (locationServicable == false) {
274
    var pincode = document.getElementById("pincode").value;
275
    if ( typeof _gaq != "undefined" && _gaq != null) {
276
      _gaq.push(["_trackEvent", "Cart", "Location not serviceable", pincode]);
277
    }
278
    document.getElementById("error").style.display = "block";
279
    if (itemsNotServicable == items.length) {
11708 anikendra 280
      document.getElementById("error").innerHTML = "Location not serviceable. Please try a different pincode";
11558 lgm 281
    } else {
282
      if (itemsNotServicable != items.length) {
11708 anikendra 283
        document.getElementById("error").innerHTML = "Location not serviceable for one of the products. Please try a different pincode or try removing the product";
11558 lgm 284
      }
285
    }
286
    window.scrollTo(0, 0);
287
    return false;
288
  }
289
  if ((notServiceableLocation != undefined) && (notServiceableLocation != 0)) {
290
    var pincode = document.getElementById("pincode").value;
291
    if ( typeof _gaq != "undefined" && _gaq != null) {
292
      _gaq.push(["_trackEvent", "Cart", "Location not serviceable", pincode]);
293
    }
294
    document.getElementById("error").style.display = "block";
295
    if (notServiceableLocation == items.length) {
11708 anikendra 296
      document.getElementById("error").innerHTML = "Location not serviceable. Please try a different pincode";
11558 lgm 297
    } else {
298
      if (notServiceableLocation != items.length) {
11708 anikendra 299
        document.getElementById("error").innerHTML = "Location not serviceable for one of the products. Please try a different pincode or try removing the product";
11558 lgm 300
      }
301
    }
302
    window.scrollTo(0, 0);
303
    return false;
304
  }
305
  window.location.href = base_url + "shipping";
306
}
10582 lgm 307
 
11558 lgm 308
var j = 0;
10582 lgm 309
var locationServicable;
11558 lgm 310
var itemsNotServicable = 0;
311
function checkShipping() {
312
  if (j != 0) {
313
    j = 0;
10743 lgm 314
  }
11638 lgm 315
  if (itemsNotServicable != 0) {
316
    itemsNotServicable = 0;
317
  }
11558 lgm 318
  var pincode = document.getElementById("pincode").value;
11717 lgm 319
  pincode = pincode.trim();
11558 lgm 320
  if (/^\d+$/.test(pincode) && pincode.length == 6) {
321
    if (document.getElementById("error")) {
322
      document.getElementById("error").style.display = "none";
323
    }
324
    for ( i = 0; i < items.length; i++) {
325
      itemId = items[i].id;
326
      var url = base_url + "productinfo/getDeliveryDetails/" + itemId + "/" + pincode;
327
      j = i;
328
      microAjax(url, function(res) {
329
        if (res != "") {
330
          data = JSON.parse(res);
331
          days = data.business_days;
332
          if (days >= 0) {
11638 lgm 333
            locationServicable = true;
11558 lgm 334
            var service = items[j].id + "service";
335
            document.getElementById(service).style.display = "none";
336
            var delivery = items[j].id + "delivery";
337
            if (document.getElementById(delivery)) {
338
              document.getElementById(delivery).style.display = "block";
339
              var del = items[j].id + "del";
340
              document.getElementById(del).innerHTML = data.delivery_estimate;
341
            }
342
            if (data.is_cod_available_for_location == true) {
343
              var cod = items[j].id + "cod";
344
              if (document.getElementById(cod).style.display == "none") {
345
                document.getElementById(cod).style.display = "block";
346
              }
347
            }
348
            if (data.on_time_guarantee == true) {
349
              var otg = items[j].id + "otg";
350
              if (document.getElementById(otg).style.display == "none") {
351
                document.getElementById(otg).style.display = "block";
352
              }
353
            }
354
          } else {
355
            var del = items[j].id + "delivery";
356
            document.getElementById(del).style.display = "none";
357
            var cod = items[j].id + "cod";
358
            document.getElementById(cod).style.display = "none";
359
            var otg = items[j].id + "otg";
360
            document.getElementById(otg).style.display = "none";
361
            var service = items[j].id + "service";
362
            document.getElementById(service).style.display = "block";
363
            document.getElementById(service).innerHTML = "Location is not serviceable";
364
            locationServicable = false;
365
            itemsNotServicable++;
366
          }
367
          j--;
368
        }
369
      });
370
    }
371
  } else {
372
    document.getElementById("error").style.display = "block";
373
    document.getElementById("error").innerHTML = "Invalid pincode!";
374
  }
10582 lgm 375
}
376
 
11558 lgm 377
function shomoreredirect() {
378
  window.location.href = base_url;
11708 anikendra 379
}