// JavaScript Document
//Changes 2023
/*
1-30-24 AJ added expand-next-open
7-28-23 AJ changed expand/collapse span
5-4-23 AJ - added anchorSectionExpand
1-5-23 added comp hr pro script
8-18-23 PB - added title attribute to help center link
*/
//Global variables
var userSelectedRegion;
// accessMode will be in new theme at which time this should be removed
var accessMode = document.getElementsByName('DCSext.accessMode')[0].getAttribute('content');
//this function checks if user is logged in
function loggedIn() {
var modArray = document.getElementsByName('DCSext.authStatus');
for (var i = 0; i < modArray.length; i++) {
if (modArray[i].content == "Authenticated") {
return true;
}
}
}
// To show help content in a modal (used for Total Perfomance transactions)
// pzn component brings help content for all divs
// this function is to show only the relevant one (eg setyourgaols) and hide others
// this can be removed when business process page for TP is created
function showHelpcontent(param, title) {
var activediv = $("#" + param + "content");
$(activediv).show();
$(".modal-body").children().not($(activediv)).hide();
$("h2.tphelp-modalheader").text(title);
$("#tpHelpcontent").modal('show');
// To show this content only for PO and IT regions in the Tot Perf help modals
if ((userSelectedRegion == "Program Offices")||(userSelectedRegion == "KPIT")) {
$(".tpcoordinatorlink").html("
Didn\'t find what you needed? Contact your Total Performance Coordinator for help.
");
}
}
/***********intercept which is theme code. when region is selected on intercept page , the region is updated in the header ************/
function updateAction() {
// var target_url_ret = document.getElementById('target_url_ret');
//var target_url_ret = '/wps/portal/hr/home';
/*
if ((document.referrer.indexOf('epf')>=0) ||(document.referrer.indexOf('myhr')>=0) || (document.referrer.indexOf('hrconnect')>=0)){
var target_url_ret = document.referrer;
} else if (intAccess()) {
var target_url_ret = '/wps/portal/hrpublic/home';
} else {
var target_url_ret = '/wps/portal/hr/home';
}
*/
if ((document.referrer =='' )|| (document.referrer.indexOf('fam')>=0) || (document.referrer.indexOf('intercept_default')>=0) || (document.referrer.indexOf('google')>=0) || (document.referrer.indexOf('yahoo')>=0) ||(document.referrer.indexOf('bing')>=0) ){
if (intAccess()) {
var target_url_ret = '/wps/portal/hrpublic/home';
} else {
var target_url_ret = '/wps/portal/hr/home';
}
}
else {
var target_url_ret = document.referrer;
}
console.log("target:" + target_url_ret);
if (target_url_ret != null && target_url_ret.value != '') {
// document.SelectRegionForm.action = target_url_ret.value;
document.SelectRegionForm.action = target_url_ret
}
}
function submitRegionForm() {
updateAction();
}
// Generic functions moved from Support JS -
// generic function to render decision trees. There are a few in Support.
// Other sections like OE, PMC and CW have to be remediated to use this function
function decisiontreescripts() {
$(".level1-choice").each(function(index) {
$(this).click(function() {
var thiselem = $(".level1-answer").eq(index);
$(thiselem).show("slow");
$(".level1-answer").not($(thiselem)).hide("slow");
});
});
$(".level2-choice").each(function(index) {
$(this).click(function() {
var thiselem = $(".level2-answer").eq(index);
$(thiselem).show("slow");
$(".level2-answer").not($(thiselem)).hide("slow");
});
});
$(".level3-choice").each(function(index) {
$(this).click(function() {
var thiselem = $(".level3-answer").eq(index);
$(thiselem).show("slow");
$(".level3-answer").not($(thiselem)).hide("slow");
});
});
}
// generic function that redirects user to page after sign on
// used in Help and Commenting component
function SignInY() {
var fullurl = window.location.href;
var l = fullurl.length;
var hostname = "https://" + window.location.hostname;
var i = hostname.length;
var path = fullurl.substring(i, l);
var loc = path.replace("/wps/portal", "/wps/myportal");
var urltoken = path.split("/wps/portal/hr/home")
window.location.href = "/wps/hr/common/secure/login.jsp?uri=landingPage-" + urltoken[1];
}
/***** ADDED: open psft transaction in new window *****/
function myhrOpenPage(url, width, height) {
newWin = window.open(url, 'newWindow', 'location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=yes,width=' + width + ',height=' + height + '');
}
/****** / open psft transaction in new window ******/
/****** Utility functions from util.js *******/
// This function checks if user is accessing the site from the Internet
function intAccess() {
var accArray = document.getElementsByName('DCSext.accessMode');
for (var i = 0; i < accArray.length; i++) {
if (accArray[i].content == "internet") {
return true;
}
}
}
// gup stands for Get Url Parameter. It is used to retrieve parameters
// encoded in page url
function gup(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return "";
else
return results[1];
}
// This function checks if the current env is Production (auth & prod)
function isProd() {
var domain = window.location.hostname;
if ((domain.indexOf("epf.kp.org") != -1) || (domain.indexOf("epf-auth7.kp.org") != -1)) {
return true;
}
}
// this defines the ACA environments for use with FAM presentation template
function FAMEnvironment() {
var domain = window.location.hostname;
var acaProdEnv = ['epf.kp.org', 'epf-auth7.kp.org', 'hrconnect.kp.org', 'hrconnect-auth.kp.org'];
var nonACAProdEnv = ['epf-dr.kp.org'];
var acaTestEnv = ['myhr-uat2.kp.org', 'myhr-uat3.kp.org', 'epf-uat7.kp.org', 'epf-qa7.kp.org'];
var nonACATestEnv = ['myhr-qa.appl.kp.org'];
if (acaProdEnv.indexOf(domain) != -1) {
return 'isACA';
}else if (nonACAProdEnv.indexOf(domain) != -1) {
return 'isNonACA';
}else if (acaTestEnv.indexOf(domain) != -1) {
return 'isACATest';
}else if (nonACATestEnv.indexOf(domain) != -1) {
return 'isNonACATest';
}else { alert("Not Defined");
}
}
// this defines the HCM Oracle and Peoplesoft environments for use with HCM Testing.
// this should go away when HCM goes live and presentation will only use HCM link
function isHCMEnvironment() {
var domain = window.location.hostname;
var OracleEnv = ['myhr-uat3.kp.org', 'hrconnect-uat3.kp.org', 'epf-qa7.kp.org', 'hrconnect-qa.kp.org', 'epf-load7.kp.org', 'hrconnect-load.kp.org', 'myhr-qa.kp.org', 'myhr-uat2.kp.org', 'hrconnect-uat2.kp.org', 'epf-uat7.kp.org', 'hrconnect-uat.kp.org', 'epf.kp.org', 'epf-auth7.kp.org', 'hrconnect-auth.kp.org', 'hrconnect.kp.org'];
var PeoplesoftEnv = ['myhr-qa.appl.kp.org'];
if (OracleEnv.indexOf(domain) != -1) {
return 'isOracleEnv';
}else if (PeoplesoftEnv.indexOf(domain) != -1) {
return 'isPeoplesoftEnv';
}
}
// this shows HCM links based on css style so that items can be presented in prod for HCM testing
function showHCMLinks() {
isHCMEnvironment();
var environment = isHCMEnvironment();
console.log(environment)
if (environment=='isOracleEnv') {
$(".hcm-link").show();
$(".non-hcm-link").hide();
}else if (environment=='isPeoplesoftEnv') {
$(".non-hcm-link").show();
$(".hcm-link").hide();
}
}
// If qa7 or uat3, and MHS region ,show MHS logo
function showMHSLogo(){
var hrConnectMHSLogo = '/wps/wcm/connect/3ce8e174-4e49-47f1-9574-dc01a2f74efb/KP-HRconnect-MHS-Color-RGB_Logo_New.png?MOD=AJPERES&CACHEID=ROOTWORKSPACE-3ce8e174-4e49-47f1-9574-dc01a2f74efb-o5vJMdm';
if(userSelectedRegion=="Maui Health System"){
$('.hr-logo').attr('src', hrConnectMHSLogo);
}
}
showMHSLogo();
//This function cleans up specials characters in a url string
function urlDecode(str) {
str = str.replace(new RegExp('\\+', 'g'), ' ');
return unescape(str);
}
// This function is used to validate email fields in forms.
// This can be removed in the future since html5 forms have in-built validation
function testEmail(src) {
//var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
var regex = /^[-a-zA-Z0-9._\']+@kp.org$/;
return regex.test(src);
}
// utility function to check if a string is 'like' another string
String.prototype.like = function(search) {
if ( typeof search !== 'string' || this === null) {
return false;
}
// Remove special chars
search = search.replace(new RegExp("([\\.\\\\\\+\\*\\?\\[\\^\\]\\$\\(\\)\\{\\}\\=\\!\\<\\>\\|\\:\\-])", "g"), "\\$1");
// Replace % and _ with equivalent regex
search = search.replace(/%/g, '.*').replace(/_/g, '.');
// Check matches
return RegExp('^' + search + '$', 'gi').test(this);
}
// utility function to check if a string contains another string
String.prototype.contains = function(it) {
return this.indexOf(it) != -1;
};
// utility function to capitalize a string
String.prototype.capitalize = function() {
return this.replace(/(^|\s)([a-z])/g, function(m, p1, p2) {
return p1 + p2.toUpperCase();
});
};
// utility function to count the number of occurrences of a parameter in a string
String.prototype.count = function(c) {
var result = 0,
i = 0;
for (i; i < this.length; i++)
if (this[i] == c)
result++;
return result;
};
// utility function to check if an Array contains a specific string or object
Array.prototype.contains = function(it) {
return this.indexOf(it) != -1;
};
/****** / Utility functions from util.js******/
/********** Jquery UIpopup/modal *******/
$(document).ready(function() {
// add title attribute to Help center link (#20115)
$("#hrHelpLink a, #hrHelpLinkMobile a").attr("title","Contact Us & FAQs");
if (typeof intranetOnly !== 'undefined') {
if (intranetOnly === 'yes' && accessMode === 'internet') {location.href= "/wps/poc?urile=wcm:path:/myhr/epfsite/InternetAccess";}
}
showHCMLinks();
//CompHRpro();
/******* network access function. Add class network-access to links where
the content is available only on the intranet ******/
$(".network-access").click(function(event) {
event.preventDefault();
if (intAccess()) {
// user is not in the network
console.log("Internet");
window.open("/wps/poc?urile=wcm:path:/myhr/epfsite/InternetAccess");
//location.href= "/wps/poc?urile=wcm:path:/myhr/epfsite/InternetAccess";
} else {
// user is in the network
console.log("Intranet");
window.open($(this).attr("href"));
//location.href= $(this).attr("href");
}
});
/******* /network access function ******/
/******* HRPro Status ************/
if ((loggedIn())) {
if (hrProStatus == "Yes") {
$(".hrpro").show();
}
}
/****** HRPro and Manager************/
if ((loggedIn())) {
if ((hrProStatus == "Yes") || (_kpIsManager=="Yes")) {
$(".hrpro-manager").show();
}
}
/************ manager content show *************/
if ((loggedIn())) {
if (_kpIsManager=="Yes") {
$(".myhr-manager").show();
}
}
/************ /manager content show *************/
/******** update theme links to be trackable ******/
$(".header-links-nav").attr("id" , "themeHeaderLinks");
$("#hrMyProfileLink").addClass("wtlinktrack");
$("#hrHelpLink").addClass("wtlinktrack");
$("#hrHelpLinkMobile").addClass("wtlinktrack");
$("#hrSignoffLink").addClass("wtlinktrack");
$("#adminLinks").addClass( "wtlinktrack");
/******** /update theme links to be trackable ******/
/******** carousel indicators *********/
var imglength = $(".carousel-inner > .item").length
var indicators = $(".carousel-indicators > li ");
var index = 0;
var showCarouselIndicators = function() {
indicators.hide();
var noOfImages = index + imglength;
indicators.slice(index, noOfImages).show();
}
showCarouselIndicators();
/*********** Copy paste fuction *********/
$(document).on("click", ".copy-button", function() {
var text = $(this).parents('.copy-paste').find('.copy-content').clone().find('br').prepend('\r\n').end().text()
console.log("text:" + text);
element = $('