var open=false; var uc=0; ajaxchat_init(); if (window.addEventListener) { window.addEventListener('onload', ajaxchat_init, false); } else if (window.attachEvent) { window.attachEvent('onload', ajaxchat_init); } function ajaxchat_init() { var cook,split,tmp,i; cook=document.cookie.split(";"); for(i=0;iajaxchat_xml.php?action=online_count&t="+new Date().getTime()); cReq.send(null); } function im_kp(el, e) { if(!e) { e=window.event; } if(e.keyCode==13) { updateName(el); } } function reloadChat() { loadEl(document.getElementById("online_list"),"ajaxchat_xml.php?action=online_list",function() { return true; }); } function updateName(el) { var updateReq=getXML(); updateReq.onreadystatechange=function() { if(updateReq.readyState==4 && updateReq.status==200) { if(updateReq.responseText.match("OK")) { var tmp=updateReq.responseText; tmp=tmp.split(":"); document.getElementById("myName").value=tmp[1]; document.getElementById("msg").focus(); reloadChat(); } else { alert(updateReq.responseText); } } } updateReq.open("GET","ajaxchat_xml.php?action=updateName&name="+el.value); updateReq.send(null); } function messagesCB() { var el=document.getElementById("messages"); if(!el) { return false; } el.scrollTop=el.scrollHeight; if(open) { setTimeout("loadEl(document.getElementById(\"messages\"),\"ajaxchat_xml.php?action=messages\",messagesCB);",1000); } } function listCB() { if(open) { setTimeout("loadEl(document.getElementById(\"online_list\"),\"ajaxchat_xml.php?action=online_list\",listCB);",5000); } } function openCB() { loadEl(document.getElementById("messages"),"ajaxchat_xml.php?action=messages",messagesCB); loadEl(document.getElementById("online_list"),"ajaxchat_xml.php?action=online_list",listCB); el=document.getElementById("msg"); if(el) { setTimeout("document.getElementById('msg').focus();",200); } //Stupid IE hack } function openOnline() { if(document.getElementById("online")) { document.getElementById("online").parentNode.removeChild(document.getElementById("online")); document.cookie="ajaxchat_open=0;"; open=false; return; } document.cookie="ajaxchat_open=1;"; open=true; var el=document.createElement("div"); el.style.position="fixed"; el.style.bottom="20px"; el.style.right="0px"; el.style.backgroundColor="#ffffff"; el.id="online"; el.innerHTML="
loading.gif'>
Loading..
\n"; document.body.appendChild(el); loadEl(el,"ajaxchat_xml.php?action=online&t="+new Date().getTime(),openCB); } function loadEl(el, url, cb) { if(!el || !url) { return false; } var req=getXML(); req.onreadystatechange=function() { if(req.readyState==4 && req.status==200) { el.innerHTML=req.responseText; cb(); } }; req.open("GET",url); req.send(null); } function getXML() { try { httpreq=new XMLHttpRequest(); } catch(err) { try { httpreq=new ActiveXObject("Microsoft.XMLHTTP"); } catch(err) { try { httpreq=new ActiveXObject("Msxml2.XMLHTTP"); } catch(err) { } } } if(!httpreq) { alert("XMLHttpRequest not supported"); return false; } return httpreq; } function pingIM() { var pingReq=getXML(); pingReq.open("GET","ajaxchat_ping.php?"+new Date().getTime()); pingReq.send(null); } function msg_kp(el,e) { if(!e) { e=window.event; } if(e.keyCode==13 && el.value.length) { sendMsg(el.value); el.value=""; } } function sendMsg(txt) { var sendReq=getXML(); sendReq.onreadystatechange=function() { if(sendReq.readyState==4 && sendReq.status==200) { if(sendReq.responseText.match("ERROR")) { alert("There was an error sending your message."); return false; } } } sendReq.open("GET","ajaxchat_xml.php?action=send&msg="+escape(txt)); sendReq.send(null); }