// detect browser and flag browser type as local variables var agt=navigator.userAgent.toLowerCase(); var is_major = parseInt(navigator.appVersion); var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1)); var is_ie = (agt.indexOf("msie") != -1); var is_nav4up = (is_nav && (is_major >= 4)); var is_ie4up = (is_ie && (is_major >= 4)); // returns the system date from the client's PC in mm/dd/yyyy format function getClientSysDate() { var now = new Date(); var month = now.getMonth(); var date = now.getDate(); var year = now.getYear(); var today; // format the month field correctly if (month == 0) month = '01'; else if (month == 1) month = '02'; else if (month == 2) month = '03'; else if (month == 3) month = '04'; else if (month == 4) month = '05'; else if (month == 5) month = '06'; else if (month == 6) month = '07'; else if (month == 7) month = '08'; else if (month == 8) month = '09'; else if (month == 9) month = '10'; else if (month == 10) month = '11'; else if (month == 11) month = '12'; // format the day field correctly (precede single digit days with a zero) if (date < 10) date = '0' + date; // format the year field correctly (IE uses 2 digit years until y2k; NN uses # of years since 1900) // IE if (is_ie) { var i = '' + year; if (i.length == 2) { year = '19' + year; } } // Netscape if (is_nav) { year = 1900 + year; } // piece the date together in its correct format today = month + '/' + date + '/' + year; return(today); } function isValidDate(dateString) { var err=0 var psj=0; if (dateString.length != 10) return false; b = dateString.substring(0, 2) // month c = dateString.substring(2, 3) // '/' d = dateString.substring(3, 5) // day e = dateString.substring(5, 6) // '/' f = dateString.substring(6, 10) // year //basic error checking if (b<1 || b>12) return false; if (c != '/') return false; if (d<1 || d>31) return false; if (e != '/') return false; if (!isValidWholeNumber(f)) return false; //advanced error checking // months with 30 days if (b==4 || b==6 || b==9 || b==11) { if (d==31) return false; } // february, leap year if (b==2) { var g=parseInt(f/4); if (isNaN(g)) return false; if (d>29) return false; if (d==29 && ((f/4)!=parseInt(f/4))) return false; } return true; } function isValidEmailAddress(emailString) { if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailString)) return true; else return false; } // check for a null string or a string containing all spaces function isEmptyString(string) { re=/\S/ // regular expression matches all non-digits if (!re.test(string)) return true; else return false; } // determine if the string contains only numbers function isValidWholeNumber(inputstring) { if (isEmptyString(inputstring)) return false; re=/\D/ // regular expression matches all non-digits if (!re.test(inputstring)) return true; else return false; } // returns true if the date passed is in the future function isFutureDate(dateString) { if (Date.parse(dateString) > Date.parse(getClientSysDate())) return true; else return false; } // returns true if the date passed is in the past function isPastDate(dateString) { if (Date.parse(dateString) < Date.parse(getClientSysDate())) return true; else return false; } // returns true if the 'from' date preceeds the 'to' date function isValidDateRange(fromDateString, toDateString) { if (Date.parse(fromDateString) <= Date.parse(toDateString)) return true; else return false; } // Canadian zip following format: A9A 9A9 or A9A9A9 // ds - There's definitely room for improvment here. This validation // could be greatly simplified with a regular expression function isValidCanadianPostalCode(checkzip) { if (checkzip.length == 7) { if (checkzip.charAt(3) != " ") { return false; } if ((checkzip.charAt(0) == "0") || (parseFloat(checkzip.charAt(0)) > 0 )) { return false; } if ((checkzip.charAt(1) != "0") && (parseFloat(checkzip.charAt(1)) < 1)) { return false; } if (isNaN(parseFloat(checkzip.charAt(1)))) { return false; } if ((checkzip.charAt(2) == "0") || (parseFloat(checkzip.charAt(2)) > 0 )) { return false; } if ((checkzip.charAt(4) != "0") && (parseFloat(checkzip.charAt(4)) < 1)) { return false; } if (isNaN(parseFloat(checkzip.charAt(4)))) { return false; } if ((checkzip.charAt(5) == "0") || (parseFloat(checkzip.charAt(5)) > 0 )) { return false; } if ((checkzip.charAt(6) != "0") && (parseFloat(checkzip.charAt(6)) < 1)) { return false; } if (isNaN(parseFloat(checkzip.charAt(6)))) { return false; } return true; } else if (checkzip.length == 6) { if ((checkzip.charAt(0) == "0") || (parseFloat(checkzip.charAt(0)) > 0 )) { return false; } if ((checkzip.charAt(1) != "0") && (parseFloat(checkzip.charAt(1)) < 1)) { return false; } if (isNaN(parseFloat(checkzip.charAt(1)))) { return false; } if ((checkzip.charAt(2) == "0") || (parseFloat(checkzip.charAt(2)) > 0 )) { return false; } if ((checkzip.charAt(3) != "0") && (parseFloat(checkzip.charAt(3)) < 1)) { return false; } if (isNaN(parseFloat(checkzip.charAt(3)))) { return false; } if ((checkzip.charAt(4) == "0") || (parseFloat(checkzip.charAt(4)) > 0 )) { return false; } if ((checkzip.charAt(5) != "0") && (parseFloat(checkzip.charAt(5)) < 1)) { return false; } if (isNaN(parseFloat(checkzip.charAt(5)))) { return false; } return true; } else return false; } function isValidUSPostalCode(checkzip) { if ((!isValidWholeNumber(checkzip)) || (checkzip.length != 5)) { return false; } return true; } // This function populates a select list based on the value of another select // list. For an example of usage, see the Supplier Registration or Supplier // Update Profile form. function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) { var i, j; var prompt; // empty existing items for (i = selectCtrl.options.length; i >= 0; i--) { selectCtrl.options[i] = null; } prompt = (itemArray != null) ? goodPrompt : badPrompt; if (prompt == null) { j = 0; } else { selectCtrl.options[0] = new Option(prompt); j = 1; } if (itemArray != null) { // add new items for (i = 0; i < itemArray.length; i++) { selectCtrl.options[j] = new Option(itemArray[i][0]); if (itemArray[i][1] != null) { selectCtrl.options[j].value = itemArray[i][1]; } j++; } // select first item (prompt) for sub list selectCtrl.options[0].selected = true; } }