// Javascript validation routines for Biscom Delivery Server /* * Checks for the correct version of JRE and * displays/hides the applet element depending on it * Author: Fahim Hasan * Used in: * deliveryCreateQuickWithApplet.jsp * deliveryView.jsp * deliveryViewFullWithApplet.jsp * downloadProgress.jsp * packageCreateWithApplet.jsp * uploadProgress.jsp */ function initializeAppletContainer() { var jreVersion = PluginDetect.getVersion('Java'); if (jreVersion != null && jreVersion >= '1,5'){ document.getElementById('jreNotFound').style.display='none'; } else{ document.getElementById('appletContainer').style.display='none'; } } /* * Checks for the correct version of JRE and * displays/hides the applet element depending on it * Author: Fahim Hasan * Used in: * deliveryPrintPreview.jsp * deliveryViewFull.jsp * deliveryViewNS.jsp * viewComplianceDelivery.jsp * viewComplianceDeliverySummary.jsp * viewComplianceReplyDelivery.jsp */ function initializeAppletElements() { var jreVersion = PluginDetect.getVersion('Java'); var appletElement = document.getElementById('appletButton') var appletCheckBoxHeader = document.getElementById('appletCheckBoxHeader'); var appletCheckBoxList = document.getElementsByName('documentIdArray'); if (jreVersion != null && jreVersion >= '1,5'){ // Everythings fine, do nothing } else{ if(appletElement != null) appletElement.style.display='none'; appletCheckBoxHeader.style.display='none'; // If there's only one checkbox, set its style if (typeof(appletCheckBoxList.length) != 'number') { appletCheckBoxList.style.display = 'none'; } else{ // Else its an array, iterate and set style for(var i=0; i= '1,5'){ if(nonAppletElement != null){ nonAppletElement.style.display='none'; } } else{ if(appletElement != null && nonAppletElement != null){ appletElement.style.display='none'; } if(appletHrefElement != null){ appletHrefElement.style.display='none'; } } } /* * String formatting utility for building strings similiar to C#. * We can use it to populate params messages with params from application.properties by javascript */ String.format = function( text ) { //check if there are two arguments in the arguments list if ( arguments.length <= 1 ) { //if there are not 2 or more arguments there's nothing to replace //just return the original text return text; } //decrement to move to the second argument in the array var tokenCount = arguments.length - 1; for( var token = 0; token < tokenCount; token++ ) { //iterate through the tokens and replace their placeholders from the original text in order text = text.replace( new RegExp( "\\{" + token + "\\}", "gi" ), arguments[ token + 1 ] ); } return text; }; /* * Validates a password * Author: Fahim Hasan * Param details: * upperCase: Defines whether uppercase letters should be present in the password * lowerCase: Defines whether lowercase letters should be present in the password * numerals: Defines whether digits should be present in the password * symbols: Defines whether non-alphanumeric characters should be present in the password * allowedList: Contains the list of allowed chars for the the password * message: The list of error messages * password: The string to validate */ function checkPassword(upperCase, lowerCase, numeral, symbol, allowedList, message, password){ if(password == null || password.length == 0){ alert(message["enterPassword"]); return false; } // These variables are used to track whether the password contains at least one char from the corresponding character group var upperCaseFlag = false; var lowerCaseFlag = false; var numeralFlag = false; var symbolFlag = false; var errorMessage = message["mustContain"]; var len = errorMessage.length; // Used to track whether the default error message has changed if(upperCase == true && password.match(/[A-Z]/)) upperCaseFlag = true; // If uppercase letter is required, test if present in password if(lowerCase == true && password.match(/[a-z]/)) lowerCaseFlag = true; if(numeral == true && password.match(/\d+/)) numeralFlag = true; if(symbol == true && password.match(/[^a-zA-Z0-9]/)) symbolFlag = true; if(upperCase == true && upperCaseFlag == false) errorMessage += message["upperCase"]; // If uppercase is required and not found.. if(lowerCase == true && lowerCaseFlag == false) errorMessage += message["lowerCase"]; if(numeral == true && numeralFlag == false) errorMessage += message["digit"]; if(symbol == true && symbolFlag == false) errorMessage += message["nonAlphaNumeric"]; // If the allowed list is defined, check whether the password contains only allowed chars if(allowedList.length > 0 && symbol == true){ for(var i=0; i= 'A' && password.charAt(i) <= 'Z') || (password.charAt(i) >= 'a' && password.charAt(i) <= 'z') || (password.charAt(i) >= '0' && password.charAt(i) <= '9') ) continue; // Skip alphanumeric chars if(allowedList.indexOf(password.charAt(i)) == -1){ if(errorMessage.length != len) errorMessage += "\n"; else errorMessage = ""; errorMessage += message["allowed"]; errorMessage += allowedList; break; } } } if(errorMessage.length != len){ alert(errorMessage); return false; } return true; } // Checks whether the parameter is a non negative integer function isNonNegativeInteger(val){ if(val == null) return false; if (val.length == 0) return false; for (var i = 0; i < val.length; ++i){ var ch = val.charAt(i); if (ch < '0' || ch > '9') return false; } return true; } // Checks whether the parameter is a positive integer. function isPositiveInteger(val){ if(val == null) return false; if (val.length == 0) return false; var flag = false; for (var i = 0; i < val.length; ++i){ var ch = val.charAt(i); if(ch > '0' && ch <= '9') flag = true; if (ch < '1' || ch > '9' ){ if (ch != '0') return false; else if(flag == false) return false; } } return true; } // Check whether the parameter is a positive integer with value > param2 function isGreater(val1, val2){ if(isNonNegativeInteger(val1) == false) return false; val1 = parseInt(val1, 10); val2 = parseInt(val2, 10); if(val1 > val2) return true; } // Check whether val1 > val2 function isGreater2(val1, val2){ if(!isPositiveInteger(val1) || !isPositiveInteger(val2)) return false; val1 = parseInt(val1, 10); val2 = parseInt(val2, 10); return (val1 > val2); } // Checks whether the parameter is a non negative integer, null allowed function checkValueAllowedEmpty(val){ if(val == null) return true; var value = trimWhitespace(val); if (value.length == 0) return true; var retval = isNonNegativeInteger(value); return retval; } //Checks if a value is empty or not function isEmptyValue(val) { if(val == null) return true; var value = trimWhitespace(val); if (value.length == 0) return true; return false; } // Function to validate inactivityPeriod function isValidInactivityPeriod() { if (isEmpty(document.serverConfigForm.inactivityPeriod)) { return true; } else { return (isGreater2(document.serverConfigForm.inactivityPeriod.value, "29")); } } // Validate daysBeforeFirstWarning function isValidDaysBeforeFirstWarning() { var inactivityPeriod = document.serverConfigForm.inactivityPeriod.value; var daysBeforeFirstWarning = document.serverConfigForm.daysBeforeFirstWarning.value; if (isEmpty(document.serverConfigForm.daysBeforeFirstWarning)) { return true; } else { if (isEmpty(document.serverConfigForm.inactivityPeriod)) { return isPositiveInteger(daysBeforeFirstWarning); } else { if(isPositiveInteger(daysBeforeFirstWarning) == false) { return false; } return ((parseInt(inactivityPeriod) == parseInt(daysBeforeFirstWarning)) || isGreater2(inactivityPeriod, daysBeforeFirstWarning)); } } } // Validate daysBeforeFinalWarning function isValidDaysBeforeFinalWarning() { var daysBeforeFirstWarning = document.serverConfigForm.daysBeforeFirstWarning.value; var daysBeforeFinalWarning = document.serverConfigForm.daysBeforeFinalWarning.value; if (isEmpty(document.serverConfigForm.daysBeforeFinalWarning)) { return true; } else { if (isEmpty(document.serverConfigForm.daysBeforeFirstWarning)) { return false; } return (isGreater2(daysBeforeFirstWarning, daysBeforeFinalWarning)); } } // Called from adminServerConfig.jsp->process(), validates several fields function validateFields(){ var i, j; if (isEmpty(document.serverConfigForm.administratorEmail)) { alert('The Administrator Email field must be entered'); document.serverConfigForm.administratorEmail.focus(); return false; } if(!isValidInactivityPeriod()) { alert('You cannot specify an expiration value less than 30 days'); document.serverConfigForm.inactivityPeriod.focus(); return false; } if(!isValidDaysBeforeFirstWarning()) { alert('Send first warning message before (in days) can be up to the inactivity period'); document.serverConfigForm.daysBeforeFirstWarning.focus(); return false; } if(!isValidDaysBeforeFinalWarning()) { alert('Send final warning message before (in days) cannot be greater than or equal to the inactivity period or Send first warning message before (in days)'); document.serverConfigForm.daysBeforeFirstWarning.focus(); return false; } if(!checkValueAllowedEmpty(document.serverConfigForm.daysToDeleteExpiredUsers.value)){ alert('Invalid value entered for delete expired users after (in days)'); document.serverConfigForm.daysToDeleteExpiredUsers.focus(); return false; } if(!isValidIPList(document.serverConfigForm.intranet.value)){ alert('Invalid value entered for intranet'); return false; } var isInvalidIntranetChunkSize = false; if (isEmpty(document.serverConfigForm.intranetChunkSize)) { if (!isEmpty(document.serverConfigForm.intranet)) { isInvalidIntranetChunkSize = true; // Value required if intranet has been defined } } else { if (!isGreater(document.serverConfigForm.intranetChunkSize.value, 0)) { isInvalidIntranetChunkSize = true; } } if (isInvalidIntranetChunkSize) { alert('Intranet chunk size must be a number with value 1 or higher'); return false; } if(!isGreater(document.serverConfigForm.defaultDaysBeforePurge.value, 0)){ alert('Days before purge must be a number with value 1 or higher'); return false; } if(!isNonNegativeInteger(document.serverConfigForm.defaultDaysBeforeWipe.value)){ alert('Invalid value entered for days before wipe'); return false; } if(!isGreater(document.serverConfigForm.defaultDaysBeforePurgeInProgress.value, 0)){ alert('Days before purge for in-progress files must be a number with value 1 or higher'); return false; } if(!isNonNegativeInteger(document.serverConfigForm.sessionTimeout.value)){ alert('Invalid value entered for session timeout'); return false; } if(!isGreater(document.serverConfigForm.sessionTimeout.value, 0)){ alert('Minimum allowed session timeout value is 1'); return false; } if(!isNonNegativeInteger(document.serverConfigForm.deliveryExpirationDays.value)){ alert('Invalid value entered for delivery expiration days'); return false; } if(!checkValueAllowedEmpty(document.serverConfigForm.logoWidth.value)){ alert('Invalid value entered for logo width'); return false; } if(!checkValueAllowedEmpty(document.serverConfigForm.logoHeight.value)){ alert('Invalid value entered for logo height'); return false; } if(!isNonNegativeInteger(document.serverConfigForm.packageFileUploadsPerPage.value)){ alert('Invalid value entered for file upload slots per page'); return false; } if(parseInt(document.serverConfigForm.packageFileUploadsPerPage.value, 10) > 10){ alert('File upload slots per page cannot be greater than 10'); return false; } if(!isNonNegativeInteger(document.serverConfigForm.logonAttemptsMax.value)){ alert('Invalid value entered for maximum sign in attempts'); return false; } if(!isNonNegativeInteger(document.serverConfigForm.passwordExpirationDays.value)){ alert('Invalid value entered for password expiration days'); return false; } if(!isNonNegativeInteger(document.serverConfigForm.passwordExpirationWarningDays.value)){ alert('Invalid value entered for password expiration warning days'); return false; } if(!isNonNegativeInteger(document.serverConfigForm.autoPackageDeletionDays.value)){ alert('Invalid value entered for auto package deletion days'); return false; } if(!isNonNegativeInteger(document.serverConfigForm.autoPackageDelReminderDays.value)){ alert('Invalid value entered for auto package deletion reminder days'); return false; } if(!isNonNegativeInteger(document.serverConfigForm.passwordResetAttemptsMax.value)){ alert('Invalid value entered for maximum password reset attempts'); return false; } if(!isNonNegativeInteger(document.serverConfigForm.passwordLengthMin.value)){ alert('Invalid value entered for minimum password length'); return false; } if(!isGreater(document.serverConfigForm.passwordLengthMin.value, 0)){ alert('Minimum allowed password length is 1'); return false; } if(!isNonNegativeInteger(document.serverConfigForm.passwordLengthMax.value)){ alert('Invalid value entered for maximum password length'); return false; } document.serverConfigForm.defaultDaysBeforePurge.value = parseInt(document.serverConfigForm.defaultDaysBeforePurge.value, 10); document.serverConfigForm.defaultDaysBeforeWipe.value = parseInt(document.serverConfigForm.defaultDaysBeforeWipe.value, 10); document.serverConfigForm.defaultDaysBeforePurgeInProgress.value = parseInt(document.serverConfigForm.defaultDaysBeforePurgeInProgress.value, 10); document.serverConfigForm.sessionTimeout.value = parseInt(document.serverConfigForm.sessionTimeout.value, 10); document.serverConfigForm.deliveryExpirationDays.value = parseInt(document.serverConfigForm.deliveryExpirationDays.value, 10); document.serverConfigForm.packageFileUploadsPerPage.value = parseInt(document.serverConfigForm.packageFileUploadsPerPage.value, 10); if (trimWhitespace(document.serverConfigForm.logoWidth.value).length > 0) { document.serverConfigForm.logoWidth.value = parseInt(document.serverConfigForm.logoWidth.value, 10); } if (trimWhitespace(document.serverConfigForm.logoHeight.value).length > 0) { document.serverConfigForm.logoHeight.value = parseInt(document.serverConfigForm.logoHeight.value, 10); } document.serverConfigForm.logonAttemptsMax.value = parseInt(document.serverConfigForm.logonAttemptsMax.value, 10); document.serverConfigForm.passwordExpirationDays.value = parseInt(document.serverConfigForm.passwordExpirationDays.value, 10); document.serverConfigForm.passwordExpirationWarningDays.value = parseInt(document.serverConfigForm.passwordExpirationWarningDays.value, 10); document.serverConfigForm.autoPackageDeletionDays.value = parseInt(document.serverConfigForm.autoPackageDeletionDays.value, 10); document.serverConfigForm.autoPackageDelReminderDays.value = parseInt(document.serverConfigForm.autoPackageDelReminderDays.value, 10); document.serverConfigForm.passwordResetAttemptsMax.value = parseInt(document.serverConfigForm.passwordResetAttemptsMax.value, 10); i = parseInt(document.serverConfigForm.passwordLengthMin.value, 10); j = parseInt(document.serverConfigForm.passwordLengthMax.value, 10); document.serverConfigForm.passwordLengthMin.value = i; document.serverConfigForm.passwordLengthMax.value = j; if(i > 50 || j > 50){ alert('Password length cannot be greater than 50'); return false; } if(i > j){ alert('Minimum password length cannot be greater than maximum password length'); return false; } var str = document.serverConfigForm.customHelpUrl.value; str = str.replace(/ /g, ""); if((str.indexOf("\">") != -1) || (str.indexOf("\'>") != -1)){ alert('Illegal text entered for custom help URL'); return false; } return true; } function frameBuster() { if (top.frames.length != 0) { top.location=self.document.location; } } function gotoUrl(url) { location.href=url; } function textCounter(field, max) { if (field.value.length > max) field.value = field.value.substring(0, max); } // Get the current time and format it as HH:MM:SS AM|PM function getCurrentTime() { var now = new Date(); var hours = now.getHours(); var ampm = "AM"; if (hours > 12) { hours = hours - 12; ampm = "PM"; } var minutes = now.getMinutes(); if (minutes < 10) { // minutes below 10 are sent back as "1, 2, 3, ... 9" minutes = "0" + minutes; } var seconds = now.getSeconds(); if (seconds < 10) { // seconds below 10 are sent back as "1, 2, 3, ... 9" seconds = "0" + seconds; } var currentTime = "(" + hours + ":" + minutes + ":" + seconds + " " + ampm + ")"; return currentTime; } // Remove leading and trailing whitespace from a string function trimWhitespace(string) { if (string == null) { return ''; } var newString = ''; var substring = ''; beginningFound = false; // copy characters over to a new string // retain whitespace characters if they are between other characters for (var i = 0; i < string.length; i++) { // copy non-whitespace characters if (string.charAt(i) != ' ' && string.charCodeAt(i) != 9) { // if the temporary string contains some whitespace characters, copy them first if (substring != '') { newString += substring; substring = ''; } newString += string.charAt(i); if (beginningFound == false) beginningFound = true; } // hold whitespace characters in a temporary string if they follow a non-whitespace character else if (beginningFound == true) substring += string.charAt(i); } return newString; } /* Cookie Functions */ // For now, the username is the email address -- so read the stored email and insert into the username field. function cookieReadUsername(emailAddress, domainName) { var allCookies = document.cookie; var pos = allCookies.indexOf("email="); if (pos != -1) { var start = pos + 6; var end = allCookies.indexOf(";", start); if (end == -1) { end = allCookies.length; } var value = unescape(allCookies.substring(start, end)); var domainNameValue = ""; var setChecked = false; if (value.length > 0) { // Get the stored domain name var storedDomainName = ""; pos = allCookies.indexOf("domain="); if (pos != -1) { start = pos + 7; end = allCookies.indexOf(";", start); if (end == -1) { end = allCookies.length; } storedDomainName = unescape(allCookies.substring(start, end)); } // If the username is not null, then the remember me checkbox was checked // previously, so check it again. // If the user is coming from a delivery notification link, must first // check to see if the delivery user is the same as the "saved" user in // cookie. If so, then set the rememberMe checkbox to true, otherwise set it to false. // Domain name follows the same logic. Use stored domain name for all cases except // when coming from delivery notification link. if ((arguments.length > 0) && (emailAddress.length > 0) && (emailAddress.toLowerCase() != value.toLowerCase())) { setChecked = false; document.forms[0].username.value = emailAddress; domainNameValue = domainName; } else { setChecked = true; document.forms[0].username.value = value; domainNameValue = storedDomainName; } } // Set the domain name if the domain field is displayed if (document.forms[0].displayDomainName.value == "Y") { document.forms[0].domain.value = domainNameValue; } // Set the checkbox value document.forms[0].elements["rememberMe"].checked = setChecked; if ((value.length > 0) || (emailAddress.length > 0)) { // If username is filled in, then focus on the password field. var focusControl = document.forms[0].elements["password"]; if (focusControl.type != "hidden" && !focusControl.disabled) { focusControl.focus(); } } } } // Store the username as the "email address" for now -- because we are storing the email address from the registration page function cookieStoreUsername() { var expiresDate = new Date(2050, 11, 31); var username = document.forms[0].username.value; document.cookie = "email=" + escape(username) + "; expires=" + expiresDate; // Store the domain value var domainName = ""; if (document.forms[0].displayDomainName.value == "Y") { domainName = document.forms[0].domain.value; } document.cookie = "domain=" + escape(domainName) + "; expires=" + expiresDate; } function cookieStoreEmail() { var expiresDate = new Date(2050, 11, 31); var email = document.forms[0].email.value; document.cookie = "email=" + escape(email) + "; expires=" + expiresDate; } function cookieRemoveEmail() { var expiresDate = new Date(1999, 12, 31); document.cookie = "email=; expires=" + expiresDate; document.cookie = "domain=; expires=" + expiresDate; } function cookieStoreSecureCheckbox() { var expiresDate = new Date(2010, 11, 31); var secureChecked = "unchecked"; if (document.forms[0].secure.checked) { secureChecked = "checked"; } document.cookie = "secureChecked=" + secureChecked + "; expires=" + expiresDate; } function cookieReadSecureCheckbox() { var allCookies = document.cookie; var pos = allCookies.indexOf("secureChecked="); if (pos != -1) { var start = pos + 14; var end = allCookies.indexOf(";", start); if (end == -1) { end = allCookies.length; } var value = allCookies.substring(start, end); if (value == 'checked') { document.forms[0].secure.checked = true; } else { document.forms[0].secure.checked = false; } } } function cookieReadEmail() { var allCookies = document.cookie; var pos = allCookies.indexOf("email="); if (pos != -1) { var start = pos + 6; var end = allCookies.indexOf(";", start); if (end == -1) { end = allCookies.length; } var value = unescape(allCookies.substring(start, end)); document.forms[0].email.value = value; if (value.length > 0) { var focusControl = document.forms[0].elements["password"]; if (focusControl.type != "hidden" && !focusControl.disabled) { focusControl.focus(); } } } } /* Validation Functions */ function isValidPositiveNumber(x) { var anum=/(^\d+$)|(^\d+\.\d+$)/ if (anum.test(x)) testresult=true else{ testresult=false } return (testresult) } function isEmpty(aTextField) { if ((aTextField.value.length==0) || (aTextField.value==null)) { return true; } else { return false; } } function validatePassword(p1, p2) { /* if ((p1.value.length < 1) && (p2.value.length < 1)) { alert('Passwords cannot be blank'); return false; } */ if (p1.value != p2.value) { alert('Passwords do not match'); return false; } return true; } function isValidPassword(password1, password2, min, max) { var msg = ""; if (password1 != password2) { msg += "\n - " + 'Passwords do not match'; } if ((password1.length < min) || (password2.length < min) || (password1.length > max) || (password2.length > max)) { msg += "\n - " + String.format("Passwords must be between {0} and {1} characters long", min, max); } return msg; } // Check that an email address is valid based on RFC 821 (?) function isValidEmail(address) { if (address != '' && address.search) { if (address.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true; else return false; } // allow empty strings to return true - screen these with either a 'required' test or a 'length' test else return true; } // Check that an email address has the form something@something.something // This is a stricter standard than RFC 821 (?) which allows addresses like postmaster@localhost function isValidEmailStrict(address) { if (isValidEmail(address) == false) return false; var domain = address.substring(address.indexOf('@') + 1); if (domain.indexOf('.') == -1) return false; if (domain.indexOf('.') == 0 || domain.indexOf('.') == domain.length - 1) return false; return true; } function checkEmail (strng) { var error=""; if (strng == "") { error = "\n - " + 'The Email Address field must be entered'; } var emailFilter=/^.+@.+\..{2,4}$/; if (!(emailFilter.test(strng))) { error = "\n - " + 'The Email Address field is not valid'; } else { //test email for illegal characters var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ if (strng.match(illegalChars)) { error = "\n - " + 'The Email Address field contains illegal characters'; } } return error; } function getInvalidEmails(strEmails) { var invalid = null; if (strEmails != null) { var inData = strEmails.value; if (inData.length != 0) { /* extract all valid recognizable emails */ var emails = inData.match(/([a-zA-Z'0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi); /* and the remainings */ var remains = inData; if (emails != null) { for (var i=0; i -1) || (value.indexOf('/') > -1) || (value.indexOf('<') > -1) || (value.indexOf('>') > -1) || (value.indexOf('[') > -1) || (value.indexOf(']') > -1) || (value.indexOf(':') > -1) || (value.indexOf(';') > -1) || (value.indexOf('|') > -1) || (value.indexOf('=') > -1) || (value.indexOf(',') > -1) || (value.indexOf('+') > -1) || (value.indexOf('*') > -1) || (value.indexOf('?') > -1) || (value.indexOf('@') > -1)) { msg = invalidGroupNameMsg; alert(msg); return false; } return true; } // Check to see if the user has selected any files to delete function validatePackageDeleteFiles(theForm) { var docIdArray = theForm.documentIdArray; var atLeastOneSelected = false; if (typeof docIdArray.length != "number") { // Only one checkbox -- check for that if (docIdArray.checked == true) { atLeastOneSelected = true; } } else { // More than one checkbox -- can loop through array for (var i=0; i < docIdArray.length ; i++ ) { if (docIdArray[i].checked == true) { atLeastOneSelected = true; } } } if (!atLeastOneSelected) { alert('Please select at least one file to delete to continue'); } return atLeastOneSelected; } // Check to see if the user has selected at least one check box function checkAtLeastOne(checkboxes, msg) { var atLeastOneSelected = false; if (typeof checkboxes.length != "number") { // Only one checkbox -- check for that if (checkboxes.checked == true) { atLeastOneSelected = true; } } else { // More than one checkbox -- can loop through array for (var i=0; i < checkboxes.length ; i++ ) { if (checkboxes[i].checked == true) { atLeastOneSelected = true; } } } if (!atLeastOneSelected) { alert(msg); } return atLeastOneSelected; } // Check to see if Dropdown Box is empty function validateDropdownBox(dItem, msg) { if (dItem.selectedIndex == -1) { alert(msg); return false; } else { return true; } } function validateDelivery(theForm) { var why = ""; var restrictedFiles = ""; if (isEmpty(theForm.recipientsTo) && isEmpty(theForm.recipientsCc) && isEmpty(theForm.recipientsBcc)) { why += "\n - " + 'At least one email must be entered'; } else { // var invalidTo = getInvalidEmails(theForm.recipientsTo); // if (invalidTo != null) { // why += "\n - " + 'Please correct or remove the following invalid recipient email addresses in the To field:'; // for (var i=0; i d2) { why += "\n - " + 'Expiration date occurs before available date'; } } restrictedFiles = checkRestrictedFilesJS(theForm); if (restrictedFiles != "") { why += restrictedFiles; } if (why != "") { why = 'There are problems with your delivery:' + why; alert(why); return false; } else { return true; } } /* Check for restricted files to be uploaded in a form Author - Shahed */ function checkRestrictedFilesJS(theForm) { var restrictedFiles = ""; for (var i=0; i') { retval += '>'; } else if (c == '&') { retval += '&'; } else if (c == '\'' ) { retval += '''; } else if (c == '"') { retval += '"'; } else { retval += c; } } return(retval); } function previewDelivery(appName) { var srcDelivery = document.forms[0]; // put focus on the new popup window preWin = window.open('', 'DeliveryPreview', 'height=400,width=550,resizable,scrollbars,status'); preWin.focus(); var preDoc = preWin.document; var htmlContent = "\n"; var subjectLine = fdsEscape(srcDelivery.name.value); htmlContent += "\n" + subjectLine + "\n"; htmlContent += "\n"; // onlbur will close the popup window htmlContent += "\n\n

\n"; // onblur='window.close()'>\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "
Close
\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n"; htmlContent += "\n" htmlContent += "\n\n\n"; htmlContent += "
From: " + fdsEscape(srcDelivery.fromAddress.value) +"
To: " + fdsEscape(srcDelivery.recipientsTo.value) +"
Cc: " + fdsEscape(srcDelivery.recipientsCc.value) +"
Bcc: " + fdsEscape(srcDelivery.recipientsBcc.value) +"
Subject: " + subjectLine + "
\n
\n"; // message body var message = fdsEscape(srcDelivery.message.value); var re = new RegExp ('\n', 'gi') ; message = message.replace(re, '
'); htmlContent += message; htmlContent += "

\n"; // Sender htmlContent += "Sender: " + fdsEscape(srcDelivery.senderInfo.value) + "\n"; htmlContent += "
\n"; // Link htmlContent += "Link: " + fdsEscape(srcDelivery.deliveryLink.value) + "\n"; htmlContent += "


\n"; htmlContent += fdsEscape(srcDelivery.permanentMessage.value) + "\n"; htmlContent += "
\n
\n"; // footer htmlContent += "
Close
* The URL link in this preview is an example only -- it is not the actual link sent to recipients
\n"; htmlContent += "\n"; htmlContent += "\n"; preDoc.write(htmlContent); preDoc.close(); } function openJsp(jspURL, title) { // put focus on the new popup window preWin = window.open(jspURL, title, 'height=500,width=600,resizable,scrollbars,status'); preWin.focus(); } function moreLess(layer, text) { var obj; obj = document.getElementById(layer); if (obj != null && obj.style.display == "none") { obj.style.display = "block"; } else { obj.style.display = "none"; } obj = document.getElementById(text); if (obj != null && obj.innerHTML == "+") { obj.innerHTML = "-"; } else { obj.innerHTML = "+"; } } function toggleSelect(arr, value) { if (arr) { if (typeof arr.length == "number") { for (var i = 0; i < arr.length; i ++) { if (! arr[i].disabled) { // no op on disabled arr[i].checked = value; } } } else { if (! arr.disabled) { // no op on disabled arr.checked = value; } } } } function uncheckCheckAll(checkAll, value) { if (checkAll && !value) { checkAll.checked = value; } } // Take in the two sizes (shrunk and expanded) and toggle the size between the two sizes function resizeDeliveryField(form, element, rows_shrunk, rows_expanded) { if (element == form.recipientsTo) { form.recipientsTo.rows = (form.recipientsTo.rows == rows_shrunk)?rows_expanded:rows_shrunk; } else if (element == form.recipientsCc) { form.recipientsCc.rows = (form.recipientsCc.rows == rows_shrunk)?rows_expanded:rows_shrunk; } else if (element == form.recipientsBcc) { form.recipientsBcc.rows = (form.recipientsBcc.rows == rows_shrunk)?rows_expanded:rows_shrunk; } else if (element == form.name) { form.name.rows = (form.name.rows == rows_shrunk)?rows_expanded:rows_shrunk; } else if (element == form.secureMessage) { form.secureMessage.rows = (form.secureMessage.rows == rows_shrunk)?rows_expanded:rows_shrunk; } else if (element == form.message) { form.message.rows = (form.message.rows == rows_shrunk)?rows_expanded:rows_shrunk; } } ///////////////AJAX // Timestamp of cart that page was last updated with var lastUpdateTime = 0; var req; /* * Returns a new XMLHttpRequest object, or false if the browser * doesn't support it */ function newXMLHttpRequest() { var xmlreq = false; // Create XMLHttpRequest object in non-Microsoft browsers if (window.XMLHttpRequest) { /* if (typeof XMLHttpRequest != 'undefined') { */ xmlreq = new XMLHttpRequest(); } else if (window.ActiveXObject) { try { // Try to create XMLHttpRequest in later versions of Internet Explorer xmlreq = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e1) { // Failed to create required ActiveXObject try { // Try version supported by older versions of Internet Explorer xmlreq = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e2) { // Unable to create an XMLHttpRequest by any means xmlreq = false; } } } return xmlreq; } //var reqMessage; /* * Returns a function that waits for the specified XMLHttpRequest * to complete, then passes it XML response to the given handler function. * * req - The XMLHttpRequest whose state is changing * responseXmlHandler - Function to pass the XML response to */ function getReadyStateHandler_ob(req, responseXmlHandler, id, v1, v2, v3) { //reqMessage += "state: " + req.readyState + "\n"; // If the request's status is "complete" if (req.readyState == 4) { // Check that we received a successful response from the server if (req.status == 200) { /* alert(req.getAllResponseHeaders()); */ // Pass the XML payload of the response to the handler function. responseXmlHandler(id, v2, v3); //alert(reqMessage); } else { // An HTTP problem has occurred alert("HTTP error "+req.status+": "+req.statusText); } } else if (req.readyState == 1) { document.getElementById(id).innerHTML = v1; } } /* * Adds the specified item to the shopping cart, via Ajax call * itemCode - product code of the item to add */ function processStatus_ob(method, svrName, id, v1, v2, v3) { var url = "/" + svrName + "/AdminProcessSubmit.do?method=" + method; req = newXMLHttpRequest(); //alert(req); //reqMessage = ""; // Open a connection to the server req.open("POST", url, true); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // Return an anonymous function that listens to the XMLHttpRequest instance req.onreadystatechange = function() { getReadyStateHandler_ob(req, updateProcessStatus_ob, id, v1, v2, v3); }; // Send the request req.send(null); } /* * Update shopping-cart area of page to reflect contents of cart * described in XML document. */ function updateProcessStatus_ob(id, v2, v3) { var contact = req.responseXML.getElementsByTagName("contact")[0]; var generated = contact.getAttribute("generated"); if (generated > lastUpdateTime) { var tagName, content, value; for (var i=0; i\n"; } opContent += "Start\n"; if (bStartClickable) { opContent += "\n"; } opContent += "  \n"; if (bStopClickable) { opContent += "\n"; } opContent += "Stop\n"; if (bStopClickable) { opContent += "\n"; } return opContent; } /* * Returns a function that waits for the specified XMLHttpRequest * to complete, then passes it XML response to the given handler function. * * req - The XMLHttpRequest whose state is changing * responseXmlHandler - Function to pass the XML response to */ function getReadyStateHandler(req, responseXmlHandler, mthdName, svrName, idTimer, idOperations) { if (req.readyState == 4) { if (req.status == 200) { responseXmlHandler(mthdName, svrName, idTimer, idOperations); } else { alert("HTTP error "+req.status+": "+req.statusText); } } else if (req.readyState == 1) { document.getElementById(idTimer).innerHTML = "please wait..."; document.getElementById(idOperations).innerHTML = startStopIcons(false, false, mthdName, svrName, idTimer, idOperations); } } function processStatus(mthdName, svrName, idTimer, idOperations) { var url = "/" + svrName + "/AdminProcessSubmit.do?method=" + mthdName; req = newXMLHttpRequest(); req.open("POST", url, true); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.onreadystatechange = function() { getReadyStateHandler(req, updateProcessStatus, mthdName, svrName, idTimer, idOperations); }; req.send(null); } function updateProcessStatus(mthdName, svrName, idTimer, idOperations) { var contact = req.responseXML.getElementsByTagName("contact")[0]; var generated = contact.getAttribute("generated"); if (generated > lastUpdateTime) { var tagName, content, value; for (var i=0; i 0) { var patterns = expression.split(DELIMETER_AND); var isMatch = true; for (var j = 0; j < patterns.length; j++) { var pattern = patterns[j].trim(); var isApplyNot = false; // Check if the string starts with "not" var callingPattern = ""; if (startsWith(pattern, START_WITH_NOT) || startsWith(pattern, START_WITH_NOT.toLowerCase())) { isApplyNot = true; callingPattern = pattern.substring(4).trim(); } else { callingPattern = pattern; } var regex = convertWildcardToRegex(callingPattern); // Check if the string matches the pattern //var result = cmpStr.match(regex); //if (isApplyNot) { // result = !result; //} //if (!result || !(result == cmpStr)) { // isMatch = false; // Missmatch for one pattern, thats why turn "isMatch" to false // break; //} var result = cmpStr.match(regex); var boolResult = false; if (result != null && (result == cmpStr)) { boolResult = true; } if (isApplyNot) { boolResult = !boolResult; } if (!boolResult) { isMatch = false; // Missmatch for one pattern, thats why turn "isMatch" to false break; } } if (isMatch) { //document.write("Pattern matches
"); //alert(msg); //inp1.value = ""; return true; } } } //document.write("Didn't find matched pattern!
"); return false; } function getFieldValue(field, defaultValue) { if (field == null) { return defaultValue; } else { return field.checked; } } /** * Checks the validity of IP address * * @param ip address with subnet mask like 122.32.34.32/32 * @return true if IP is valid */ function isValidIP (ipValue) { var ipPattern = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\/(\d{1,5})$/; var ipArray = ipValue.match(ipPattern); if (ipArray == null ) return false; // check ip adress 0.0.0.0 which is invalid else if (ipValue.match("0.0.0.0") == "0.0.0.0") return false; // check ip adress 255.255.255.255 which is invalid else if (ipValue.match("255.255.255.255") == "255.255.255.255") return false; else { for (i = 0; i < 5; i++) { thisSegment = ipArray[i]; if (isGreater(thisSegment,255)) { return false; } } } // all checking passed so valid ip address return true; } /** * Checks if the IP array list is valid * * @param ipArrayStr(comma separated multiple ip) like 122.32.34.32/32,122.32.24.12/64 * @return true if the array list is valid */ function isValidIPList(ipArrayStr) { var ipArraySpace = ipArrayStr.split(" "); // first spliting with space for (var i = 0 ; i < ipArraySpace.length ; i++){ // now spliting with comma var ipArrayComma = ipArraySpace[i].split(","); for(var j = 0 ; j < ipArrayComma.length ; j++){ if(ipArrayComma[j]!="" && !isValidIP(ipArrayComma[j])) return false; } } return true; }