var request; var fetchid=0; var counter=1785504439; var latestid=0; var interval=10000; function runChat() { requestid = false; requestbody = false; send_data = false; if (window.XMLHttpRequest) { requestid = new XMLHttpRequest(); requestbody = new XMLHttpRequest(); send_data = new XMLHttpRequest(); } else if (window.ActiveXObject) { requestid = new ActiveXObject("Microsoft.XMLHTTP"); requestbody = new ActiveXObject("Microsoft.XMLHTTP"); send_data = new ActiveXObject("Microsoft.XMLHTTP"); } if ( requestid ) { requestid.onreadystatechange = compareId; checkId(); } setTimeout( 'runChat()', interval ); } function checkId() { counter++; requestid.onreadystatechange = compareId; requestid.open( 'GET', '/chat_return_id_xml.php?rnd='+counter, true ); requestid.send(null); compareId(); } function loadChat() { counter++; requestbody.onreadystatechange = displayChat; requestbody.open( 'GET', '/chat_body_xml.php?'+counter , true ); requestbody.send(null); displayChat(); } function compareId() { if (( requestid.readyState == 4 ) && ( requestid.status == 200 )){ fetchid=requestid.responseText; if (fetchid != latestid) { loadChat(); latestid=fetchid; } } } function displayChat() { if (( requestbody.readyState == 4 ) && ( requestbody.status == 200 )) { var chatfield = document.getElementById( 'chatfield' ); chatfield.innerHTML = requestbody.responseText; } } function sendData() { counter++; msgauthor=escape(document.getElementById("chatmsgauthor").value); msgbody=escape(document.getElementById("chatmsgbody").value); if (msgauthor == "") { alert("DU MÅSTE HA NAMN I CHATTEN LEN"); return false; } document.getElementById("chatmsgbody").value=""; send_data.onreadystatechange = updateWhenSent; send_data.open( 'GET', '/chat_input.php?author='+msgauthor+'&messagebody='+msgbody , true ); send_data.send(null); } function updateWhenSent() { if (( send_data.readyState == 4 ) && ( send_data.status == 200 )){ loadChat(); } }