rendered paste bodyvar GetChaturl = "getChatData.php";var SetUserurl = "setuser.php";var SendChaturl = "sendChatData.php";var GetUserurl = "getuser.php";var GetLogOuturl = "logout.php";var lastID = -1; //initial value will be replaced by the latest known idvar httpReceiveChat = getHTTPObject();var httpSendChat = getHTTPObject();var httpbReceiveChat = getHTTPObject();var httpcReceiveChat = getHTTPObject();var httpLogOut = getHTTPObject();function getUser() { if (httpcReceiveChat.readyState == 4 || httpcReceiveChat.readyState == 0) { httpcReceiveChat.open("GET",'modules/Chat/getuser.php', true); httpcReceiveChat.onreadystatechange = handlehHttpReceiveUser; httpcReceiveChat.send(null); }}function handlehHttpReceiveUser() { if (httpcReceiveChat.readyState == 4) { result = httpcReceiveChat.responseText.split('---'); //the fields are seperated by --- buh = ""; for(i=0;i < (result.length-1);i=i+2) { //goes through the result one message at a time buh= buh +"<br>" +result[i]; } insertNewContentUser(buh); //inserts the new content into the page setTimeout('getUser();',4000); //executes the next data query in 4 seconds }}function insertNewContentUser(liUser) { document.getElementById("userList").innerHTML= liUser;}function logOut(){ try{ if (httpReceiveChat.readyState == 4){ if (httpLogOut.readyState == 4 || httpLogOut.readyState == 0) { currentName = document.forms['chatForm'].elements['name'].value; param3 = 'n='+ currentName; httpLogOut.open("POST",'modules/Chat/logout.php', true); //httpLogOut.onreadystatechange = handlehHttpReceiveUser; httpLogOut.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); httpLogOut.send(param3); httpLogOut.send(null); } } }catch(e){ }finally{ }}function insertUser() { if (httpbReceiveChat.readyState == 4 || httpbReceiveChat.readyState == 0) { currentName = document.forms['chatForm'].elements['name'].value; param1 = 'n='+ currentName; httpbReceiveChat.open("POST",'modules/Chat/setuser.php', true); httpbReceiveChat.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); httpbReceiveChat.onreadystatechange = handlehHttpReceiveChat; httpbReceiveChat.send(param1); httpbReceiveChat.send(null); }}function receiveChatText() { if (httpReceiveChat.readyState == 4 || httpReceiveChat.readyState == 0) { httpReceiveChat.open("GET",'modules/Chat/getChatData.php?lastID=' + lastID, true); httpReceiveChat.onreadystatechange = handlehHttpReceiveChat; httpReceiveChat.send(null); getUser(); } }//deals with the servers' reply to requesting new contentfunction handlehHttpReceiveChat() { if (httpReceiveChat.readyState == 4 ) { results = httpReceiveChat.responseText.split('---'); //the fields are seperated by --- if (results.length > 2) { for(i=0;i < (results.length-1);i=i+4) { //goes through the result one message at a time insertNewContent(results[i+1],results[i+2],results[i+3]); //inserts the new content into the page } lastID = results[results.length-5]; } setTimeout('receiveChatText();',4000); //executes the next data query in 4 seconds }}//inserts the new content into the pagefunction insertNewContent(liName,liText,liTime) { insertO = document.getElementById("outputList"); oLi = document.createElement('li'); oSpan = document.createElement('span'); oSpan.setAttribute('className','name'); //for IE's sake oSpan.setAttribute('class','name'); oName = document.createTextNode(liName+': '); oText = document.createTextNode(liText); oTime = document.createTextNode(liTime+'-'); oSpan.appendChild(oTime); oSpan.appendChild(oName); oLi.appendChild(oSpan); oLi.appendChild(oText); insertO.insertBefore(oLi, insertO.firstChild);}//stores a new comment on the serverfunction sendComment() { currentChatText = document.forms['chatForm'].elements['chatbarText'].value; if (currentChatText != '' & (httpSendChat.readyState == 4 || httpSendChat.readyState == 0)) { currentName = document.forms['chatForm'].elements['name'].value; param = 'n='+ currentName+'&c='+ currentChatText; httpSendChat.open("POST",'modules/Chat/sendChatData.php', true); httpSendChat.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); httpSendChat.onreadystatechange = handlehHttpSendChat; httpSendChat.send(param); document.forms['chatForm'].elements['chatbarText'].value = ''; } else { setTimeout('sendComment();',1000); }}//deals with the servers' reply to sending a commentfunction handlehHttpSendChat() { if (httpSendChat.readyState == 4) { receiveChatText(); //refreshes the chat after a new comment has been added (this makes it more responsive) }}//does celver things to the input and submitfunction checkStatus(focusState) { currentChatText = document.forms['chatForm'].elements['chatbarText']; oSubmit = document.forms['chatForm'].elements['submit']; if (currentChatText.value != '' || focusState == 'active') { oSubmit.disabled = false; } else { oSubmit.disabled = true; }}//autoasigns a random name to a new userfunction checkName() { currentName = document.forms['chatForm'].elements['name']; if (currentName.value == '') { currentName.value = 'guest_'+ Math.floor(Math.random() * 10000); }}//initiates the XMLHttpRequest object//as found here: http://www.webpasties.com/xmlHttpRequestfunction getHTTPObject() { var xmlhttp; /*@cc_on @if (@_jscript_version >= 5) try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } @else xmlhttp = false; @end @*/ if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; } } return xmlhttp;}function unLoadFnc(evt){ var e = (window.event) ? window.event : evt; logOut();}