var page,portal;console.log("Loading portal.js (generic)");window.__portalGeneric=function(){function s(){return _portalInfo.allowPasswordResetLink}function t(){var n=document.location.pathname.substr(_portalInfo.portalRoot.length);return n.startsWith("/")&&(n=n.substr(1)),n}function h(){return _portalInfo.portalId}function c(n,t,r){if(n&&t){var u={clientId:n,password:t,testingInExternalWebBrowser:_portalInfo.testingInExternalWebBrowser};page._SystemGetString("PortalAuthenticateClient",u,i,r)}else r&&r("Client Id and Password must be specified.")}function i(t){for(var f,e,i="/",u=window.location.href.replace("?","&").split("&"),r=0;r<u.length;r++)if(u[r].startsWith("returnTo=")){i=u[r].substring(9);break}_portalInfo.testingInExternalWebBrowser&&(i+="&",i+="__token="+t);switch(_portalInfo.hostingContext){case"HtmlViewer":_portalInfo.testingInExternalWebBrowser?(f=window.location.href.indexOf("/HTMLWIDGETTEST?"),e=window.location.href.substr(0,f+16),i=e+"id=PORTAL:"+_portalInfo.portalId+i,window.location.href=i):window.location.href=i;break;case"WebExternal":i&&i.startsWith("/")&&(i=i.substring(1));n(i);break;default:window.alert("Unknown Portal Hosting Context '"+_portalInfo.hostingContext+"'.")}}function l(n,t,r){if(n&&t){var u={userId:n,password:t,testingInExternalWebBrowser:_portalInfo.testingInExternalWebBrowser};page._SystemGetString("PortalAuthenticateUser",u,i,r)}else r&&r("User Id and Password must be specified.")}function a(t,i,r){var u,e;u=window.parent&&window.parent.widget?window.parent.widget.UI:widget.UI;t?i?(e={existingPassword:t,newPassword:i,testingInExternalWebBrowser:_portalInfo.testingInExternalWebBrowser},page._SystemGetString("PortalChangePassword",e,function(){if(_portalInfo.testingInExternalWebBrowser){window.alert("Testing Portals in a external Web Browser and changing a password will cause any further portal requests to not be authenticated correctly without closing this page and re-opening it from finPOWER Connect.");return}if(widget.GetHostingContext()=="HtmlViewer"){window.alert("You are running this Portal internally within finPOWER Connect.\n\nPlease close all Portal windows and sign in again.");return}u.MsgBoxInfo("Your password has been successfully updated.\n\nYou will now return to the sign-in form.",{},function(){f()?window.parent.portal.Navigate("@Login"):n("@Login")})},r)):r&&r("New Password must be specified."):r&&r("Existing Password must be specified.")}function v(n){var t={testingInExternalWebBrowser:_portalInfo.testingInExternalWebBrowser};page._SystemGetString("PortalSignIn",t,function(t){y(t,n)})}function y(t,i){var r=t;i&&(r+=r.indexOf("?")===-1?"?returnTo="+encodeURIComponent(i):"&returnTo="+encodeURIComponent(i));n(r,null,!0)}function p(){var n={testingInExternalWebBrowser:_portalInfo.testingInExternalWebBrowser};page._SystemGetString("PortalSignOut",n,w,b)}function w(t){n(t,null,!0)}function b(n){window.alert(n)}function k(n,t,i){var r={testingInExternalWebBrowser:_portalInfo.testingInExternalWebBrowser};page._SystemGetString("PortalPasswordChange",r,function(r){d(r,n,t,i)})}function d(t,i,u,f){if(u===!0)f=$.extend({},{title:"Change Password",minWidth:"320px",minHeight:"500px",maxWidth:"320px",maxHeight:"640px"},f),r(t,{},f);else{var e=t;i&&(e+=e.indexOf("?")===-1?"?returnTo="+encodeURIComponent(i):"&returnTo="+encodeURIComponent(i));n(e,null,!1)}}function g(n,t,i){t=$.extend({},{message:"",subject:""},t);var r={testingInExternalWebBrowser:_portalInfo.testingInExternalWebBrowser,email:n,message:t.message,subject:t.subject};page._SystemGetString("PortalSendPasswordResetLink",r,function(){widget.UI.MsgBoxInfo("A Password Reset link has been sent to you.\n\nThis link is only valid for 10 minutes.\n\nNOTE: If you do not receive this email, please check your Junk or Spam folders.",{},i)},function(n){widget.UI.MsgBoxAlert(n,{},i)})}function nt(n,t,i){var r={testingInExternalWebBrowser:_portalInfo.testingInExternalWebBrowser,token:n,newPassword:t};page._SystemGetString("PortalPasswordResetFromToken",r,function(){widget.UI.MsgBoxInfo("Your password has been reset.\n\nYou can now sign in using your new password.",{},function(){document.location.href=_portalInfo.portalRoot})},function(n){i&&i(n)})}function n(n,t,i,r){var f=window,s=!1,h,c,o,e;n&&n.toUpperCase().startsWith("PORTAL://")?n=n.substr(9):n&&n.toUpperCase().startsWith("PORTAL:")&&(n=n.substr(7));n&&!n.startsWith("/")&&(n="/"+n);t&&t.prop&&t.prop("tagName")==="IFRAME"&&(f=t[0].contentWindow,s=!0);r||f.parent&&f.parent!==window&&f.parent.postMessage({message:"portal-url-changed",url:n},"*");switch(_portalInfo.hostingContext){case"HtmlViewer":if(_portalInfo.testingInExternalWebBrowser){if(h=window.location.href.indexOf("/HTMLWIDGETTEST?"),c=window.location.href.substr(0,h+16),n=c+"id=PORTAL:"+_portalInfo.portalId+n,!i||s)for(o=window.location.href.split("&"),e=0;e<o.length;e++)if(o[e].startsWith("__token=")){n+="&"+o[e];break}f.location.href=n}else f.location.href=n;break;case"WebExternal":n&&n.startsWith("/")&&(n=n.substring(1));u.setItem("_highDpi",widget.IsHighDpi());f.location.href=_portalInfo.portalRoot+n;break;default:window.alert("Unknown Portal Hosting Context '"+_portalInfo.hostingContext+"'.")}}function r(n,t,i){var r=page.UI.Modal(i);r.Show();t||(t={});t.__modal=!0;r.LoadPortalPage(n,t)}function tt(n){widget.ExecuteApplicationShortcutUrl("app://portal?id="+encodeURIComponent(n))}function it(n,t,i){var r,u;switch(_portalInfo.hostingContext){case"HtmlViewer":r={resourceId:n,highDpi:widget.IsHighDpi()};page._SystemGetString("PortalGetResourceUrl",r,function(n){t(n)},i);break;case"WebExternal":u=_portalInfo.portalRoot+"?GetResource&resourceId="+encodeURIComponent(n)+"&ts="+_portalInfo.portalTimestamp+"&highDpi="+widget.IsHighDpi();t&&window.setTimeout(function(){t(u)},10);break;default:window.alert("portal.GetResourceUrl: Unknown Portal Hosting Context '"+_portalInfo.hostingContext+"'.")}}function rt(n,t,i,r){page.GetString(n,t,i,r,!0)}function ut(n,t,i,r){page.DownloadFile(n,t,i,r,!0)}function ft(n,t,i,r,u){page.UploadFiles(n,t,i,r,u,!0)}function et(){var t=$(document);t.off("click","a[href^='/'],a[href^='portal:'],a[href^='PORTAL:'],a[href^='Portal:']");t.on("click","a[href^='/'],a[href^='portal:'],a[href^='PORTAL:'],a[href^='Portal:']",function(){var t=$(this);return n(t.attr("href")+"",t),!1})}function ot(n,t){var i,r;return n=widget.UI.GetElement(n),t=$.extend({},{id:"",startupParametersJson:null,startupParameters:null},t),t.startupParameters&&!t.startupParametersJson&&(t.startupParametersJson=JSON.stringify(t.startupParameters)),i=$("<iframe/>"),n.append(i),r={widgetId:t.id,startupParametersJson:t.startupParametersJson,hostingContext:_portalInfo.testingInExternalWebBrowser,testingInExternalWebBrowser:_portalInfo.testingInExternalWebBrowser},page._SystemGetString("PortalGetHtmlWidgetHtml",r,function(n){ct(n,i)},lt),ht(n,i,t)}function f(){return e()!==null}function st(){if(_portalInfo.hostingContext==="HtmlViewer")window.location.href="custom://PortalParentModalClose";else{var n=e();n&&n.Close()}}function e(){if(!window.parent||window.parent===window||!window.frameElement)return null;var n=window.frameElement.id;if(n.startsWith("IFRAME_")){n=n.substring(7);try{return window.parent.widget.UI.GetModalById(n)}catch(t){return null}}return null}function ht(){return{TypeName:"HostedWidget"}}function ct(n,t){var i=t[0].contentDocument;switch(_portalInfo.hostingContext){case"HtmlViewer":i.open();i.write(n);i.close();_portalInfo.testingInExternalWebBrowser;break;case"WebExternal":n="../../External/"+n;i.location.href=n;break;default:window.alert("portal.InsertWidget: Unknown Portal Hosting Context '"+_portalInfo.hostingContext+"'.")}}function lt(n){widget.UI.MsgBoxAlert(n)}function at(){return"1.00"}var u,o;return window.addEventListener("message",function(i){if(i.data&&i.data.message)switch(i.data.message){case"portal-navigate":var r=i.data.url,u=t();r.startsWith("/")&&(r=r.substr(1));r.toUpperCase()!==u.toUpperCase()&&n(i.data.url,null,!1,!0)}},!1),u={getItem:function(n){return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*"+encodeURIComponent(n).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*([^;]*).*$)|^.*$"),"$1"))||null},setItem:function(n,t,i,r,u,f){if(!n||/^(?:expires|max\-age|path|domain|secure)$/i.test(n))return!1;var e="";if(i)switch(i.constructor){case Number:e=i===Infinity?"; expires=Fri, 31 Dec 9999 23:59:59 GMT":"; max-age="+i;break;case String:e="; expires="+i;break;case Date:e="; expires="+i.toUTCString()}return document.cookie=encodeURIComponent(n)+"="+encodeURIComponent(t)+e+(u?"; domain="+u:"")+(r?"; path="+r:"")+(f?"; secure":""),!0},removeItem:function(n,t,i){return!n||!this.hasItem(n)?!1:(document.cookie=encodeURIComponent(n)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT"+(i?"; domain="+i:"")+(t?"; path="+t:""),!0)},hasItem:function(n){return new RegExp("(?:^|;\\s*)"+encodeURIComponent(n).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=").test(document.cookie)},keys:function(){for(var n=document.cookie.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g,"").split(/\s*(?:\=[^;]*)?;\s*/),t=0;t<n.length;t++)n[t]=decodeURIComponent(n[t]);return n}},o={AllowPasswordResetLink:s,AuthenticateClient:c,AuthenticateUser:l,ChangePassword:a,DownloadFile:ut,GetResourceUrl:it,GetString:rt,InsertWidget:ot,IsInModal:f,ParentModalClose:st,PasswordResetFromToken:nt,PortalId:h,Navigate:n,OpenPageInModal:r,OpenPortal:tt,SendPasswordResetLink:g,ShowPasswordChange:k,SignIn:v,SignOut:p,UploadFiles:ft,Version:at,InitialisePage:et},window.parent&&window.parent!==window&&$(function(){try{var n=t().toUpperCase();n.startsWith("LOGIN")||n.startsWith("@LOGIN")||window.parent.postMessage({message:"portal-loaded"},"*")}catch(i){}}),o}();page=widget;page.PageId=function(){return _portalInfo.portalPageId};page._DownloadFile=widget.DownloadFile;page.DownloadFile=function(n,t,i,r,u){u?page._DownloadFile(n,t,i,r):page._DownloadFile(n+"~~~"+_portalInfo.portalPageId,t,i,r)};page._GetString=widget.GetString;page.GetString=function(n,t,i,r,u){u?page._GetString(n,t,i,r):page._GetString(n+"~~~"+_portalInfo.portalPageId,t,i,r)};page._UploadFiles=widget.UploadFiles;page.UploadFiles=function(n,t,i,r,u,f){f?page._UploadFiles(n,t,i,r,u):page._UploadFiles(n+"~~~"+_portalInfo.portalPageId,t,i,r,u)};console.log("  portal (generic)");console.log("Loading portal_external.js (external functionality)");portal=window.__portalGeneric,function(){portal.OpenPortal=function(n,t){var i=_portalInfo.portalRoot,r=i.toUpperCase().indexOf("/PORTAL/");r===-1?window.alert("Could not determine Portal root folder."):(i=i.substr(0,r+8)+n,t?window.open(i):document.location.href=i)};widget.__requestForm=function(n,t){var r,u;switch(n){case"HtmlWidget":if(t){var f=t.id,e=t.startupParametersJson||"",o={forceIFrame:!1,showWait:!1,width:t.width||"98%",height:t.height||"98%",title:t.title||"HTML Widget"},i="../../External/HtmlWidgetHost1.aspx";i+="?_widget="+encodeURIComponent(f);i+="&startupParametersJson="+e;i+="&_hostedInPortalId="+portal.PortalId();r=widget.UI.Modal(o);u="<iframe border='no' style='border:none; position:absolute; left:0; right:0; top:0; bottom:0; width:100%; height:100%' src='"+i+"' modalwidget='true' id='IFRAME_"+r.ModalId()+"' />";r.Show({content:u})}break;default:window.alert("Showing the '"+n+"' form from a Portal is not supported.")}};widget.__refreshParent=function(){document.location.href=document.location.href}}();console.log("  portal (external functionality)")