const strSearch = document.currentScript.getAttribute("data-str")?.replace(/<[^>]*>/g,'') || '';
const searchMinLength = parseInt(document.currentScript.getAttribute("data-minlength")) ?? 0;

$("#offlineSearch", parent.document).iFrameResize();

$(".results", document).on("click", "a", function(e) {
  $(this).attr("target", "_top");
});
$("input#zoom_searchbox", document).attr("placeholder", strSearch);
$("input.zoom_button", document).css("display", "none");
// Prefill search entry if available
let zoomH = "";
if (typeof parent.findGetParameter !== "undefined")
  zoomH = parent.findGetParameter("zoom_highlightsub");
if (parent.zoomH && parent.zoomH.length >= searchMinLength)
  $("input#zoom_searchbox", document).val(parent.zoomH);
$(".zoom_searchform", document).on("click", "input.zoom_button", function(e) {
  $(".results", document).css("background-color", "#ffffff");
});
$(".zoom_searchform", document).attr("target", "_self");
$(".zoom_searchform", document).submit(function(e) {
  if (parent.document.getElementById("lightbox")) return;
  if ($("input#zoom_searchbox", document).val().length < searchMinLength)
    return false;
  $("body", parent.document).prepend('<div id="lightbox"></div>');
  $("#lightbox", parent.document).animate({opacity: 0.6}, 800, function() {
    $(".zoom_searchform", document).submit();
  });
  e.preventDefault();
});
// Not required elements
$(".zoom_results_per_page", document).css("position", "absolute").css("top", "-1000px");
$(".zoom_match", document).css("position", "absolute").css("top", "-1000px");
// Close search lightbox
$(".searchheading", document).css("position", "relative");
$(".searchheading", document).append('<a href="javascript:void(null);" onclick="parent.hideLightBox();" class="closeButton"><span>[X]</span></a>');

