function pxSan(str) {
  if (str.includes("in")) {
    str = str.replace("in","")
    str = (parseFloat(str) * 96) + ""
  }
  str = str.replace("px","");
  return parseFloat(str);
}

function calcParse(str) {
  return str.replace("calc(","(")
}

function resizeMulticolDivs() {
  var divs = document.querySelectorAll("[colspan]:not([colspan=\"1\"]) .dco");
  divs.forEach(function(div) {
      
      //alert("VALUE: " + (div.parentNode.getBoundingClientRect().top - div.getBoundingClientRect().top));
      
      //div.style.setProperty("--heightsub",div.parentElement.getElementsByClassName("longcont")[0].clientHeight + "px");
      div.style.setProperty("--heightsub", (div.getBoundingClientRect().top - div.parentNode.getBoundingClientRect().top) + "px");
      /*alert(div.parentElement.getElementsByClassName("longcont")[0].clientHeight)*/
  });
}

function placeDiv(td, dir) {
  var styl = getComputedStyle(td);
  var vmar = pxSan(styl.getPropertyValue("--vbordermar"));
  var width = pxSan(styl.getPropertyValue("--vborderwidth"));
  var xline = td.getBoundingClientRect().top + window.scrollY;
  var yline = eval("td.getBoundingClientRect()."+dir) + window.scrollX;
  borderDiv = document.createElement("div");
  borderDiv.classList.add("jsborderdiv");
  borderDiv.innerHTML = "&nbsp";
  borderDiv.style.position = "absolute";
  borderDiv.style.display = "block";
  borderDiv.style.backgroundColor = styl.getPropertyValue("--vbordercolor");
  borderDiv.style.setProperty("z-index","100");
  borderDiv.style.width = width + "px";
  borderDiv.style.height = "calc("+calcParse(styl.getPropertyValue("--realcheight")+" - (2 * "+vmar+"px))");
  borderDiv.style.top = (xline + vmar) + "px";
  borderDiv.style.left = (yline - (width / 2)) + "px";
  document.body.appendChild(borderDiv);
}

function placeHorizontalDivs() {
  var ldivs = document.querySelectorAll(".ldiv");
  var rdivs = document.querySelectorAll(".rdiv");
  ldivs.forEach((div) => {placeDiv(div,"left");});
  rdivs.forEach((div) => {placeDiv(div,"right");});
}

resizeMulticolDivs();
placeHorizontalDivs();

/*for (el of document.getElementsByClassName("washhead")) {
    el.style.top = el.getBoundingClientRect().top + window.scrollY+"px";
}*/

document.body.dispatchEvent(new Event("themeLoaded"));