document.addEventListener("DOMContentLoaded",function(){var e=document.getElementById("message-container"),n=document.getElementById("message-input"),t=document.getElementById("send-button"),a=new Audio("notification.mp3");function s(e){var t=n.value.trim();if(""!==t){var a=new XMLHttpRequest;a.open("POST","../pages/support/send_message.php",!0),a.setRequestHeader("Content-type","application/x-www-form-urlencoded"),a.onreadystatechange=function(){4===a.readyState&&200===a.status&&r()},a.send("user="+encodeURIComponent(e)+"&message="+encodeURIComponent(t)),n.value=""}}function r(){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("user2")&&a.play(),e.innerHTML=t.innerHTML,e.scrollTop=e.scrollHeight)}},n.send()}t.addEventListener("click",function(){s("User1")}),n.addEventListener("keydown",function(e){"Enter"===e.key&&(e.preventDefault(),s("User1"))}),r(),setInterval(r,1e3)}),document.getElementById("clearButton").addEventListener("click",function(){var e=new XMLHttpRequest;e.open("GET","remove_all_message.php",!0),e.onreadystatechange=function(){e.readyState===XMLHttpRequest.DONE&&(200===e.status?e.responseText:alert("Error: "+e.statusText))},e.send(),window.location.reload()});