/* * $RCSfile$ * $Revision: 19342 $ * $Date: 2005-07-20 09:30:31 -0700 (Wed, 20 Jul 2005) $ * * Copyright (C) 2003-2008 Jive Software. All rights reserved. * * This software is the proprietary information of Jive Software. Use is subject to license terms. */ // 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 = "location=no,status=no,toolbar=no,personalbar=no,menubar=no,directories=no,"; var winUp = 0; var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left; var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top; w = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width; h = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height; var winleft = ((w / 2) - (width / 2)) + dualScreenLeft; var wintop = ((h / 2) - (height / 2)) + dualScreenTop; defaultOptions += "scrollbars=no,resizable=yes,top=" + winUp + ",left=" + winleft + ",top=" + wintop + ","; defaultOptions += "width=" + width + ",height=" + height; return 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(); return null; } } 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 = rel2full(getTopLevelWindow(),'userinfo.jsp'); return true; } else{ return false; } } function cancelQueue(workgroup, chatID){ getTopLevelWindow().location.href = rel2full(getTopLevelWindow(),'userinfo.jsp?workgroup=' + workgroup +'&chatID='+chatID); return true; } function confirmCancelAndClose(message) { if (confirm(message)) { getTopLevelWindow().location.href = rel2full(getTopLevelWindow(),'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 = rel2full(getTopLevelWindow(),'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); } } function informConnectionClosed() { alert('Your support session has ended, you will be redirected to the transcript page.'); parent.location.href = rel2full(parent,'transcriptmain.jsp'); } function checkTime(i) { if (i < 10) { i = "0" + i; } return i; } var lastMessageFrom; var agentName = ''; var partecipants = new Array(); function getNumPartecipants(name) { var count = 0; for(var i=0;i 0 ) { partecipants.push(name); return true; } return false; } function delPartecipant(name) { for(var i=0;i 2) addName = true; if( partecipants.length == 2 && !isMe) { if( agentName != from ) { agentName = from; document.getElementById('initialAgent').innerHTML = agentName; } } var hours = today.getHours(); var minutes = today.getMinutes(); if(hours < 10){ hours = "0" + hours; } if(minutes < 10){ minutes = "0" + minutes; } var time = hours + ":" + minutes; var body = ''; if(isAnnouncement) { // Visualizzo messaggio centrale di benvenuto body = '
  • '; body += '

    '; if( !isdecode) body += text.replace(/
    /g,""); else body += decodeURIComponent(text); body += '

    '; body += '
  • '; yakDiv.append(body); } else { // Visualizzo mesaggio chat var cssClass = ''; if( isMe ){ if(sameFrom){ cssClass='bubble-right'; } else { cssClass='first-bubble-right'; } } else { if(sameFrom){ cssClass='bubble-left'; } else { cssClass='first-bubble-left'; } } if( boxid !== undefined ) body = '
  • '; else body = '
  • '; body += '
    '; // search for yakDiv.find('#msg1 .header .pull-right')[0]; // if found - Replace waiting with clock // va inserito al posto di //'+ time+... var elem = null; if( boxid !== undefined ) elem = yakDiv.find('#' + boxid + ' .header small')[1]; var rig = ''; var rsf = ''; if( state === undefined || (state !== undefined && state == 0) ) { rig = '' + time; rsf = ''; } if( state !== undefined && state == 1 ) { rig = ''; rsf = rig; } if( state !== undefined && state == -1 ) { rig = 'Message not sent! '; rsf = rig; } if( elem == null && text != '' ) { if(!sameFrom){ if(isMe) { body += ' '; body += ''+ rig+ ''; } else { if( addName) { body += ''+ from+ ''; } body += ''+ rig+ ''; } } else { if(isMe) { body += ' '; body += ''+ rsf+ ''; } else { body += ''+ rsf+ ''; } } body += '
    '; body += '

    '; if( !isdecode) body += text; else body += decodeURIComponent(text); body += '

    '; body += '
  • '; yakDiv.append(body); } else if( elem != null) { if( elem.getAttribute('role') == 'data-nsm') { elem.innerHTML = rig; } else { elem.innerHTML = rsf; } } } lastMessageFrom = from; } function toggleTyping(yakWin,flag) { var endDiv = $jq('#'+yakWin.name).contents().find('#enddiv'); if( flag) { endDiv.html(''); scrollYakToEnd(yakWin); } else { endDiv.html(''); } } function scrollYakToEnd(yakWin) { try { document.getElementsByName(yakWin.name)[0].contentWindow.scrollBottom(); } catch(er){ } } function doChatByURL(url, query) { var form = document.createElement("form"); form.setAttribute("method", "post"); form.setAttribute("action", url); // Check for query string if( query ) { var pairs = query.split("&"); for (var i = 0; i < pairs.length; i++) { var keyValuePair = pairs[i].split("="); var input = document.createElement("input"); input.setAttribute("type", "hidden"); input.setAttribute("name", keyValuePair[0]); input.setAttribute("value", unescape(keyValuePair[1])); form.appendChild(input); } } // Check for engagement parameter if (typeof(engagement) != 'undefined' && engagement && engagement.getDomainUserId() != null) { var domain_userid = document.createElement("input"); domain_userid.setAttribute("type", "hidden"); domain_userid.setAttribute("name", "engage_duid"); domain_userid.setAttribute("value", unescape(engagement.getDomainUserId())); form.appendChild(domain_userid); } if (typeof(engagement) != 'undefined' && engagement && engagement.getDomainSessionId() != null) { var domain_sessionid = document.createElement("input"); domain_sessionid.setAttribute("type", "hidden"); domain_sessionid.setAttribute("name", "engage_sid"); domain_sessionid.setAttribute("value", unescape(engagement.getDomainSessionId())); form.appendChild(domain_sessionid); } document.body.appendChild(form); form.target = "_self"; form.submit(); } function doChat(name, url, width, height, query) { var form = document.createElement("form"); form.setAttribute("method", "post"); form.setAttribute("action", url); // Check for query string if( query ) { var pairs = query.split("&"); for (var i = 0; i < pairs.length; i++) { var keyValuePair = pairs[i].split("="); var input = document.createElement("input"); input.setAttribute("type", "hidden"); input.setAttribute("name", keyValuePair[0]); input.setAttribute("value", unescape(keyValuePair[1])); form.appendChild(input); } } // Check for engagement parameter if (typeof(engagement) != 'undefined' && engagement && engagement.getDomainUserId() != null) { var domain_userid = document.createElement("input"); domain_userid.setAttribute("type", "hidden"); domain_userid.setAttribute("name", "engage_duid"); domain_userid.setAttribute("value", unescape(engagement.getDomainUserId())); form.appendChild(domain_userid); } if (typeof(engagement) != 'undefined' && engagement && engagement.getDomainSessionId() != null) { var domain_sessionid = document.createElement("input"); domain_sessionid.setAttribute("type", "hidden"); domain_sessionid.setAttribute("name", "engage_sid"); domain_sessionid.setAttribute("value", unescape(engagement.getDomainSessionId())); form.appendChild(domain_sessionid); } document.body.appendChild(form); var w = launchWin(name, '', width, height); if (w != null) { form.target = name; form.submit(); } } function inIframe () { try { return window.self !== window.top; } catch (e) { return true; } } function bindEvent(el, eventName, eventHandler) { if (el.addEventListener){ el.addEventListener(eventName, eventHandler); } else if (el.attachEvent){ el.attachEvent('on'+eventName, eventHandler); } } function oneTime(el, s, fn) { var evts = s.split(' '); for (var i=0, iLen=evts.length; i -1; } function removeElement(element) { element.parentNode.removeChild(element); } /* executeFunctionByName("My.Namespace.functionName", window, arguments); * http://stackoverflow.com/questions/359788/how-to-execute-a-javascript-function-when-i-have-its-name-as-a-string * */ function executeFunctionByName(functionName, context /*, args */) { var args = [].slice.call(arguments).splice(2); var namespaces = functionName.split("."); var func = namespaces.pop(); for(var i = 0; i < namespaces.length; i++) { context = context[namespaces[i]]; } return context[func].apply(this, args); } function aurl(url) { if( parent == null) return url; var scheme = window.location.protocol; try { scheme = parent.location.protocol; } catch(err) {} var new_url = url; var indexs = url.indexOf("/"); if (indexs != -1) { new_url = scheme + url.substring( indexs ); } return new_url; } function rel2full(w, url) { var new_url = w.location.protocol + '//' + w.location.hostname; if( w.location.port != '' ) new_url += ':' + w.location.port; var path = w.location.pathname.split('/'); new_url += '/' + path[1] + '/'; new_url += url; return new_url; } function ajaxCall(url,params,onsuccess,onerror) { var ajax = new XMLHttpRequest(); ajax.open("GET", url+"?"+params, true); ajax.send(); ajax.onreadystatechange = function() { if (ajax.readyState == 4 ) { if (ajax.status == 200) { onsuccess(ajax.responseText); } else if (ajax.status == 400) { if( onerror) onerror(ajax.status); } else { if( onerror) onerror(ajax.status); } } } }