<script>
  (function () {
    window.METAPHOR_DISABLED = true;
    function getCookie(cookieName) {
      var name = cookieName + "=";
      var decodedCookie = decodeURIComponent(document.cookie);
      var ca = decodedCookie.split(';');
      for(var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
          c = c.substring(1);
        }
        if (c.indexOf(name) == 0) {
          return c.substring(name.length, c.length);
        }
      }
      return "";
    }
    function getURLParam(name, url) {
      if (!url) {
        url = window.location.href;
      }
      name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
      var regexS = "[\\?&]"+name+"=([^&#]*)";
      var regex = new RegExp( regexS );
      var results = regex.exec( url );
      return results == null ? null : results[1];
    }
    document.addEventListener("DOMContentLoaded", function(event) {
      var url = "https://privacyportal-cdn.onetrust.com/dsarwebform/be95c02f-4f55-491d-8ab4-67d62790be9c/7a39ed82-42c9-41b8-ae01-74a9d32208ae.html";
      var queryString = [];
      queryString.push("s=" + HRST.site.prefix);
      var hdpcid = getCookie("_hdpcid");
      if (hdpcid) {
        queryString.push("hdpcid=" + hdpcid);
      }
      var coreappapl = getURLParam("coreappapl");
      if (coreappapl) {
        queryString.push("coreappapl=" + coreappapl);
      }
      var coreappand = getURLParam("coreappand");
      if (coreappand) {
        queryString.push("coreappand=" + coreappand);
      }
      url += "?" + queryString.join("&");
      var iframeEl = document.createElement("iframe");
      iframeEl.setAttribute("src", url);
      iframeEl.setAttribute("title", "California Consumer Privacy Act Compliance Form");
      iframeEl.style.width = "100%";
      iframeEl.style.height = "2000px";
      iframeEl.setAttribute("frameborder", 0);
      var parentEl = document.querySelector("#ccpa-parent");
      if (parentEl) {
        parentEl.appendChild(iframeEl);
      }
      var ads = Array.prototype.slice.call(document.querySelectorAll(".ad-leaderboard, .ad-rectangle"));
      ads.forEach(function(item) {
        var parent = item.parentNode;
        if (parent) {
          parent.removeChild(item);
        }
      });
    });
  })();
</script>

<div id="ccpa-parent"></div>