fixed jquery datepicker errors
authorAnthony Talarico <talarico@gaslightmedia.com>
Tue, 1 Dec 2015 19:45:22 +0000 (14:45 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Tue, 1 Dec 2015 19:45:22 +0000 (14:45 -0500)
js/app.js
js/custom/pageSetup.js

index 040f1e4..3208cd1 100644 (file)
--- a/js/app.js
+++ b/js/app.js
@@ -30,7 +30,7 @@ $(document).ready(function () {
         }
         //
     });
-    var start, context, context2, end, arrival, currentDate, currentDate2, requiredDate, requiredDate1, minDays, departure, stay, d, dd,  m, y, bayView = 'vD4ZpIFk4%2b7FyPsaBnkCqP1cBHWnJili9k5D83MqJq4%3d&',
+    var start, nights, extraDay, end, arrival, currentDate, currentDate2, requiredDate, requiredDate1, minDays, departure, stay, d, dd,  m, y, bayView = 'vD4ZpIFk4%2b7FyPsaBnkCqP1cBHWnJili9k5D83MqJq4%3d&',
         crookedRiver = 'ZhWXD46i2%2fq319vcR%2fcw69rZvA2bz%2fttOOxO9t1%2fBJ0%3d&',
         adults,
         kids,
@@ -121,37 +121,35 @@ $(document).ready(function () {
     $("#arrive").datepicker({
         minDate: 0,
         onSelect: function (date) {
-            $("#arrive").datepicker({dateFormat: 'mm/dd/yy'}).val();
-            arrival = $("#arrive").datepicker('getDate');
-            d = arrival.getDate();
-            dd = arrival.getDate() + 1;
-            m = arrival.getMonth() + 1;
-            y = arrival.getFullYear();
-            minDays = m + '/' + dd + '/' + y;
-            console.log(minDays);
-            arrival = d + '-' + m + '-' + y; // to pass as a date value in the url
-            start = "arrival_date=" + y + '-' + m + '-' + d + '&'; // for date parsing to get length of stay
-            arrival.toString();
-            arrival = arrival.replace(/\//g, "");
-            arrival = parseInt(arrival, 10);
-            $("#depart").datepicker("option", "minDate", minDays);
+            $("#arrive").datepicker({dateFormat: 'yy-mm-dd'}).val();
+            currentDate = $("#arrive").datepicker('getDate');
+            extraDay = $("#arrive").datepicker('getDate');
+            extraDay.setDate(extraDay.getDate() + 1);
+            $("#depart").datepicker("option", {minDate: new Date(extraDay)});
+            
+            // set up variables to pass to booking site
+            currentDate = new Date(currentDate);
+            currentDate = new Date(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate());
+            currentDate.setDate(currentDate.getDate());
+            d = currentDate.getDate();
+            if (d <= 9) {
+                d = '0' + d;
+            }
+            m = currentDate.getMonth() + 1;
+            if (m <= 9) {
+                m = '0' + m;
+            }
+            y = currentDate.getFullYear();
+            start = "arrival_date=" + y + '-' + m + '-' + d + '&';
         }
-    }); 
+    });
     $("#depart").datepicker({
         onSelect: function (date) {
-            $("#depart").datepicker({dateFormat: 'mm/dd/yy'}).val();
+            $("#depart").datepicker({dateFormat: 'yy-mm-dd'}).val();
             departure = $("#depart").datepicker('getDate');
-            d = departure.getDate();
-            m = departure.getMonth() + 1;
-            y = departure.getFullYear();
-            departure = d + '-' + m + '-' + y;
-            end = y + '-' + m + '-' + d + '&';
-            departure.toString();
-            departure = departure.replace(/\//g, "");
-            departure = parseInt(departure, 10);
-            $("#nights").val(departure - arrival);
-            stay = 'stay_nights=' + (departure - arrival) + '&';
+            $("#nights").val(Math.ceil(departure - currentDate) / (1000 * 60 * 60 * 24));
+            stay = 'stay_nights=' + $('#nights').val() + '&';
+
         }
     }); 
     $("#arriveCal").click(function () {
index 1d2441d..97c3a99 100644 (file)
@@ -21,7 +21,7 @@ $(document).ready(function () {
         }
         //
     });
-    var start, context, context2, end, arrival, currentDate, currentDate2, requiredDate, requiredDate1, minDays, departure, stay, d, dd,  m, y, bayView = 'vD4ZpIFk4%2b7FyPsaBnkCqP1cBHWnJili9k5D83MqJq4%3d&',
+    var start, nights, extraDay, end, arrival, currentDate, currentDate2, requiredDate, requiredDate1, minDays, departure, stay, d, dd,  m, y, bayView = 'vD4ZpIFk4%2b7FyPsaBnkCqP1cBHWnJili9k5D83MqJq4%3d&',
         crookedRiver = 'ZhWXD46i2%2fq319vcR%2fcw69rZvA2bz%2fttOOxO9t1%2fBJ0%3d&',
         adults,
         kids,
@@ -112,37 +112,35 @@ $(document).ready(function () {
     $("#arrive").datepicker({
         minDate: 0,
         onSelect: function (date) {
-            $("#arrive").datepicker({dateFormat: 'mm/dd/yy'}).val();
-            arrival = $("#arrive").datepicker('getDate');
-            d = arrival.getDate();
-            dd = arrival.getDate() + 1;
-            m = arrival.getMonth() + 1;
-            y = arrival.getFullYear();
-            minDays = m + '/' + dd + '/' + y;
-            console.log(minDays);
-            arrival = d + '-' + m + '-' + y; // to pass as a date value in the url
-            start = "arrival_date=" + y + '-' + m + '-' + d + '&'; // for date parsing to get length of stay
-            arrival.toString();
-            arrival = arrival.replace(/\//g, "");
-            arrival = parseInt(arrival, 10);
-            $("#depart").datepicker("option", "minDate", minDays);
+            $("#arrive").datepicker({dateFormat: 'yy-mm-dd'}).val();
+            currentDate = $("#arrive").datepicker('getDate');
+            extraDay = $("#arrive").datepicker('getDate');
+            extraDay.setDate(extraDay.getDate() + 1);
+            $("#depart").datepicker("option", {minDate: new Date(extraDay)});
+            
+            // set up variables to pass to booking site
+            currentDate = new Date(currentDate);
+            currentDate = new Date(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate());
+            currentDate.setDate(currentDate.getDate());
+            d = currentDate.getDate();
+            if (d <= 9) {
+                d = '0' + d;
+            }
+            m = currentDate.getMonth() + 1;
+            if (m <= 9) {
+                m = '0' + m;
+            }
+            y = currentDate.getFullYear();
+            start = "arrival_date=" + y + '-' + m + '-' + d + '&';
         }
-    }); 
+    });
     $("#depart").datepicker({
         onSelect: function (date) {
-            $("#depart").datepicker({dateFormat: 'mm/dd/yy'}).val();
+            $("#depart").datepicker({dateFormat: 'yy-mm-dd'}).val();
             departure = $("#depart").datepicker('getDate');
-            d = departure.getDate();
-            m = departure.getMonth() + 1;
-            y = departure.getFullYear();
-            departure = d + '-' + m + '-' + y;
-            end = y + '-' + m + '-' + d + '&';
-            departure.toString();
-            departure = departure.replace(/\//g, "");
-            departure = parseInt(departure, 10);
-            $("#nights").val(departure - arrival);
-            stay = 'stay_nights=' + (departure - arrival) + '&';
+            $("#nights").val(Math.ceil(departure - currentDate) / (1000 * 60 * 60 * 24));
+            stay = 'stay_nights=' + $('#nights').val() + '&';
+
         }
     }); 
     $("#arriveCal").click(function () {