(function(C,i){var o=13;var B="_bcpin";var j="_bc-curl";var H="#bc-curl=";var l={CHAT_LOADED_CALLBACK:"onChatLoaded",CHAT_LOAD_ERROR_CALLBACK:"onChatLoadError",CHAT_LOAD_ERROR_TEXT:"chatLoadErrorText",PIN_CODE_VALIDATION_ERROR_CALLBACK:"onPinCodeValidationError",PIN_CODE_VALIDATION_ERROR_TEXT:"pinCodeValidationText"};var c="Failed to load chat!";var F="Invalid Pin Code!";var M=/^\d{6}$/;var e="pin-input";var f="pin-submit";var v="pin-message-container";var A="invalid-pin-code";var z="bc-pin-parameters";var d;var w;var m;var u={"1":".boldchat.com","2":"-eu.boldchat.com"};var n="https://livechat";var E="https://vmss";var t=C[B]||[];if(i.readyState==="loading"){i.addEventListener("DOMContentLoaded",K)}else{K()}function K(){a();w.addEventListener("click",function(){k()});d.addEventListener("keyup",function(N){var O=N.which||N.keyCode;if(O===o){k()}});J()}function g(){if(C.location.hash.toLowerCase().indexOf(H)!==0){return}C._bcvm.setCookie(j,(C.decodeURIComponent||C.unescape)(C.location.hash.substring(H.length)));C.location.hash=""}function a(){d=i.getElementById(e);if(!d){throw new Error('Cannot find mandatory HTMLInputElement with id "pin-input"!')}w=i.getElementById(f);if(!w){throw new Error('Cannot find mandatory clickable html element with id "pin-submit"!')}m=i.getElementById(v);if(!m){throw new Error('Cannot find mandatory html element with id "pin-message-container"!')}}function J(){var Q=L();if(!Q){return}var O=n+Q.serverSet;var P=E+Q.serverSet;I(Q.accountId,Q.pinvitationId,O,R,N);function R(S){if(!S.isActive){D();return}s(P,S.accountId,S.chatWindowDefId,S.pinvitationId,S.websiteDefId,S.isLayered,false)}function N(){}}function k(){var U=d.value;var O=U[0];var T=u[O];if(!T||!M.test(U)){if(d.className.indexOf(A)===-1){d.className+=" "+A}x();p(l.PIN_CODE_VALIDATION_ERROR_CALLBACK);return}d.className=d.className.replace(new RegExp("\\s?"+A),"");G("");var P=n+T;var R=E+T;b(U,P,S,N);function S(V){I(V.accountId,V.pinvitationId,P,Q,N)}function Q(V){q(T,V.accountId,V.pinvitationId);s(R,V.accountId,V.chatWindowDefId,V.pinvitationId,V.websiteDefId,V.isLayered,true)}function N(W){var V=W.status===404;if(V){x();p(l.PIN_CODE_VALIDATION_ERROR_CALLBACK)}else{h();p(l.CHAT_LOAD_ERROR_CALLBACK)}}}function b(Q,P,N,O){y(P+"/pinvites/"+Q+"/aid",N,O)}function I(R,O,Q,N,P){y(Q+"/aid/"+R+"/pinvites/"+O,N,P)}function y(P,N,O){var Q=new XMLHttpRequest();Q.onreadystatechange=function(){if(this.readyState==4){if(this.status===200){N(JSON.parse(this.responseText))}else{O(this)}}};Q.open("GET",P,true);Q.send()}function s(V,R,U,N,P,O,T){C._bcvma=C._bcvma||[];_bcvma.push(["setAccountID",R]);_bcvma.push(["setParameter","WebsiteID",P]);_bcvma.push(["setParameter","PinvitationID",N]);var S=function(){if(C.bcLoaded){return}C.bcLoaded=true;var W=i.createElement("script");W.type="text/javascript";W.async=true;W.addEventListener("load",Q,false);W.src=V+"/aid/"+R+"/bc.vms4/vms.js";var X=i.getElementsByTagName("script")[0];X.parentNode.insertBefore(W,X)};if(C.pageViewer&&pageViewer.load){pageViewer.load();Q()}else{if(i.readyState=="complete"){S()}else{if(C.addEventListener){C.addEventListener("load",S,false)}else{C.attachEvent("onload",S)}}}function Q(){if(T){C._bcvm.setCookie(j,"",0)}else{g()}C._bcvmw.chatWindow({type:"chat",cwdid:U,embed:O});p(l.CHAT_LOADED_CALLBACK)}}function h(){G(r(l.CHAT_LOAD_ERROR_TEXT)||c)}function x(){G(r(l.PIN_CODE_VALIDATION_ERROR_TEXT)||F)}function G(N){m.innerText=N}function q(O,P,N){C.localStorage.setItem(z,JSON.stringify({serverSet:O,accountId:P,pinvitationId:N}))}function L(){var N=C.localStorage.getItem(z);if(!N){return null}return JSON.parse(N)}function D(){C.localStorage.removeItem(z)}function r(O){for(var P=0,N=t.length;P<N;P++){var Q=t[P];if(Q[0]===O){return Q[1]}}return null}function p(N,P){var O=r(N);if(O&&typeof(O)==="function"){O.apply(this,P)}}}(window,window.document));