/* Based in the XHTML live Chat (http://www.plasticshore.com) This script is published under a creative commons license license: http://creativecommons.org/licenses/by-nc-sa/2.0/ for support go to www.kinfule.tk */ var current_class = 'row2'; var counter = 0; var receiveDoAbort = 0; var sendDoAbort = 0; var ChatActionurl = "{view_shoutbox_js.U_ACTION}"; var refresh_time = {view_shoutbox_js.REFRESH_TIME}*1; var sendTimeout, receiveTimeout, cssRules, row1_color, row2_color, update_online; // Timeout time for XML Requests var TIMEOUT = 6000; // Initial value will be replaced by the latest known id var lastID = -1; // Has to do with the session updates var rc = 0; var su = (parseInt(30000/refresh_time)-2); window.onload = initJavaScript; // Initiates the two objects for sending and receiving data var httpReceiveChat = getHTTPObject(); var httpSendChat = getHTTPObject(); function initJavaScript() { if(document.forms['chatForm']) { document.forms['chatForm'].elements['chatbarText'].setAttribute('autocomplete','off'); //this non standard attribute prevents firefox' autofill function to clash with this script checkStatus(''); //sets the initial value and state of the input comment checkName(); //checks the initial value of the input name } get_colors(); receiveChatText(); //initiates the first data query // Get background colors from classes if (!document.styleSheets) { return; } } // Get the background colors from css classes function get_colors() { var prefix; var theRules = new Array(); if (document.styleSheets[0].cssRules) { theRules = document.styleSheets[0].cssRules prefix = 'td.'; } else if (document.styleSheets[0].rules) { theRules = document.styleSheets[0].rules prefix = 'TD.'; } for (x=0;x 0) { sibl2 = sibl.childNodes.item(0); field = sibl.tagName; if (field != undefined) { arr[field] = sibl2.data; if (arr['error_status'] == 1 && field == 'error_msg') { alert(arr['error_msg']); return false; } } } } } } // Add Content if (node.tagName == 'shout' && arr['id'] > lastID) { var shouter = (arr['shouter_link'] != -1) ? ''+arr['shouter']+'' : arr['shouter']; var message = unescape(arr['msg']); insertNewContent(arr['id'], shouter, message, arr['date'], lastID); } // Online List if (node.tagName == 'online' && update_online == true) { updating_s = 1; var temp = new Array; temp['id'] = arr['user_id']; temp['username'] = arr['username']; temp['link'] = arr['user_link']; temp['style'] = arr['link_style']; dbonline.push(temp); arr['link_style'] = ''; } if (node.tagName == 'onstats' && update_online == true) { var on_total = arr['total']; var on_guests = arr['guests']; var on_regs = arr['reg']; update_counters(on_total, on_regs, on_guests); } } } } // We need this for preventing an error when the request fails // Start the timer for the next request to read data if (obj == httpReceiveChat) { // Get the last id of this round or else keep the lastId untouch if ('id' in arr) { lastID = arr['id']*1; } else { lastID = lastID; } setTimeout('receiveChatText();', refresh_time); // Only update the online list when is loaded. if (update_online == true && updating_s == 1) { updateOnline(); } } } catch (e) { if (obj == httpReceiveChat) { // Don't loose the failed session update if (rc == 0) { rc = su; } } } } } function indicator_switch(state) { if(document.getElementById("act_indicator")) { var img = document.getElementById("act_indicator"); if(state==1) { img.style.visibility = "visible"; } else { img.style.visibility = "hidden" } } } // Lets put the shouts to the table function insertNewContent(liId, liName, liText, liTime, last_id) { // Row Id var id = 'row_'+counter; // Get a reference to the table var tableRef = document.getElementById("outputList"); // Insert a row in the table at row index 0 var newRow = tableRef.insertRow(0); // Put some attributes to the row newRow.setAttribute('id', id); if(current_class == "row2") { newRow.style.backgroundColor = row1_color; } else { newRow.style.backgroundColor = row2_color; } // Insert 2 cells in the row var newCell = newRow.insertCell(0); var newCell2 = newRow.insertCell(1); // Put some attributes to the rows newCell.setAttribute('width', 140); // Append a text node to the cell newCell.innerHTML = '' + liName + ''; newCell.innerHTML = newCell.innerHTML+ ' [x]'; newCell.innerHTML = newCell.innerHTML + '
' + liTime + ''; newCell2.innerHTML = '' + liText + ''; // Add 1 to counter counter++; // Fade effect // We don't want to fade the first pack of messages if(last_id != -1) { Fat.fade_element(id, 30, 2000, '{HEADER_LINK_COLOR}'); // Finally we can set the cells classes after the fade setTimeout("classChanger('"+newRow.id+"');", 2006); return true; } // Finally we can set the cells classes after the fade classChanger(newRow.id); } function classChanger(obj_id) { var obj = document.getElementById(obj_id); obj.childNodes[0].className = current_class; obj.childNodes[1].className = current_class; if(current_class == "row2") { current_class = "row1"; } else { current_class = "row2"; } } function removeShout (tblId, index, id) { // Ask for confirmation for the deletion of the shout if(confirm("{L_CONFIRM}")) { // Delete the data from the Database deleteShout(id); // Remove row removeRow(tblId, index); } } // Remove row from table function removeRow (tblId, index) { var tbl = document.getElementById(tblId); // Set the index to 0 if no index have been entered if(!index) { var index = 0; } // Try to delete the row, if error occurs, alert the user try { tbl.deleteRow(index); } catch (ex) { alert(ex); } } // Delete shout from DB function deleteShout(shout_id) { param = 'act=del&s='+ shout_id; httpSendChat.open("POST", ChatActionurl, true); httpSendChat.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); httpSendChat.onreadystatechange = new Function("handlehResponse(httpSendChat)"); // Timeout Prevention sendTimeout = setTimeout("ajaxTimeout(2);", TIMEOUT); sendDoAbort=0; httpSendChat.send(param); } // Stores a new comment on the server function sendComment() { currentChatText = encodeURIComponent(document.forms['chatForm'].elements['chatbarText'].value); if (currentChatText != '' && (httpSendChat.readyState == 4 || httpSendChat.readyState == 0)) { if(document.forms['chatForm'].elements['name']) { currentName = encodeURIComponent(document.forms['chatForm'].elements['name'].value); } else { // We put a letter for not sending the string empty. // The server will see if the user is logged in or not. currentName = "e"; } param = 'act=add&n='+ currentName+'&c='+ currentChatText; httpSendChat.open("POST", ChatActionurl, true); httpSendChat.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); httpSendChat.onreadystatechange = new Function("handlehResponse(httpSendChat)"); // Timeout Prevention sendTimeout = setTimeout("ajaxTimeout(3);", TIMEOUT); sendDoAbort=0; httpSendChat.send(param); // Disable the submit button document.forms['chatForm'].elements['submit'].disabled = true; } else if (currentChatText != '') { alert("{L_UNABLE}"); } } //does clever things to the input and submit function 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 user function checkName() { if(document.forms['chatForm'].elements['name']) { 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/xmlHttpRequest function 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; }