document.addEventListener("DOMContentLoaded",function(){var e=document.getElementById("message-container"),n=document.getElementById("message-input"),t=document.getElementById("send-button"),s=document.getElementById("contactSupport"),a=new Audio("notification.mp3");function r(e){var t=n.value.trim();if(""!==t){var s=new XMLHttpRequest;s.open("POST","../pages/support/send_message.php",!0),s.setRequestHeader("Content-type","application/x-www-form-urlencoded"),s.onreadystatechange=function(){4===s.readyState&&200===s.status&&i()},s.send("user="+encodeURIComponent(e)+"&message="+encodeURIComponent(t)),n.value=""}}function i(){var n=new XMLHttpRequest;n.open("GET","../pages/support/get_messages.php",!0),n.onreadystatechange=function(){if(4===n.readyState&&200===n.status){var t=document.createElement("div");t.innerHTML=n.responseText,t.children.length>e.children.length&&(t.lastElementChild.classList.contains("user1")&&(e.children.length>0&&a.play(),s.classList.add("show-contact-support")),e.innerHTML=t.innerHTML,e.scrollTop=e.scrollHeight)}},n.send()}t.addEventListener("click",function(){r("User2")}),n.addEventListener("keydown",function(e){"Enter"===e.key&&(e.preventDefault(),r("User2"))}),e.children.length>0&&a.play(),i(),setInterval(i,1e3)});