/* * convertError() * * this function generates an error message based on the passed parameters, and returns * the resulting string. * parameters: * msg -- a format specifier * any other parameters -- message arguments * * the format specifier takes a string and inserts the values of the corresponding message * arguments. insertion order is determined by positional arguments within the format * specifier -- %0 corresponds to the first argument. There is no upper limit to argument * numbers. * * A positional argument is defined as '%' + number + (' ' | '%') * Valid positional arguments: * "%0" "%0 text" "text%0" "%0%" "%0%1" etc... * * example: * convertError("%0 and %1", "this", "that") ==> "this and that" * convertError("%1 and %0", "this", "that") ==> "that and this" * convertError("%another%1", "test") ==> "%anothertest" */ function convertError(msg) { var i; // Find out how many "extra" arguments were passed in var numArgs = arguments.length - Function.length; // split the msg at each "%". var msgParts = msg.split("%"); /* * if the string started with a "%", then the first msgPart will be blank * otherwise, the string started with something else, and the first msgPart * will contain that something else. Regardless, don't process that first * msgPart */ var newMsg = msgParts[0]; for(i = 1; i < msgParts.length; i++) { // split the part at the first non-digit var spaceIdx = 0; var nextChar = msgParts[i].charAt(spaceIdx); while (nextChar >= '0' && nextChar <= '9' && spaceIdx <= msgParts[i].length) { spaceIdx++; nextChar = msgParts[i].charAt(spaceIdx); } var numberPart = msgParts[i].substring(0, spaceIdx); // we want to keep the space... var stringPart = msgParts[i].substring(spaceIdx); // convert the first chunk into a number idx = parseInt(numberPart); // if is not a valid number if (isNaN(idx)) { // add the % and the chunk back into the newMsg newMsg += "%" + numberPart; } else { // if idx is within range if ((idx < numArgs) && (idx >= 0)) { newMsg += arguments[Function.length + idx]; } else { newMsg += "%" + numberPart; } } newMsg += stringPart; } //workaround to generate properly when the error message ends with a ? or ) or . if ((newMsg.charAt(newMsg.length - 1) != '.') && (newMsg.charAt(newMsg.length - 2) != ')') && (newMsg.charAt(newMsg.length - 1) != '?')) { newMsg += "."; } return newMsg; } // VALIDATE FORM function genericVal(frm) { var elementcount = frm.elements.length; var obj =null; for(var i=0; i< elementcount; i++) { obj = frm.elements[i]; if( obj.required != null && obj.required.toString() == "true" && !isValidEntry(obj)) { if (obj.label != null && obj.label != "") { alert( convertError("\"%0\" is a required field. Please ensure information exists in this field.", obj.label) ); } obj.focus(); select(obj); return false; } else if (obj.min != null && obj.max != null && obj.min != "" && obj.max != "") { if (!isInRange(obj.min, obj, obj.max)) { if (obj.label != null && obj.label != "") { alert( convertError("The value of \"%0\" must be between %1 and %2. Please enter a new range.", obj.label, obj.min, obj.max) ); } obj.focus(); select(obj); return false; } else if (obj.isNumber != null && obj.isNumber.toString() == "true" && !isNumber(obj)) { if (obj.label != null && obj.label != "") { alert( convertError("Entry %0 must be a number. Please enter a number.", obj.label) ); } obj.focus(); select(obj); return false; } } else if (obj.maxLen != null && obj.maxLen < obj.value.length) { if (obj.label != null && obj.label != "") { alert( convertError("The maximum %0 size is %1 characters.", obj.label, obj.maxLen) ); } obj.focus(); select(obj); return false; } else if(obj.isPhone != null && obj.isPhone.toString() == "true" && !isPhoneNumber(obj) && obj.value != "") { if (obj.label != null && obj.label != "") { phonePat = "(123) 456-7890" alert( convertError("\"%0\" is not a valid telephone number. Use the following format: %1.", obj.label, phonePat) ); } obj.focus(); select(obj); return false; } else if( obj.isEmail != null && obj.isEmail.toString() == "true" && !isEmail(obj) && obj.value != "") { if (obj.label != null && obj.label != "") { var emailPat = "abc@xyz.com"; alert( convertError("\"%0\" is not a valid e-mail address. Use the following format: %1.", obj.label, emailPat) ); } obj.focus(); select(obj); return false; } } return true; } function isNumber(obj) { var _this = (obj==null)?this:obj; // get object reference var _value = ""; if( String(typeof(_this)).toUpperCase()=="OBJECT" ) { var objType = String(_this.type).toUpperCase(); if( objType=="TEXT" || objType=="TEXTAREA" || objType=="HIDDEN" ) { _value = obj.value.toString(); } } else { // treat is as a string _value = obj; } var valid = "0123456789"; var ok = true; var temp; for (var i=0; i < _value.length; i++) { temp = "" + _value.substring(i, i+1); if (valid.indexOf(temp) == "-1") ok = false; } return ok; } // Date format check function isDate(obj) { // get object reference var _this = (obj == null) ? this : obj; if (String(typeof(_this)).toUpperCase() == "OBJECT") { var objType = String(_this.type).toUpperCase(); var data; if (objType=="TEXT" || objType=="TEXTAREA" || objType=="HIDDEN") { data = obj.value; } else { data = obj; } /* * Format: m/d/yyyy * Rules: 1 <= m <= 12, * 1 <= d <= 28,29,30,31 (depending on m and y) * 1900 < y < Whatever */ var sl1 = data.indexOf('/'); var sl2 = data.indexOf('/', sl1 + 1); var mStr = data.substring(0, sl1); var dStr = data.substring(sl1 + 1, sl2); var yStr = data.substring(sl2 + 1); if (yStr.length != 4) { return false; } var m = parseInt(mStr, 10); var d = parseInt(dStr, 10); var y = parseInt(yStr, 10); // make sure month is a number and is within range if (isNaN(m) || m < 1 || m > 12) { return false; } // make sure that year is a number and is within range if (isNaN(y) || y < 1900) { return false; } // month lengths: var daysInMonth = new Array(31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); // set Feb. according to leap-year rules... /* this reads as: * if the year is divisible by 4 but not 100, then it's a leap year. * if the year is divisible by 4, 100 and 400, then it's a leap year. Otherwise, not. */ daysInMonth[1] = (y % 4 == 0) ? (y % 100 == 0) ? (y % 400 == 0) ? 29 : 28 : 29 : 28; // finally, make sure that month is a number and is in the proper range return !isNaN(m) && m >= 1 && d <= daysInMonth[m - 1]; } alert ("Error\nObject type unknown."); return false; } function isExisting(obj) { var _this = (obj==null)?this:obj; // get object reference if ( String(typeof(_this)).toUpperCase()=="OBJECT" ) { var objType = String(_this.type).toUpperCase(); // check to see if array objType = ( objType=="UNDEFINED" )?String(obj[0].type).toUpperCase():objType; if( objType=="UNDEFINED" ) { // do nothing } else if( objType=="TEXT" || objType=="TEXTAREA" ) { return ( obj.value!="" && obj.value!=null && String(obj.value).match(/\S/gi) )?true:false; } else if(objType == "SELECT-ONE" || objType == "SELECT-MULTIPLE") { for (var j = 0; j < _this.options.length; j++) { if (_this.options[j].selected && _this.options[j].value != null && _this.options[j].value != "") { return true; } } return false; } else if ( objType=="RADIO" || objType=="CHECKBOX" ) { var ret = false; for(var i=0; i 0); } else { return false; } } else if (objType == "SELECT-MULTIPLE") { return _this.length > 0; } else if (objType == "RADIO" || objType == "CHECKBOX") { var ret = false; for (var i = 0; i < obj.length; i++) { ret = (obj[i].checked) ? true : ret; } return ret; } } else { // treat it as a string return obj != "" && obj != null && String(obj).match(/\S/gi); } alert("Error\nObject type unknown."); return false; } // NUMERIC function isNumeric(obj) { var _this = (obj==null)?this:obj; // get object reference if (_this.value != null) { return !isNaN(parseInt(_this.value)); } else { return !isNaN(parseInt(_this)); } } // ALPHA function isAlpha(obj) { var _this = (obj==null)?this:obj; // get object reference if (String(typeof(_this)).toUpperCase()=="OBJECT") { var objType = String(_this.type).toUpperCase(); if (objType=="TEXT" || objType=="TEXTAREA") { return obj.value!="" && obj.value!=null && String(obj.value).match(/^\w*$/); } } else { //treat it as a string return obj!="" && obj!=null && String(obj).match(/^\w*$/gi); } alert("Error\nObject type unknown."); return false; } // LENGTH CHECK function isWithinLength(obj,len) { // get object reference var _this = (obj==null)?this:obj; if (String(typeof(_this)).toUpperCase()=="OBJECT" && (_this.value).length!=null) { return _this.value.length <= len; } else { // treat it as a string return obj.length <= len; } alert("Error\nObject type unknown."); return false; } // EMAIL FORMAT CHECK function isEmail(obj) { var _this = (obj==null)?this:obj; // get object reference if (String(typeof(_this)).toUpperCase()=="OBJECT") { var objType = String(_this.type).toUpperCase(); if (objType=="TEXT" || objType=="TEXTAREA") { return obj.value!="" && obj.value!=null && String(obj.value).match(/\b(^(\S+@).+((\...)|(\....)|(\..{2,2}))$)\b/gi); } } else { //treat it as a string return obj.value!="" && obj.value!=null && String(obj.value).match(/\b(^(\S+@).+((\...)|(\....)|(\..{2,2}))$)\b/gi); } alert("Error\nObject type unknown."); return false; } //PHONE NUMBER FORMAT CHECK function isPhoneNumber(obj) { var _this = (obj==null)?this:obj; // get object reference if (String(typeof(_this)).toUpperCase()=="OBJECT") { var objType = String(_this.type).toUpperCase(); if (objType=="TEXT" || objType=="TEXTAREA") { return obj.value!=null && obj.value!="" && String(obj.value).match(/\(\d{3}\) \d{3}-\d{4}$/g); } } else { //treat it as a string return obj.value!=null && obj.value!="" && String(obj).match(/\(\d{3}\) \d{3}-\d{4}$/g); } alert("Error\nObject type unknown."); return false; } // RANGE CHECK function isInRange(obj1,obj2,obj3) { if (isNumeric(obj2)) { if (isNull(obj1) && isNumeric(obj3)) { return getNumber(obj2) <= getNumber(obj3); } if (isNull(obj3) && isNumeric(obj1)) { return getNumber(obj2) >= getNumber(obj1); } if (isNull(obj1) && isNull(obj3)){ return isNumeric(obj2); } if (isNumeric(obj1) && isNumeric(obj3)) { return ((getNumber(obj2) >= getNumber(obj1)) && (getNumber(obj2) <= getNumber(obj3))); } } return false; } // AUXILLIARY FUNCTION FOR isInRange() function getNumber(obj) { var _this = (obj==null)?this:obj; // get object reference if (String(typeof(_this)).toUpperCase()=="OBJECT") { var objType = String(_this.type).toUpperCase(); if (objType=="TEXT" || objType=="TEXTAREA" || objType=="HIDDEN") { return parseFloat(obj.value.toString()); } } else { // treat is as a string return parseFloat(obj); } alert("Error\nObject type unknown."); return false; } // AUXILLIARY FUNCTION FOR isInRange() function isNull(obj) { var _this = obj; // get object reference if (_this == null) { return true; } if (String(typeof(_this)).toUpperCase()=="OBJECT") { var objType = String(_this.type).toUpperCase(); if( objType=="TEXT" || objType=="TEXTAREA" || objType=="HIDDEN") { return (obj.value.toString().toUpperCase() == "NULL") || (obj.value==null); } } else { // treat is as a string return (obj == null)?true:false; } return false; } // POPUP ACCESSORIES WINDOW function popupAccessoriesWin() { var page="/y_accessories"; var myString = document.URL; var before = myString.substr(0, myString.lastIndexOf('/')); var result = ""; if(myString.indexOf('?') > 0) { result = myString.substr(myString.indexOf('?'), myString.length); } page = before + page + result; window.open(page, "AccessoryWin","toolbar=no,menubar=no,status=no,location=no,directories=no,titlebar=no,copyhistory=no,resizable=no,scrollbars=yes,width=750,height=500"); } // Popup Window for 5.0.0 Carrier UI - Aug 16/02 Martin Barnes function popupCarrierWin( URL, name, width, height, chrome, scroll ) { if (chrome == "no" && scroll == "no") { window.open(URL, name,'width='+width+',height='+height); } else if ( chrome == "no" && scroll == "yes" ) { window.open(URL, name,'scrollbars,width='+width+',height='+height); } else if ( chrome == "yes" && scroll == "no" ) { window.open(URL, name,'status,toolbar,location,width='+width+',height='+height); } else if ( chrome == "yes" && scroll == "yes" ) { window.open(URL, name,'status,toolbar,location,scrollbars,width='+width+',height='+height); } } function formatPhone(obj) { // Make sure that I know how to talk to the object if (!obj.value) { return; } var oldVal = obj.value; //remove everything except digits inculding white space var newVal = ""; for (var i = 0; i < oldVal.length; i++) { if (oldVal.charAt(i) >= '0' && oldVal.charAt(i) <= '9') { newVal += oldVal.charAt(i); } } if (newVal.length == 0) { return; } var areaCode = ""; var firstPart = ""; var lastPart = ""; if (newVal.length > 3) { areaCode = newVal.substring(0, 3); newVal = newVal.substring(3); if (newVal.length > 3) { firstPart = newVal.substring(0, 3); newVal = newVal.substring(3); lastPart = newVal; } else { firstPart = newVal; } } else { areaCode = newVal; } obj.value = '(' + areaCode + ') ' + firstPart + '-' + lastPart; obj.isPhone='true'; } // Select the object on the html page, but only if it understands the "select" method function select(obj) { if (obj.select) { obj.select(); } } // Rollover functions function MM_swapImgRestore() { //v3.0 var i; var x; var a = document.MM_sr; for (i = 0; a && i < a.length && ( x = a[i]) && x.oSrc; i++) { x.src = x.oSrc; } } function MM_preloadImages() { //v3.0 var d = document; if (d.images) { if (!d.MM_p) { d.MM_p = new Array(); } var i; var j = d.MM_p.length; var a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++) { if (a[i].indexOf("#")!=0) { d.MM_p[j] = new Image; d.MM_p[j++].src=a[i]; } } } } function MM_findObj(n, d) { //v3.0 var p; var i; var 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 < d.forms.length; i++) { x = d.forms[i][n]; } for (i = 0; !x && d.layers && i < d.layers.length; i++) { x = MM_findObj(n, d.layers[i].document); } return x; } function MM_swapImage() { //v3.0 var i; var j = 0; var x; var a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3) { if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) { x.oSrc = x.src; } x.src = a[i + 2]; } } } // THIS FUNCTION IS TO CONFIRM AN ITEM DELETION. function confirmAnItemDeletion(item) { return confirm( convertError("Are you sure you want to delete \"%0\"?", item)); } // THIS FUNCTION IS TO CONFIRM ADDRESS BOOKS DELETION. function confirmAddressBookDeletion(items) { if (items == null || items == "") { return alert( convertError("There is no item to delete.")); } else { return confirm( convertError("Are you sure that you want to remove the following contact(s) from your Address Book? %0",items)); } } function confirmPopTemplate() { return alert( convertError("You are creating a new design. Use the choose button to select an existing plan template.")); } // ALERT USER OF PRICING MODEL CHANGES function alertAdditionOfPricingModel() { return confirm( convertError("Changes made to the pricing model do not affect active pricing events.")); } function window_popup1() { window.open("","Win2","titlebar=no,toolbar=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no,location=no,copyhistory=no,width=450,height=350"); } function window_popup2() { window.open("","Win2","titlebar=no,toolbar=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no,location=no,copyhistory=no,width=500,height=150"); } function getLastModified() { // last modified script by Bernhard Friedrich; should work in all browsers var a = new Date(document.lastModified); var year = a.getYear(); //just in case date is delivered with 4 digits if (lm_year<1000) { if (lm_year<70) { year += 2000; } else { year += 1900; } } //end workaround var month = a.getMonth() + 1; if (month < 10) { month = '0' + month; } var day = a.getDate(); if (lm_day < 10) { day = '0' + day; } var hour = a.getHours(); if (hour < 10) { hour = '0' + hour; } var minute = a.getMinutes(); if (minute < 10) { minute = '0' + minute; } var second = a.getSeconds(); if (second < 10) { second = '0' + second; } return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second; } function writeLastModified() { document.write("Last Modified " + getLastModified()); } /* Jeff Kelm Oct 4, 2001 Returns 'false' if the set of radio buttons supplied doesn't exist or if none of the selection has been checked. Commonly used to evaluate if a submit button (for example) should be active based on the current state of its form's radio buttons. You can apply this to a list of any HTML elements that have the 'checked' property. To use: Supply an HTML element or array of HTML representing the radio button set. For example, if you have a form named 'myForm' and its radio buttons are all named ID_RADIO, you would supply 'document.myForm.ID_RADIO' as radioButtonsArg. Jeff Kelm Nov 5, 2001 Used getElements method to convert the arg to an array. */ function checkForSelection(radioButtonsArg) { var radioButtons = getElements(radioButtonsArg); var i = 0; var found = false; var selectionMade = true; if(radioButtons.length == 0) { selectionMade = false; } else { for (i = 0; i < radioButtons.length && !found; i++) { if (radioButtons[i].checked) { selectionMade = true; found = true; } } } return selectionMade; } /* * Print page. */ function printPage() { var da = (document.all) ? 1 : 0; var pr = (window.print) ? 1 : 0; var mac = (navigator.userAgent.indexOf("Mac") != -1); if (pr) { // NS4, IE5 window.print(); } else if (da && !mac) { // IE4 (Windows) alert("Your page is printing."); vbPrintPage(); } else { // other browsers alert("Please press your browser's PRINT button now."); return false; } } /* * Return an array containing all of the elements on the page represented by the object passed in. */ function getElements(obj) { var result; if (obj == null) { // the object doesn't exist, return an empty array result = new Array(); } else if (obj.length == null || obj[0] == null) { // the object doesn't represent an array -- return an array of length 1 result = new Array(); result[0] = obj; } else { // the object is an array, return it result = obj; } return result; } /* Jeff Kelm Nov 5, 2001 */ function removeBlanks(str) { var returnString = ""; var i; var nextChar; for(i = 0 ; i < str.length ; i++) { nextChar = str.charAt(i); if(nextChar != " ") { returnString = returnString + nextChar; } } return returnString; } /* Jeff Kelm Nov 7, 2001 parseFloat(arg)/parseInt(arg) return a valid number as long as the first part of 'arg' is a valid number (i.e. parseInt("34jyu") returns '34'). Therefore, !isNaN(parseInt()) is not a reliable validation method. Use these functions instead. */ function isStringAnInteger(str) { str = removeBlanks(str); var OK = !isNaN(parseInt(str)); var i = parseInt(str).toString().length; if(OK) { while((i < str.length) && OK) { OK = !isNaN(parseInt(str.charAt(i++))); } } return OK; } function isStringAFloat(str) { str = removeBlanks(str); var OK = !isNaN(parseFloat(str)); var i = parseFloat(str).toString().length; while((i < str.length) && OK) { OK = !isNaN(parseFloat(str.charAt(i++))); } return OK; } //Added Sept 23/02 MBarnes used by inv messaging (open, view, print) function popup_email_action() { if(confirm("Are you sure you want to send this document via email?")) { return true; } else { return false; } } // For plan design to parse benefit values. function getBenefitValueAndFootnote(value) { var valueAndFootnote = [value, ""]; var pattern = /\[FN:\d+\]$/; var result = valueAndFootnote[0].match(pattern); if(result != null) { valueAndFootnote[0] = value.substring(0, result.index); valueAndFootnote[1] = result[0].substring(result[0].indexOf(":") + 1, result[0].lastIndexOf("]")); } return valueAndFootnote; } // Validate password function validatePassword(password, confirmPassword, username, minCharacters, minUppercase, minLowercase, minDigits, minSpecials) { if (password.match(/^\s/)) { alert("The new password cannot begin with any whitespace character."); return false; } if (confirmPassword != password) { alert("The 'confirm password' does not match the 'new password'."); return false; } if (password.toUpperCase() == username.toUpperCase()) { alert("The new password cannot be the same as the username, regardless of letter case."); return false; } if (password.length < minCharacters) { alert("The new password must contain a minimum of " + minCharacters + " characters."); return false; } // Verify minimums var upperArray = password.match(/[A-Z]/g); var lowerArray = password.match(/[a-z]/g); var digitArray = password.match(/\d/g); var speclArray = password.match(/[!@#$%^&\*\(\)~]/g); var numUppercase = upperArray == null ? 0 : upperArray.length; var numLowercase = lowerArray == null ? 0 : lowerArray.length; var numDigits = digitArray == null ? 0 : digitArray.length; var numSpecial = speclArray == null ? 0 : speclArray.length; var genMsg = "The new password must contain a minimum of "; if (numUppercase < minUppercase) { var sLetter = minUppercase > 1 ? 's' : ''; alert(genMsg + minUppercase + " upper case letter" + sLetter + " (A-Z)."); return false; } if (numLowercase < minLowercase) { var sLetter = minLowercase > 1 ? 's' : ''; alert(genMsg + minLowercase + " lower case letter" + sLetter + " (a-z)."); return false; } if (numDigits < minDigits) { var sLetter = minDigits > 1 ? 's' : ''; alert(genMsg + minDigits + " digit" + sLetter + " (0-9)."); return false; } if (numSpecial < minSpecials) { var sLetter = minSpecials > 1 ? 's' : ''; alert(genMsg + minSpecials + " special character" + sLetter + " (!@#$%^&*()~)."); return false; } return true; } function isAllChecked(boxes) { for (var i = 0; i < boxes.length; i++) { if (!boxes[i].checked) { return false; } } return true; } function isInArray(item, items) { for (var j = 0; j < items.length; j++) { if (items[j] == item) return true; } return false; } function getFormData(form) { var dataString = ""; function addParam(name, value) { dataString += (dataString.length > 0 ? "&" : "") + escape(name).replace(/\+/g, "%2B") + "=" + escape(value ? value : "").replace(/\+/g, "%2B"); } var elemArray = form.elements; for (var i = 0; i < elemArray.length; i++) { var element = elemArray[i]; var elemType = element.type.toUpperCase(); var elemName = element.name; if (elemName) { if (elemType == "TEXT" || elemType == "TEXTAREA" || elemType == "PASSWORD" || elemType == "HIDDEN") addParam(elemName, element.value); else if (elemType == "CHECKBOX" && element.checked) addParam(elemName, element.value ? element.value : "On"); else if (elemType == "RADIO" && element.checked) addParam(elemName, element.value); else if (elemType.indexOf("SELECT") != -1) for (var j = 0; j < element.options.length; j++) { var option = element.options[j]; if (option.selected) addParam(elemName, option.value ? option.value : option.text); } } } return dataString; } function getCurrentDateAsString() { // current date in format d/m/yyyy var a = new Date(); var year = a.getYear(); var month = a.getMonth() + 1; var day = a.getDate(); return month + '/' + day + '/' + year; } function isDateAsString() { }