var write = function() { if(ZITALK_LASTPID==-1) // if lastPId is -1 the chat is loading you can't send message return false; var comment = document.getElementById('zitalk_comment'); var loading = document.getElementById('loading'); var a = new zajax(); a.page = ZITALK_PAGE+"?"+Math.random()+"="+Math.random(); a.query = "action=write&data="+encodeURIComponent(comment.value); a.onRequest = function() { ZITALK_SENDING = true; // if message is sending the chat stop loading for syncronyzing reasons }; a.onError = function() { alert('Error saving comment, please try again'); ZITALK_SENDING = false; }; a.onComplete = function(t) { removeAllChilds(loading); // hide loading message ZITALK_SENDING = false; // finish saving comment, the chat can load normally comment.value = ''; // empty comment box comment.focus(); // focus comment box }; a.request(); }; var read = function(id) { if(ZITALK_SENDING==true) return false; var chat = document.getElementById('chat'); var tmpCommentsId = new Array(); if(ZITALK_LASTPID==-1) //first DDBB read { ZITALK_LASTPID = 0; ZITALK_FIRSTLOAD = true; // first load of chat don't show with animations } var a = new zajax(); a.page = ZITALK_PAGE+"?"+Math.random()+"="+Math.random(); a.query = "action=read&data="+id; a.response = 'XML'; a.onRequest = function() { ZITALK_SENDING = true; if(ZITALK_FIRSTLOAD==true) { removeAllChilds(chat); var txt = document.createTextNode('Loading...'); var img = document.createElement('img'); img.src = 'img/loading.gif'; img.alt = 'loading'; chat.appendChild(txt); chat.appendChild(img); } }; a.onError = function() { alert('Error reading DDBB'); ZITALK_SENDING = false; }; a.onComplete = function(t) { if(ZITALK_FIRSTLOAD==true) removeAllChilds(chat); // hide loading message if(t) { var messages = t; messages = messages.getElementsByTagName('ms').item(0); var message = messages.getElementsByTagName('m'); for(var i=0;i0) { lis[0].parentNode.removeChild(lis[0]); len--; } if(t) { var users = t.getElementsByTagName('us').item(0); var user = users.getElementsByTagName('u'); for(var i=0;i0) window.setTimeout(function() { ele.scrollTop = type; }, time); }; var setIntervals = function(option) { if(option==='open') { ZITALK_CHATINTERVAL = window.setInterval(function(){lastId()}, ZITALK_REFRESH_RATE); // set chat refresh interval in milisecons ZITALK_OUINTERVAL = window.setInterval(function(){onlineUsers()}, ZITALK_REFRESH_RATE_OU); // set online users refresh interval in milisecons } else if(option==='close') { window.clearInterval(ZITALK_CHATINTERVAL); window.clearInterval(ZITALK_OUINTERVAL); } };