function validateMethodSelections (alertMethodCboxes) {
var needsPhone = false;
var hasPhone = false;
-
+
var needsEmail = false;
var hasEmail = false;
-
+
var needsSms = false;
var hasSms = false;
var inputNames = { e: "email_address", ph: "phone_notify", sms: "sms_notify", carrier: "sms_carrier"};
}
}
}
-
+
var culprits = [];
var emailOK = (needsEmail && hasEmail) || (!needsEmail);
var phoneOK = needsPhone && hasPhone || (!needsPhone);
var smsOK = needsSms && hasSms || (!needsSms);
-
+
if (!phoneOK) {
culprits.push("phone_notify");
}
if (!smsOK) {
culprits.push("sms_notify", "sms_carrier");
}
-
+
var isFormOK = emailOK && phoneOK && smsOK;
return { isValid: isFormOK, culpritNames : culprits };
}
return result;
}
+function isValidDate(dateString){
+ // First check for the pattern
+ if(!/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(dateString))
+ return false;
+
+ // Parse the date parts to integers
+ var parts = dateString.split("/");
+ var day = parseInt(parts[1], 10);
+ var month = parseInt(parts[0], 10);
+ var year = parseInt(parts[2], 10);
+
+ var today = new Date();
+
+ if (today.getFullYear() > year){
+ return false;
+ }
+ else if (today.getFullYear() == year ) {
+ if(today.getMonth() +1 > month) {
+ return false;
+ }
+ else if (today.getMonth() +1 == month) {
+ if (today.getDate() > day) return false;
+ }
+ }
+
+ // Check the ranges of month and year
+ if(year < 2000 || year > 3000 || month == 0 || month > 12) return false;
+
+ var monthLength = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
+
+ // Adjust for leap years
+ if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) monthLength[1] = 29;
+
+ // Check the range of the day
+ return day > 0 && day <= monthLength[month - 1];
+}
+
function validateHoldForm() {
var res = validateMethodSelections(document.getElementsByClassName("hold-alert-method"));
+
+ if (document.getElementById('hold_suspend').checked && document.getElementById('thaw_date').value.length > 0){
+ //check that the date is not in the past
+ if(!isValidDate(document.getElementById('thaw_date').value)) {
+ alert(eg_opac_i18n.EG_INVALID_DATE);
+ document.getElementById('thaw_date').style.backgroundColor = "yellow";
+ return false;
+ }
+ }
+
+
if (res.isValid) {
var result = confirmMultipleHolds();
if (result) {