const currentScript=document.currentScript;document.addEventListener("DOMContentLoaded",function(){setTimeout(function(){(function(){function getQueryParam(param){const scriptSrc=currentScript.src;const urlParams=new URLSearchParams(scriptSrc.split('?')[1]);return urlParams.get(param)}const comp_id=getQueryParam('live_chat_id');function getCookieValue(name){const decodedCookies=decodeURIComponent(document.cookie);const cookies=decodedCookies.split(';');for(let cookie of cookies){cookie=cookie.trim();if(cookie.startsWith(name+"=")){return cookie.substring(name.length+1)}}return null}const liveChatLeadId=getCookieValue(`live_chat_lead_id_${comp_id}`);var iframeSrc=`https://leads.tgminfotech.com/get-live-chat?comp_id=${comp_id}`;if(liveChatLeadId){iframeSrc=`https://leads.tgminfotech.com/get-live-chat?comp_id=${comp_id}&lead_id=${liveChatLeadId}`}const iframeDiv=document.createElement("div");const iframe=document.createElement("iframe");iframe.src=iframeSrc;if(liveChatLeadId){iframe.style.height='800px';iframe.style.width='400px';iframe.style.maxHeight='80vh';iframe.style.maxWidth='80vw'}else{iframe.style.height='50px';iframe.style.width='50px';iframe.style.maxHeight='';iframe.style.maxWidth=''}iframe.style.position="fixed";iframe.style.opacity="0%";iframe.style.zIndex="999999";iframe.style.bottom="20px";iframe.style.border="none";iframe.style.transition="0.3s ease-in-out all";iframeDiv.appendChild(iframe);window.addEventListener("beforeunload",function(){iframe.contentWindow.postMessage({type:'notifyServer',status:0},'*')});window.addEventListener("pagehide",function(){iframe.contentWindow.postMessage({type:'notifyServer',status:0},'*')});window.addEventListener("blur",function(){iframe.contentWindow.postMessage({type:'notifyServer',status:0},'*')});window.addEventListener("focus",function(){iframe.contentWindow.postMessage({type:'notifyServer',status:1},'*')});document.addEventListener("visibilitychange",function(){if(document.hidden){iframe.contentWindow.postMessage({type:'notifyServer',status:0},'*')}else{iframe.contentWindow.postMessage({type:'notifyServer',status:1},'*')}});window.addEventListener("online",function(){iframe.contentWindow.postMessage({type:'notifyServer',status:1},'*')});window.addEventListener("offline",function(){iframe.contentWindow.postMessage({type:'notifyServer',status:0},'*')});const scriptTag=currentScript;scriptTag.parentNode.replaceChild(iframeDiv,scriptTag);window.addEventListener("message",function(event){if(event.data.type==='iframeResize'){if(event.data.position=='left'){iframe.style.left='20px';iframe.style.opacity="100%"}else{iframe.style.right='20px';iframe.style.opacity="100%"}}if(event.data.type==='lead_id'){const date=new Date();date.setTime(date.getTime()+(12*60*60*1000));const expires="expires="+date.toUTCString();document.cookie=`live_chat_lead_id_${comp_id}=${event.data.lead_id}; ${expires}; path=/`}if(event.data.type==='iframeHeightResize'){if(event.data.height=='800px'){iframe.style.height='800px';iframe.style.width='400px';iframe.style.maxHeight='80vh';iframe.style.maxWidth='80vw'}else{iframe.style.height='50px';iframe.style.width='50px';iframe.style.maxHeight='';iframe.style.maxWidth=''}}})})();},2000);});