(function(){if(BX.PhoneNumber)return;var t;var e=null;var r=false;var n="/bitrix/js/main/phonenumber/metadata.json";var a="/bitrix/tools/phone_number.php";var o={};var i;var u=3;var s=2;var l=17;var h=250;var f="+";var c="0-9";var p="-";var m="/";var y=".";var g="\\s";var N="()\\[\\]";var d="~";var v=";#";var b=",";var P="["+f+c+"]";var C="[^"+c+v+b+"]+$";var x="["+c+"]{"+s+"}";var B=p+m+y+g+N+d+v+b;var X=c+f+v+b;var F="["+f+"]{0,1}"+"(?:"+"["+B+"]*"+"["+c+"]"+"){3,}"+"["+B+c+"]*";var w="^(?:"+"^"+x+"$"+"|"+"^"+F+"$"+")$";var I=function(){if(r){var t=new BX.Promise;t.fulfill({codeToCountries:i,metadata:o});return t}else if(e){return e}else{e=new BX.Promise;BX.ajax.load({url:n,type:"json",callback:function(t){i=t.codeToCountries;o=t.metadata;t.metadata.forEach((function(t){o[t["id"]]=t}));r=true;e.fulfill({codeToCountries:i,metadata:o})}});return e}};BX.PhoneNumber=function(){this.rawNumber=null;this.country=null;this.valid=false;this.countryCode=null;this.nationalNumber=null;this.numberType=null;this.extension=null;this.extensionSeparator=null;this.international=false;this.nationalPrefix=null;this.hasPlusChar=false};BX.PhoneNumber.Format={E164:"E.164",INTERNATIONAL:"International",NATIONAL:"National"};BX.PhoneNumber.getDefaultCountry=function(){return BX.message("phone_number_default_country")};BX.PhoneNumber.getUserDefaultCountry=function(){return BX.message("user_default_country")};BX.PhoneNumber.getIncompleteFormatter=function(t){var e=new BX.Promise;if(r){e.fulfill(new BX.PhoneNumber.IncompleteFormatter(t))}else{I().then((function(){e.fulfill(new BX.PhoneNumber.IncompleteFormatter(t))}))}return e};BX.PhoneNumber.getValidNumberPattern=function(){return F};BX.PhoneNumber.getValidNumberRegex=function(){return new RegExp(F)};BX.PhoneNumber.prototype.format=function(t){if(this.valid){if(!t){return BX.PhoneNumberFormatter.formatOriginal(this)}else{return BX.PhoneNumberFormatter.format(this,t)}}else{if(z.isApplicable(this.getRawNumber())){return z.format(this.getRawNumber())}else{return this.rawNumber}}};BX.PhoneNumber.prototype.getRawNumber=function(){return this.rawNumber};BX.PhoneNumber.prototype.setRawNumber=function(t){this.rawNumber=t};BX.PhoneNumber.prototype.getCountry=function(){return this.country};BX.PhoneNumber.prototype.setCountry=function(t){this.country=t};BX.PhoneNumber.prototype.isValid=function(){return this.valid};BX.PhoneNumber.prototype.setValid=function(t){this.valid=t};BX.PhoneNumber.prototype.getCountryCode=function(){return this.countryCode};BX.PhoneNumber.prototype.setCountryCode=function(t){this.countryCode=t};BX.PhoneNumber.prototype.getNationalNumber=function(){return this.nationalNumber};BX.PhoneNumber.prototype.setNationalNumber=function(t){this.nationalNumber=t};BX.PhoneNumber.prototype.getNumberType=function(){return this.numberType};BX.PhoneNumber.prototype.setNumberType=function(t){this.numberType=t};BX.PhoneNumber.prototype.hasExtension=function(){return!!this.extension};BX.PhoneNumber.prototype.getExtension=function(){return this.extension};BX.PhoneNumber.prototype.setExtension=function(t){this.extension=t};BX.PhoneNumber.prototype.getExtensionSeparator=function(){return this.extensionSeparator};BX.PhoneNumber.prototype.setExtensionSeparator=function(t){this.extensionSeparator=t};BX.PhoneNumber.prototype.isInternational=function(){return this.international};BX.PhoneNumber.prototype.setInternational=function(t){this.international=t};BX.PhoneNumber.prototype.getNationalPrefix=function(){return this.nationalPrefix};BX.PhoneNumber.prototype.setNationalPrefix=function(t){this.nationalPrefix=t};BX.PhoneNumber.prototype.hasPlus=function(){return this.hasPlusChar};BX.PhoneNumber.prototype.setHasPlus=function(t){this.hasPlusChar=t};BX.PhoneNumberParser=function(){};BX.PhoneNumberParser.getInstance=function(){if(!(t instanceof BX.PhoneNumberParser))t=new BX.PhoneNumberParser;return t};BX.PhoneNumberParser.prototype.parse=function(t,e){var n=this;var a=new BX.Promise;if(!e)e=BX.PhoneNumber.getDefaultCountry();if(r){a.fulfill(n._realParse(t,e))}else{I().then((function(){a.fulfill(n._realParse(t,e))}))}return a};BX.PhoneNumberParser.prototype._realParse=function(t,e){var r=new BX.PhoneNumber;r.setRawNumber(t);var n=W(t);if(!j(n)){return r}var a=U(n);var o=a.extension;var i=a.extensionSeparator;n=a.phoneNumber;var u=H(n);if(u===false){return r}var s;var h=u["countryCode"];var f=u["localNumber"];var c;var p;var m=false;if(h){c=true;m=true;p=G(h);s=null}else if(!e){return r}else{s=e;p=nt(s);if(!p)return r;h=p["countryCode"];var y=Z(f,p);c=y!==f;f=y}if(!p){return r}var g=J(f,p);var N=false;var d="";if(g!==f){N=Q(g,p);if(N){d=f.substr(0,f.length-g.length);f=g}}if(s===null){s=K(h,f);if(!s){return r}p=nt(s)}if(f.length>l){return r}var v=new RegExp("^(?:"+p["generalDesc"]["nationalNumberPattern"]+")$");if(!f.match(v)){return r}var b=q(f,s);r.setCountry(s);r.setCountryCode(h);r.setNationalNumber(f);r.setNumberType(b);r.setInternational(c);r.setHasPlus(m);r.setNationalPrefix(d);r.setExtension(o);r.setExtensionSeparator(i);r.setValid(b!==false);return r};BX.PhoneNumberFormatter={};BX.PhoneNumberFormatter.format=function(t,e){if(!(t instanceof BX.PhoneNumber)){throw new Error("number should be instance of BX.PhoneNumber")}if(!r){throw new Error("Metadata should be loaded prior to calling format")}if(!t.isValid())return t.getRawNumber();if(e===BX.PhoneNumber.Format.E164){var n="+"+t.getCountryCode()+t.getNationalNumber()+(t.hasExtension()?t.getExtensionSeparator()+" "+t.getExtension():"");return n}var a=nt(t.getCountry());var o=e===BX.PhoneNumber.Format.INTERNATIONAL;var i=this.selectFormatForNumber(t.getNationalNumber(),o,a);if(i){var u=this.formatNationalNumber(t.getNationalNumber(),o,a,i)}else{u=t.getNationalNumber()}if(t.hasExtension()){u+=t.getExtensionSeparator()+" "+t.getExtension()}if(e===BX.PhoneNumber.Format.INTERNATIONAL){return"+"+t.getCountryCode()+" "+u}else if(e===BX.PhoneNumber.Format.NATIONAL){return u}return t.getRawNumber()};BX.PhoneNumberFormatter.formatOriginal=function(t){if(!t.isValid())return t.getRawNumber();var e=this.selectOriginalFormatForNumber(t);if(!e)return t.getRawNumber();var r=this.formatNationalNumberWithOriginalFormat(t,e);if(t.hasExtension()){r+=t.getExtensionSeparator()+" "+t.getExtension()}if(t.isInternational()){var n=(t.hasPlus()?"+":"")+t.getCountryCode()+" "+r}else{n=r}var a=mt(n);var o=mt(t.getRawNumber());if(a!==o){n=t.getRawNumber()}return n};BX.PhoneNumberFormatter.selectFormatForNumber=function(t,e,r){var n=it(r);for(var a=0;aa.length)return false;if(this.hasNationalPrefix){var o=st(e,this.countryMetadata);if(o){o=o.replace("$NP",this.nationalPrefix).replace("$FG","$1");r=r.replace(new RegExp("(\\$\\d)"),o)}else{r=this.nationalPrefix+" "+r}}var i=a.replace(new RegExp(n,"g"),r);i=i.replace(T,S);return i};BX.PhoneNumber.IncompleteFormatter.prototype.formatUsingTemplate=function(){if(!this.formattingTemplate)return false;var t=this.formattingTemplate;var e;for(var r=0;ra)){e=e+a+1}return t.substr(0,e).replace(_," ")};BX.PhoneNumber.IncompleteFormatter.prototype.formatCompleteNumber=function(){var t=new BX.PhoneNumber;t.setRawNumber(this.rawInput);t.setHasPlus(this.hasPlusChar);t.setInternational(this.isInternational);t.setNationalPrefix(this.nationalPrefix);t.setNationalNumber(this.nationalNumber);t.setCountry(this.country);t.setCountryCode(this.countryCode);var e=BX.PhoneNumberFormatter.selectOriginalFormatForNumber(t);if(!e)return false;var r=BX.PhoneNumberFormatter.formatNationalNumberWithOriginalFormat(t,e);if(this.isInternational){r=(this.hasPlusChar?f:"")+this.countryCode+" "+r}this.selectedFormat=e;return r};BX.PhoneNumber.IncompleteFormatter.prototype.isFormatSuitable=function(t){if(this.isInternational){return ot(t)?true:false}else{return!this.hasNationalPrefix||ft(t,this.countryMetadata)}};BX.PhoneNumber.IncompleteFormatter.prototype.replaceCountry=function(t){this.isInternational=true;this.hasPlusChar=true;this.country=t;this.countryMetadata=nt(this.country);this.countryCode=this.countryMetadata["countryCode"];this.rawInput="+"+this.countryCode+this.nationalNumber;this.nationalPrefix=""};BX.PhoneNumber.Input=function(t){if(!BX.type.isDomNode(t.node)||t.node.nodeName!=="INPUT"||t.node.type!=="text"){throw new Error("params.node should be text input node")}this.inputNode=t.node;this.defaultCountry=t.defaultCountry||BX.PhoneNumber.getDefaultCountry();this.userDefaultCountry=t.userDefaultCountry||BX.PhoneNumber.getUserDefaultCountry();this.savedCountryCode=t.savedCountryCode||"";this.forceLeadingPlus=t.forceLeadingPlus===true;this.flagNode=BX.type.isDomNode(t.flagNode)?t.flagNode:null;this.flagSize=[16,24,32].indexOf(t.flagSize)!==-1?t.flagSize:16;this.countryPopupHeight=t.countryPopupHeight||180;this.countryPopupClassName=t.countryPopupClassName||"";this.countryTopList=t.countryTopList||[];this.flagNodeInitialClass="";this.countries=null;this.callbacks={initialize:BX.type.isFunction(t.onInitialize)?t.onInitialize:BX.DoNothing,change:BX.type.isFunction(t.onChange)?t.onChange:BX.DoNothing,countryChange:BX.type.isFunction(t.onCountryChange)?t.onCountryChange:BX.DoNothing};this.formatter=null;this.countrySelectPopup=null;this._lastCaretPosition=null;this._digitsToTheLeft=0;this._digitsToTheRight=0;this._digitsCount=0;this._selectedDigitsBeforeAction=0;this._countryBefore="";this.initialized=false;this.initializationPromises=[];this.init();this.bindEvents()};BX.PhoneNumber.Input.prototype.init=function(){var t=this;if(this.flagNode){this.flagNodeInitialClass=this.flagNode.className;BX.adjust(this.flagNode,{style:{cursor:"pointer",display:"inline-block"}})}BX.PhoneNumber.getIncompleteFormatter(this.defaultCountry).then((function(e){t.formatter=e;if(t.inputNode.value){t.inputNode.value=t.formatter.format(t.inputNode.value);if(BX.Type.isStringFilled(t.savedCountryCode)&&t.formatter.country!==t.savedCountryCode){t.formatter.replaceCountry(t.savedCountryCode)}}else if(t.userDefaultCountry!=""){t.formatter.replaceCountry(t.userDefaultCountry);t.inputNode.value=t.userDefaultCountry==="XX"?"":t.formatter.getFormattedNumber()}t.drawCountryFlag();t.initialized=true;t.initializationPromises.forEach((function(t){t.resolve()}));t.callbacks.initialize()}))};BX.PhoneNumber.Input.prototype.bindEvents=function(){this.inputNode.addEventListener("keydown",this._onKeyDown.bind(this));this.inputNode.addEventListener("input",this._onInput.bind(this));if(this.flagNode){this.flagNode.addEventListener("click",this._onFlagClick.bind(this))}};BX.PhoneNumber.Input.prototype.setValue=function(t){this.waitForInitialization().then(function(){this.inputNode.value=this.formatter.format(t.toString());this.callbacks.change({value:this.getValue(),formattedValue:this.getFormattedValue(),country:this.getCountry(),countryCode:this.getCountryCode()});if(this._countryBefore!==this.getCountry()){this.drawCountryFlag();this.callbacks.countryChange({country:this.getCountry(),countryCode:this.getCountryCode()})}}.bind(this))};BX.PhoneNumber.Input.prototype.waitForInitialization=function(){var t=new BX.Promise;if(this.initialized){t.resolve();return t}this.initializationPromises.push(t);return t};BX.PhoneNumber.Input.prototype.getValue=function(){return yt(this.inputNode.value)};BX.PhoneNumber.Input.prototype.getFormattedValue=function(){return this.inputNode.value};BX.PhoneNumber.Input.prototype.getCountry=function(){return this.formatter.country||this.formatter.defaultCountry};BX.PhoneNumber.Input.prototype.getCountryCode=function(){var t=nt(this.getCountry());return t?t["countryCode"]:false};BX.PhoneNumber.Input.prototype.drawCountryFlag=function(){if(!this.flagNode)return;var t=this.getCountry();if(!BX.type.isNotEmptyString(t))return;t=t.toLowerCase();BX.adjust(this.flagNode,{props:{className:this.flagNodeInitialClass+" bx-flag-"+this.flagSize+" "+t}})};BX.PhoneNumber.Input.prototype.tryRedrawCountryFlag=function(){if(this._countryBefore!==this.getCountry()){this.drawCountryFlag();this.callbacks.countryChange({country:this.getCountry(),countryCode:this.getCountryCode()})}};BX.PhoneNumber.Input.prototype._onKeyDown=function(t){if(!t.key)return;var e=this.inputNode.selectionEnd-this.inputNode.selectionStart;if(t.key===f){if(this.inputNode.selectionStart!==0){t.preventDefault();t.stopPropagation();return}}else if(t.key.length===1&&t.key.search(/[\d,;#]/)!==0&&!t.ctrlKey&&!t.metaKey){t.preventDefault();t.stopPropagation();return}var r=dt(this.inputNode.value);this._lastCaretPosition=this.inputNode.selectionStart;this._digitsToTheLeft=Nt(X,this.inputNode.value.substr(0,this._lastCaretPosition));this._digitsToTheRight=Nt(X,this.inputNode.value.substr(this._lastCaretPosition));this._digitsCount=Nt(X,this.inputNode.value);this._countryBefore=this.getCountry();if(e>0){var n=this.inputNode.value.substr(this.inputNode.selectionStart,e);this._selectedDigitsBeforeAction=Nt(X,n)}else{this._selectedDigitsBeforeAction=0}var a=null;if(t.key==="Backspace"&&e===0){a=r[this._digitsToTheLeft-1]+1}if(t.key==="Delete"&&e===0&&this._digitsToTheRight>0){a=r[this._digitsToTheLeft]}if(a!==null){this.inputNode.setSelectionRange(a,a)}};BX.PhoneNumber.Input.prototype._onInput=function(t){var e=null;if(this.formatter){var r=this.formatter.format(this.inputNode.value);var n=dt(r);var a=this._digitsCount;var o=this._selectedDigitsBeforeAction;var i=Nt(X,r);var u=i-a;var s=u+o;if(this._lastCaretPosition!==null){switch(t.inputType){case"deleteContentBackward":if(u==-1)e=n[this._digitsToTheLeft+u-1]+1;else e=n[this._digitsToTheLeft];break;case"deleteContentForward":if(this._digitsToTheLeft===0){e=n[0]}else{e=n[this._digitsToTheLeft-1]+1}break;case"insertText":case"insertFromPaste":e=n[this._digitsToTheLeft-1+s]+1;break}}this.inputNode.value=r;if(e!==null){this.inputNode.setSelectionRange(e,e)}this.callbacks.change({value:this.getValue(),formattedValue:this.getFormattedValue(),country:this.getCountry(),countryCode:this.getCountryCode()});this.tryRedrawCountryFlag()}this._lastCaretPosition=null};BX.PhoneNumber.Input.prototype._onFlagClick=function(t){this.selectCountry({node:this.flagNode,countryPopupHeight:this.countryPopupHeight,countryPopupClassName:this.countryPopupClassName,countryTopList:this.countryTopList,onSelect:this._onCountrySelect.bind(this)})};BX.PhoneNumber.Input.prototype._onCountrySelect=function(t){var e=t.country;if(e===this.getCountry())return false;this.formatter.replaceCountry(e);this.inputNode.value=this.formatter.getFormattedNumber();this.drawCountryFlag();this.callbacks.change({value:this.getValue(),formattedValue:this.getFormattedValue(),country:this.getCountry(),countryCode:this.getCountryCode()});this.callbacks.countryChange({country:this.getCountry(),countryCode:this.getCountryCode()});BX.userOptions.save("main","phone_number","default_country",e)};BX.PhoneNumber.Input.prototype.loadCountries=function(){var t=new BX.Promise;if(this.countries){t.fulfill();return t}BX.ajax.runAction("main.phonenumber.getCountries").then(function(e){this.countries=e.data;t.fulfill()}.bind(this)).catch((function(t){if(t.errors){t.errors.map((function(t){console.error(t.message)}))}else{console.error(t)}}));return t};BX.PhoneNumber.Input.prototype.selectCountry=function(t){var e=this;var r=BX.type.isFunction(t.onSelect)?t.onSelect:BX.DoNothing;var n=BX.create("span",{events:{click:BX.delegateEvent({attribute:"data-country"},(function(){e.countrySelectPopup.close();r({country:this.getAttribute("data-country")})}))}});var a=null;var o={};if(t.countryTopList&&t.countryTopList.length>0){a=n.appendChild(BX.create("span",{props:{className:"main-phonenumber-country-separator"}}))}this.loadCountries().then((function(){e.countries.forEach((function(e){var r=e.CODE;var a=at(r);if(!a)return;var i=n.appendChild(BX.create("div",{props:{className:"main-phonenumber-country"},attrs:{"data-country":e.CODE},children:[BX.create("span",{props:{className:"main-phonenumber-country-flag bx-flag-16 "+r.toLowerCase()}}),BX.create("span",{props:{className:"main-phonenumber-country-name"},text:e.NAME+" (+"+a+")"})]}));if(t.countryTopList.indexOf(e.CODE)>=0){o[e.CODE]=i.cloneNode(true)}}));if(t.countryTopList&&t.countryTopList.length>0){t.countryTopList.forEach((function(t){if(typeof o[t]!=="undefined"){n.insertBefore(o[t],a)}}));if(n.firstChild===a){n.removeChild(a)}}e.countrySelectPopup=new BX.PopupWindow("phoneNumberInputSelectCountry",t.node,{className:t.countryPopupClassName||"",autoHide:true,closeByEsc:true,bindOptions:{position:"top"},height:t.countryPopupHeight,offsetRight:35,padding:0,contentPadding:10,angle:{offset:33},overlay:{backgroundColor:"white",opacity:0},content:n,events:{onPopupClose:function(){e.countrySelectPopup.destroy()},onPopupDestroy:function(){e.countrySelectPopup=null}}});e.countrySelectPopup.show()}))};var z={templates:{3:"x-xx",4:"xx-xx",5:"x-xx-xx",6:"xx-xx-xx",7:"xxx-xx-xx"},format:function(t){var e=this.templates[t.length];if(!e){return t}var r=0;var n=new RegExp(e.replace(/[^x]/g,"").replace(/x/g,"(\\d)"));var a=e.replace(/x/g,(function(){return"$"+ ++r}));return t.replace(n,a)},isApplicable:function(t){return/^\d{3,7}$/.test(t)}};var W=function(t){if(!t||t.length>h){return""}var e=t.search(new RegExp(P));if(e<0){return""}var r=t.substr(e);r=r.replace(new RegExp(C),"");return r};var H=function(t){t=yt(t);if(!t)return false;if(t[0]!==f){return{countryCode:"",localNumber:t}}t=t.substr(1);if(t[0]==="0"){return false}for(var e=u;e>0;e--){var r=t.substr(0,e);if(tt(r)){return{countryCode:r,localNumber:t.substr(e)}}}return false};var j=function(t){return t.length>=s&&t.search(new RegExp(w))!==-1};var U=function(t){var e="";var r="";var n=t.search(new RegExp("["+v+"]"));if(n>=0){r=t[n];e=t.substr(n);t=t.substr(0,n)}return{extensionSeparator:r,extension:gt(e,b+c),phoneNumber:t}};var G=function(t){if(!tt(t)){return false}var e=et(t);return nt(e[0])};var K=function(t,e){if(!t||!e)return false;var r=et(t);var n;var a;if(r.length===1){return r[0]}for(var o=0;o1){i=t.replace(n,o)}else{i=t.substr(a[0].length)}return i};var Q=function(t,e){var r=new RegExp("^(?:"+e["generalDesc"]["nationalNumberPattern"]+")$");if(t.match(r,t))return true;else return false};var Y=function(t,e,r,n){if(!e["availableFormats"])return true;for(var a=0;a