// Override the default trim method of String. String.prototype.trim = function() { var text = this; var start = 0; var end = text.length; var display = ""; for (var i = 0; i < text.length; i++) { display += text.charCodeAt(i) + " "; } for (var i = 0; i < text.length; i++) { var code = text.charCodeAt(i); if (code >= 33) { start = i; break; } else{ start++; } } for (var i = text.length; i > start; i--) { var code = text.charCodeAt(i - 1); if (code >= 33) { end = i; break; } } return text.substring(start, end); } // variable to tell whether or not a form has been clicked var clicked = false; function allowClick() { if (! clicked) { clicked = true; return true; } return false; } // Sequence for open window names var windowNameSeq = 0; // Array of all open windows var windows = new Array(); // Checks to see if a window exists function windowExists(name) { for (var i = 0; i < windows.length; i++) { // IE needs a try/catch here for to avoid an access violation on windows[i].name // in some cases. try { if (windows[i].name == name) { return true; } } catch (exception) { } } return false; } // Returns the window object - returns nothing if not found. function getWindow(name) { for (var i = 0; i < windows.length; i++) { try { if (windows[i].name == name) { return windows[i]; } } catch (exception) { } } } function removeWindow(name) { for (var i = 0; i < windows.length; i++) { try { if (windows[i].name == name) { windows.splice(i, 1); return; } } catch (exception) { } } } // Open a window given its unique name, url, width and height. function pushWin(name, url, width, height) { var defaultOptions = "location=yes,status=yes,toolbar=no,personalbar=no,menubar=no,directories=no,"; defaultOptions += "scrollbars=yes,resizable=yes,"; defaultOptions += "width=" + width + ",height=" + height; launchWinWithOptions(name, url, defaultOptions); } // Open a window given its unique name, url, width and height. function launchWin(name, url, width, height) { var defaultOptions = "fullscreen=no,location=no,status=no,titlebar=no,toolbar=no,personalbar=no,menubar=no,directories=no,"; var winleft = (screen.width - width) / 2; var winUp = (screen.height - height) / 2; defaultOptions += "scrollbars=no,resizable=no,edge:Raised,top=" + winUp + ",left=" + winleft + ","; defaultOptions += "width=" + width + ",height=" + height; launchWinWithOptions(name, url, defaultOptions); } // Open a window with given name, url, and options list function launchWinWithOptions(name, url, options) { if (! windowExists(name)) { var winVar = window.open(url, name, options); windows[windows.length] = winVar; return winVar; } else{ var theWin = getWindow(name); theWin.focus(); } } function getTopLevelWindow() { var win = window; if (win.parent == win) { return win; } while (win.parent != win) { win = window.parent.window; } return win; } // Close the current window object function closeWin(win) { win.close(); } // Handle closing of the current window function handleClose(message) { if (confirm(message)) { removeWindow(getTopLevelWindow().name); closeWin(getTopLevelWindow()); return true; } else{ return false; } } // Handle closing of the current window function confirmCancel(message) { if (confirm(message)) { getTopLevelWindow().location.href = 'userinfo.jsp'; return true; } else{ return false; } } function cancelQueue(workgroup, chatID){ getTopLevelWindow().location.href = 'userinfo.jsp?workgroup=' + workgroup +'&chatID='+chatID; return true; } function confirmCancelAndClose(message) { if (confirm(message)) { getTopLevelWindow().location.href = 'userinfo.jsp'; getTopLevelWindow().close(); return true; } else{ return false; } } // Handle closing of the current window function confirmCancel(message, workgroup, chatID) { if (confirm(message)) { getTopLevelWindow().location.href = 'userinfo.jsp?workgroup=' + workgroup +'&chatID='+chatID; return true; } else{ return false; } } function closeAll() { removeWindow(getTopLevelWindow().name); closeWin(getTopLevelWindow()); } // Opens the help window: function launchHelpWin() { var win = launchWin('helpwin', 'helpwin.jsp', 550, 350); } // Hide a DIV function hide(divId) { if (document.layers) { document.layers[divId].visibility = 'hide'; } else if (document.all) { document.all[divId].style.visibility = 'hidden'; } else if (document.getElementById) { document.getElementById(divId).style.visibility = 'hidden'; } } // Show a DIV function show(divId) { if (document.layers) { document.layers[divId].visibility = 'show'; } else if (document.all) { document.all[divId].style.visibility = 'visible'; } else if (document.getElementById) { document.getElementById(divId).style.visibility = 'visible'; } } function getDiv(divID) { if (document.layers) { return document.layers[divID]; } else if (document.all) { return document.all[divID]; } else if (document.getElementById) { return document.getElementById(divID); } } function getDivByDoc(divID, doc) { if (doc.layers) { return doc.layers[divID]; } else if (doc.all) { return doc.all[divID]; } else if (doc.getElementById) { return doc.getElementById(divID); } } // TODO function showTypingIndicator(flag) { if (flag) { // put the text in the div } else{ // blank out the div } } function getTimeStr(){ var now= new Date(); var hour=now.getHours(); var minute=now.getMinutes(); var second=now.getSeconds(); var time = ""; if(hour/10 >= 1) time = time + hour; else time = time + "0"+hour; if(minute/10 >= 1) time = time +":"+ minute; else time = time + ":0"+minute; if(second/10 >=1) { time = time +":"+ second; } else { time = time + ":0"+second; } return time; } function informConnectionClosed() { alert('Your support session has ended, you will be redirected to the transcript page.'); parent.location.href = 'transcriptmain.jsp'; } function addChatText(yakWin, time, from, text) { // The div to write to: var yakDiv = yakWin.document.getElementById('ytext'); // This will be an announcement if there is no from passed in var isAnnouncement = (from == ""); // Create a new span node in the yakDiv. Record the num of nodes right now - used later // to see if the node was really added: var numChildren = yakDiv.childNodes.length; var nameSpan = document.createElement("span"); var textSpan = document.createElement("span"); if (isAnnouncement) { nameSpan.setAttribute("class", "chat-announcement"); textSpan.setAttribute("class", "chat-announcement"); } else{ textSpan.setAttribute("class", "text"); } // add another span containing the username if this is not an announcement: var fromIsCurrentUser = false; if (! isAnnouncement) { // is the from the same as the current user? fromIsCurrentUser = (nickname == from); if (fromIsCurrentUser) { nameSpan.setAttribute("class", "client-name"); } else{ nameSpan.setAttribute("class", "operator-name"); } } var chatLineDiv = document.createElement("div"); chatLineDiv.setAttribute("class", "chat-line"); var appendFailed = false; try { if (! isAnnouncement) { nameSpan.innerHTML = "["+time+"]"+from + ": "; chatLineDiv.appendChild(nameSpan); } textSpan.innerHTML = text; chatLineDiv.appendChild(textSpan); yakDiv.appendChild(chatLineDiv); } catch (exception) { appendFailed = true; } if (! appendFailed) { // Make sure the browser appended: appendFailed = (numChildren == yakDiv.childNodes.length); } if (appendFailed) { var inn = yakDiv.innerHTML; inn += "
"; if (! isAnnouncement) { inn += "" + from + ": "; // yakDiv.innerHTML = inn; } // var inn = yakDiv.innerHTML; inn += "" : "chat_text\">"); inn += text + "
"; yakDiv.innerHTML = inn; } else{ // yakDiv.appendChild(document.createElement("br")); } } function addChatWords(yakWin,time, from, text) { // The div to write to: //var userNickname='<'+Nickname+'>'+'say:'; //text=userNickname+text; //chatwordsWin.innerText+=text; // The div to write to: var yakDiv = yakWin.document.getElementById('ytext'); // This will be an announcement if there is no from passed in var isAnnouncement = (from == ""); // Create a new span node in the yakDiv. Record the num of nodes right now - used later // to see if the node was really added: var numChildren = yakDiv.childNodes.length; var nameSpan = document.createElement("span"); var textSpan = document.createElement("span"); if (isAnnouncement) { nameSpan.setAttribute("class", "chat-announcement"); textSpan.setAttribute("class", "chat-announcement"); } else{ textSpan.setAttribute("class", "text"); } // add another span containing the username if this is not an announcement: var fromIsCurrentUser = false; if (! isAnnouncement) { // is the from the same as the current user? fromIsCurrentUser = (nickname == from); if (fromIsCurrentUser) { nameSpan.setAttribute("class", "client-name"); } else{ nameSpan.setAttribute("class", "operator-name"); } } var chatLineDiv = document.createElement("div"); chatLineDiv.setAttribute("class", "chat-line"); var appendFailed = false; try { if (! isAnnouncement) { nameSpan.innerHTML = ""+time+" "+from + ": "; chatLineDiv.appendChild(nameSpan); } textSpan.innerHTML = text; chatLineDiv.appendChild(textSpan); yakDiv.appendChild(chatLineDiv); } catch (exception) { appendFailed = true; } if (! appendFailed) { // Make sure the browser appended: appendFailed = (numChildren == yakDiv.childNodes.length); } if (appendFailed) { var inn = yakDiv.innerHTML; inn += "
"; if (! isAnnouncement) { inn += "[" +time+ "] " + from + ": "; // yakDiv.innerHTML = inn; } // var inn = yakDiv.innerHTML; inn += "" : "chat_text\">"); inn += text + "
"; yakDiv.innerHTML = inn; } else{ //yakDiv.appendChild(document.createElement("br")); } } function scrollYakToEnd(yakWin) { var endDiv = yakWin.document.getElementById('enddiv'); yakWin.scrollTo(0, endDiv.offsetTop); } /* utf.js - UTF-8 <=> UTF-16 convertion * * Copyright (C) 1999 Masanao Izumo * Version: 1.0 * LastModified: Dec 25 1999 * This library is free. You can redistribute it and/or modify it. */ /* * Interfaces: * utf8 = utf16to8(utf16); * utf16 = utf16to8(utf8); */ function utf16to8(str) { var out, i, len, c; out = ""; len = str.length; for(i = 0; i < len; i++) { c = str.charCodeAt(i); if ((c >= 0x0001) && (c <= 0x007F)) { out += str.charAt(i); } else if (c > 0x07FF) { out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F)); out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F)); out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F)); } else { out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F)); out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F)); } } return out; } function utf8to16(str) { var out, i, len, c; var char2, char3; out = ""; len = str.length; i = 0; while(i < len) { c = str.charCodeAt(i++); switch(c >> 4){ case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: // 0xxxxxxx out += str.charAt(i-1); break; case 12: case 13: // 110x xxxx 10xx xxxx char2 = str.charCodeAt(i++); out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F)); break; case 14: // 1110 xxxx 10xx xxxx 10xx xxxx char2 = str.charCodeAt(i++); char3 = str.charCodeAt(i++); out += String.fromCharCode(((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0)); break; } } return out; } function UrlEncode(str) { return transform(str); } function transform(s) { var hex='' var i,j,t j=0 for (i=0; i 65535) { return ("err!") } first = Math.round(num/4096 - .5); temp1 = num - first * 4096; second = Math.round(temp1/256 -.5); temp2 = temp1 - second * 256; third = Math.round(temp2/16 - .5); fourth = temp2 - third * 16; return (""+getletter(third)+getletter(fourth)); } function getletter(num) { if (num < 10) { return num; } else { if (num == 10) { return "A" } if (num == 11) { return "B" } if (num == 12) { return "C" } if (num == 13) { return "D" } if (num == 14) { return "E" } if (num == 15) { return "F" } } } function showChatButton(workgroup) { var d = new Date(); var v1 = d.getSeconds() + '' + d.getDay(); var img = "http://webchat.appl.800best.com/webchat/live?action=isAvailable&workgroup=" + workgroup; var gotoURL = "http://webchat.appl.800best.com/webchat/start.jsp?workgroup=" + workgroup + "&location=" + window.location.href; document.write( ""); } function displayWorkgroup(workgroup,online,offline) { var d = new Date(); var v1 = d.getSeconds() + '' + d.getDay(); var img = "http://webchat.appl.800best.com/webchat/live?action=isAvailable&workgroup=" + workgroup +"&online="+ online + "&offline="+offline; var gotoURL = "http://webchat.appl.800best.com/webchat/start.jsp?workgroup=" + workgroup + "&location=" + window.location.href; document.write( ""); } function showChatButtonWithAgent(workgroup, agent) { var d = new Date(); var v1 = d.getSeconds() + '' + d.getDay(); var img = "http://webchat.appl.800best.com/webchat/live?action=isAvailable&workgroup=" + workgroup; var gotoURL = "http://webchat.appl.800best.com/webchat/start.jsp?workgroup=" + workgroup + "&agent=" + agent + "&location=" + window.location.href; document.write(""); } function showButtonWithoutUI(workgroup, params){ var d = new Date(); var v1 = d.getSeconds() + '' + d.getDay(); var img = "http://webchat.appl.800best.com/webchat/live?action=isAvailable&workgroup=" + workgroup; params = encodeURI(params); var gotoURL = "http://webchat.appl.800best.com/webchat/start.jsp?workgroup=" + workgroup + "&location=" + window.location.href + "&noUI=true&"+params; document.write(""); } function callHelp(serverAddress, workgroup, params ){ params = encodeURI(params==null?"":params); launchWin('framemain', 'http://'+serverAddress+'/webchat/start.jsp?workgroup='+workgroup+'&noUI=true&'+params, 700, 465 ); }