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='