function popupHelp(helpContentPage) {
  var options = "width=800,height=400,top=40,left=40,scrollbars=yes,status=no,menubar=no,toolbar=no,resizable=yes";
  var helpremote = window.open(helpContentPage, '_blank', options);
  if (helpremote.opener == null) helpremote.opener = window;
  helpremote.opener.name = "opener";
  helpremote.focus();
}

function openSecondaryPopup(url,name) {
   var options = "width=680,height=600,top=40,left=40,scrollbars=yes,status=no,menubar=no,toolbar=no,resizable=yes";
   window.open(url,name,options);
}

var isLoaded = false;
var checkForFileError = false;
var uploadingWindow;
function handleFrameOnLoad() {
   try {
      if (checkForFileError == true) {
         var url = uploadingWindow.location.href.toUpperCase();
         if (url.indexOf("SUPPORTREQUESTSENT.ASPX") == -1) {
            uploadingWindow = window.open("/help/crm/uploadError.aspx", "ServiceRequestWindow", "width=400,height=250,resizable=yes,scrollbars=no");
            uploadingWindow.focus();
         }
      } else if (isLoaded == true && uploadingWindow) {
         checkForFileError = true;
         setTimeout("handleFrameOnLoad();", 5000);
      }
      isLoaded = true;
   } catch (e) {
      // ignore.
   }
}

window.onerror = handleWindowError;
function handleWindowError(sMsg, sUrl, sLine) {
   try {
      if (uploadingWindow) {
         var url = uploadingWindow.location.href;
         if (url.indexOf("SUPPORTREQUESTSENT.ASPX") == -1) {
            uploadingWindow = window.open("/help/crm/uploadError.aspx", "ServiceRequestWindow", "width=400,height=250,resizable=yes,scrollbars=no");
            uploadingWindow.focus();
            return true;
         }
      }
   } catch (e) {
      // Ignore.
   }
   return false;
}

function popupProcessWindow( urlForBasePage ) {
   checkForFileError = false;
   var f = window.document.getElementsByName("servicerequest");
   var attachments = window.document.getElementsByName("Attachment");
   if (attachments.length > 0) {
      if (attachments[0].value.length > 0) {
         uploadingWindow = window.open("/help/crm/uploading.aspx", "ServiceRequestWindow", "width=400,height=250,resizable=yes,scrollbars=no");
         f[0].submit();
         //window.location = urlForBasePage;
         return;
      }
   }
   uploadingWindow = window.open("/help/crm/uploading.aspx", "ServiceRequestWindow", "width=400,height=250,resizable=yes,scrollbars=no");
   f[0].submit();
   //window.location = urlForBasePage;
   return;
}

function productChoicePopup(url) {
   var options = "width=680,height=600,top=40,left=40,scrollbars=yes,status=no,menubar=no,toolbar=no,resizable=yes";
   window.open(url,'productChoice',options);
}

function initPopup() {
  if (this.parent) {
    if (this.parent.dialogHeight) {
      if (container) {
        if (container.offsetHeight) {
          this.parent.dialogHeight = container.offsetHeight + 30 + 'px';
          this.parent.dialogWidth = container.offsetWidth + 'px';
        }
      }
    }
  }
  if (this.init) {
    this.init();
  }
}
