Subversion Repositories SmartDukaan

Rev

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