123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- // 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<form.elements.length;i++) {
- var e = form.elements[i];
- if (e.name == p && e.checked) {
- return e.value;
- }
- }
- return "";
- }
- function getSelectedValue(p) {
- for (var i=0;i<document.pform.elements.length;i++) {
- var e = document.pform.elements[i];
- if (e.name == p && e.checked) {
- return e.value;
- }
- }
- return "";
- }
- function checkB4Download(downloadName)
- {
- var changeName=false;
- for(i=0;i < downloadName.length; i++)
- {
- switch(downloadName.charCodeAt(i))
- {
- case 0x22: // Quote
- case 0x2A: // Asterisk
- case 0x2F: // Forward slash
- case 0x3A: // Colon
- case 0x3C: // Left Arrow
- case 0x3E: // Right Arrow
- case 0x3F: // Question mark
- case 0x5C: // Back slash
- case 0x7C: // Vertical bar
- {
- changeName=true;
- }
- default:
- {
- continue;
- }
- }
- }
- return changeName;
- }
- function checkDocumentDownload(downloadName, downloadMsg, sURL) {
- if (checkB4Download(downloadName)) {
- alert(downloadMsg);
- }
- window.setTimeout("window.location.href='" + sURL + "';", 1);
- }
- function scrollingTableResizeHandler(evt, isIE, divId, divBody, divHeader, nBottomSpace, minSize) {
- var eBody = document.body;
- var div_results_content = document.getElementById(divId);
- var div_results_contentBody = document.getElementById(divBody);
- var div_results_contentHeader = document.getElementById(divHeader);
- if (!div_results_content && !div_results_contentBody) {
- return;
- }
- var nNewHeight = eBody.clientHeight - scrollingTableGetTop(div_results_content) - nBottomSpace;
- // adjust height of the results content div (right pane)
- if (isIE) {
- if (nNewHeight > minSize) {
- div_results_content.style.height = nNewHeight;
- } else {
- div_results_content.style.height = minSize;
- }
- } else {
- if (nNewHeight > minSize) {
- div_results_contentBody.style.height = nNewHeight - div_results_contentHeader.offsetHeight;
- } else {
- div_results_contentBody.style.height = minSize;
- }
- }
- }
- function scrollingTableGetTop(obj) {
- var curtop = 0;
- try {
- while (obj.offsetParent) {
- curtop += obj.offsetTop;
- obj = obj.offsetParent;
- }
- } catch (e) {}
- return curtop;
- }
- function scrollingTableAddEvent(obj, eventName, handler) {
- if (obj.attachEvent) {
- obj.attachEvent("on" + eventName, handler);
- } else if (obj.addEventListener) {
- obj.addEventListener(eventName, handler, false);
- }
- }
- // Checks if element is checked and returns the value for it.
-
- function getSelectedValueForFormElement(p, form) {
- for (var i=0;i<form.elements.length;i++) {
- var e = form.elements[i];
- if (e.name == p && e.checked) {
- return e.value;
- }
- }
- return "";
- }
-
- function getSelectedValue(p) {
- for (var i=0;i<document.pform.elements.length;i++) {
- var e = document.pform.elements[i];
- if (e.name == p && e.checked) {
- return e.value;
- }
- }
- return "";
- }
- function xmlDecodeResponse(sResponse)
- {
- // Decode stuff which has been encoded/escaped out.
- // ORDER IS IMPORTANT - amp_re must be the last value to replace!
- return (((sResponse.replace(/</g, "<")).replace(/>/g, ">")).replace(/'/g, "'")).replace(/&/g, "&");
- }
|