/*
*+------------------------------------------------------------------------+
*| Licensed Materials - Property of IBM
*| BI and PM: prmt
*| (C) Copyright IBM Corp. 2002, 2018
*|
*| US Government Users Restricted Rights - Use, duplication or
*| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
*|
*+------------------------------------------------------------------------+
*/
var Class = function( v_oProperties ) {
var v_class = function() {
if (this.f_initialize && arguments[0] != 'noinit')
{
return this.f_initialize.apply(this, arguments);
}
else
{
return this;
}
};
for (var v_oProperty in this)
{
v_class[v_oProperty] = this[v_oProperty];
}
v_class.prototype = v_oProperties;
return v_class;
};
Class.prototype = {
f_extend: function( v_oProperties ) {
var v_oProto = new this('noinit');
var f_parentize = function( v_oPrevious, v_oCurrent )
{
if ( !v_oPrevious.apply || !v_oCurrent.apply )
{
return false;
}
return function()
{
this.f_parent = v_oPrevious;
return v_oCurrent.apply( this, arguments );
};
};
for (var v_oProperty in v_oProperties){
var v_oPrevious = v_oProto[ v_oProperty ];
var v_oCurrent = v_oProperties[ v_oProperty ];
if (v_oPrevious && v_oPrevious != v_oCurrent)
{
v_oCurrent = f_parentize(v_oPrevious, v_oCurrent) || v_oCurrent;
}
v_oProto[ v_oProperty ] = v_oCurrent;
}
return new Class( v_oProto );
}
};
/**
Copies all properties from v_oSource into v_oTarget.
if v_oSource is null, we copy v_oTarget into 'this'.
@param v_oTarget
@param v_oSouce
*/
Object.f_extend = function( v_oTarget, v_oSource )
{
if ( !v_oSource )
{
v_oTarget = this;
v_oSource = v_oTarget;
}
for ( var v_oProperty in v_oSource )
{
v_oTarget[v_oProperty] = v_oSource[v_oProperty];
}
return v_oTarget;
};
/**
Short for document.getElementById()
*/
function $()
{
if (arguments.length == 1)
{
var element = arguments[0];
if (typeof element == 'string')
{
return document.getElementById(element);
}
return element;
}
else
{
var elements = new Array();
var i, l = arguments.length;
for (i = 0; i < l; i++)
{
var element = arguments[i];
if (typeof element == 'string')
{
element = document.getElementById(element);
}
elements.push(element);
}
return elements;
}
}
/**
Short for new C_PromptElement().
*/
function $CE( v_sTag, v_oProps, v_elParent )
{
return ( new C_PromptElement(v_sTag, v_oProps, v_elParent) );
}
var PRMTUtils =
{
f_addClass: function( v_oElement, v_sName ) {
if ( v_oElement )
{
v_sName = v_sName.f_trim();
var v_sClass = v_oElement.className;
if ( !v_sClass )
{
v_sClass = K_PRMT_sEMPTY;
}
if ( !v_sClass.match(new RegExp("\\b" + v_sName + "\\b")) )
{
v_sClass = (v_sClass + K_PRMT_sSP + v_sName);
v_oElement.className = v_sClass.f_trim();
}
}
return this;
},
f_addEvent: function( v_oElement, v_sType, v_oFct ) {
if ( v_oElement )
{
if ( v_oElement.addEventListener )
{
v_oElement.addEventListener( v_sType, v_oFct, false );
}
else
{
v_oElement.attachEvent( 'on' + v_sType, v_oFct );
}
}
},
f_addText: function( v_oElement, v_sText ) {
v_oElement.appendChild( document.createTextNode( K_PRMT_sEMPTY + v_sText ) );
},
f_createElement: function( v_sTag, v_oProps, v_elParent ) {
var v_el = document.createElement( v_sTag );
if ( v_oProps )
{
for (var p in v_oProps)
{
v_el.setAttribute( p, v_oProps[p] );
}
}
if ( v_elParent )
{
v_elParent.appendChild( v_el );
}
return v_el;
},
f_parseNumber:function( v_sValue ) //CText::sParseOutCommon(sNumber)
{
var v_sRetval = v_sValue;
// strip out the following
// currency unit
v_sRetval = v_sRetval.replace( new RegExp(sEscapeRegularExpression(g_currencySymbol), K_PRMT_sG), K_PRMT_sEMPTY);
// group separator
v_sRetval = v_sRetval.replace(new RegExp(sEscapeRegularExpression(g_groupingSeparator), K_PRMT_sG), K_PRMT_sEMPTY);
// remove whitespace
v_sRetval = v_sRetval.replace(new RegExp("\\s", K_PRMT_sG), K_PRMT_sEMPTY);
// is there a decimal point, replace with SQL format
v_sRetval = v_sRetval.replace(new RegExp(sEscapeRegularExpression(g_decimalSeparator), K_PRMT_sG), K_PRMT_sDOT);
// remove the percent symbol
v_sRetval = v_sRetval.replace(new RegExp(sEscapeRegularExpression(g_percentSymbol), K_PRMT_sG), K_PRMT_sEMPTY);
return(v_sRetval);
},
f_isNumberOnly: function( v_sValue ) {
var v_re = new RegExp("^[\\s\\+\\-]*[0-9\\s,\\.]+$");
v_sValue = this.f_parseNumber(K_PRMT_sEMPTY + v_sValue);
return ( v_re.test(v_sValue) ? true : false );
},
f_removeClass: function( v_oElement, v_sName ) {
if ( v_oElement )
{
v_sName = v_sName.f_trim();
var v_sClass = v_oElement.className;
if ( !v_sClass )
{
v_sClass = K_PRMT_sEMPTY;
}
v_sClass = v_sClass.replace( new RegExp( "\\s*\\b" + v_sName + "\\b" ), K_PRMT_sEMPTY );
v_oElement.className = v_sClass.f_trim();
}
},
f_removeElement: function( v_oElement ) {
if (v_oElement && v_oElement.parentNode)
{
v_oElement.parentNode.removeChild( v_oElement );
}
},
F_PreventSubmit: function(evt) {
var v_oEvt = (evt ? evt : (typeof event != K_PRMT_sUNDEFINED ? event : null ));
if ( v_oEvt )
{
if (v_oEvt.keyCode == 13)
{
return this.F_StopEvent( v_oEvt );
}
}
},
F_StopEvent: function( v_oEvt ) {
if (typeof v_oEvt.stopPropagation == K_PRMT_sFUNCTION)
{
v_oEvt.stopPropagation();
}
if (typeof v_oEvt.preventDefault == K_PRMT_sFUNCTION)
{
v_oEvt.preventDefault();
}
v_oEvt.cancelBubble = true;
return false;
},
f_log: function( v_sCode, v_sMsg, v_bError ) {
var s = v_sCode + "\n" + v_sMsg;
if ( typeof console != K_PRMT_sUNDEFINED )
{
// Use Firebug's console
if ( v_bError ) {
console.warn( s );
}
else {
console.log( s );
}
}
else if ( K_PRMT_DEBUG )
{
s = '
";
if ( this._WIN_LOG_ )
{
this._WIN_LOG_.document.write( s );
}
else
{
var w = window.open( K_PRMT_sEMPTY, "PRMTUtil_LOG" + (new Date()).getTime() );
w.document.write( s );
w.document.close();
this._WIN_LOG_ = w;
}
}
},
f_parseStyle: function ( sStyle ) {
var v_aRetVal = [];
if ( !sStyle || typeof sStyle != K_PRMT_sSTRING )
{
return v_aRetVal;
}
var v_sStyleParsed = sStyle.replace(/\s*;\s*$/g, K_PRMT_sEMPTY);
v_sStyleParsed = v_sStyleParsed.replace(/\s*;\s*/g,';');
v_sStyleParsed = v_sStyleParsed.replace(/\s*:\s*/g,K_PRMT_sCOLON);
var aStyle = v_sStyleParsed.split(";");
for ( var v_iStyle = 0; v_iStyle < aStyle.length; v_iStyle++ )
{
var v_aParsedStyled = aStyle[v_iStyle].split(K_PRMT_sCOLON);
if ( v_aParsedStyled.length > 0 && v_aParsedStyled[0] )
{
v_aRetVal.push( v_aParsedStyled );
}
}
return v_aRetVal;
},
f_camelCase: function( v_str ) {
return v_str.replace(
/-\D/g,
function( v_str ) {
return v_str.charAt(1).toUpperCase();
}
);
},
f_error: function( v_sCode, v_sMsg ) {
this.f_log( v_sCode, v_sMsg, true );
},
F_OnChange: function( v_eEvent, v_el ) {
if (v_el.type == "checkbox") {
var v_div = v_el.parentNode;
if (v_el.checked) {
v_div.className = K_PRMT_CSS_CHECKBOX_CHECKED;
} else
{
v_div.className = K_PRMT_CSS_CHECKBOX;
}
} else if (v_el.type == "radio") {
// must update all radio button classes
var v_valueObject = v_el.parentNode.parentNode.parentNode.m_oPrompt;
if (v_valueObject && v_valueObject.f_getOptions) {
var v_aOptions = v_valueObject.f_getOptions();
var v_iLength = v_aOptions.length;
for (var i = 0; i < v_iLength; i++) {
var v_cb = v_aOptions[i];
var v_div = v_cb.parentNode;
v_div.className = (v_cb.checked ? K_PRMT_CSS_RADIOBUTTON_CHECKED : K_PRMT_CSS_RADIOBUTTON);
}
}
}
if ( window.ie )
{
while( v_el && !v_el.m_oPrompt )
{
v_el = v_el.parentNode;
}
if ( v_el && v_el.m_oPrompt && v_el.m_oPrompt.f_onChange )
{
v_el.m_oPrompt.f_onChange();
}
return true;
}
},
f_updateRadioButtons : function(v_el) {
if (v_el && v_el.name) {
var v_sName = v_el.name;
var aRadios = document.getElementsByName(v_sName);
var v_iLength = aRadios.length;
for (var i = 0; i < v_iLength; i++) {
var v_cb = aRadios[i];
var v_div = v_cb.parentNode;
v_div.className = (v_cb.checked ? K_PRMT_CSS_RADIOBUTTON_CHECKED : K_PRMT_CSS_RADIOBUTTON);
}
}
},
f_CheckboxOnFocus: function(v_el) {
v_el.parentNode.nextSibling.style.border = "1px dotted";
},
f_CheckboxOnBlur: function(v_el) {
v_el.parentNode.nextSibling.style.border = "0 none";
},
f_RangeRadioOnFocus: function(v_el) {
v_el.parentNode.style.border = "1px dotted";
},
f_RangeRadioOnBlur: function(v_el) {
v_el.parentNode.style.border = "0 none";
},
f_SearchOptionOnFocus: function(v_el) {
v_el.parentNode.parentNode.nextSibling.firstChild.style.border = "1px dotted";
},
f_SearchOptionOnBlur: function(v_el) {
v_el.parentNode.parentNode.nextSibling.firstChild.style.border = "0 none";
},
f_isDOMElem: function (v_obj) {
var v_result = false;
if(typeof v_obj == "object" && "nodeType" in v_obj && v_obj.nodeType === 1 && v_obj.cloneNode){
// most probably this is a DOM node
v_result = true;
}
return v_result;
},
f_alertId: function (inputId, alertSuffix)
{
var v_elAlertId = "alert_" + inputId;
if (typeof alertSuffix != K_PRMT_sUNDEFINED && alertSuffix != null && alertSuffix.length && alertSuffix.length > 0)
{
v_elAlertId += "_" + alertSuffix;
}
return v_elAlertId;
},
f_isMobileDevice: function (){
return (/iPad|iPhone/.test(navigator.platform)) || (/Linux/.test(navigator.platform) && /Android/.test(navigator.userAgent) );
},
f_isHighContrast: function () {
if (window.prmt_bHighContrast === false || window.prmt_bHighContrast === true) {
return window.prmt_bHighContrast;
}
var tempDiv = document.createElement("div");
tempDiv.id = this.m_sId + "hc";
tempDiv.style.border = "1px solid";
tempDiv.style.borderColor = "red green";
tempDiv.style.height = "10px";
tempDiv.style.top = "-999px";
tempDiv.style.position = "absolute";
document.body.appendChild(tempDiv);
var computedStyle = null;
if (window.ie && !window.edge) {
computedStyle = tempDiv.currentStyle;
}
else {
computedStyle = tempDiv.ownerDocument.defaultView.getComputedStyle(tempDiv, null);
}
window.prmt_bHighContrast = computedStyle.borderTopColor == computedStyle.borderRightColor;
document.body.removeChild(tempDiv);
return window.prmt_bHighContrast;
},
f_updateElementAriaChecked: function (v_el, ariaChecked)
{
if (v_el) {
if (v_el[K_PRMT_ARIA_CHECKED]) {
v_el[K_PRMT_ARIA_CHECKED] = ariaChecked;
}
else {
v_el.setAttribute(K_PRMT_ARIA_CHECKED, ariaChecked);
}
}
},
f_removeARIAMessageAlert: function (v_inputElem, v_inputId, alertSuffix)
{
try
{
if ( this.f_isDOMElem(v_inputElem) )
{
// remove ARIA alert div if it exists
var v_elAlertId = this.f_alertId(v_inputId, alertSuffix);
var v_alertDiv = $(v_elAlertId);
if ( v_alertDiv && this.f_isDOMElem(v_alertDiv) )
{
this.f_removeElement(v_alertDiv);
}
}
}
catch(err)
{
}
},
f_showARIAMessageAlert: function (v_inputElem, v_inputId, skinPath, v_sMsg, alertSuffix)
{ // render ARIA "alert" message
try {
// add ARIA alert unless it exists
var v_elAlertId = this.f_alertId(v_inputId, alertSuffix);
var v_alertDiv = $(v_elAlertId);
if (v_alertDiv && this.f_isDOMElem(v_alertDiv))
{
// if errorMessage is different
var v_alertImg = v_alertDiv.firstChild;
if (v_alertImg.getAttribute("alt") != v_sMsg)
{
this.f_removeElement(v_alertDiv);
v_alertDiv = K_PRMT_sUNDEFINED;
}
}
if (!(v_alertDiv && this.f_isDOMElem(v_alertDiv)) )
{
var v_newAlert = document.createElement("div");
v_newAlert.setAttribute("role", "alert");
if (v_elAlertId != null)
{
v_newAlert.setAttribute("id", v_elAlertId);
}
var v_container = v_inputElem.parentNode;
if (v_container)
{
v_container.appendChild(v_newAlert);
}
}
}
catch(err)
{
}
},
f_showARIAFail: function (v_inputElem, v_inputId, skinPath, v_sErrorMsg, alertSuffix)
{ // render ARIA test failure
try
{
v_inputElem.setAttribute("aria-invalid", true);
this.f_showARIAMessageAlert(v_inputElem, v_inputId, skinPath, v_sErrorMsg, alertSuffix);
}
catch(err)
{
}
},
f_showARIAPass: function (v_inputElem, v_inputId, alertSuffix)
{ // render ARIA test pass
try
{
if ( this.f_isDOMElem(v_inputElem) )
{
v_inputElem.setAttribute("aria-invalid", false);
this.f_removeARIAMessageAlert(v_inputElem, v_inputId, alertSuffix);
}
}
catch(err)
{
}
}
};
String.prototype.f_trim = function()
{
return ( this.replace(/^(\s|\n)*|(\s|\n)*$/g, K_PRMT_sEMPTY) );
};
String.prototype.f_xmlSafe = function()
{
return ( this.replace(/&/g, "&").replace(//g, ">").replace(K_PRMT_reQU, """) );
};
Function.prototype.bind = function(v_oBindFct)
{
var v_fct = this;
var v_object = v_oBindFct;
var v_args = [];
for (var v_idx =1; v_idx < arguments.length; v_idx++)
{
v_args.push( arguments[v_idx] );
}
return (
function(e) {
if (e) {
v_args.push(e);
}
return v_fct.apply(v_object, v_args);
}
);
};
/*
Class: window
Some properties are attached to the window object by the browser detection.
Properties:
window.ie - will be set to true if the current browser is internet explorer (any).
window.ie6 - will be set to true if the current browser is internet explorer 6.
window.ie7 - will be set to true if the current browser is internet explorer 7.
window.khtml - will be set to true if the current browser is Safari/Konqueror.
window.gecko - will be set to true if the current browser is Mozilla/Gecko.
*/
if (!!window.MSInputMethodContext && !!document.documentMode && (document.documentMode == 11)) { window.ie = window.ie11 = true; }
else if (document.all && !!window.atob) { window.ie = window['ie10'] = true; }
else if (document.all && !!document.addEventListener) { window.ie = window['ie9'] = true; }
else if (document.all && !!document.querySelector) { window.ie = window['ie8'] = true; }
else if (document.all && !!window.XMLHttpRequest) { window.ie = window['ie7'] = true; }
else if (document.all && !!document.compatMode) { window.ie = window['ie6'] = true; }
else if (document.all) { window.ie = window['ie5'] = true; }
else if (document.childNodes && !document.all && !navigator.taintEnabled) { if (!!window.StyleMedia) { window.ie = window.ie11 = window.edge = true; } else window.khtml = true; }
else if (document.getBoxObjectFor != null) window.gecko = true;