// Page Name: Common.js // Description: Include member of common javascript functions for all pages to use as necessary // Modifications: // Date Programmer Description // -------- -------------- ------------------------------------------------------------- // 10/22/02 Tim Stalter New // 04/17/03 Tim Stalter Modified for Netscape 6 changes (layers are no longer used. // 07/01/03 Tim Stalter New function setHourglass(). // 08/28/03 Tim Stalter Added setScrollMax(). // 09/03/03 Tim Stalter Modified openDialog for latest version of browsers // 06/04/04 Bill Plumstead New function processURL(). // 07/09/04 Tim Stalter New function openLeaveLink(). // 02/21/05 Bill Plumstead Added global variable sDateFormat and modified EditDate / EditDateTime // functions to support mm/dd/yyyy or dd/mm/yyyy format // 02/28/05 Bill Plumstead Modified processURL call to setMessage function if sFunction is not populated // 10/11/05 Tim Stalter Only allow a date format of mm/dd/yyyy "-" separators are no longer valid // 02/13/05 John Ross Segui Added ec: tag to retrieve language translation // 03/08/06 Tim Stalter Added getURL, used by issue detail to return owner selection list. //Determine Browser var isNS4 = (document.layers) ? true : false; var isIE4 = (document.all && !document.getElementById) ? true : false; var isIE5 = (document.all && document.getElementById) ? true : false; var isNS6 = (!document.all && document.getElementById) ? true : false; //Blinking Message variables var iBlinkTimer = 0; //timer for blinking message var iBlinkCount = 0; //counter for number of blinks //LeaveLink window var winLeaveLink = null; //Absence Mgt window var winAbsenceMgt = null; //Message (email) window var winMessage = null; //Authoria window var winAuthoriaLink = null; //Default Date Format var sDateFormat = "MM/DD/YYYY"; //Returns TRUE if date is valid --------------------------------------------------------------- function EditDate(sDate, sCur, bRequired, bFutureDtAllowed, bPastDtAllowed){ sDateMsg = ""; if (sDate.length == 0 && bRequired){ sDateMsg = "Date is required "; return(false); } if (sDate.length == 0) return(true); // Checks for the following valid date formats: MM/DD/YYYY var datePat = /^(\d{1,2})(\/)(\d{1,2})\2(\d{4})$/; var matchArray = sDate.match(datePat); if (matchArray == null){ sDateMsg = "Date must be in " + sDateFormat + " " + "format "; return(false); } // parse date into variables var month = ((sDateFormat.substring(0,2) == "DD")?matchArray[3]:matchArray[1]); var day = ((sDateFormat.substring(0,2) == "DD")?matchArray[1]:matchArray[3]); var year = matchArray[4]; if (month < 1 || month > 12){ sDateMsg = "Date has invalid month " + "(" + month + ")"; return(false); } if (day < 1 || day > 31){ sDateMsg = "Date has invalid day " + "(" + day + ")"; return(false); } if ((month==4 || month==6 || month==9 || month==11) && day==31){ sDateMsg = "Date has invalid day " + "(" + day + ")"; return(false); } if (month == 2) { // check for february 29th var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if (day>29 || (day==29 && !isleap)){ sDateMsg = "Date has invalid day " + "(" + day + ")"; return(false); } } if (year < 1902){ sDateMsg = "Date has invalid year " + "(" + year + ")"; return(false); } // var dDate = new Date(sDate); // var dCur = new Date(sCur); //Create date variable for sDate and sCur based on sDateFormat //******************************* matchArray = sDate.match(datePat); month = ((sDateFormat.substring(0,2) == "DD")?matchArray[3]:matchArray[1]); day = ((sDateFormat.substring(0,2) == "DD")?matchArray[1]:matchArray[3]); year = matchArray[4]; //******************************* var dDate = new Date(year,month,day); //******************************* matchArray = sCur.match(datePat); month = ((sDateFormat.substring(0,2) == "DD")?matchArray[3]:matchArray[1]); day = ((sDateFormat.substring(0,2) == "DD")?matchArray[1]:matchArray[3]); year = matchArray[4]; //******************************* var dCur = new Date(year,month,day); if (dDate.getFullYear() < 1902){ sDateMsg = "Date has invalid year " + "(" + dDate.getFullYear() + ")"; return(false); } if (!bFutureDtAllowed && (dCur.getFullYear() < dDate.getFullYear() || (dCur.getFullYear() == dDate.getFullYear() && dCur.getMonth() < dDate.getMonth()) || (dCur.getFullYear() == dDate.getFullYear() && dCur.getMonth() == dDate.getMonth() && dCur.getDate() < dDate.getDate()))){ sDateMsg = "Date may not be a future date "; return(false); } if (!bPastDtAllowed && (dCur.getFullYear() > dDate.getFullYear() || (dCur.getFullYear() == dDate.getFullYear() && dCur.getMonth() > dDate.getMonth()) || (dCur.getFullYear() == dDate.getFullYear() && dCur.getMonth() == dDate.getMonth() && dCur.getDate() > dDate.getDate()))){ sDateMsg = "Date may not be a past date"; return(false); } return(true); } //Returns TRUE if datetime is valid --------------------------------------------------------------- function EditDateTime(sDateTime, sCur, bRequired, bFutureDtAllowed, bPastDtAllowed){ sDateMsg = ""; if (sDateTime.length == 0 && bRequired){ sDateMsg = "Date is required "; return(false); } if (sDateTime.length == 0) return(true); var sDate; var sTime; var sDTArray = sDateTime.split(' '); if (sDTArray.length != 2){ sDateMsg = "Date must be in " + sDateFormat + " HH24:MI"; return(false); } sDate = sDTArray[0]; sTime = sDTArray[1]; // *** Validate Date Section *** if (sDate.length == 0 && bRequired){ sDateMsg = "Date is required "; return(false); } if (sDate.length == 0) return(true); // Checks for the following valid date formats: MM/DD/YYYY var datePat = /^(\d{1,2})(\/)(\d{1,2})\2(\d{4})$/; var matchArray = sDate.match(datePat); if (matchArray == null){ sDateMsg = "Date must be in " + sDateFormat + " " + "format "; return(false); } // parse date into variables var month = ((sDateFormat.substring(0,2) == "DD")?matchArray[3]:matchArray[1]); var day = ((sDateFormat.substring(0,2) == "DD")?matchArray[1]:matchArray[3]); var year = matchArray[4]; if (month < 1 || month > 12){ sDateMsg = "Date has invalid month " + "(" + month + ")"; return(false); } if (day < 1 || day > 31){ sDateMsg = "Date has invalid day " + "(" + day + ")"; return(false); } if ((month==4 || month==6 || month==9 || month==11) && day==31){ sDateMsg = "Date has invalid day " + "(" + day + ")"; return(false); } if (month == 2) { // check for february 29th var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); if (day>29 || (day==29 && !isleap)){ sDateMsg = "Date has invalid day " + "(" + day + ")"; return(false); } } // var dDate = new Date(sDate); // var dCur = new Date(sCur); //Create date variable for sDate and sCur based on sDateFormat //******************************* matchArray = sDate.match(datePat); month = ((sDateFormat.substring(0,2) == "DD")?matchArray[3]:matchArray[1]); day = ((sDateFormat.substring(0,2) == "DD")?matchArray[1]:matchArray[3]); year = matchArray[4]; //******************************* var dDate = new Date(year,month,day); //******************************* matchArray = sCur.match(datePat); month = ((sDateFormat.substring(0,2) == "DD")?matchArray[3]:matchArray[1]); day = ((sDateFormat.substring(0,2) == "DD")?matchArray[1]:matchArray[3]); year = matchArray[4]; //******************************* var dCur = new Date(year,month,day); if (dDate.getFullYear() < 1902){ sDateMsg = "Date has invalid year " + "(" + dDate.getFullYear() + ")"; return(false); } if (!bFutureDtAllowed && (dCur.getFullYear() < dDate.getFullYear() || (dCur.getFullYear() == dDate.getFullYear() && dCur.getMonth() < dDate.getMonth()) || (dCur.getFullYear() == dDate.getFullYear() && dCur.getMonth() == dDate.getMonth() && dCur.getDate() < dDate.getDate()))){ sDateMsg = "Date may not be a future date " return(false); } if (!bPastDtAllowed && (dCur.getFullYear() > dDate.getFullYear() || (dCur.getFullYear() == dDate.getFullYear() && dCur.getMonth() > dDate.getMonth()) || (dCur.getFullYear() == dDate.getFullYear() && dCur.getMonth() == dDate.getMonth() && dCur.getDate() > dDate.getDate()))){ sDateMsg = "Date may not be a past date"; return(false); } // *** Validate Time Section *** var timePat = /^([01]?[0-9]|[2][0-3])(:[0-5][0-9])$/; marchArray = ""; matchArray = sTime.match(timePat); if (matchArray == null){ sDateMsg = "Time must be in " + " HH24:MI " + "format "; return(false); } return(true); } //Returns true if any form value has changed -------------------------------------------------- function FormChanged(oForm){ for (i=0; i < (oForm.length); i++){ if (oForm[i].name.substring(0,3) == "txt" || oForm[i].name.substring(0,3) == "tar" || oForm[i].name.substring(0,3) == "pwd"){ if (oForm[i].value != oForm[i].defaultValue){ return(true); } } else if (oForm[i].name.substring(0,3) == "chk" || oForm[i].name.substring(0,3) == "rdo"){ if (oForm[i].checked != oForm[i].defaultChecked){ return(true); } } else if (oForm[i].name.substring(0,3) == "sel"){ for (s=0; s < (oForm[i].length); s++){ if (oForm[i].options[s].selected != oForm[i].options[s].defaultSelected){ return(true); } } } } return(false); } //Write message to message line and locate window to top ----------------------------------- function setMessage(sMessage){ if (sMessage == null){ if (parent.frames["bottom"].sMessage == null){ sMessage = ""; } else { sMessage = parent.frames["bottom"].sMessage; } } if (topframe.document.getElementById("tdMsg") != null){ topframe.document.getElementById("tdMsg").innerHTML = sMessage; if (sMessage.length > 85) { alert(sMessage); } if (sMessage.length > 0 && isIE5){ clearInterval(iBlinkTimer); iBlinkCount = 0; iBlinkTimer = setInterval("blinkMessage()",500); } } } //blink the message several times to get their attention ----------------------------------- function blinkMessage(){ //frames["topframe"].tdMsg.style.visibility = frames["topframe"].tdMsg.style.visibility == "" ? "hidden" : ""; frames["topframe"].trMsg.bgColor = frames["topframe"].trMsg.bgColor == "" ? "yellow" : ""; if (iBlinkCount++ > 5){ frames["topframe"].trMsg.bgColor = ""; iBlinkCount = 0; clearInterval(iBlinkTimer); } } //Set Breadcrumb message ------------------------------------------------------------------------------------------ function setBreadCrumb(){ if (topframe.document.getElementById("tdBreadCrumb") == null) return; if (bottom.sBreadCrumb == null) var sBreadCrumb = ""; else var sBreadCrumb = bottom.sBreadCrumb; topframe.document.getElementById("tdBreadCrumb").innerHTML = sBreadCrumb; if (topframe.document.body != null) topframe.document.body.style.cursor = "default"; } //Set Note Required message --------------------------------------------------------------------------------------- function setNoteReq(){ if (topframe.document.getElementById("tdNoteReq") == null) return; if (parent.frames["bottom"].sNoteReq == null) var sNoteReq = ""; else var sNoteReq = parent.frames["bottom"].sNoteReq; topframe.document.getElementById("tdNoteReq").innerHTML = sNoteReq; } //Common edit before saving ------------------------------------------------------------------ function SaveEdit(sFrmName){ if (isIE5 && parent.frames["bottom"].event != null) parent.frames["bottom"].event.returnValue = false; oForm = parent.frames["bottom"].document.forms[sFrmName]; if (!FormChanged(oForm)){ setMessage("No changes have been made "); return(false); } oForm.submit(); setHourglass(); return(true); } //confirm box before deleting ------------------------------------------------------------------ function DeleteEdit(sMessage, sUrl){ sMessage = "Are you sure you want to delete " + " " + sMessage; if (confirm(sMessage)){ parent.frames["bottom"].location = sUrl; return(true); }else{ return(false); } } //Returns the value of a cookie------------------------------------------------------------ function getCookie(name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) return getCookieVal (j); i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } function getCookieVal(offset) { var endstr = document.cookie.indexOf (";", offset); if (endstr == -1) endstr = document.cookie.length; return unescape(document.cookie.substring(offset, endstr)); } //Deletes cookie -------------------------------------------------------------------------- function deleteCookie(name) { var exp = new Date(); exp.setTime (exp.getTime() - 1); document.cookie = name + "=; expires=" + exp.toGMTString() + "; path=/"; } // remove leading and trailing spaces and special characters ------------------------------ function Trim(sValue){ // Remove special characters sValue = sValue.replace(/\"|\||\^/g,""); //Remove all " and | and ^ // Remove Leading Spaces while('' + sValue.charAt(0) == ' '){ sValue = sValue.substring(1,sValue.length); } // Remove Trailing Spaces while('' + sValue.charAt(sValue.length - 1) == ' '){ sValue = sValue.substring(0,sValue.length-1); } return(sValue); } //numeric check ------------------------------------------------------------------- function IsNumeric(sValue){ var rNumbers = /\D/gi; return(!rNumbers.test(sValue)); } // currency check (removes "$", ",", and "." before checking for numeric ------------------------------ function isCurrency(sValue) { var re = /\$|\,|\./g; return(IsNumeric(sValue.replace(re, ""))); } // turn hourglass on -------------------------------------------------------------------------- function setHourglass() { if (topframe.document.getElementById("tdMsg") != null) topframe.document.getElementById("tdMsg").innerHTML = "Please Wait ... "; if (topframe.document.body != null) topframe.document.body.style.cursor = "wait"; if (bottom.document.body != null) bottom.document.body.style.cursor = "wait"; } // Set the ScrollMax _-------------------------------------------------------------------------- function setScrollMax(sPage, sDefault) { var sMax = "a"; var sMessage = "Enter the maximum number of rows you would like displayed "; while(!IsNumeric(sMax)){ sMax = prompt(sMessage, sDefault); if (sMax.length == 0) return; if (!IsNumeric(sMax)) alert("Your input must be numeric "); } parent.frames["bottom"].location = sPage + "&scrollmax=" + sMax; } //Open the dialog box given a ULR -------------------------------------------------------------- function openDialog(sURL, iWidth, iHeight) { if (window.showModalDialog) { // used for testing window.open(sURL); sReturn = window.showModalDialog(sURL,window,'dialogHeight:' + iHeight + 'px;' + 'dialogWidth:' + iWidth + 'px;' + 'center:yes;status:no'); } else { // Center on the main window. var iLeft = window.screenX + ((window.outerWidth - iWidth) / 2); var iTop = window.screenY + ((window.outerHeight - iHeight) / 2); var attr = "screenX=" + iLeft + ",screenY=" + iTop + ",resizable=no,width=" + iWidth + ",height=" + iHeight + ",scrollbars=yes,modal=yes" window.open(sURL, 'DialogBox', attr) } } //send a URL through HTTPRequest object and check the return for SUCCESSFUL --------------------------------------- function processURL(sURL, sSearch, sFunction) { setHourglass(); var oHTTP = new ActiveXObject("MSXML2.XMLHTTP"); oHTTP.Open("Get", sURL, false); oHTTP.send(); //Check for page success if (oHTTP.responsetext.indexOf(sSearch) > -1){ if (sFunction.length > 0){ setMessage(sFunction + " " + "Successful "); } else { setMessage(""); } } else { if (sFunction != null){ setMessage("ERROR: " + sFunction + " " + "Failed "); //alert(oHTTP.responsetext); } } oHTTP=null; resetHourglass(); } //get a URL through HTTPRequest object ------------------------------------------------------ function getURL(sURL) { var oHTTP = new ActiveXObject("MSXML2.XMLHTTP"); oHTTP.Open("Get", sURL, false); oHTTP.send(); sResponse = oHTTP.responsetext; oHTTP=null; return sResponse; } function resetHourglass(){ if (topframe.document.body != null) topframe.document.body.style.cursor = "default"; if (bottom.document.body != null) bottom.document.body.style.cursor = "default"; } //Open a window to LeaveLink if one is not already open ------------------------------------------------------- function openLeaveLink(sPartid, sLeavelinkid) { var sURL = "run?page=pages.LeaveLink&id=" + sPartid + "&leavelinkid=" + sLeavelinkid; if (winLeaveLink && !winLeaveLink.closed && !winLeaveLink.closed){ if (confirm("LeaveLink window already open. Do you wish to continue ")) winLeaveLink.location=sURL; winLeaveLink.focus(); }else{ winLeaveLink=open(sURL,"LLWindow","height=500,width=650,menubar=no,toolbar=no,status=yes,location=no,resizable=yes,scrollbars=yes"); } } //Open a window to Absence Mgt if one is not already open ------------------------------------------------------- function openAbsenceMgt(sPartid, AbsenceMgtApp) { var sURL = "run?page=pages." + AbsenceMgtApp + "&id=" + sPartid; if (winAbsenceMgt && !winAbsenceMgt.closed && !winAbsenceMgt.closed){ if (confirm("LeaveLink window already open. Do you wish to continue ")) winAbsenceMgt.location=sURL; winAbsenceMgt.focus(); }else{ winAbsenceMgt=open(sURL,AbsenceMgtApp + "Window","height=500,width=650,menubar=no,toolbar=no,status=yes,location=no,resizable=yes,scrollbars=yes"); } } //Open a window to messages if one is not already open ------------------------------------------------------- function openMessage(sURL) { if (winMessage && !winMessage.closed && !winMessage.closed){ winMessage.location=sURL; winMessage.navigate(sURL); winMessage.location.reload(); winMessage.focus(); }else{ winMessage=null; winMessage=open(sURL,"MessageWindow","height=500,width=650,menubar=no,toolbar=no,status=yes,location=no,resizable=yes,scrollbars=yes"); winMessage.location.reload(); winMessage.focus(); } } //Open a window to Authoria if one is not already open ------------------------------------------------------- function openAuthoriaLink(sURL) { if (winAuthoriaLink && !winAuthoriaLink.closed && !winAuthoriaLink.closed){ winAuthoriaLink.focus(); winAuthoriaLink.location=sURL; }else{ winAuthoriaLink=null; winAuthoriaLink=open(sURL,"AuthoriaWindow","height=500,width=650,menubar=no,toolbar=no,status=yes,location=no,resizable=yes,scrollbars=yes"); } }