var updatepending = false; var lastTimestamp = 0; var targetid = ""; var intervalID = 0; function checkEnter(e){ var characterCode; if(e && e.which){ //e = e characterCode = e.which; } else{ //e = event; characterCode = e.keyCode; } if(characterCode == 13){ sendText(); } return false; } function sendText(){ var chatlineentry = document.getElementById('chatline'); var chatline = encodeURIComponent(chatlineentry.value); ajax_appendContent("chat-pane", "/phos-shed/rest/channel/service.do", "lastTimestamp="+lastTimestamp+"&targetid="+targetid+"&content="+chatline); chatlineentry.value = ""; } function ajax_appendContent(divId,pathToFile,urlString){ var ajaxIndex = dynamicContent_ajaxObjects.length; dynamicContent_ajaxObjects[ajaxIndex] = new sack(); dynamicContent_ajaxObjects[ajaxIndex].requestFile = pathToFile; dynamicContent_ajaxObjects[ajaxIndex].URLString = urlString; dynamicContent_ajaxObjects[ajaxIndex].method="POST"; dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function(){ ajax_showAppend(divId,ajaxIndex); }; dynamicContent_ajaxObjects[ajaxIndex].runAJAX(); updatepending = true; } function ajax_showAppend(divId,ajaxIndex) { ajax_innerHTML(divId, dynamicContent_ajaxObjects[ajaxIndex].response); dynamicContent_ajaxObjects[ajaxIndex] = false; updatepending = false; } function ajax_innerHTML(divId, content){ if(content!=null && trim(content)!=""){ var div = document.getElementById(divId); var oldTimestamp = document.getElementById("lastTimestamp"); if(oldTimestamp){ var parent = oldTimestamp.parentNode; parent.removeChild(oldTimestamp); } var el = document.createElement("div"); div.appendChild(el); el.innerHTML=decodeURIComponent(content); lastTimestamp = document.getElementById("lastTimestamp").value; scrolltobottom(); } } function myajaxloader(){ if (updatepending==false){ updatepending=true; var now = new Date(); var time = now.getTime(); ajax_appendContent("chat-pane", "/phos-shed/rest/channel/service.do", "lastTimestamp="+lastTimestamp+"&targetid="+targetid); } } function trim(str){ return str.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); } function scrolltobottom(){ var objDiv = document.getElementById("chat-pane"); objDiv.scrollTop = objDiv.scrollHeight; } function initChannel(aTargetid){ clearInterval(intervalID); targetid = aTargetid; updatepending = false; lastTimestamp = 0; intervalID = setInterval("myajaxloader()",1000); var winH = screen.height; var winW = screen.width; // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight if (typeof window.innerWidth != 'undefined') { winW = window.innerWidth, winH = window.innerHeight } // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document) else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) { winW = document.documentElement.clientWidth, winH = document.documentElement.clientHeight } // older versions of IE else { winW = document.getElementsByTagName('body')[0].clientWidth, winH = document.getElementsByTagName('body')[0].clientHeight } var chatPane = document.getElementById('chat-pane'); chatPane.style.height = ""+(winH-400)+"px"; var channelDiv = document.getElementById('channel'); channelDiv.style.top = "100px"; channelDiv.style.right = "20px"; } function closeChatPane(){ clearInterval(intervalID); /* ajax call to close chat (remove sessionAttr "chatting" and append "{USER} has left the channel") */ ajax_appendContent("chat-pane", "/phos-shed/channel/close.do", "targetid="+targetid); var div = document.getElementById("channel"); div.style.display = "none"; div.style.visibility = "hidden"; } function showChannelNotify(targetid){ ajax_loadContent('channelNotification','/phos-shed/channel/notification.do?targetid='+targetid); var div = document.getElementById("channelNotification"); div.style.display = "block"; div.style.visibility = "visible"; } function hideChannelNotify(){ var div = document.getElementById("channelNotification"); div.style.display = "none"; div.style.visibility = "hidden"; return false; } function submitChannelNotificationForm(username, password, emailadd, currentUsername, targetid){ ajax_loadContent('channelNotification', '/phos-shed/channel/notificationSubmit.do?username='+username+'&emailadd='+emailadd+'&password='+password+'¤tUsername='+currentUsername+'&targetid='+targetid); } function submitChannelLeaveMessageForm(targetid, replyToMessageid, message){ var messageEnc = encodeURIComponent(message); ajax_loadContent('channelNotification', '/phos-shed/channel/sendMessage.do?targetid='+targetid+'&replyToMessageid='+replyToMessageid+'&message='+messageEnc); } function refreshme(){ window.location.reload(true); } function toggleChatMinimized(){ var channelInnerDiv = document.getElementById("channelinner"); if(channelInnerDiv){ if(channelInnerDiv.style.display == "none"){ channelInnerDiv.style.display = "block"; channelInnerDiv.style.visibilty = "visible"; }else{ channelInnerDiv.style.display = "none"; channelInnerDiv.style.visibilty = "hidden"; } } }