function hesk_insertTag(e){e="%%"+e+"%%";hesk_insertAtCursor(document.form1.msg,e),document.form1.msg.focus()}function hesk_insertAtCursor(e,t){var n,o;document.selection?(e.focus(),sel=document.selection.createRange(),sel.text=t):e.selectionStart||"0"==e.selectionStart?(n=e.selectionStart,o=e.selectionEnd,e.value=e.value.substring(0,n)+t+e.value.substring(o,e.value.length),e.selectionStart=n+t.length,e.selectionEnd=n+t.length):e.value+=t}function hesk_changeAll(e){for(var t=document.form1,n=!!e.checked,o=0;o<t.elements.length;o++)"checkbox"==t.elements[o].type&&"checkall"!=t.elements[o].name&&(t.elements[o].checked=n)}function hesk_attach_disable(e){for($i=0;$i<e.length;$i++)"c11"!=e[$i]&&"c21"!=e[$i]&&"c31"!=e[$i]&&"c41"!=e[$i]&&"c51"!=e[$i]||(document.getElementById(e[$i]).checked=!1),document.getElementById(e[$i]).disabled=!0}function hesk_attach_enable(e){for($i=0;$i<e.length;$i++)document.getElementById(e[$i]).disabled=!1}function hesk_attach_handle(e,t){for($i=0;$i<t.length;$i++)document.getElementById(t[$i]).disabled=!e.checked}function hesk_attach_toggle(e,t){(document.getElementById(e).checked?hesk_attach_enable:hesk_attach_disable)(t)}function hesk_window(e,t,n){window.open(e,"Hesk_window","height="+t+",width="+n+",menubar=0,location=0,toolbar=0,status=0,resizable=1,scrollbars=1").focus()}function hesk_toggleLayerDisplay(e){document.all?document.all[e].style.display="none"==document.all[e].style.display?"block":"none":document.getElementById&&(document.getElementById(e).style.display="none"==document.getElementById(e).style.display?"block":"none")}function hesk_confirmExecute(e){return!!confirm(e)}function hesk_deleteIfSelected(e,t){if(document.getElementById(e).checked)return hesk_confirmExecute(t)}function hesk_rate(e,t){if(0==e.length)return!1;var n=document.getElementById(t);xmlHttp=GetXmlHttpObject(),null!=xmlHttp?(xmlHttp.open("GET",e,!0),xmlHttp.onreadystatechange=function(){4==xmlHttp.readyState&&200==xmlHttp.status&&(n.innerHTML=xmlHttp.responseText)},xmlHttp.send(null)):alert("Your browser does not support AJAX!")}function stateChanged(){4==xmlHttp.readyState&&(document.getElementById("rating").innerHTML=xmlHttp.responseText)}function GetXmlHttpObject(){var t=null;try{t=new XMLHttpRequest}catch(e){try{t=new ActiveXObject("Msxml2.XMLHTTP")}catch(e){t=new ActiveXObject("Microsoft.XMLHTTP")}}return t}var heskKBquery="",heskKBfailed=!1;function hesk_suggestKB(){var e=document.form1,t=e.subject.value,n=e.message.value,o=document.getElementById("kb_suggestions");if(""!=t&&""!=n&&(heskKBquery!=t+" "+n||1==heskKBfailed)){o.style.display="block";e="p=1&q="+encodeURIComponent(t+" "+n);if(heskKBquery=t+" "+n,xmlHttp=GetXmlHttpObject(),null==xmlHttp)return;xmlHttp.open("POST","suggest_articles.php",!0),xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"),xmlHttp.onreadystatechange=function(){heskKBfailed=4!=xmlHttp.readyState||200!=xmlHttp.status||(o.innerHTML=xmlHttp.responseText,!1)},xmlHttp.send(e)}setTimeout(function(){hesk_suggestKB()},2e3)}function hesk_suggestKBsearch(e){var t,n=document.searchform.search.value,o=document.getElementById("kb_suggestions");if(t=e?"admin_suggest_articles.php":"suggest_articles.php",""!=n&&(heskKBquery!=n||1==heskKBfailed)){o.style.display="block";var s="q="+encodeURIComponent(n);if(heskKBquery=n,xmlHttp=GetXmlHttpObject(),null==xmlHttp)return;xmlHttp.open("POST",t,!0),xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"),xmlHttp.onreadystatechange=function(){heskKBfailed=4!=xmlHttp.readyState||200!=xmlHttp.status||(o.innerHTML=unescape(xmlHttp.responseText),!1)},xmlHttp.send(s)}setTimeout(function(){hesk_suggestKBsearch(e)},2e3)}function hesk_suggestEmail(s,e,t,n,o){var l=document.getElementById(s).value,a=document.getElementById(e);n=n?"../suggest_email.php":"suggest_email.php",""!=l&&(t="e="+encodeURIComponent(l)+"&ef="+encodeURIComponent(s)+"&dd="+encodeURIComponent(e)+"&pd="+encodeURIComponent(t),o&&(t+="&am=1"),xmlHttp=GetXmlHttpObject(),null!=xmlHttp&&(xmlHttp.open("POST",n,!0),xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"),xmlHttp.onreadystatechange=function(){if(4===xmlHttp.readyState&&200===xmlHttp.status){a.innerHTML="";for(var e='<div class="notification-flash service-message orange" id="{0}" style="display: block; margin-bottom: 10px;"><div class="notification--title">{1}</div><div class="notification--text"><a class="link" href="javascript:" onclick="hesk_applyEmailSuggestion(\'{0}\', \''+s+"', '{2}', '{3}')\">{4}</a> | <a class=\"link\" href=\"javascript:void(0);\" onclick=\"document.getElementById('{0}').style.display='none';\">{5}</a></div></div>",t=JSON.parse(xmlHttp.responseText),n=0;n<t.length;n++){var o=t[n];a.innerHTML+=e.replace(/\{0}/g,o.id).replace(/\{1}/g,o.suggestText).replace(/\{2}/g,o.originalAddress).replace(/\{3}/g,o.formattedSuggestedEmail).replace(/\{4}/g,o.yesResponseText).replace(/\{5}/g,o.noResponseText),console.log(t[n])}a.style.display="block"}},xmlHttp.send(t)))}function hesk_applyEmailSuggestion(e,t,n,o){var s=document.getElementById(t).value,n=new RegExp(n,"gi");document.getElementById(t).value=s.replace(n,o),document.getElementById(e).style.display="none"}function hesk_btn(e,t){e.className=t}function hesk_checkPassword(e,t="progressBar"){var n="!.@$#*()%~<>{}[]",o=0,s=0;0<hesk_contains(e,"0123456789")&&(o+=10,s+=25),0<hesk_contains(e,"abcdefghijklmnopqrstuvwxyz")&&(o+=26,s+=25),0<hesk_contains(e,"ABCDEFGHIJKLMNOPQRSTUVWXYZ")&&(o+=26,s+=25),0<hesk_contains(e,n)&&(o+=n.length,s+=25);n=Math.pow(o,e.length)/200/2/86400/365e3;(o=hesk_cap(Math.round(100*n),s))<5*e.length&&(o+=5*e.length);o=hesk_cap(o,s),t=document.getElementById(t);t.style.width=o+"%",1<n&&75<o?t.style.backgroundColor="#3bce08":.5<n&&50<o?t.style.backgroundColor="#ffd801":.1<n&&10<o?t.style.backgroundColor="orange":(n<=.1||o<=10)&&(t.style.backgroundColor="red")}function hesk_cap(e,t){return t<e?t:e}function hesk_contains(e,t){for(count=0,i=0;i<e.length;i++){var n=e.charAt(i);-1<t.indexOf(n)&&count++}return count}function setCookie(e,t,n,o,s,l){document.cookie=e+"="+escape(t)+(n?"; expires="+n.toGMTString():"")+(o?"; path="+o:"")+(s?"; domain="+s:"")+(l?"; secure":"")}function getCookie(e){var t=document.cookie,n=e+"=",o=t.indexOf("; "+n);if(-1==o){if(0!=(o=t.indexOf(n)))return null}else o+=2;e=document.cookie.indexOf(";",o);return-1==e&&(e=t.length),unescape(t.substring(o+n.length,e))}function deleteCookie(e,t,n){getCookie(e)&&(document.cookie=e+"="+(t?"; path="+t:"")+(n?"; domain="+n:"")+"; expires=Thu, 01-Jan-70 00:00:01 GMT")}function outputAttachmentIdHolder(e,t){$("#attachment-holder-"+t).append('<input type="hidden" name="attachments[]" value="'+e+'">')}function removeAttachment(e,t,n){void 0!==t&&(n=n?"../":"",$('input[name="attachments[]"][value="'+t+'"]').remove(),$.ajax({url:n+"upload_attachment.php?action=delete&fileKey="+encodeURIComponent(t),method:"GET"}))}function hesk_updateDeleteCategoryUrl(e){var t=$("#targetCat"+e).val(),e=$("a[data-confirm-button]")[e];e.href=e.href.replace(/&targetCategory=\d+/i,"&targetCategory="+t)}jQuery.fn.preventDoubleSubmission=function(){return $(this).on("submit",function(e){var t=$(this);!0===t.data("submitted")?e.preventDefault():t.data("submitted",!0)}),this};