function openPopup(n){var r,u;showLoader();var f=n.onBeforeOpen||function(){},e=n.onAfterOpen||function(){},o=n.onClosePopup||function(){},s=n.onInitPopup||function(){},i=$.Deferred(),t;!isHasPopup(n.popupId)||n.isDisposable?(r=n.onBeforeLoad||function(){},u=n.onAfterLoad||function(){},r(),removePopup(getPopup(n.popupId)),$.ajax({url:n.url,data:n.data,type:n.httpType||"GET",traditional:!0,success:function(r){addPopup(r);u();t=getPopup(n.popupId);i.resolve()},error:function(n,t,r){i.reject(n,t,r)}})):i.resolve();i.done(function(){if(f(),t=getPopup(n.popupId),!t.hasClass("popup-init")){t.addClass("popup-init");$(".popup-close",t).on("click",function(){o()});s()}t.addClass("opened");$("#popup-overlay").css("z-index",popupStack.length+1);t.css("z-index",popupStack.length+1);popupStack.push(t);t.trigger("opened");hideLoader();t.fadeIn(300);alignmentPopup();e();var i=$('input[type="text"], input[type="password"], textarea',t).first();i.length>0&&i.trigger("focus")}).fail(function(n,t,i){failPopup(n,t,i)})}function failPopup(n,t,i){var r=getPopup("#popup-error"),u;$(".popup-title",r).text(n.status+": "+i);u=$("<div/>").append(n.responseText);$("style",u).remove();$(".popup-content",r).html(u);r.addClass("opened");$("#popup-overlay").css("z-index",popupStack.length+1);r.css("z-index",popupStack.length+1);popupStack.push(r);showOverlay();hideLoader();r.fadeIn(300);alignmentPopup()}function showOverlay(){$("body").width($("body").width());$("body").css("overflow","hidden");$("#overlay").fadeIn(300)}function hideOverlay(){$("#overlay").fadeOut(300,function(){$("body").css("width","");$("body").css("overflow","visible");$("body").removeAttr("style");_hideLoader()})}function addPopup(n){$("#overlay").append(n)}function showLoader(){popupStack.length==0&&showOverlay();var n=$("#overlay-loader","#overlay");n.css("z-index",popupStack.length+1);n.show(0,function(){$("img",n).css({top:$(window).outerHeight()/3})});_isVisibleOverlayLoader=!0}function hideLoader(){_isVisibleOverlayLoader=!1;popupStack.length==0||getOpenedPopups().length==0?hideOverlay():_hideLoader()}function _hideLoader(){var n=$("#overlay-loader","#overlay");n.hide();n.css("z-index","")}function removePopup(n){n.hasClass("opened")&&popupStack.pop();n.remove()}function isHasPopup(n){return getPopup(n).length>0}function getPopup(n){return $(n,"#overlay")}function getOpenedPopups(){return $(".popup.opened","#overlay")}function alignmentPopup(){getOpenedPopups().each(function(){var t=$(this),i=($(window).outerHeight()-t.outerHeight())/4,n;i<0&&(i=0);n=($(window).outerWidth()-t.outerWidth())/2;n<0&&(n=0);t.css({top:i,left:n})})}var popupStack=[],_isVisibleOverlayLoader=!1;$(document).ready(function(){$("#overlay").click(function(n){n.which==1&&getOpenedPopups().trigger("close")});$("#overlay").on("click",".popup, #overlay-loader",function(n){n.stopPropagation()});$("#overlay").on("click",".popup .popup-close",function(){$(this).closest(".popup").trigger("close")});$("#overlay").on("close",".popup",function(){popupStack.pop();var n=$(this);n.removeClass("opened");n.fadeOut(300,function(){n.hasClass("popup-removable")&&removePopup(n)});n.css("z-index","");popupStack.length!=0&&getOpenedPopups().length!=0||_isVisibleOverlayLoader||hideOverlay();$("#popup-overlay").css("z-index",popupStack.length)});$(window).resize(function(){alignmentPopup();var n=$("#overlay-loader","#overlay");$("img",n).css({top:$(window).outerHeight()/3})})})