var chtfltLogado=!1;var chtfltAtendimento=null;var src=sessionStorage.getItem('urlAtual')?sessionStorage.getItem('urlAtual'):chtfltUrl;var frame=null;var autenticar=!0;var debug=!1;var pathDev='';visitor=!1;function getScript(source,id,callback){var script=document.createElement('script');var prior=document.getElementsByTagName('script')[0];script.async=1;script.id=id;script.onload=script.onreadystatechange=function(_,isAbort){if(isAbort||!script.readyState||/loaded|complete/.test(script.readyState)){script.onload=script.onreadystatechange=null;script=undefined;if(!isAbort){if(callback)callback()}}};script.src=source;prior.parentNode.insertBefore(script,prior)} function closeIFrameChtflt(){document.getElementById('chatBot').style.display='none';document.getElementById('btnChatFlt').style.display='block';window.sessionStorage.setItem('chatBotPosition','close')} var checkOpenIframe=!1;function openIFrameChtflt(visitante){if(typeof visitante!=='undefined'){visitor=!0} if(typeof chtfltLogin!=='undefined'&&chtfltLogin!==''&&src.indexOf('inline')===-1){src=src+'/inline/1'} if(document.getElementById('bodyIframe')&&document.getElementById('bodyIframe').getElementsByTagName('iframe').length===0){var split=chtfltUrl.split('/Chat');var mainUrl=split[0];document.getElementById('bodyIframe').innerHTML='
';document.getElementById('bodyIframe').getElementsByTagName('iframe')[0].style.background="url("+pathDev+"/public/imagens/dots-load.gif) center center / 100px no-repeat";window.sessionStorage.setItem('chatBotPosition','open');checkOpenIframe=!0;setCss();frame=document.getElementById('iframeChatBot');frame.contentWindow.postMessage(JSON.stringify({action:"setCss",chtfltTema:chtfltTema}),'*');frame.style.display='block';document.getElementById('closeChatBot').style.display='block';document.getElementById('chatBot').style.display='block';document.getElementById('btnChatFlt').style.display='none';if(typeof chtfltWidthLogin!=='undefined'&&chtfltWidthLogin!='') document.getElementById("chatBot").style.width=chtfltWidthLogin+'px';if(typeof chtfltHeightLogin!=='undefined'&&chtfltHeightLogin!=''){document.getElementById("chatBot").style.height=chtfltHeightLogin+'px';setIframeHeight(chtfltHeightLogin)} if(typeof chtfltHeightLogin==='undefined'){document.getElementById("chatBot").style.height='540px';setIframeHeight(540)}}else{if(window.sessionStorage.getItem('chatBotPosition')!=='open'){document.getElementById('chatBot').style.display='block';document.getElementById('btnChatFlt').style.display='none';window.sessionStorage.setItem('chatBotPosition','open')}}} function setCss(){document.getElementById('closeChatBot').style.display='block'} function atualizarSessaoChtflt(){if(debug) console.log("Funcao: atualizarSessaoChtflt",typeof chtfltLogin!=='undefined'?chtfltLogin:"",chtfltAtendimento);var split=chtfltUrl.split('id/');var nomIdentificador=split[1];if(typeof chtfltLogin==='undefined') chtfltLogin={};chtfltLogin['id']=nomIdentificador;chtfltLogin['position']='open';frame.contentWindow.postMessage(JSON.stringify({action:'hideLogin'}),'*');frame.contentWindow.postMessage(JSON.stringify({action:'autenticar',chtfltLogin:chtfltLogin}),'*')} function gerarAtendimentoChtflt(){if(debug) console.log("Funcao: gerarAtendimentoChtflt");frame.contentWindow.postMessage(JSON.stringify({action:'reautenticar'}),'*')} function chtfltDeslogarSite(){frame.contentWindow.postMessage(JSON.stringify({action:'logout'}),'*')} function chtfltLogarSite(){chtfltDeslogarSite()} function iFrameLoaded(){if(document.getElementById('chtLoader')!==null){document.getElementById('chtLoader').remove()} if(!checkOpenIframe){return!1} checkOpenIframe=!1;frame.style.backgroundImage='none';if(debug){console.log("=================Iframe carregado...");console.log("=================frame = "+frame)} if(debug)console.log("=================Checando login");frame.contentWindow.postMessage(JSON.stringify({action:'checkLogin'}),'*');if(visitor){frame.contentWindow.postMessage(JSON.stringify({action:'visitor'}),'*')}else{frame.contentWindow.postMessage(JSON.stringify({action:'loginAtivado'}),'*')} checkLogin();var myEvent=window.attachEvent||window.addEventListener;var chkevent=window.attachEvent?'onmessage':'message';myEvent(chkevent,function(event){try{evento=JSON.parse(event.data)}catch(e){evento=event.data} if(evento.action!='resize'&&debug){console.log(evento)} if(evento.action=='resize'){if(typeof evento.origin!=='undefined'&&evento.origin=='login'&&typeof chtfltLogin!=='undefined'&&chtfltLogin!=""&&('cpf' in chtfltLogin||'email' in chtfltLogin||'telefone' in chtfltLogin)){if(debug)console.log("=================Fechando Chat");closeIFrameChtflt();if(debug)console.log("=================Ocultando Login");frame.contentWindow.postMessage(JSON.stringify({action:'hideLogin'}),'*');if(debug)console.log("=================chtfltLogado = false");chtfltLogado=!1}} if(evento=='errorLogin'){if(debug)console.log("=================autenticar = false");autenticar=!1} if(evento=='atualizar-sessao'){if(debug)console.log("=========e=======Atualizando sessao");atualizarSessaoChtflt()} if(evento.action=='autenticar'){if(debug)console.log("=================Autenticado!");var response=evento.response;if(typeof response.url!=='undefined'){if(debug)console.log("=================chtfltAtendimento = "+response.cod_atendimento);chtfltAtendimento=response.cod_atendimento}else{if(debug)console.log("=================chtfltLogado = true");chtfltLogado=!0}}else if(evento.action=='reautenticar'){if(debug)console.log("=================Reautenticado!");var response=evento.response;if(debug)console.log("=================chtfltAtendimento = "+response.cod_atendimento);chtfltAtendimento=response.cod_atendimento}else if(evento.origin=='chat'&&evento.action=='addUrlAtual'){sessionStorage.setItem('urlAtual',evento.value)}else if(evento.origin=='chat'&&evento.action=='removeUrlAtual'){sessionStorage.removeItem('urlAtual')}})} function checkLogin(){if(autenticar&&typeof chtfltLogin!=='undefined'&&chtfltLogin!=""&&('cpf' in chtfltLogin||'email' in chtfltLogin||'telefone' in chtfltLogin)&&chtfltLogado&&chtfltAtendimento==null){if(debug)console.log("=================Gerando atendimento");gerarAtendimentoChtflt()}else if(autenticar&&typeof chtfltLogin!=='undefined'&&chtfltLogin!=""&&('cpf' in chtfltLogin||'email' in chtfltLogin||'telefone' in chtfltLogin)&&!chtfltLogado){if(debug)console.log("=========abrechat========Atualizando sessao SAC");atualizarSessaoChtflt()}} function pageLoaded(){var position=window.sessionStorage.getItem('chatBotPosition');if(position=='open'){if(debug)console.log("=================Position = open => Abrindo Chat");openIFrameChtflt()}else{document.getElementById('btnChatFlt').style.display='block'}} function dragElement(elmnt){var pos1=0,pos2=0,pos3=0,pos4=0;var screenWidth=window.innerWidth;var screenHeight=window.innerHeight;var divWidth=elmnt.offsetWidth;var divHeight=elmnt.offsetHeight;if(document.getElementById(elmnt.id+"header")){document.getElementById(elmnt.id+"header").onmousedown=dragMouseDown}else{elmnt.onmousedown=dragMouseDown} function dragMouseDown(e){e=e||window.event;e.preventDefault?e.preventDefault():(e.returnValue=!1);pos3=e.clientX;pos4=e.clientY;screenWidth=window.innerWidth;screenHeight=window.innerHeight;divWidth=elmnt.offsetWidth;divHeight=elmnt.offsetHeight;document.onmouseup=closeDragElement;document.onmousemove=elementDrag} function elementDrag(e){e=e||window.event;e.preventDefault?e.preventDefault():(e.returnValue=!1);const posX=pos3-e.clientX;const posY=pos4-e.clientY;pos3=e.clientX;pos4=e.clientY;let newPosX=elmnt.offsetLeft-posX;let newPosY=elmnt.offsetTop-posY;if(newPosX<0){newPosX=0}else if(newPosX+divWidth>screenWidth){newPosX=screenWidth-divWidth} if(newPosY<0){newPosY=0}else if(newPosY+divHeight>screenHeight){newPosY=screenHeight-divHeight} elmnt.style.top=newPosY+"px";elmnt.style.left=newPosX+"px"} function closeDragElement(){document.onmouseup=null;document.onmousemove=null}} function setIframeHeight(chtfltHeight){"use strict";var ocultar=!1;if(document.getElementById("chatBot").style.display==='none'){document.getElementById("chatBot").style.display='block';ocultar=!0} var iframeHeight=parseInt(chtfltHeight)-parseInt(document.getElementById('chatBotCollapse').offsetHeight);if(ocultar){document.getElementById("chatBot").style.display='none'} document.getElementById("bodyIframe").style.height=iframeHeight+'px'} function detectmob(){if(navigator.userAgent.match(/Android/i)||navigator.userAgent.match(/webOS/i)||navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPad/i)||navigator.userAgent.match(/iPod/i)||navigator.userAgent.match(/BlackBerry/i)||navigator.userAgent.match(/Windows Phone/i)){return!0}else{return!1}} function detectmobSize(){if(window.innerWidth<=800&&window.innerHeight<=600){return!0}else{return!1}} function init(){if(debug)console.log('=================Construindo iframe...');var mainDiv='
'+'
'+'
'+'
'+''+'
'+'
'+'
'+'
'+'
'+'
';var divBtn='';var content=document.createElement('div');content.setAttribute("id","chatBot");content.setAttribute("class",chtfltTema);content.setAttribute("style",'display:none;'+((typeof chtfltWidth!=='undefined')?"width:"+chtfltWidth:""));content.innerHTML=mainDiv;document.body.appendChild(content);if(debug)console.log("=================Iframe criado!");var contentButton=document.createElement('div');contentButton.setAttribute('id','divBtnChtflt');contentButton.setAttribute('class',chtfltTema);contentButton.innerHTML=divBtn;document.body.appendChild(contentButton);var bol_robo=chtfltRobo;if(bol_robo==1&&typeof chtfltLogin!=='undefined'&&chtfltLogin!=""){if(debug)console.log("=================Redimensionando chat para robo");document.getElementById("chatBot").style.width='900px'} var abreChat=function(e){e.preventDefault?e.preventDefault():(e.returnValue=!1);if(debug)console.log("=================Abrindo Chat");if(frame!=null){checkLogin()} openIFrameChtflt()};if(document.getElementById('btnChatFlt').addEventListener){document.getElementById('btnChatFlt').addEventListener('click',abreChat)}else{document.getElementById('btnChatFlt').attachEvent('onclick',abreChat)} dragElement(document.getElementById("chatBot"));var myEvent=window.attachEvent||window.addEventListener;var chkevent=window.attachEvent?'onmessage':'message';myEvent(chkevent,function(event){event=event||window.event;try{evento=JSON.parse(event.data)}catch(e){evento=event.data} if(evento.action=='resize'){if(debug)console.log("Evento recebido: ",evento);if(debug)console.log("=================Redimensionando tela");if(typeof evento.origin!=='undefined'&&evento.origin=='login'){if(typeof chtfltWidthLogin!=='undefined'&&chtfltWidthLogin!='') document.getElementById("chatBot").style.width=chtfltWidthLogin+'px';if(typeof chtfltHeightLogin!=='undefined'&&chtfltHeightLogin!=''){document.getElementById("chatBot").style.height=chtfltHeightLogin+'px';setIframeHeight(chtfltHeightLogin)} if(typeof chtfltWidthLogin==='undefined') document.getElementById("chatBot").style.width=evento.width+'px';if(typeof chtfltHeightLogin==='undefined'){document.getElementById("chatBot").style.height='540px';setIframeHeight(540)}}else if(typeof evento.origin!=='undefined'&&evento.origin=='pesquisa'){if(typeof chtfltWidthPesquisa!=='undefined'&&chtfltWidthPesquisa!='') document.getElementById("chatBot").style.width=chtfltWidthPesquisa+'px';if(typeof chtfltHeightPesquisa!=='undefined'&&chtfltHeightPesquisa!=''){document.getElementById("chatBot").style.height=chtfltHeightPesquisa+'px';setIframeHeight(chtfltHeightPesquisa)} if(typeof chtfltWidthPesquisa==='undefined') document.getElementById("chatBot").style.width=evento.width+'px';if(typeof chtfltHeightPesquisa==='undefined'){document.getElementById("chatBot").style.height='540px';setIframeHeight(540)}}else if(typeof evento.origin!=='undefined'&&evento.origin!='login'&&evento.origin!='pesquisa'){if(typeof chtfltWidth!=='undefined'&&chtfltWidth!='') document.getElementById("chatBot").style.width=chtfltWidth+'px';if(typeof chtfltHeight!=='undefined'&&chtfltHeight!=''){document.getElementById("chatBot").style.height=chtfltHeight+'px';setIframeHeight(chtfltHeight)} if(typeof chtfltWidth==='undefined') document.getElementById("chatBot").style.width=evento.width+'px';if(typeof chtfltHeight==='undefined'){document.getElementById("chatBot").style.height='540px';setIframeHeight(540)}}else{document.getElementById("chatBot").style.width=evento.width+'px';document.getElementById("chatBot").style.height='540px';setIframeHeight(540)} if(detectmob()&&detectmobSize()){document.getElementById("chatBot").style.height='80vh'} if(typeof evento.chtfltLogado!=='undefined'){if(debug)console.log("=================Contato ja logado no SAC");chtfltLogado=!0} if(typeof evento.chtfltAtendimento!=='undefined'){if(debug)console.log("=================Atendimento existente");chtfltAtendimento=evento.chtfltAtendimento} if(typeof evento.origin!=='undefined'&&evento.origin=='pesquisa'&&typeof chtfltLogin!=='undefined'&&chtfltLogin!=""){if(debug)console.log("=================Tela de pesquisa => Atendimento ja finalizado.");chtfltAtendimento=null}}else{if(typeof evento.origin!=='undefined'&&evento.origin=='chat'&&evento.action=='closeWindow'){closeIFrameChtflt();document.getElementById('bodyIframe').innerHTML='';if(typeof ascCloseDialog!=='undefined'){if(evento.type=='finished'){ascCloseDialog(!0)}else{ascCloseDialog()}}} if(typeof evento.origin!=='undefined'&&evento.origin=='chat'&&evento.action=='inviteAccepted'){if(typeof ascConfirmDialog!=='undefined'){ascConfirmDialog(!0)} visitor=!1}}});pageLoaded()} if(!window.console){console={log:function(){}}};init()