/****************************************************************************** ** Version 2.6 ** Global JavaScript Functions ** LastMod: 02/05/2002 Author: Chris Drake ****************************************************************************** ** Change History ****************************************************************************** ** Date Author Description ** ---- ------ ----------- ** 20030513 Al Eardley Tidied for v3.1 ** 20030617 Al Eardley Changed file from .js to .inc.asp so application variables can be used ****************************************************************************** ** function confirmlogoff(astrRoot) ** function openViewApplication(aoForm, astrRoot) ** function openViewCV(aoForm, astrRoot) ** function openViewEmail(aoForm, astrRoot) ** function openViewNote(aoForm, astrRoot) ** function ValidateDate(aintYear, aintMonth, aintDay) ** function IsEmail(astrEmailAddress) ** function trim(astrString) ****************************************************************************** ** Archived: ****************************************************************************** ** function zzzloadRolloverImages() ** function zzzreturnImageObject(n, d) ** function zzzswapImages() ** function zzzrestoreImages() ** function zzzsetStatusBar(astrText) ** function zzzrefereeConfirmLogoff ******************************************************************************/ /****************************************************************************** ** Confirms logoff before redirecting to logout page ******************************************************************************/ function confirmLogoff(astrRoot) { var confirmedLogoff = window.confirm("Do you want to log out?\n\nClick 'OK' to proceed."); if (confirmedLogoff) { document.location.href = astrRoot+'/Logout.asp'; return true; } } /****************************************************************************** ** Opens a new window to view an application ******************************************************************************/ function openViewApplication(aoForm, astrRoot) { if (document.forms.length > 0) { aoForm.target = '_BLANK'; aoForm.action = astrRoot + '/View/ViewApplication.asp'; aoForm.submit(); } else { var newWindow; newWindow = window.open(astrRoot + '/View/ViewApplication.asp'); newWindow.focus(); } } /****************************************************************************** ** Opens a new window to view CV ******************************************************************************/ function openViewCV(aoForm, astrRoot) { if (document.forms.length > 0) { aoForm.target = '_BLANK'; aoForm.action = astrRoot + '/View/ViewCV.asp'; aoForm.submit(); } else { var newWindow; newWindow = window.open(astrRoot + '/View/ViewCV.asp'); newWindow.focus(); } } /****************************************************************************** ** Opens a new window to view an e-mail ******************************************************************************/ function openViewEmail(aoForm, astrRoot) { if (document.forms.length > 0) { aoForm.target = '_BLANK'; aoForm.action = astrRoot + '/View/ViewEmail.asp'; aoForm.submit(); } else { alert('Error opening the e-mail for viewing.'); } } /****************************************************************************** ** Opens a new window to view a note ******************************************************************************/ function openViewNote(aoForm, astrRoot) { if (document.forms.length > 0) { aoForm.target = '_BLANK'; aoForm.action = astrRoot + '/View/ViewNote.asp'; aoForm.submit(); } else { alert('Error opening the note for viewing.'); } } /****************************************************************************** ** Validates a date given as a 8 character string ******************************************************************************/ function IsValidDate (strFMode, theDate, blnMandatory) { var theDay = theDate.substring(6,9); var theMonth = theDate.substring(4,6); var theYear = theDate.substring(0,4); var correctDays = 0; //alert (theDay); //alert (theMonth); //alert (theYear); if (blnMandatory == false && theDate == "00000000") { return true; } else { //Check that all have value other than "00", "00, "0000" if (theDay == "00") { if (strFMode != "MONTHYEAR") { return false; } } if (theMonth == "00") { return false; } if (theYear == "0000") { return false; } // 30 days has September,April, June and November if ((theMonth == 4) || (theMonth == 6)|| (theMonth == 9)|| (theMonth ==11)) { correctDays = 30; } else { // All the rest have 31 except February if((theMonth == 2)) { if (( theYear % 4 == 0 && theYear % 100 != 0) || theYear % 400 == 0 ) { correctDays = 29; } else { correctDays = 28; } } else { correctDays = 31; } } if (theDay > correctDays) { return false; } if (blnMandatory == true && theDate == "00000000") { return false; } return true; } } /****************************************************************************** ** Validates a date given integer Year, Month & Day ******************************************************************************/ function ValidateDate(aintYear, aintMonth, aintDay) { var intCorrectDays = 0; if ((aintYear == 0) || (aintMonth == 0) || (aintDay == 0)) { return false; } else { // 30 days has September,April, June and November if ((aintMonth == 4) || (aintMonth == 6)|| (aintMonth == 9)|| (aintMonth ==11)) { intCorrectDays = 30; } else { // All the rest have 31 except February if((aintMonth == 2)) { if (( aintYear % 4 == 0 && aintYear % 100 != 0) || aintYear % 400 == 0 ) { intCorrectDays = 29; } else { intCorrectDays = 28; } } else { intCorrectDays = 31; } } if (aintDay > intCorrectDays) { return false; } return true; } } /****************************************************************************** ** Validates an e-mail address for format ******************************************************************************/ function IsEmail(astrEmailAddress) { /*var reEMail = /^\S+@\S+\.\S+$/; */ //old version var reEMail = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{1,7}|[0-9]{1,3})(\]?)$/; return reEMail.test(astrEmailAddress); } /****************************************************************************** ** Removes leading and trailing spaces from a string ******************************************************************************/ function trim(astrString) { var i; var j; var strNew; var intStartIndex = 0; var intFinishIndex = astrString.length; var blnFoundChar = false; // if the string has a length then if (intStartIndex != intFinishIndex) { //loop through string from the front counting how many spaces occur before the first character for (i = 0; i <= astrString.length - 1; i++) { if ((astrString.charAt(i) == ' ') && (blnFoundChar == false)) { intStartIndex = i + 1; } else { blnFoundChar = true; } } blnFoundChar = false; //loop through string from the end counting how many spaces occur before the last character for (j = astrString.length - 1; j >= 0; j--) { if ((astrString.charAt(j) == ' ') && (blnFoundChar == false)) { intFinishIndex = intFinishIndex - 1; } else { blnFoundChar = true; } } strNew = astrString.substr(intStartIndex, intFinishIndex - intStartIndex); } else { strNew = astrString; } return strNew; } /****************************************************************************** ** Approximate word count function; mimics MS Word. ******************************************************************************/ function countWords(strTarget) { var arrWords = strTarget.match(/\S+/g); if (arrWords) return arrWords.length; return 0; } /****************************************************************************** ** Returns true if argument is an integer. ******************************************************************************/ function isInteger(intTarget) { var reInteger = /^[0-9]+$/; return reInteger.test(intTarget); } /****************************************************************************** ** Returns true if first date is earlier. Handles dates with or without day. ******************************************************************************/ function isFirstDateEarlier() { if (arguments.length == 4) { // Month1,Year1,Month2,Year2 if (arguments[1] < arguments[3]) return true; if (arguments[1] > arguments[3]) return false; if (arguments[0] <= arguments[2]) return true; // Allows identical months when not using days if (arguments[0] > arguments[2]) return false; } else if (arguments.length == 6) { // Date1,Month1,Year1,Date1,Month2,Year2 if (arguments[2] < arguments[5]) return true; if (arguments[2] > arguments[5]) return false; if (arguments[1] < arguments[4]) return true; if (arguments[1] > arguments[4]) return false; if (arguments[0] < arguments[3]) return true; if (arguments[0] >= arguments[3]) return false; // Does not allow identical days } else { window.alert("Function isFirstDateEarlier requires 4 or 6 arguments:\n\nd1,m1,y1,d2,m2,y2 or\nm1,y1,m2,y2"); return false; } } /****************************************************************************** ** Prevents form from being submitted twice. Used as part of a checkForm ** function, returns false if run more than once. ******************************************************************************/ function isSubmitted() { if (blnSubmitted == true) return true; else { blnSubmitted = true; return false; } } /****************************************************************************** ** Date validator for Grad Advantage DayMonthYear function ******************************************************************************/ function IsValidDayMonthYear (strFMode, theDate, blnMandatory) { var theDay = theDate.substring(6,9); var theMonth = theDate.substring(4,6); var theYear = theDate.substring(0,4); var correctDays = 0; //alert (theDay); //alert (theMonth); //alert (theYear); if (blnMandatory == false && theDate == "00000000") { return true; } else { //Check that all have value other than "00", "00", "0000" if (theDay == "00") { if (strFMode != "MONTHYEAR") { return false; } } if (theMonth == "00") { return false; } if (theYear == "0000") { return false; } // 30 days has September,April, June and November if ((theMonth == 4) || (theMonth == 6)|| (theMonth == 9)|| (theMonth ==11)) { correctDays = 30; } else { // All the rest have 31 except February if((theMonth == 2)) { if (( theYear % 4 == 0 && theYear % 100 != 0) || theYear % 400 == 0 ) { correctDays = 29; } else { correctDays = 28; } } else { correctDays = 31; } } if (theDay > correctDays) { return false; } if (blnMandatory == true && theDate == "00000000") { return false; } return true; } } //****************************************************************************** //****************************************************************************** //****************************************************************************** //****************************************************************************** //****************************************************************************** //****************************************************************************** //****************************************************************************** //****************************************************************************** //****************************************************************************** //****************************************************************************** //****************************************************************************** //****************************************************************************** //****************************************************************************** //****************************************************************************** //****************************************************************************** //****************************************************************************** //****************************************************************************** //****************************************************************************** //****************************************************************************** /****************************************************************************** ** Loads all images passed as arguments into an image array. Can be run ** multiple times in a page. ******************************************************************************/ function zzzloadRolloverImages() { var d=document; if (d.images) { if (!d.arrPreloadedImages) d.arrPreloadedImages = new Array(); var i, j = d.arrPreloadedImages.length, a = preloadRolloverImages.arguments; for (i=0; i < a.length; i++) { if (a[i].indexOf("#") != 0) { d.arrPreloadedImages[j] = new Image; d.arrPreloadedImages[j++].src = a[i]; } } } } /******************************************************************************* ** Returns a reference to an image via the browser's main DHTML object. *******************************************************************************/ function zzzreturnImageObject(n, d) { var p,i,x; if (!d) d=document; if ((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p); } if (!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i