function trimString (s) { while (s.substring(0,1) == ' ') { s = s.substring(1,s.length); } while (s.substring(s.length-1,s.length) == ' ') { s = s.substring(0,s.length-1); } return s; } function getCookies() { // [JAS]: Set up the scope for reading back in the cookies tempArray = document.cookie.split(';'); cookieArray = new Array(); x = 0; for (idx in tempArray) { cookieArray[x] = tempArray[idx].split('='); cookieArray[x][0] = trimString(cookieArray[x][0]); x++; } return cookieArray; } function getCookieVal(cookies,findCookieName) { for (idx in cookies) { cookieName = cookies[idx][0]; if(cookieName == findCookieName) { return cookies[idx][1]; } } return false; } function getCerPacketData(strPacket) { tempArray = strPacket.split(';'); packetArray = new Array(); x = 0; for (idx in tempArray) { packetArray[x] = tempArray[x].split('='); packetArray[x][0] = trimString(packetArray[x][0]); x++; } return packetArray; } function getCerPacketFlag(packetFlags,findPacketFlag) { for (idx in packetFlags) { flagName = packetFlags[idx][0]; if(flagName == findPacketFlag) { return packetFlags[idx][1]; } } return false; } function chatInviteAccept(inviteId) { inviteWindow = document.getElementById("chatWdw"); inviteWindow.style.visibility = "hidden"; var voiderThread = new Image(); voiderThread.src = "http://www.pcb123.com/cerberus/cerberus-livehelp/visitor.php?action=accept_invite&invite=" + inviteId + "&chatVisitor=" + chatVisitor; cer_launchChat(); } function chatInviteReject(inviteId) { inviteWindow = document.getElementById("chatWdw"); inviteWindow.style.visibility = "hidden"; var voiderThread = new Image(); voiderThread.src = "http://www.pcb123.com/cerberus/cerberus-livehelp/visitor.php?action=reject_invite&invite=" + inviteId + "&chatVisitor=" + chatVisitor; } function showInviteWindow(inviteId, agentName, message) { try { inviteWindow = document.getElementById("chatWdw"); if(undefined == inviteWindow) { var tmpInviteWdw = document.createElement("DIV"); tmpInviteWdw.id = "chatWdw"; document.body.appendChild(tmpInviteWdw); inviteWindow = document.getElementById("chatWdw"); } inviteWindow.innerHTML = "" + "" + "" + "
" + "" + ""+ "" + "" + "
You've been invited to chat!
" + "" + agentName + ": " + message + "" + "
" + ""+ ""+ ""+ "
" + "
" + "
"; positionInviteWindow(); } catch(exception) { alert(exception); } } function positionInviteWindow() { if(document.getElementById) { inviteWindow = document.getElementById("chatWdw"); } else return; if(null == inviteWindow) return; if(inviteWindow.style.visibility == "hidden") return; // Konq if (window && window.innerHeight && document.body && document.body.scrollTop != undefined) { xPos = window.innerWidth; yPos = window.innerHeight; xPos = (xPos - 250) / 2; yPos = (yPos - 150) / 2; xPos += document.body.scrollLeft; yPos += document.body.scrollTop; } // IE + Firefox else if(document.body && document.body.clientWidth) { xPos = document.body.clientWidth; yPos = document.body.clientHeight; xPos = (xPos - 250) / 2; yPos = (yPos - 150) / 2; xPos += document.body.scrollLeft; yPos += document.body.scrollTop; } else if(document.documentElement && document.documentElement.clientWidth) { xPos = document.documentElement.clientWidth; yPos = document.documentElement.clientHeight; xPos = (xPos - 250) / 2; yPos = (yPos - 150) / 2; xPos += document.documentElement.scrollLeft; yPos += document.documentElement.scrollTop; } else { xPos = 100; yPos = 100; } inviteWindow.style.position = "absolute"; inviteWindow.style.top = yPos + "px"; inviteWindow.style.left = xPos + "px"; inviteWindow.style.visibility = "visible"; setTimeout('positionInviteWindow()', 100); } // [JAS]: Keep a heartbeat going so we can detect visitors who have idled out from // those who are simply reading a page a long time. function runChatHeartbeat(is_heartbeat) { // [JAS]: Thump, thump. var url = "http://www.pcb123.com/cerberus/cerberus-livehelp/visitor.php?is_heartbeat=" + is_heartbeat + "&chatVisitor=" + chatVisitor + "&location=" + escape(document.location) + "&referrer=" + escape(document.referrer); try { if(document.getElementById) cerData = document.getElementById("cerData"); if(!cerData && document.body && document.body.appendChild) { var tDataObj=document.createElement('iframe'); tDataObj.setAttribute('id','cerData'); tDataObj.setAttribute('name','cerData'); tDataObj.setAttribute('border','0'); tDataObj.setAttribute('src', url); tDataObj.style.border='0px'; tDataObj.style.width='0px'; tDataObj.style.height='0px'; tDataObj.style.visibility='hidden'; tmpData = document.body.appendChild(tDataObj); cerData = document.getElementById("cerData"); cerReload = false; } else { cerReload = true; } cerDataPacketString = ""; if(cerData.contentDocument && cerData.contentDocument.body) { cerDataPacketString = cerData.contentDocument.body.innerHTML; if(cerReload) { cerData.contentDocument.location = url; } } else if (cerData.contentWindow.document && cerData.contentWindow.document.body) { cerDataPacketString = cerData.contentWindow.document.body.innerHTML; if(cerReload) { cerData.contentWindow.document.location = url; } } else { //alert("I'm something else entirely!"); } // [JAS]: Get any flags we need to know about from the server packet cerDataPacket = new Array(); if(cerDataPacketString) { cerDataPacket = getCerPacketData(cerDataPacketString); } // Chat invites? if((flagChatInvite = getCerPacketFlag(cerDataPacket,"invite_request")) && (inviteAgentName = getCerPacketFlag(cerDataPacket,"invite_agent_name")) && (inviteMessage = getCerPacketFlag(cerDataPacket,"invite_message"))) { if(!cerInviteActive) { showInviteWindow(flagChatInvite,inviteAgentName,inviteMessage); cerInviteActive = true; } } } catch(exception) { //alert(exception); var visit = new Image(); visit.src = url; } num_heartbeats++; // [JAS]: Only keep the heartbeat alive for 15 mins on a single page if(num_heartbeats <= 31) { setTimeout('runChatHeartbeat(1)',(!cerReload || num_heartbeats < 4) ? 10000 : 30000); } } function cer_launchChat() { window.open("http://www.pcb123.com/cerberus/cerberus-livehelp/chat_window/index.php?visitor=" + chatVisitor,"cer_ChatWnd","width=400,height=500,resize=yes,menu=no,scrollbars=no,status=no"); } var num_heartbeats = 0; var cookies = new Array(); var chatVisitor = null; var cerData = null; var cerDataPacketString = null; var cerDataPacket = new Array(); var cerReload = null; var cerInviteActive = false; cookies = getCookies(); var todayDate = new Date; todayDate.setDate(todayDate.getDate() + 7); if(chatVisitor = getCookieVal(cookies,"chatVisitor")) { // alert("We are a returning visitor with GUID: " + chatVisitor); } else { chatVisitor = escape('343adaa58eeaa5cb0f26813c7a406088'); document.cookie = 'chatVisitor=' + chatVisitor + '; expires=' + todayDate.toGMTString() + ';'; } setTimeout('runChatHeartbeat(0);',1000);