// Licensed Materials - Property of IBM // // IBM Cognos Products: ps // // (C) Copyright IBM Corp. 2005, 2011 // // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated). //-- Browser detection var isNS = false, isIE = false; navigator.appName == "Netscape" ? isNS = true : isIE = true; //-- List supported URL protocols here. var g_sValidURLProtocols = "http:// https:// file:// ftp:// crn/ ../"; //-- Removes leading and trailing spaces function trim(s) { var j = s.length; var strCd; for (var i = 0; i < j; i++) { strCd = s.charCodeAt(i); if (32 != strCd && 12288 != strCd) { //-- check for unicode space - normal and wide. break; } } if (i < j - 1) { for (; j > i; j--) { strCd = s.charCodeAt(j - 1); if (32 != strCd && 12288 != strCd) { break; } } } return s.substring(i, j); } /** * Verifies the port range: return true if it is between 0 and 65535, false otherwise. */ function isPortRangeValid(field) { if (field != null) { var value = field.value; if (!isNaN(value) && (parseInt(value, 10) == value) && value >= 0 && value <= 65535) { return true; } } return false; } // Checks that the specified form field contains an integer value that // is greater than or equal to zero. function checkPositiveInteger(field) { if (field) { if (field.value < 1 || isNaN(field.value) || parseInt(field.value, 10) != field.value) { field.value = '0'; } } } // Examines the value of the given object, if it's not a numerical // value greater than or equal to 0, it is replaced with the // supplied default value. function checkPositiveIntegerDefault(field, def) { if (field) { if (field.value < 1 || isNaN(field.value) || parseInt(field.value, 10) != field.value) { field.value = def; } } } function checkURLFormat(field) { var item = field.value.toLowerCase(); var aValidProtocols = []; var bIsValidProtocol = false; aValidProtocols = g_sValidURLProtocols.toLowerCase().split(" "); for (var i = 0; i < aValidProtocols.length; i++) { // Reject URL's that do not start with or are equal to the list of URL prefixes defined in g_sValidURLProtocols. // In addition to the supported protocols, we disallow the following characters from immediatelly following the protocol: ? @ : / \ # if (item.indexOf(aValidProtocols[i]) == 0 && aValidProtocols[i] != item && item.indexOf(aValidProtocols[i] + "?") != 0 && item.indexOf(aValidProtocols[i] + "\\") != 0) { var s = "^" + aValidProtocols[i] + "(@|:|#|/| )"; var re = new RegExp(s); if (!re.test(item)) { bIsValidProtocol = true; break; } } } if (bIsValidProtocol) { if (item == "http://www.") { bIsValidProtocol = false; } } return bIsValidProtocol; } // Format is name value pairs. // To override the use of the default document name (pform is assumed), // the word "form" must be specified as the first parameter followed by the form name as the value for the second parameter // in the name/value pair list. Example setSelectParams("form","myformname",...); function setSelectParams() { var docform; var args = arguments.length; if (args > 0) { var i = 0; if (arguments[i] == 'form') { docform = document[arguments[++i]]; i++; } else { docform = document.pform; } for (; i < args ; i++) { nm = arguments[i]; vl = arguments[++i]; docform[nm].value = vl; } } } // Sets the value of the form input field - otherwise creates the entry on the form. // When the type (typ) is not specified, hidden is assumed. // When the formname is not specified, pform is assumed. function setFormInputElement(elename, val, typ, form) { var docform; if (typeof form != "undefined" && form != null) { docform = document[form]; } else { docform = document.pform; } if (docform[elename]) { docform[elename].value = val; } else { var eleTyp; if (typeof typ != "undefined" && typ != null) { eleTyp = typ; } else { eleTyp = "hidden"; } var formElement = document.createElement("input"); formElement.setAttribute("type", eleTyp); formElement.setAttribute("name", elename); formElement.setAttribute("value", val); docform.appendChild(formElement); } } // Checks if elements starting with a particular prefix are checked. // Typically used to determine if any checkboxes in a column of checkboxes are selected function isSelected(p) { for (var i = 0; i < document.pform.elements.length; i++) { var e = document.pform.elements[i]; if (e.name.substring(0, p.length) == p) { if (e.checked == true) { return true; } } } return false; } // Checks if element is checked and returns the value for it. function getSelectedValueForFormElement(p, form) { for (var i=0;i