function popupCalendar(dateField) { window.dateField=dateField; cal=window.open('/toolkit/html/calendar.html','cal','WIDTH=200,HEIGHT=250'); } function dateFormat(inDate){ var DateVal = inDate.value; var inMonth; var inDay; var inYear; var numDays; var monthName; var parsed = 0; var firstDash; var lastDash; var textMonth; var chr; var validChars; if (DateVal != ""){ //make sure all characters are valid if (!(ValidChars(DateVal, "ABCDEFGJLMNOPRSTUVYabcdefgjlmnoprstuvy0123456789-/"))){ TextAlert(inDate, '"' + inDate.value + '" is not a valid date.');inDate.value = "";return; } //make sure input is of correct length if ((DateVal.length < 6) || (DateVal.length > 11)){ TextAlert(inDate, '"' + inDate.value + '" is not a valid date.');inDate.value = "";return; } //make sure de-limiters exist if (DateVal.indexOf("-") == -1){ if (DateVal.indexOf("/") == -1){ TextAlert(inDate, '"' + inDate.value + '" is not a valid date.');inDate.value = "";return; } } //determine input format and parse date in component parts if (parsed != 1){ var firstSlash = DateVal.indexOf("/"); var lastSlash = DateVal.lastIndexOf("/"); //if a slash exists if (firstSlash != -1){ if (firstSlash == lastSlash){ //only one slash TextAlert(inDate, '"' + inDate.value + '" is not a valid date.');inDate.value = "";return; } else{ //more than one slash exists if (lastSlash - firstSlash > 4){ TextAlert(inDate, '"' + inDate.value + '" is not a valid date.');inDate.value = "";return; } else{ //parse date inMonth = DateVal.substring(0,DateVal.indexOf("/")); inDay = DateVal.substring(DateVal.indexOf("/") + 1,DateVal.lastIndexOf("/")); inYear = DateVal.substring(DateVal.lastIndexOf("/") + 1,DateVal.length); parsed = 1; } } } } if (parsed != 1){ firstDash = DateVal.indexOf("-"); lastDash = DateVal.lastIndexOf("-"); //if a dash exists if (firstDash != -1){ if (firstDash == lastDash){ TextAlert(inDate, '"' + inDate.value + '" is not a valid date.');inDate.value = "";return; } else{ if ((lastDash - firstDash == 3) || (lastDash - firstDash == 2)){ //assumes numeric value inbetween inMonth = DateVal.substring(0,DateVal.indexOf("-")); inDay = DateVal.substring(DateVal.indexOf("-") + 1,DateVal.lastIndexOf("-")); inYear = DateVal.substring(DateVal.lastIndexOf("-") + 1,DateVal.length); parsed = 1; } else{ //else assume text representation (3 char abbreviation) of month is inbetween if (lastDash - firstDash != 4){ TextAlert(inDate, '"' + inDate.value + '" is not a valid date.');inDate.value = "";return; } } } } } // this could be nested, but it was moved out for readability if (parsed != 1){ firstDash = DateVal.indexOf("-"); lastDash = DateVal.lastIndexOf("-"); //if a dash exists if (firstDash != -1){ if (firstDash == lastDash){ TextAlert(inDate, '"' + inDate.value + '" is not a valid date.');inDate.value = "";return; } else{ textMonth = DateVal.substring(firstDash+1,lastDash); inMonth = 0; if (textMonth.toUpperCase() == "JAN"){inMonth = 1;} if (textMonth.toUpperCase() == "FEB"){inMonth = 2;} if (textMonth.toUpperCase() == "MAR"){inMonth = 3;} if (textMonth.toUpperCase() == "APR"){inMonth = 4;} if (textMonth.toUpperCase() == "MAY"){inMonth = 5;} if (textMonth.toUpperCase() == "JUN"){inMonth = 6;} if (textMonth.toUpperCase() == "JUL"){inMonth = 7;} if (textMonth.toUpperCase() == "AUG"){inMonth = 8;} if (textMonth.toUpperCase() == "SEP"){inMonth = 9;} if (textMonth.toUpperCase() == "OCT"){inMonth = 10;} if (textMonth.toUpperCase() == "NOV"){inMonth = 11;} if (textMonth.toUpperCase() == "DEC"){inMonth = 12;} if (inMonth == 0){ TextAlert(inDate, '"' + inDate.value + '" is not a valid date.');inDate.value = "";return; } inDay = DateVal.substring(0,DateVal.indexOf("-")); inYear = DateVal.substring(DateVal.lastIndexOf("-") + 1,DateVal.length); parsed = 1; } } } //check for all numeric characters within parsed components if (!(ValidChars(inMonth, "0123456789"))){ TextAlert(inDate, '"' + inDate.value + '" is not a valid date.');inDate.value = "";return; } if (!(ValidChars(inDay, "0123456789"))){ TextAlert(inDate, '"' + inDate.value + '" is not a valid date.');inDate.value = "";return; } if (!(ValidChars(inYear, "0123456789"))){ TextAlert(inDate, '"' + inDate.value + '" is not a valid date.');inDate.value = "";return; } //check for valid month if ((inMonth < 1 ) || (inMonth > 12)){ TextAlert(inDate, '"' + inDate.value + '" is not a valid date.');inDate.value = "";return; } else{ // need entire month name to use in error messages if (inMonth == 1){monthName = "January";} if (inMonth == 2){monthName = "February";} if (inMonth == 3){monthName = "March";} if (inMonth == 4){monthName = "April";} if (inMonth == 5){monthName = "May";} if (inMonth == 6){monthName = "June";} if (inMonth == 7){monthName = "July";} if (inMonth == 8){monthName = "August";} if (inMonth == 9){monthName = "September";} if (inMonth == 10){monthName = "October";} if (inMonth == 11){monthName = "November";} if (inMonth == 12){monthName = "December";} inMonth = monthName.substring(0,3); } //set max days in month if ((inMonth == "Jan") || (inMonth == "Mar") || (inMonth == "May") || (inMonth == "Jul") || (inMonth == "Aug") || (inMonth == "Oct") || (inMonth == "Dec")){ numDays = 31; } else{ if ((inMonth == "Apr") || (inMonth == "Jun") || (inMonth == "Sep") || (inMonth == "Nov")){ numDays = 30; } else{ numDays = 29; } } if ((inDay > numDays) || (inDay < 1)){ TextAlert(inDate, 'Day "' + inDay + '" does not exist in ' + monthName + '.\nPlease enter a valid date.'); inDate.value = ""; return; } //ensure a two digit day for continuity if (inDay.length == 1){ inDay = 0 + inDay; } //ensure a four digit or two digit year was entered if ((inYear.length != 4) && (inYear.length != 2)){ TextAlert(inDate, '"' + inDate.value + '" is not a valid date.');inDate.value = "";return; } //modify two digit years to four digit years for continuity and calendar wizard if (inYear.length == 2){ inYear = parseInt(inYear); if (inYear > 49){ inYear += 1900; } else{ inYear += 2000; } } //check for leap year if ((inMonth == "Feb") && (inDay == "29")){ if ((inYear % 4) != 0){ TextAlert(inDate, inYear + " is not a leap year.\nPlease enter a valid date.");inDate.value = "";return; } if (((inYear % 100) == 0) && ((inYear % 400) != 0)) { TextAlert(inDate, inYear + " is not a leap year.\nPlease enter a valid date.");inDate.value = "";return; } } inDate.value = inDay + "-" + inMonth + "-" + inYear; } } function ValidChars(inString, inRefString){ var tempChar; inString = inString + ""; for (var count=0; count < inString.length; count++){ tempChar= inString.substring (count, count+1); if (inRefString.indexOf (tempChar, 0) == -1){ return (false); } } return (true); } function TextAlert(inField, inError){ alert(inError); inField.focus(); inField.select(); }