function PortalDialogResult(sButtonText, oArgs) {
   this.button = sButtonText;
   this.value = oArgs;
}

function PortalDialogArguments(sUrl) {
   this.win = self;
   this.url = sUrl;
}

function ShowPortalDialog(sUrl, sHeadTitle, nWidth, nHeight, bResize, bModeless) {
   var sFeatures = 'center:yes;help:no;status:no;unadorned:yes;scroll:no;resizable:' + (bResize ? 'yes' : 'no') + ';';
   var sDialogUrl = APP_ROOT_PATH + 'Portal/Pages/PortalDialog.aspx?HeadTitle=' + sHeadTitle;

   sUrl = ReplaceScriptVariables(sUrl);
   sUrl = AppendQueryString(sUrl, 'pdlgTitle=' + sHeadTitle);

   if (nWidth  != null) {
      sFeatures += 'dialogWidth:' + nWidth  + 'px;';
      sUrl += '&pdlgWidth=' + nWidth;
   }

   if (nHeight != null) {
      sFeatures += 'dialogHeight:' + nHeight + 'px;';
      sUrl += '&pdlgHeight=' + nHeight;
   }
   
   var args = new PortalDialogArguments(sUrl);
   var bAutoSignoff = (Portal_AutoSignoffID != 0);
   var result = null;

   if (bAutoSignoff) Portal_DisableAutoSignoff();

   if (bModeless) {
      showModelessDialog(sDialogUrl, args, sFeatures);
   }
   else {
      result = showModalDialog(sDialogUrl, args, sFeatures);

      if (result.button == '__AutoSignoff') {
         location.href = APP_ROOT_PATH + 'Portal/Pages/SignOffPage.aspx';
         result.button = 'cancel';
      }
      else if (bAutoSignoff) Portal_RegisterAutoSignoff();
   }

   return result;
}

function PortalDialogButtonPressed(sButtonText, oArgs) {
   window.parent.returnValue = new PortalDialogResult(sButtonText, oArgs);
   window.close();
   return false;
}

function PortalDialog_SetTitle(vsTitle) {
   if (window.parent.tdTitle) window.parent.tdTitle.innerText = vsTitle;
}

function PortalDialog_SetMessage(vsMsg) {
   if (window.parent.tdMessage) window.parent.tdMessage.innerText = vsMsg;
}

function PortalDialog_AutoSize() {
   alert('The Dialog AutoSize feature is not yet implemented.');
}

function PortalDialog_SetDimensions(vnWidth, vnHeight, vbRecenter) {
   window.parent.dialogWidth = vnWidth.toString() + 'px';
   window.parent.dialogHeight = vnHeight.toString() + 'px';

   if (vbRecenter) {
      var nLeft = ((screen.availWidth  - vnWidth)  / 2);
      var nTop  = ((screen.availHeight - vnHeight) / 2);

      if (nLeft < 0) nLeft = 0;
      if (nTop  < 0) nTop  = 0;

      window.parent.dialogLeft = nLeft.toString() + 'px';
      window.parent.dialogTop = nTop.toString() + 'px';
   }
}

function PortalDialog_Escape() {
   var nKeyCode;

   if (navigator.appName.indexOf('Microsoft Internet Explorer') >= 0) {
      nKeyCode = event.keyCode;
   }
   else {
      nKeyCode = evt.which;
   }

   if (nKeyCode == 27) PortalDialogButtonPressed('cancel', '');
}

function PortalDialog_ShowPleaseWait() {
   window.parent.ShowPleaseWait();
}

