fetch('https://sspanel.serversistemleri.com/getclient', {
  method: 'GET',
  credentials: 'include'
})
.then(response => {
  const contentType = response.headers.get("content-type");
  if (contentType && contentType.indexOf("application/json") !== -1) {
			console.log(response);
      // Yanıt JSON ise
      return response.json().catch(error => {
        console.error('Error parsing JSON:', error);
        throw new Error('Invalid JSON');
      });
  } else {
      return response.text().then(text => {
        try {
          return JSON.parse(text);
        } catch (error) {
          console.error('Error parsing text as JSON:', error);
          throw new Error('Expected JSON, received text');
        }
      });
  }
})
.then(data => {
  return fetch('https://serversistemleri.com/save_session.php', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    credentials: 'include',
    body: JSON.stringify(data)
  });
})
.then(response => {
  return response.json().catch(error => {
  });
})
.then(result => {
})
.catch(error => {

});

document.addEventListener('DOMContentLoaded', function() {
    var tryElements = document.querySelectorAll('try');
    var usdElements = document.querySelectorAll('usd');
    var checkbox = document.getElementById('BtnPrice2');

    var currency = localStorage.getItem('currency') || 'usd';
    if (currency === 'usd') {
        checkbox.checked = true;
        tryElements.forEach(function(el) {
            el.style.display = 'none';
        });
        usdElements.forEach(function(el) {
            el.style.display = 'inline-block';
        });
        document.querySelector("html").className = "USD";
    } else {
        checkbox.checked = false;
        tryElements.forEach(function(el) {
            el.style.display = 'inline-block';
        });
        usdElements.forEach(function(el) {
            el.style.display = 'none';
        });
        document.querySelector("html").className = "TRY";
    }

    checkbox.addEventListener('change', function() {
        if (checkbox.checked) {
            tryElements.forEach(function(el) {
                el.style.display = 'none';
            });
            usdElements.forEach(function(el) {
                el.style.display = 'inline-block';
            });
            localStorage.setItem('currency', 'usd');
        } else {
            tryElements.forEach(function(el) {
                el.style.display = 'inline-block';
            });
            usdElements.forEach(function(el) {
                el.style.display = 'none';
            });
            localStorage.setItem('currency', 'try');
        }
    });
});

document.addEventListener('DOMContentLoaded', function () {
    const domainInput = document.getElementById('domain');
    const allowedCharacters = /^[a-zA-Z0-9çğüşıöÇĞÜŞİÖ\-\.]+$/;
    domainInput.addEventListener('input', function () {
        const value = domainInput.value;
        const filteredValue = value.split('').filter(char => allowedCharacters.test(char)).join('');
        if (value !== filteredValue) {
            domainInput.value = filteredValue;
        }
    });
});

const backToTopBtn = document.getElementById("backToTopBtn");

window.addEventListener("scroll", function() {
    if (window.scrollY > 250) {
        backToTopBtn.style.display = "block";
    } else {
        backToTopBtn.style.display = "none";
    }
});

backToTopBtn.addEventListener("click", function() {
    window.scrollTo({
        top: 0,
        behavior: "smooth"
    });
});

(function () {
	var options = {
			whatsapp: "+904443717",
			call_to_action: "Merhaba Server Sistemleri, yardıma ihtiyacım var.",
			position: "left",
	};
	var proto = document.location.protocol, host = "serversistemleri.com", url = proto + "//" + host;
	var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = url + '/design/js/whatsapp.js';
	s.onload = function () { WhWidgetSendButton.init(host, proto, options); };
	var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x);
})();
