// ----> Create Functions
// Set Style
// Use: setStyleInEleId("idElement", "background-color", "#ff9914");
function setStyleInEleId(id, style, value) {
    const ele = document.getElementById(id);
    if (ele) {
        ele.style.setProperty(style, value);
    }
};

// Use: setStyleInEleClass();
function setStyleInEleClass(classNa, styleToChange, value) {
    let divsToChange = document.querySelectorAll(classNa);
    if (divsToChange) {
        divsToChange.forEach(function (div) {
            div.style[styleToChange] = value;
        });
    }
};

// SetChildDiv
// Use: deleteChildStyleId("idParent", 1, "height", "");
function deleteChildStyleId(idParent, childrenPosition, prop, value){
    const parentContainer = document.getElementById(idParent);
    if(parentContainer){
        const child = parentContainer.children[childrenPosition];
        if(child){
            child.style[prop] = value;
        }
    }
};

// ----> CRUD OPERATIONS

// 01. Add Class in ID element
// Use: addClassesInEleId("step1_customDivBoostrap", ["mt-4", "text-center", "bg-red"]);
function addClassesInEleId(id, classNames) {
    const ele = document.getElementById(id);
    if (ele) {
        classNames.forEach(className => {
            ele.classList.add(className);
        });
    }
};


// 02. Delete Class in ID element
// Use: deleteClassesInEleId("step1_customDivBoostrap", ["mt-4", "text-center", "bg-red"]);
function deleteClassesInEleId(id, classNames) {
    const ele = document.getElementById(id);
    if (ele) {
        classNames.forEach(className => {
            ele.classList.remove(className);
        });
    }
};

// 03. Add Class in Class element
// Use: addClassesInEleClass(".step1_customDivBoostrap", ["mt-4", "text-center", "bg-red"]);
function addClassesInEleClass(classNa, classNames) {
    const elements = document.querySelectorAll(classNa);
    if (elements.length > 0) {
        elements.forEach((element) => {
            classNames.forEach(className => {
                element.classList.add(className);
            });
        });
    }
};

// 04. Delete Class in Class element
// Use: deleteClassesInEleClass(".step1_customDivBoostrap", ["mt-4", "text-center", "bg-red"]);
function deleteClassesInEleClass(classNa, classNames) {
    const elements = document.querySelectorAll(classNa);
    if (elements.length > 0) {
        elements.forEach(element => {
            classNames.forEach(className => {
                element.classList.remove(className);
            })
        });
    }
};

// 05. Add HTML Contain
// Change the html content in id element
function setHTMLInEleId(id, newHMTL){
    const element = document.getElementById(id);

    if(element){
        while(element.firstChild){
            element.removeChild(element.firstChild);
        }
        element.innerHTML = newHMTL;
    }
};

window.onload = function() {
    var button = document.getElementById('button_Next');

    button.disabled = true;
}


function toggleButtonState() {
    var checkbox = document.getElementById('myCheckbox');

    var button = document.getElementById('button_Next');

    if (checkbox.checked) {
        button.disabled = false;
    } else {
        button.disabled = true;
    }
}


function Show() {
    $(".menu-container, .logo , li, .close, .icon-bar, #nav-lists").addClass("responsive");

    $("#checkContainer").css("flex-direction", "column");
    
  }
  
  function Hide(){
    $(".menu-container, .logo , li, .close, .icon-bar, #nav-lists").removeClass("responsive");

    $("#checkContainer").css("flex-direction", "");
  }
  
  let createHeader = () => {
      let menu = $("#menu");
      let list = $("<ul>",{class: "nav-list"});
      menu.append(list)
      list.append("<li class='close'><span onclick='Hide()'>x</span></li>");
      json_menu.forEach((menu_item) => {
          list.append(
              getMenuItem(menu_item)
          );
      })
  }
  
  let getMenuItem = function (itemData) {
      let active = "";
      if(itemData.active){
          active = "active";
      }
      let item = $("<li>")
          .append(
      $("<a>", {
          href: itemData.href,
          html: itemData.name,
          class: active
      }));
      return item;
  };
  
  let createFooter = () => {
      let menu = $("#menu-footer");
      json_menu.forEach((menu_item) => {
          menu.append(
              getMenuItemFooter(menu_item)
          );
      })
  }
  
  let getMenuItemFooter = function (itemData) {
      let active = "";
      if(itemData.active){
          active = "active";
      }
      let item = 
      $("<a>", {
          href: itemData.href,
          html: itemData.name,
          class: active
      });
      return item;
  };

  if (window.location.href.indexOf("sell-your-land.php") > -1) {
    document.addEventListener("DOMContentLoaded", function () {
        var ttNumberDiv = document.getElementById("tt_number");
        if (ttNumberDiv) {
            var tooltipSpan = document.createElement("span");
            tooltipSpan.className = "tooltiptext";
            tooltipSpan.textContent = "Your reference number can be found on the bottom right corner of the letter that we sent you.";
            ttNumberDiv.appendChild(tooltipSpan);
        }
    });
}


  
  
  $(document).ready(function(){
      createHeader();
      createFooter();
  
      document.querySelectorAll('a[href^="#"]').forEach(anchor => {
          anchor.addEventListener('click', function (e) {
              e.preventDefault();
  
              document.querySelector(this.getAttribute('href')).scrollIntoView({
                  behavior: 'smooth'
              });
          });
      });
  });

  function displayNoneSiteMap() {
    var enlaces = document.querySelectorAll('.footer a');
    enlaces.forEach(function(enlace) {
        if (enlace.innerText.toLowerCase() === 'sitemap') {
            enlace.style.display = 'none';
        }
    });
}

document.addEventListener('DOMContentLoaded', displayNoneSiteMap);




