var Core={elMessages:$('#messages'),options:{},optionsMascara:{textAlign:!1},optionsMessage:{timeout:5000},init:function(url_submit,url_redirect,id_cod,rulesObj,var_function,atualizar,ignorar){if(typeof ignorar==='undefined'){ignorar=':hidden'}
this.aplicarMascaras();this.elMessages.ajaxError(function(){Core.message(lngGeral.erroGenerico,'danger')});$(this).ajaxError(function(){Core.message(lngGeral.erroSolicitacao,'danger')});if(jQuery().validate){var f=function(e){$(e).closest(".form-group").removeClass("has-success")};var l=$("form[name^='f_']").validate({errorElement:"span",errorClass:"help-block",errorPlacement:function(e,t){if(t.parent(".input-group").length){e.insertAfter(t.parent())}else{e.insertAfter(t)}},rules:{f_nom_email:{email:!0}},focusInvalid:!0,onfocusout:!1,ignore:ignorar,invalidHandler:function(e,t){},highlight:function(e){id=$(e).closest('.tab-pane').attr('id');$('a[href="#'+id+'"]').addClass('tab-error');$(e).closest(".form-group").removeClass("has-success").addClass("has-error");$.each($(e).parent().children(),function(id,val){if($(this).hasClass('help-block')){$(this).remove()}})},unhighlight:function(e){$(e).closest(".form-group").removeClass("has-error");setTimeout(function(){f(e)},3e3)},success:function(e){$(e).closest(".form-group").removeClass("has-error").addClass("has-success");id=$(e).closest('.tab-pane').attr('id');$('a[href="#'+id+'"]').removeClass('tab-error');$.each($("#"+id).find('.help-block'),function(idx,val){if($(this).html()!="")
$('a[href="#'+id+'"]').addClass('tab-error');})},submitHandler:function(form){let isValid=!0
$('[id^=nom_pop3_]').each(function(idx,val){if(this.id.length==10){if($(this).val()!=''&&$(`#dsc_template_${this.id[9]}`).val()==''){isValid=!1}}});if(!isValid){Core.message(lngGeral.text_err_email_template,'danger');return}
if(var_function!=null){var_function.submit(form)}else Core.submit(form,url_submit,url_redirect,id_cod,atualizar)}});for(var item in rulesObj){$('#'+item).rules('add',rulesObj[item])}}},aplicarTransform:function(){if($("form.transform").jqTransform){$("form.transform").jqTransform()}},ativaAbas:function(){$("#tabs").tabs();$("#tabs").tab()},aplicarMascaras:function(options){if($('input:text').setMask){options=$.extend(!0,{},this.optionsMascara,options||{});$('input:text').setMask(options)}},message:function(text,type,options){options=$.extend(!0,{},Core.optionsMessage,options||{});var noty_id=noty({text:text,layout:'center',dismissQueue:!0,force:!1,template:'
',timeout:(options.timeout&&options.timeout>0?options.timeout:!1)});return noty_id.options.id},alerta:function(text,type,options){options=$.extend(!0,{},Core.optionsMessage,options||{});type=type||'';$('#alertas').html(''+text+'
')},closeMessage:function(time){$('#messages').fadeOut(time)},closeAlerta:function(){$('#alertas').find("div").alert('close')},removerItem:function(id,modulo,linha,args){$.ajax({url:url_base+'/'+modulo+'/remover',type:'post',dataType:'json',async:!1,data:{'id':id,'extras':(args=='undefined')?'':args},success:function(response){Core.getAjaxDebug(response);$("#debug").html(response.dbg);if(response.success=='1'){$("#"+linha).remove();$("#msgbox").fadeTo(200,0.1,function(){Core.message(lngGeral.registroRemovido,'success')})}else{$("#msgbox").fadeTo(200,0.1,function(){Core.message(lngGeral.falhaRemover,'danger')})}},error:function(response){Core.getAjaxDebug(response);hideLoader(notyId);resp=jQuery.parseJSON(response.responseText);Core.message(resp.Error.message,'danger')},beforeSend:function(){notyId=showLoader()},complete:function(){hideLoader(notyId)}})},removerImg:function(id,modulo,args){$.ajax({url:url_base+'/'+modulo+'/remover-imagem',type:'post',dataType:'json',async:!1,data:{'id':id,'extras':(args=='undefined')?'':args},success:function(response){Core.getAjaxDebug(response);$("#debug").text(response.dbg);if(response.success=='1'){$("#msgbox").fadeTo(200,0.1,function(){Core.message(lngGeral.imagemRemovida,'success')})}else{$("#msgbox").fadeTo(200,0.1,function(){Core.message(lngGeral.falhaRemocaoImagem,'danger')})}},error:function(response){Core.getAjaxDebug(response);hideLoader(notyId);resp=jQuery.parseJSON(response.responseText);Core.message(resp.Error.message,'danger')},beforeSend:function(){notyId=showLoader()},complete:function(){hideLoader(notyId)}})},desativarTabs:function(abas_destivadas){$("#tabs li").each(function(idx,element){if($.inArray(idx,abas_destivadas)!=-1)
$("#tabs li").eq(idx).addClass('disabled').find('a').attr('href','javascript:void(0)');else $("#tabs li").eq(idx).removeClass('disabled').find('a').attr('href',"#fragment-"+(idx+1))})},autoComplete:function(modulo,args){var dado;$.ajax({url:url_base+'/'+modulo+'/autocomplete',type:'post',dataType:'json',async:!1,data:{'extras':(args=='undefined')?'':args},success:function(data){dado=data}})
return dado},formatCampo:function(campo,chave,linha,tipo,total,temp_config_colModels=!1){var txt=linha[campo];if(typeof txt=="number")
txt=txt.toString();if(campo!='dsc_notificacao')
txt=txt.replace(/(<([^>]+)>)/ig,'')
if(total&&(txt==""||txt==null||txt==undefined))
return"";let config_colModels=config.colModels;if(temp_config_colModels!=!1){config_colModels=temp_config_colModels}
if(tipo==1){formatter=config_colModels[chave].formatter;formatoptions=config_colModels[chave].formatoptions}else if(tipo==2){formatter=config_sub.colModels[chave].formatter;formatoptions=config_sub.colModels[chave].formatoptions}else if(tipo==3){formatter=config_another.colModels[chave].formatter;formatoptions=config_another.colModels[chave].formatoptions}else{formatter=config_colModels[chave].formatter;formatoptions=config_colModels[chave].formatoptions}
if(formatter==undefined)
return txt;if(formatter=='undefined')
return txt;ret='';switch(formatter){case 'trunc':if(formatoptions.hasOwnProperty('fancybox')&&formatoptions.fancybox){(txt.length>formatoptions.size)?text=txt.substring(0,txt.length-(txt.length-formatoptions.size))+'...':text=txt;ret=''+text+''}else(txt.length>formatoptions.size)?ret=''+txt.substring(0,txt.length-(txt.length-formatoptions.size))+'...':ret=txt;break;case 'fmtBool':(txt==0)?ret=nao:ret=sim;break;case 'fmtBoolean':(txt==0)?ret=' ':ret=' ';break;case 'fmtStatus':(txt==0)?ret=' ':(txt==1)?ret=' ':ret=' ';break;case 'date':if(txt!=''&&txt!='0000-00-00 00:00:00'&&txt!=='undefined'&&typeof txt!='undefined'){d1=Date.parse(txt.replace(' ','T'));if(d1==null||d1=='undefined')
ret=txt;else ret=d1.toString(formatoptions.newformat)}else(total==!0)?ret="":ret="-";break;case 'currency':if(txt!=''){if(formatoptions.decimalPlaces!==undefined)
txt=parseFloat(txt).toFixed(formatoptions.decimalPlaces);if(formatoptions.thousandSeparator==undefined)
formatoptions.thousandSeparator=".";ret=((formatoptions.prefix!==undefined)?formatoptions.prefix:"")+' '+txt.replace(".",formatoptions.decimalsSeparator).replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+formatoptions.thousandSeparator)}else ret="-";break;case 'os_prioridade':prioridade=linha[config_colModels[chave].formatoptions.campo];if(txt!=''){if('1'==prioridade)
ret=''+txt+'';else if('3'==prioridade)
ret=''+txt+'';else ret=''+txt+''}
break;case 'cor_acao':prioridade=linha[config_colModels[chave].formatoptions.cor];if(txt!=''){if(prioridade!=txt)
ret=''+txt+'';else ret=' '}
break;case 'porcentagem':ret=''+txt+'%'
break;case 'link':(txt&&txt.length>formatoptions.size)?txt=txt.substring(0,txt.length-(txt.length-formatoptions.size))+'...':txt=txt;(formatoptions.campoRef!=undefined)?idExtra=linha[formatoptions.campoRef]:idExtra="";let titleExtra='';(formatoptions.title!=undefined&&linha[formatoptions.title]!=undefined)?titleExtra=linha[formatoptions.title]:titleExtra=formatoptions.title;ret=""+txt+"";break;case 'decimal':if(txt!=''){if(formatoptions.decimalPlaces!==undefined)
txt=parseFloat(txt).toFixed(formatoptions.decimalPlaces);ret=txt.replace(".",formatoptions.decimalsSeparator)}
break;case 'image':if(txt!=''){var width=formatoptions.width?formatoptions.width+'px':"60px";var height=formatoptions.height?formatoptions.height+'px':"20px";ret="
"}else ret='-';break;case 'icone':if(txt!=''){ret="
"}
break;case 'status':if(txt!='')
ret='';break;case 'status_color':if(txt!='')
ret=''+linha[formatoptions.title]+'';break;case 'fmtBolErro':(txt==0)?ret=' ':(txt==1)?ret=' ':ret=' ';break;case 'json':if(formatoptions.hasOwnProperty('fancybox')&&formatoptions.fancybox){(txt.length>formatoptions.size)?text=txt.substring(0,txt.length-(txt.length-formatoptions.size))+'...':text=txt;ret=''+text+''}else{(txt.length>formatoptions.size)?ret=''+txt.substring(0,txt.length-(txt.length-formatoptions.size))+'...':ret=txt}
break;case 'jsonPuro':if(formatoptions.hasOwnProperty('fancybox')&&formatoptions.fancybox){ret=''}else{(txt.length>formatoptions.size)?ret=''+txt.substring(0,txt.length-(txt.length-formatoptions.size))+'...':ret=txt}
break;case 'listaDados':var retorno='';txt=JSON.parse(txt);txt.forEach(function(texto){retorno+=''+texto+''});ret=retorno;break;case 'list':ret=(typeof formatoptions.list[txt]!='undefined')?formatoptions.list[txt]:txt;break;case 'tdLabel':if(txt!=''){if(formatoptions.type!=undefined&&formatoptions.type=='multiple'){let labels=JSON.parse(txt);let color=formatoptions.bgdColor;for(let index in labels){ret+=' '+labels[index]+''}}
if(formatoptions.campoRef!=undefined&&formatoptions.bgdColor!=undefined){if(typeof formatoptions.campoRef==='string'&&typeof formatoptions.bgdColor==='string'){let label=formatoptions.campoRef;let color=formatoptions.bgdColor;(label!='')?ret=txt+' '+linha[label]+'':ret=txt}else if(typeof formatoptions.campoRef==='object'&&typeof formatoptions.bgdColor==='object'){var labels=formatoptions.campoRef;ret=txt;for(let lab in labels){let color=formatoptions.bgdColor[lab];ret+=' '+linha[labels[lab]]+''}}}}
break;case 'color_hex':ret=" "+txt;break;case 'fmtCanaisAgrupados':ret=Core.substituirIdCanaisPorNomes(txt);break;default:(txt==null)?ret="-":ret=txt;break}
return ret},getAjaxDebug:function(response){if(typeof response.debug!='undefined'&&response.debug!=""&&response.debug!=undefined){$("#debug_content").append(response.debug)}},linkPhones:function(title){$.each($("[rel='phone']"),function(idx,val){var phone=$(this).text();if(phone!="")
$(this).html(" "+phone+"");})},maskPhones:function(){$.each($("[rel=phone]"),function(idx,val){var bolCodPais=!1;if($(this).html().substring(0,2)!="=12)
bolCodPais=!0;var regex=new RegExp("[()-.:_ ]","g");var phone=$(this).html().replace(regex,'').replace(' ','');if(phone.length>4){if(bolCodPais){var codPais=phone.substring(0,2);var ddd=phone.substring(2,4);var number=phone.substring(4)}else{var ddd=phone.substring(0,2);var number=phone.substring(2)}
if((ddd.substring(0,1)=="1"||ddd.substring(0,1)=="2")&&number.substring(0,1)=="9"){if(number.length<9)
number="9"+number;if(bolCodPais)
$(this).html("+ "+codPais+" ("+ddd+") "+number.substring(0,5)+"-"+number.substring(5));else $(this).html("("+ddd+") "+number.substring(0,5)+"-"+number.substring(5))}else if($(this).html()!=""){if(bolCodPais)
$(this).html("+ "+codPais+" ("+ddd+") "+number.substring(0,4)+"-"+number.substring(4));else $(this).html("("+ddd+") "+number.substring(0,4)+"-"+number.substring(4))}}}})},maskCpfCnpj:function(){var regex=new RegExp("[()-.:_ \/]","g");$.each($("[rel='cpf']"),function(idx,val){var num=$(this).html().replace(regex,'').replace(' ','');if(num.length==11)
$(this).html(num.substring(0,3)+"."+num.substring(3,6)+"."+num.substring(6,9)+"-"+num.substring(9,11));else if(num.length==14)
$(this).html(num.substring(0,2)+"."+num.substring(2,5)+"."+num.substring(5,8)+"/"+num.substring(8,12)+"-"+num.substring(12,14));})},mudaStatusRamal:function(cod_status,status_ramal){$("#status_ramal").tooltip('destroy');$("#status_ramal").attr('title',status_ramal);switch(parseInt(cod_status)){case 0:$("#status_ramal i").removeAttr('class').addClass('ramal ramal-disponivel');break;case 1:$("#status_ramal i").removeAttr('class').addClass('ramal ramal-uso');break;case 2:$("#status_ramal i").removeAttr('class').addClass('ramal ramal-ocupado');break;case 4:$("#status_ramal i").removeAttr('class').addClass('ramal ramal-indisponivel');break;case 8:$("#status_ramal i").removeAttr('class').addClass('ramal ramal-tocando');break;case 16:$("#status_ramal i").removeAttr('class').addClass('ramal ramal-espera');break;default:$("#status_ramal i").removeAttr('class').addClass('ramal ramal-desconhecido');break}
$("#status_ramal").tooltip({placement:'right',animation:!0})},readOnlyForm:function(){$('select').attr('readonly',!0);$('input').attr('readonly',!0);$('input:checkbox').attr('disabled',!0);$('select').attr('disabled',!0);$('textarea').attr('disabled',!0)},submit:function(form,url_submit,url_redirect,id_cod,atualizar){if(typeof CKEDITOR!="undefined")
for(instance in CKEDITOR.instances)
CKEDITOR.instances[instance].updateElement();$.ajax({url:url_submit,dataType:'json',type:'post',data:$(form).serialize(),success:function(response){Core.getAjaxDebug(response);if(response.success>0){Core.message(response.message,'success');$(id_cod).val(response.cod);if(atualizar==!0)
var redirect=url_redirect+'/'+response.cod;else var redirect=url_redirect;if(redirect){window.location=redirect}}else{console.log($('[name="form_token"]'))
Core.message(response.message,'danger');if(response.token!=undefined){$('[name="form_token"]').val(response.token)}}},error:function(response){Core.getAjaxDebug(response);hideLoader(notyId);resp=JSON.parse(response.responseText);Core.message(resp.Error.message,'danger')},beforeSend:function(){notyId=showLoader()},complete:function(){hideLoader(notyId)}})},categoriesTickGeneratorBarChart:function(axis){var res=[];for(var label in axis.categories){var v=axis.categories[label];if(v>=axis.min&&v<=axis.max){if(label.length>15)
val=label.substring(0,15)+'...';else val=label;res.push([v,val])}}
res.sort(function(a,b){return a[0]-b[0]});return res},substituirIdCanaisPorNomes:function(stringNumeros){const numeros=stringNumeros.split('-');let resultado='';numeros.forEach(numero=>{const nome=lstCanaisAtivos[numero];resultado+=(nome!==undefined)?nome:'';resultado+='-'});resultado=resultado.slice(0,-1);return resultado}};function showLoader(text=lngGeral.aguardeCarregando){var noty_id=noty({text:text,layout:'center',dismissQueue:!1,modal:!0,template:'
',animation:{open:{height:'toggle'},close:{height:'toggle'},easing:'swing',speed:0}});return noty_id.options.id}
function hideLoader(id){$.noty.close(id)}
function recarrega(){window.location.reload();$('.timer').html(lngGeral.aguardeCarregando)}
function showCKEditor(item){CKEDITOR.replace(item,{customConfig:'configsis.js'})}
function destroyCKEditor(item){if(CKEDITOR.instances[item])CKEDITOR.instances[item].destroy();}
$("form button[type='submit']").on('click',function(){if(typeof CKEDITOR!="undefined")
for(instance in CKEDITOR.instances)
CKEDITOR.instances[instance].updateElement();});$("[rel=phone] a").on('click',function(){var destino=$.trim($(this).text());$.ajax({url:url_base+'/helper/verifica-ramal-origem',type:'POST',dataType:'json',success:function(retorno){Core.getAjaxDebug(retorno);if(retorno.sucesso!=0)
realizarChamada(retorno.ramal,destino);else{noty({layout:'center',text:$("#tplRamalOrigem").tmpl(),modal:!0,buttons:[{addClass:'btn btn-primary',text:lngGeral.realizarChamada,onClick:function($noty){var origem=$("#num_origem").val();realizarChamada(origem,destino,$noty)}},{addClass:'btn btn-danger',text:'Fechar',onClick:function($noty){$noty.close()}}]})}}})});function realizarChamada(origem,destino,noty){$.ajax({url:url_base+'/helper/realizar-chamada',type:'POST',dataType:'json',data:{origem:origem,destino:destino},success:function(retorno){Core.getAjaxDebug(retorno);if(retorno.sucesso){if(noty!=undefined)
noty.close();Core.message(retorno.msg,'info');Core.mudaStatusRamal(retorno.cod_status,retorno.status_ramal)}},error:function(){Core.getAjaxDebug(retorno);Core.message('ERROR','danger');hideLoader(notyId)},beforeSend:function(){notyId=showLoader()},complete:function(){hideLoader(notyId)}})}
var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+",encode:function(input){var output="";var chr1,chr2,chr3,enc1,enc2,enc3,enc4;var i=0;input=Base64._utf8_encode(input);while(i>2;enc2=((chr1&3)<<4)|(chr2>>4);enc3=((chr2&15)<<2)|(chr3>>6);enc4=chr3&63;if(isNaN(chr2)){enc3=enc4=64}else if(isNaN(chr3)){enc4=64}
output=output+this._keyStr.charAt(enc1)+this._keyStr.charAt(enc2)+this._keyStr.charAt(enc3)+this._keyStr.charAt(enc4)}
return output},decode:function(input){var output="";var chr1,chr2,chr3;var enc1,enc2,enc3,enc4;var i=0;input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(i>4);chr2=((enc2&15)<<4)|(enc3>>2);chr3=((enc3&3)<<6)|enc4;output=output+String.fromCharCode(chr1);if(enc3!=64){output=output+String.fromCharCode(chr2)}
if(enc4!=64){output=output+String.fromCharCode(chr3)}}
output=Base64._utf8_decode(output);return output},_utf8_encode:function(string){string=string.replace(/\r\n/g,"\n");var utftext="";for(var n=0;n127)&&(c<2048)){utftext+=String.fromCharCode((c>>6)|192);utftext+=String.fromCharCode((c&63)|128)}else{utftext+=String.fromCharCode((c>>12)|224);utftext+=String.fromCharCode(((c>>6)&63)|128);utftext+=String.fromCharCode((c&63)|128)}}
return utftext},_utf8_decode:function(utftext){var string="";var i=0;var c=c1=c2=0;while(i191)&&(c<224)){c2=utftext.charCodeAt(i+1);string+=String.fromCharCode(((c&31)<<6)|(c2&63));i+=2}else{c2=utftext.charCodeAt(i+1);c3=utftext.charCodeAt(i+2);string+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3}}
return string}}