/* * General : Global Variables * */ var jvMonthInitials = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC"; var jvMonthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; var jvMonthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; var jvMonthDaysLeap = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; var jvWhitespace = " \t\n\r"; var jvCalendarWindows = Array(); /* * General : Is Empty * * @return boolean * @param s String */ function jsIsEmpty(s) { return s == null || s.length == 0; } /* * General : Is Whitespace * * @return boolean * @param s String */ function jsIsWhitespace(s) { if (jsIsEmpty(s)) return true; for (var i = 0; i < s.length; i++) { if (jvWhitespace.indexOf(s.charAt(i)) == -1) return false; } return true; } /* * General : Is Numeric * * @return boolean * @param s String */ function jsIsNumeric(n) { if (jsIsWhitespace(n)) return false; return !isNaN(n); } /* * General : Is Date * * @return boolean * @param d Date */ function jsIsDate(d) { if (jsIsWhitespace(d)) return false; d = jsFormatDate(d); return !(d == null); } /* * General : Is Month * * @return boolean * @param m String */ function jsIsMonth(m) { if (jsIsWhitespace(m)) return false; m = jsFormatMonth(m); return !(m == null); } /* * General : Is Future Date * * @return boolean * @param d Date */ function jsIsFutureDate(d) { if (!jsIsDate(d)) return false; d = jsFormatDate(d); d = d.substr(6, 4) + d.substr(0, 2) + d.substr(3, 2); // yyyymmdd var c = jsGetCurrentDate(); c = c.substr(6, 4) + c.substr(0, 2) + c.substr(3, 2); var f = jsGetFutureDate(); f = f.substr(6, 4) + f.substr(0, 2) + f.substr(3, 2); return ((c < d) && (d < f)); } /* * General : Get Current Date (MM/DD/YYYY) * * @return Date */ function jsGetCurrentDate() { var currentDate = new Date(); return jsFormatNumeric(currentDate.getMonth() + 1, 2) + "/" + jsFormatNumeric(currentDate.getDate(), 2) + "/" + currentDate.getFullYear(); } /* * General : Get Future Date (MM/DD/YYYY : 3 Years) * * @return Date */ function jsGetFutureDate() { var currentDate = new Date(); return jsFormatNumeric(currentDate.getMonth() + 1, 2) + "/" + jsFormatNumeric(currentDate.getDate(), 2) + "/" + jsFormatNumeric(currentDate.getFullYear() + 3, 4); } /* * General : Compare Dates * * @return int * @param d1 Date * @param d2 Date */ function jsCompareDates(d1, d2) { var a = jsFormatDate(d1); a = a.substr(6, 4) + a.substr(0, 2) + a.substr(3, 2); // yyyymmdd var b = jsFormatDate(d2); b = b.substr(6, 4) + b.substr(0, 2) + b.substr(3, 2); return (a < b ? -1 : (a == b ? 0 : 1)); } /* * General : Format Numeric * * @return * @param n int Number * @param l int Length */ function jsFormatNumeric(n, l){ var z = "000000000000000" + "" + n; return z.substr(z.length - l); } /* * General : Format Date (MM/DD/YYYY) * * @return Date * @param d Date (MMDDYYYY, MMDDYY, MM/DD, MM DD, MM-DD, DD-MMM-YYYY, DD-MMM-YY) */ function jsFormatDate(d){ var regexp, sp, mm, dd, yyyy, todayDate, todayMMDD; regexp = /^(\d{1,2}\/\d{1,2}\/\d{4}|\d{1,2}\s\d{1,2}\s\d{4}|\d{1,2}-\d{1,2}-\d{4}|\d{1,2}\/\d{1,2}\/\d{2}|\d{1,2}\s\d{1,2}\s\d{2}|\d{1,2}-\d{1,2}-\d{2})$/; if (regexp.test(d)) { sp = d.split(/\//); if (sp.length != 3) { sp = d.split(/\s/); if (sp.length != 3) { sp = d.split(/-/); if (sp.length != 3) { return null; } } } mm = parseInt(sp[0], 10); dd = parseInt(sp[1], 10); yyyy = parseInt(sp[2], 10); } else { regexp = /^(\d{8}|\d{6})$/; // MMDDYYYY or MMDDYY if (regexp.test(d)) { mm = parseInt(d.substr(0, 2), 10); dd = parseInt(d.substr(2, 2), 10); yyyy = parseInt(d.substr(4), 10); } else { regexp = /^(\d{1,2}\/\d{1,2}|\d{1,2}\s\d{1,2}|\d{1,2}-\d{1,2})$/; // MM/DD, MM DD, MM-DD if(regexp.test(d)) { sp = d.split(/\//); if(sp.length != 2) { sp = d.split(/\s/); if(sp.length != 2) { sp = d.split(/-/); if(sp.length != 2) { return null; } } } mm = parseInt(sp[0], 10); dd = parseInt(sp[1], 10); todayDate = new Date(); todayMMDD = ((todayDate.getMonth() + 1) * 100) + todayDate.getDate(); yyyy = todayDate.getFullYear() + ((((mm * 100) + dd) < todayMMDD) ? 1 : 0); } else { regexp = /^(\d{1,2}-\S\S\S-\d{4}|\d{1,2}-\S\S\S-\d{2})$/; // DD-MMM-YYYY, DD-MMM-YY if (regexp.test(d)) { sp = d.split(/-/); dd = parseInt(sp[0], 10); mm = sp[1]; mm = mm.toUpperCase(); mm = jvMonthInitials.indexOf(mm); if (mm % 3 != 0) return null; mm = mm / 3 + 1; yyyy = parseInt(sp[2], 10); } else { return null; } } } } if ((mm < 1) || (12 < mm) || (dd < 1) || (31 < dd)) return null; if (yyyy < 40) { yyyy = yyyy + 2000; } else if (yyyy < 100) { yyyy = yyyy + 1900; } if ((yyyy < 1900) || (2099 < yyyy)) return null; if (yyyy % 4 == 0) { if (jvMonthDaysLeap[mm - 1] < dd) return null; } else { if(jvMonthDays[mm - 1] < dd) return null; } return jsFormatNumeric(mm, 2) + "/" + jsFormatNumeric(dd, 2) + "/" + yyyy; } /* * General : Format Extended Date (01-JAN-2002) * * @return Date * @param d Date */ function jsFormatExtendedDate(d) { d = jsFormatDate(d); if (d == null) return null; return d.substr(3, 2) + '-' + jvMonthInitials.substr( (parseInt(d.substr(0, 2), 10) - 1) * 3, 3) + '-' + d.substr(6, 4); } /* * General : Format Month (MM/YYYY) * * @return String * @param m String (MMYYYY, MMYY, MM/YY, MM YY, MM-YY, MMM-YYYY, MMM-YY) */ function jsFormatMonth(m) { var d = m; if (m.length == 4) { d = m.substr(0, 2) + "01" + m.substr(2, 2); } else if (m.length == 5) { if (m.substr(2, 1) == "/" || m.substr(2, 1) == "-" || m.substr(2, 1) == " ") { d = m.substr(0, 2) + "/01/" + m.substr(3, 2); } } else if (m.length == 6) { if (m.substr(3, 1) == "-") { d = "01-" + m; } else { d = m.substr(0, 2) + "01" + m.substr(2, 4); } } else if (m.length == 8) { if (m.substr(3, 1) == "-") { d = "01-" + m; } } d = jsFormatDate(d); if (d == null) return null; return d.substr(0, 2) + "/" + d.substr(6, 4); } /* * General : Format Extended Month (JAN-2002) * * @return String * @param m String */ function jsFormatExtendedMonth(m) { m = jsFormatMonth(m); if (m == null) return null; return jvMonthInitials.substr( (parseInt(m.substr(0, 2), 10) - 1) * 3, 3) + '-' + m.substr(3, 4); } /* * General : Is valid E-Mail Address * * @return boolean * @param a String Address */ function jsIsValidEMailAddress(a){ a = a.replace(/^\s+/, ''); a = a.replace(/\s+$/, ''); var emailexp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; return emailexp.test(a); } /* * General : Get Field * * @return Field * @param fieldName String * @param formName String */ function jsGetField(fieldName, formName) { switch (arguments.length) { case 2: { return document.forms[formName].elements[fieldName]; } break; case 1: { for (f = 0; f < document.forms.length; f++) { for (e = 0; e < document.forms[f].elements.length; e++) { if (document.forms[f].elements[e].name == fieldName) { return document.forms[f].elements[e]; } } } } break; default: { for (f = 0; f < document.forms.length; f++) { for(e = 0; e < document.forms[f].elements.length; e++) { if(document.forms[f].elements[e].type != "hidden") { return document.forms[f].elements[e]; } } } } } return null; } /* * General : Get Form * * @return Form * @param formName String */ function jsGetForm(formName) { return document.forms[formName]; } /* * General : On Blur (Used with Field Validation) * * @param field Field */ function jsOnBlur(field) { if (typeof(field.jsValidation) == "object") { switch (field.jsValidation.getType()) { case "date": case "futureDate": { if (jsIsDate(field.value)) { field.value = jsFormatExtendedDate(field.value); } } break; case "month": { if (jsIsMonth(field.value)) { field.value = jsFormatExtendedMonth(field.value); } } break; } } } /* * General : On Focus (Used with Field Validation) * * @param field Field */ function jsOnFocus(field) { if (field.disabled == true && !jsIsWhiteSpace(field.focusFieldName)) { jsSetFocus(field.focusFieldName); } } /* * General : On Load (Body of Document) * */ function jsOnLoad() { jsSetFocus(); jsLocalOnLoad(); } function jsLocalOnLoad() { } /* * General : On Unload (Body of Document) * */ function jsOnUnload() { jsCloseCalendarWindows(); jsLocalOnUnload(); } function jsLocalOnUnload() { } /* * General : On Submit * * @return boolean * @param v JsValidate * @param required boolean * @param action String (Optional) */ function jsOnSubmit(v, required, action) { required = arguments.length >= 2 ? required : true; var msg = arguments.length >= 1 ? v.toString(required) : null; if (msg != null) { if (v.getFirstInError().getField() != null) { if (v.getFirstInError().getType() == "radioSelection") { v.getFirstInError().getField()[0].focus(); } else { v.getFirstInError().getField().focus(); } } } else { msg = jsLocalOnSubmit(arguments.length == 1 ? v.getFormName() : null); } if (msg != null) { alert(msg); } if (msg == null && arguments.length > 2) { jsGetField("action").value = action; document.forms[0].submit(); return false; } return msg == null; } /* * General : Local On Submit * * @return String Alert Message * @param formName String */ function jsLocalOnSubmit(formName) { return null; } /* * General : Submit * * @param boolean (Always false) * @param formName String */ function jsSubmit(formName) { jsGetForm(formName).submit(); return false; } /* * General : Action * * @param boolean (Always false) * @param action String */ function jsAction(action) { jsGetField("action").value = action; document.forms[0].submit(); return false; } /* * General : Action First Page * * @param boolean (Always false) */ function jsActionFirstPage() { return jsAction("First Page"); } /* * General : Action Previous Page * * @param boolean (Always false) */ function jsActionPreviousPage() { return jsAction("Previous Page"); } /* * General : Action Next Page * * @param boolean (Always false) */ function jsActionNextPage() { return jsAction("Next Page"); } /* * General : Action Last Page * * @param boolean (Always false) */ function jsActionLastPage() { return jsAction("Last Page"); } /* * General : Set Disabled * * @param focusFieldName String * @param disabled boolean * @param fieldNames... String (1 or More) */ function jsSetDisabled(focusFieldName, disabled /* fieldNames... */ ) { for (var i = 2; i < arguments.length; i++) { if (jsGetField(arguments[i]).type != "hidden") { jsGetField(arguments[i]).disabled = disabled == true; if (focusFieldName != null) { jsGetField(arguments[i]).focusFieldName = focusFieldName; } } } } /* * General : Set Focus * * @return * @param * @param */ function jsSetFocus(fieldName, formName) { var field; switch (arguments.length) { case 2: { field = jsGetField(fieldName, formName); } break; case 1: { field = jsGetField(fieldName); } break; default: { field = jsGetField(); } } if (field != null){ field.focus(); } } /* * General : Debug * */ function jsDebug() { if (arguments.caller.length == 0) { alert(jsDebug.caller); } else { var argList = ""; for (var i = 0; i < arguments.caller.length; i++) { argList = argList + "" + i + ": " + arguments.caller[i] + "\r"; } alert(argList + "\r" + jsDebug.caller); } } /* * General : Get Cookie * * @return String * @param name String */ function jsGetCookie(name) { var cookies = document.cookie; var start = cookies.indexOf(name + "="); if (start == -1) { return ""; } var start = cookies.indexOf("=", start) + 1; var end = cookies.indexOf(";", start); if (end == -1) { end = cookies.length; } var value = unescape(cookies.substring(start, end)); return value == null ? "" : value; } /* * General : Close Window * * @return boolean (always false) */ function jsCloseWindow() { window.close(); return false; } /* * General : Write (Deprecated) * * @deprecated * @param s String */ function jsWrite(s) { document.write(s); } /* * General : Write Break (Deprecated) * * @deprecated */ function jsWriteBreak() { jsWrite("
"); } /* * General : Get Parameter * * @return String * @param name String */ function jsGetParameter(name) { var search = location.search; var start = search.indexOf(name + "="); if (start == -1) { return ""; } var start = search.indexOf("=", start) + 1; var end = search.indexOf("&", start); if (end == -1) { end = search.length; } var value = unescape(search.substring(start, end)); return value == null ? "" : value; } /* * General : Open Calendar Window * * @param name String * @param description String */ function jsOpenCalendarWindow(name, description) { var w = jvCalendarWindows[jvCalendarWindows.length] = window.open("/corporate/html/calendarWindow.html?description=" + escape(description) + "&name=" + escape(name), name, "width=235,height=240,resizable=no,menubar=no,scrollbars=no,toolbar=no"); w.focus(); } /* * General : Close Calendar Windows * */ function jsCloseCalendarWindows() { for (var i = 0; i < jvCalendarWindows.length; i++) { if (!jvCalendarWindows[i].closed) { jvCalendarWindows[i].close(); } } jvCalendarWindows = new Array(); } /* * Login : Global Variables * */ var ljvUserCode = null; var ljvName = null; var ljvEMailAddress = null; var ljvFunctions = null; /* * Login : Is Member * * @return boolean */ function ljsIsMember() { return ljvUserCode != null; } /* * Login : Has Function * * @return boolean * @param name String Name of Function */ function ljsHasFunction(name) { return ljvFunctions == null ? false : (ljvFunctions.indexOf(";" + name + ";") != -1); } /* * Login : Process Cookie * */ function ljsProcessCookie() { eval(jsGetCookie("loginCookie")); } /* * Validation : JsValidate (Class) * */ function JsValidate() { this.firstInError = null; this.getFirstInError = new Function("return this.firstInError"); this.formName = "main"; this.getFormName = new Function("return this.formName"); this.setFormName = new Function("formName" ,"this.formName = formName; return this;"); this.jsValidation = new Array(); this.addValidation = JsValidate_addValidation; this.addJsValidation = JsValidate_addValidation; this.toString = JsValidate_toString; } /* * Validation : JsValidate : Add Validation (Private Method) * * @return String * @param required boolean */ function JsValidate_addValidation(jsValidation) { this.jsValidation[this.jsValidation.length] = jsValidation; } /* * Validation : JsValidate : To String (Private Method) * * @return String * @param required boolean */ function JsValidate_toString(required) { var msg = ""; this.firstInError = null; for (var i = 0; i < this.jsValidation.length; i++) { var s = this.jsValidation[i].toString(required); if (s != null) { if (this.firstInError == null) { this.firstInError = this.jsValidation[i]; } msg += s; } } return msg == "" ? null : msg; } /* * Validation : JsVlidation (Class) * * @param field Field * @param type String * @param message String * @param required boolean */ function JsValidation(field, type, message, required){ this.field = field; this.getField = new Function("return this.field"); this.setField = new Function("field" ,"this.field = field"); this.maxInclusive = true; this.getMaxInclusive = new Function("return this.maxInclusive"); this.setMaxInclusive = new Function("maxInclusive" ,"this.maxInclusive = maxInclusive"); this.maxLength = null; this.getMaxLength = new Function("return this.maxLength"); this.setMaxLength = new Function("maxLength" ,"this.maxLength = maxLength"); this.maxMessage = null; this.getMaxMessage = new Function("return this.maxMessage"); this.setMaxMessage = new Function("maxMessage" ,"this.maxMessage = maxMessage"); this.maxValue = null; this.getMaxValue = new Function("return this.maxValue"); this.setMaxValue = new Function("maxValue" ,"this.maxValue = maxValue"); this.message = message; this.getMessage = new Function("return this.message"); this.setMessage = new Function("message" ,"this.message = message"); this.minInclusive = true; this.getMinInclusive = new Function("return this.minInclusive"); this.setMinInclusive = new Function("minInclusive" ,"this.minInclusive = minInclusive"); this.minLength = null; this.getMinLength = new Function("return this.minLength"); this.setMinLength = new Function("minLength" ,"this.minLength = minLength"); this.minMessage = null; this.getMinMessage = new Function("return this.minMessage"); this.setMinMessage = new Function("minMessage" ,"this.minMessage = minMessage"); this.minValue = null; this.getMinValue = new Function("return this.minValue"); this.setMinValue = new Function("minValue" ,"this.minValue = minValue"); this.required = arguments.length >= 4 ? required : true; this.getRequired = new Function("return this.required"); this.setRequired = new Function("required" ,"this.required = required"); this.type = type; this.getType = new Function("return this.type"); this.setType = new Function("type" ,"this.type = type"); this.field.jsValidation = this; this.checkLength = JsValidation_checkLength; this.checkRange = JsValidation_checkRange; this.toString = JsValidation_toString; } /* * Validation : JsVlidation : Check Length (Private Method) * * @return String Message */ function JsValidation_checkLength() { var len = (new String(this.field.value)).length; if (this.minLength != null && len < this.minLength) { return this.message + " has a minimum of " + (this.minMessage == null ? this.minLength : this.minMessage) + " characters.\n"; } if (this.maxLength != null && this.maxLength < len) { return this.message + " exceeds maximum of " + (this.maxMessage == null ? this.maxLength : this.maxMessage) + " characters.\n"; } return null; } /* * Validation : JsVlidation : Check Range (Private Method) * * @return String Message */ function JsValidation_checkRange() { var msg = null; if (this.minValue != null || this.maxValue != null) { var minTest = this.minValue == null ? true : (this.minInclusive ? (this.minValue <= this.field.value) : (this.minValue < this.field.value)); var maxTest = this.maxValue == null ? true : (this.maxInclusive ? (this.maxValue >= this.field.value) : (this.maxValue > this.field.value)); var minMsg = (this.minInclusive ? " greater than or equal to " : " greater than ") + (this.minMessage == null ? this.minValue : this.minMessage); var maxMsg = (this.maxInclusive ? " less than or equal to " : " less than ") + (this.maxMessage == null ? this.maxValue : this.maxMessage); msg = this.message + " must be entered as a number"; if (this.minValue != null && this.maxValue != null) { if (minTest && maxTest) return null; msg += minMsg + " and" + maxMsg; } else if (this.minValue != null) { if (minTest) return null; msg += minMsg; } else { if (maxTest) return null; msg += maxMsg; } msg += ".\n"; } return msg; } /* * Validation : JsVlidation : To String (Private Method) * * @return String Message * @boolean required boolean */ function JsValidation_toString(required) { required = required && this.required; var msg = null; switch(this.type) { case "date": { if (!jsIsDate(this.field.value)) { if (required) { msg = this.message + " must be entered as a valid date. (01-JAN-2000)\n"; } else { if (!jsIsEmpty(this.field.value)) { msg = this.message + " must be blank or entered as a valid date. (01-JAN-2000)\n"; } } } else { this.field.value = jsFormatExtendedDate(this.field.value); } } break; case "decimal": { if (!jsIsNumeric(this.field.value)) { if (required) { msg = this.message + " must be entered as a number.\n"; } else { if (!jsIsEmpty(this.field.value)) { msg = this.message + " must be blank or entered as a number.\n"; } } } else { msg = this.checkRange(); } } break; case "futureDate": { if (!jsIsFutureDate(this.field.value)) { if (required) { msg = this.message + " must be entered as a valid future date - 3 year limit.\n"; } else { if (!jsIsEmpty(this.field.value)) { msg = this.message + " must be blank or entered as a valid future date - 3 year limit.\n"; } } } else { this.field.value = jsFormatExtendedDate(this.field.value); } } break; case "numeric": { if (!jsIsNumeric(this.field.value)) { if (required){ msg = this.message + " must be entered as a number.\n"; } else { if (!jsIsEmpty(this.field.value)) { msg = this.message + " must be blank or entered as a number.\n"; } } } else { if (this.field.value.indexOf(".") >= 0) { msg = this.message + " must be a whole number."; } else { msg = this.checkRange(); } } } break; case "selection": { if (required) { if ((this.field.options.selectedIndex < 0) || jsIsWhitespace(this.field.options[this.field.options.selectedIndex].value)) { msg = this.message + " must be selected.\n"; } } } break; case "radioSelection": { if (required) { var somethingChecked = false; for (var i = 0; i < this.field.length; i++) { if (this.field[i].checked) { somethingChecked = true; break; } } if (!somethingChecked) { msg = this.message + " must be selected.\n"; } } } break; case "text": { if (jsIsWhitespace(this.field.value)) { if (required) { msg = this.message + " must be entered.\n"; } else { this.field.value = ""; } } else { msg = this.checkLength(); } } break; case "email": { if (!jsIsValidEMailAddress(this.field.value)) { if (required) { msg = this.message + " must be entered as a valid E-Mail Address.\n"; } else { if (!jsIsEmpty(this.field.value)) { msg = this.message + " must be blank or entered as a valid E-Mail Address.\n"; } } } else { msg = this.checkLength(); } } break; case "month": { if (!jsIsMonth(this.field.value)) { if (required) { msg = this.message + " must be entered as a valid calendar month. (JAN-2000)\n"; } else { if (!jsIsEmpty(this.field.value)) { msg = this.message + " must be blank or entered as a valid calendar month. (JAN-2000)\n"; } } } else { this.field.value = jsFormatExtendedMonth(this.field.value); } } break; } return msg; } /* * Validation : Global Variables * */ var jvValidate = new JsValidate(); var jsValidate = jvValidate; // (Deprecated)