document.addEventListener("DOMContentLoaded",function(){function s(n){const i=t.findIndex(n=>n.isActive);return n==="next"&&i<t.length-1?t[i+1].url:n==="prev"&&i>0?t[i-1].url:null}function r(n,t,i){$.ajax({url:n,method:"GET",success:function(n){const r=document.createElement("div");r.innerHTML=n;const u=Array.from(r.querySelectorAll(".job-item")).map(n=>n.dataset.jobId);if(u.length!==0){let f=i=="previous"?"before":"after";y(u,f);const e=r.querySelectorAll(".pagination li"),o=Array.from(e).map(n=>({url:n.querySelector("a")?n.querySelector("a").getAttribute("href"):null,isActive:n.classList.contains("active")}));sessionStorage.setItem("paginationData",JSON.stringify(o));t()}},error:function(){console.error("Failed to fetch jobs from the page.")}})}function y(t,i){const r=100,u=JSON.parse(sessionStorage.getItem("jobIds"))||[];n=i=="before"?[...new Set([...t,...u])]:[...new Set([...u,...t])];const e=window.location.pathname,o=e.split("/")[2],f=n.indexOf(o);if(n.length>r){const t=Math.floor(r/2),i=Math.max(0,f-t),u=Math.min(n.length,f+t);n=n.slice(i,u)}sessionStorage.setItem("jobIds",JSON.stringify(n))}function u(){const f=document.getElementById("previousJobLink"),t=document.getElementById("nextJobLink");let h=n.indexOf(i),e=null,o=null,c=null;const l=h>0?n[h-1]:null;if(l)f.href=`/jobs/${l}`,f.classList.remove("disabled");else{f.classList.add("disabled");f.setAttribute("aria-disabled","true");f.removeAttribute("href");const n=s("prev");n&&(e=n,o=function(){r(n,u)},c="previous")}const a=h<n.length-1?n[h+1]:null;if(a)t.href=`/jobs/${a}`,t.classList.remove("disabled"),t.removeAttribute("aria-disabled");else{t.classList.add("disabled");t.setAttribute("aria-disabled","true");t.removeAttribute("href");const n=s("next");n&&(e=e||n,o=o||function(){r(n,u)},c="next")}e&&o&&c&&r(e,o,c)}const h=sessionStorage.getItem("searchQuery")||"",f=document.querySelector(".back-to-job");$(".job-header-content").on("show.bs.popover",'[data-toggle="popover"]',function(){$('.job-header-content [data-toggle="popover"]').not(this).popover("hide")});gJobs.nonFlickeringPopover($('.job-header-content [data-toggle="popover"], .button-parent [data-toggle="popover"]'),"job-details-popover");var c=function(){var r=$(window),n=$("#content"),t=$(".tab-pane.active"),i=t.outerHeight();n.css("min-height",i)};$(document).on("shown.bs.tab",'a[data-toggle="tab"]',function(){c()});if(f){let t=new URL("/jobs",window.location.origin),n=new URLSearchParams(h);n.has("isViewJobDetails")&&n.delete("isViewJobDetails");n.set("backToJobSearch","true");t.search=n.toString();f.href=t.toString()}let n=JSON.parse(sessionStorage.getItem("jobIds"))||[];const t=JSON.parse(sessionStorage.getItem("paginationData"))||[],l=window.location.pathname,i=l.split("/")[2];if(i){increaseHitsCount(i);const a=document.getElementById("previousJobLink"),v=document.getElementById("nextJobLink"),e=a?.closest(".button"),o=v?.closest(".button");if(!n||n.length===0){e&&(e.style.display="none");o&&(o.style.display="none");return}u()}})