e._createCheckboxInputElement = function (id, checked) {
                var checkboxInputElement = document.createElement('input');
                checkboxInputElement.type = FIELDTYPE.checkbox;
                this._addDefaultAttribute(checkboxInputElement, checked.toString());
                checkboxInputElement.id = id;
                checkboxInputElement.checked = checked;
                checkboxInputElement.classList.add('win-checkbox');
                return checkboxInputElement;
            };
            UICreator.prototype._createCheckboxLabelElement = function (id, textContent) {
                var labelElement = document.createElement('label');
                labelElement.htmlFor = id;
                labelElement.id = id + 'Label';
                labelElement.textContent = textContent;
                labelElement.setAttribute('aria-hidden', 'true'); 
                return labelElement;
            };
            UICreator.prototype._createTextInputElement = function (id, placeHolder, value) {
                var textInputElement = document.createElement('input');
                this._addDefaultAttribute(textInputElement, value);
                textInputElement.type = FIELDTYPE.text;
                textInputElement.id = id;
                textInputElement.value = value;
                textInputElement.placeholder = placeHolder;
                textInputElement.classList.add('win-textbox');
                return textInputElement;
            };
            UICreator.prototype._createEmailInputElement = function (id, placeHolder, value) {
                var emailInputElement = document.createElement('input');
                this._addDefaultAttribute(emailInputElement, value);
                emailInputElement.type = FIELDTYPE.email;
                emailInputElement.id = id;
                emailInputElement.placeholder = placeHolder;
                emailInputElement.value = value;
                emailInputElement.classList.add('win-textbox');
                
                emailInputElement.addEventListener("blur", function () {
                    var eAddress = emailInputElement.value;
                    if (eAddress.length > 0) {
                        var atPos = eAddress.lastIndexOf('@');
                        var periodPos = eAddress.lastIndexOf(".");
                        if ((((eAddress.split('@').length - 1) > 1) || ((eAddress.split('.').length - 1) < 1))
                            || !((atPos > 0) && (periodPos < eAddress.length - 1) && (periodPos > atPos + 2) && (eAddress.length - atPos > 5))) {
                            this._emailError(emailInputElement, true, oemMetadata.emailInvalidError);
                        }
                        else {
                            this._emailError(emailInputElement, false, '');
                        }
                    }
                    else {
                        this._emailError(emailInputElement, false, '');
                    }
                }.bind(this));
                return emailInputElement;
            };
            UICreator.prototype._createEmailErrorElement = function (errorDivParent) {
                var errorDiv = document.createElement('div');
                errorDiv.classList.add('template-tooltip');
                errorDiv.classList.add('tooltipType_error');
                errorDiv.id = 'email_errorDialog';
                errorDiv.setAttribute("role", "alert");
                errorDiv.setAttribute("aria-live", "assertive");
                errorDiv.style.display = 'none';
                errorDivParent.appendChild(errorDiv);
            };
            UICreator.prototype._createSelectElement = function (id, placeholderOptionValue, placeholderOptionText, option) {
                var selectElement = document.createElement('select');
                selectElement.id = id;
                selectElement.setAttribute('type', FIELDTYPE.select);
                selectElement.classList.add('win-dropdown');
                this.selectedOptionValue = option;
                this._addDefaultAttribute(selectElement, option);
                
                var optionTag = document.createElement('option');
                optionTag.value = placeholderOptionValue;
                optionTag.innerText = placeholderOptionText;
                selectElement.appendChild(optionTag);
                return selectElement;
            };
            UICreator.prototype._createAnchorElement = function (id, href, textContent, fileName) {
                var anchorElement = document.createElement('a');
                anchorElement.id = id;
                anchorElement.href = href;
                anchorElement.innerText = textContent;
                anchorElement.onclick = function () {
                    var iframeDocument = this._flyoutIframe.contentWindow.document;
                    pageHelper.getLinkFileContent(fileName).done(function (fileContent) {
                        iframeDocument.open('text/html', 'replace');
                        iframeDocument.dir = _htmlRoot.dir;
                        iframeDocument.write(fileContent);
                        iframeDocument.close();
                        this._flyoutDiv.style.marginTop = this._getPageTop(this._pageContainerDiv) + 'px';
                        this._flyoutDiv.winControl.show(anchorElement, 'top', _htmlRoot.dir === "rtl" ? 'right' : 'left');
                    }.bind(this));
                }.bind(this);
                return anchorElement;
            };
            UICreator.prototype._createInputElementWrapperDiv = function (inputElement) {
                var wrappperDiv = document.createElement('div');
                wrappperDiv.classList.add('template-input');
                wrappperDiv.classList.add(this._getFieldClass(inputElement.getAttribute('type')));
                wrappperDiv.appendChild(inputElement);
                return wrappperDiv;
            };
            
            UICreator.prototype._getFieldClass = function (fieldTypeName) {
                switch (fieldTypeName) {
                    case FIELDTYPE.text:
                        return FIELDCLASS.text;
                    case FIELDTYPE.email:
                        return FIELDCLASS.email;
                    case FIELDTYPE.select:
                        return FIELDCLASS.select;
                    default:
                        throw "Invalid Type Name";
                        break;
                }
            };
            
            UICreator.prototype._getPageTop = function (el) {
                var rect = el.getBoundingClientRect();
                var docEl = document.documentElement;
                return rect.top + (window.pageYOffset || docEl.scrollTop || 0);
            };
            
            UICreator.prototype._emailError = function (emailObject, shouldShow, errorMessage) {
                var errorDiv = emailObject.nextSibling;
                if (shouldShow) {
                    if (errorDiv.childNodes(webAuthUrl + "&appru=" + Windows.Foundation.Uri.escapeComponent(appId) + "&login_hint=" + escapedUPN + "&username=" + escapedUPN + queryString);
                } else {
                    startURI = new Windows.Foundation.Uri(webAuthUrl + "?appru=" + Windows.Foundation.Uri.escapeComponent(appId) + "&login_hint=" + escapedUPN + "&username=" + escapedUPN + queryString);
                }

                var stopURI = new Windows.Foundation.Uri(appId);
                var enterpriseManagementWorker = new EnterpriseDeviceManagement.Enrollment.ReflectedEnroller();
                enterpriseManagementWorker.allowAuthUri(startURI);

                Windows.Security.Authentication.Web.WebAuthenticationBroker.authenticateAsync(Windows.Security.Authentication.Web.WebAuthenticationOptions.useHttpPost | Windows.Security.Authentication.Web.WebAuthenticationOptions.useCorporateNetwork, startURI, stopURI).done(function (result) {
                    enterpriseManagementWorker.removeAuthUriAllowList();
                    var stringToSearch = "wresult=";
                    var beginningIndex = result.responseData.search(stringToSearch);
                    var endingIndex = result.responseData.indexOf("&", beginningIndex + stringToSearch.length);
                    var endString;
                    if (endingIndex === -1) {
                        endString = result.responseData.substring(beginningIndex + stringToSearch.length);
                    } else {
                        endString = result.responseData.substring(beginningIndex + stringToSearch.length, endingIndex);
                    }
                    var webAuthenticationResultObject = {
                        responseStatus: result.responseStatus, responseData: endString
                    };
                    if (WEB_AUTHENTICATION_STATUS_ERROR_HTTP === result.responseStatus) {
                        enterpriseManagementWorker.eventWriteForEnrollment(DMLOGGING_WEBAUTH_HTTP, result.responseErrorDetail);
                    } else if (WEB_AUTHENTICATION_STATUS_USER_CANCEL === result.responseStatus) {
                        enterpriseManagementWorker.eventWriteForEnrollment(DMLOGGING_WEBAUTH, E_ABORT);
                    } else {
                        enterpriseManagementWorker.eventWriteForEnrollment(DMLOGGING_WEBAUTH, S_OK);
                    }
                    completeDispatch(webAuthenticationResultObject);
                }, function (e) {
                    enterpriseManagementWorker.removeAuthUriAllowList();
                    enterpriseManagementWorker.eventWriteForEnrollment(1, e.number);
                    errorDispatch(e);
                });
            });
        }
        UnifiedEnroll.doWebAuth = doWebAuth;
        function checkCustomPageText() {
            return new WinJS.Promise(function (completeDispatch, errorDispatch) {
                var enterpriseManagementWorker = new EnterpriseDeviceManagement.Enrollment.ReflectedEnroller();
                enterpriseManagementWorker.retrieveCustomAllDonePageAsync().then(function (result) {
                    var customAllDonePageResultsObject = {
                        customAllDonePageTitle: result.customAllDonePageTitle, customAllDonePageBody: result.customAllDonePageBody, customAllDonePageHyperlinkHref: result.customAllDonePageHyperlinkHref,
                        customAllDonePageHyperlinkText: result.customAllDonePageHyperlinkText
                    };
                    completeDispatch(customAllDonePageResultsObject);
                }, errorDispatch);
            });
        }
        UnifiedEnroll.checkCustomPageText = checkCustomPageText;
        function retrieveMamEnrollmentID() {
            return new WinJS.Promise(function (completeDispatch, errorDispatch) {
                var enterpriseManagementWorker = new EnterpriseDeviceManagement.Enrollment.ReflectedEnroller();
                enterpriseManagementWorker.getEnrollment(ENROLL_TYPE_MAM).then(function (result) {
                    var enrollmentIDWithoutBrackets = result.substring(1, result.length -1);
                    completeDispatch(enrollmentIDWithoutBrackets);
                }, errorDispatch);
            });
        }
        UnifiedEnroll.retrieveMamEnrollmentID = retrieveMamEnrollmentID;
        function setMamEnrollmentAsDormant(enrollmentID) {
            return new WinJS.Promise(function (completeDispatch, errorDispatch) {
                var enterpriseManagementWorker = new EnterpriseDeviceManagement.Enrollment.ReflectedEnroller();
                enterpriseManagementWorker.setEnrollmentAsDormant(enrollmentID, true, false).then(completeDispatch, errorDispatch);
            });
        }
        UnifiedEnroll.setMamEnrollmentAsDormant = setMamEnrollmentAsDormant;
        function completeMAMToMDMUpgrade(mdmEnrollmentID, mamEnrollmentID, isFailedUpgrade) {
            return new WinJS.Promise(function (completeDispatch, errorDispatch) {
                var enterpriseManagementWorker = new EnterpriseDeviceManagement.Enrollment.ReflectedEnroller();
                enterpriseManagementWorker.completeMAMToMDMUpgrade(mdmEnrollmentID, mamEnrollmentID, isFailedUpgrade).then(completeDispatch, errorDispatch);
            });
        }
        UnifiedEnroll.completeMAMToMDMUpgrade = completeMAMToMDMUpgrade;
        function createCorrelationVector() {
            return new WinJS.Promise(function (completeDispatch, errorDispatch) {
                var enterpriseManagementWorker = new EnterpriseDeviceManagement.Enrollment.ReflectedEnroller();
                enterpriseManagementWorker.createCorrelationVector().then(completeDispatch, errorDispatch);
            });
        }
        UnifiedEnroll.createCorrelationVector = createCorrelationVector;
        function checkIfPinPromptScenario() {
            return new WinJS.Promise(function (completeDispatch, errorDispatch) {
                var context = CloudExperienceHost.getContext();
                if (context.host.toLowerCase() !== "nthentormdm" && context.host.toLowerCase() !== "nthaadormdm") {
                    completeDispatch(true);
                } else {
                    completeDispatch(-1 !== context.source.toLowerCase().indexOf("ngc=enabled"));
                }
            });
        }
        UnifiedEnroll.checkIfPinPromptScenario = checkIfPinPromptScenario;
        function resetDevice() {
            return new WinJS.Promise(function (completeDispatch, errorDispatch) {
                var pluginManager = new CloudExperienceHostAPI.Provisioning.PluginManager();
                pluginManager.initiateSystemResetAsync().then(function (results) {
                    bridge.invoke("CloudExperienceHost.Telemetry.logEvent", "UnifiedEnrollment_ProvisioningProgressPage_ResetDevice_Successful");
                    completeDispatch(true);
                }, function (e) {
                    bridge.invoke("CloudExperienceHost.Telemetry.logEvent", "UnifiedEnrollment_ProvisioningProgressPage_ResetDevice_Error", JSON.stringify({ error: e }));
                    errorDispatch(e);
                });
            });
        }
        UnifiedEnroll.resetDevice = resetDevice;
        function localizedStrings() {
            var unifiedEnrollmentResources = {};
            var keyList = ['Title', 'LeadText', 'Description', 'UserPlaceholder', 'ServerUrlPlaceholder', 'FooterHeader', 'DjLink', 'Error_NoUsername', 'Error_UsernameFormat',
                'Error_UsernameLookup', 'Error_DomainLookup', 'Error_Network', 'Error_Generic_Code', 'Error_Generic', 'NextButton', 'Error_MDM_StandardUser', 'Error_MDM_AlreadyConnected',
                'Error_MDM_DiscoveryError', 'DomainUsernamePlaceholder', 'PasswordPlaceholder', 'EnrollerLeadText', 'EnrollmentErrorFinishedTitle',
                'EnrollmentErrorFinishedLeadText', 'EnrollmentFinishedTitle', 'EnrollmentFinishedLeadText', 'FinishedButton', 'InsecureRedirectTitle', 'InsecureRedirectLeadText',
                'InsecureRedirectDescription', 'InvalidCertTitle', 'InvalidCertLeadText', 'InvalidCertDescription', 'TraceIdError', 'WebAuthError', 'MENROLL_E_DEVICE_UNKNOWN_ERROR', 'MENROLL_E_DEVICENOTSUPPORTED',
                'MENROLL_E_CONNECTIVITY', 'MENROLL_E_DEVICECAPREACHED', 'MENROLL_E_DEVICE_AUTHENTICATION_ERROR', 'MENROLL_E_PROV_UNKNOWN', 'MENROLL_E_PLATFORM_UNKNOWN_ERROR', 'DiscoveryProgressText',
                'WABProgressText', 'Error_MAM_DiscoveryError', 'MAMWebAuthError', 'EnrollmentProgressPoliciesText', 'EnrollmentProgressProfilesText', 'EnrollmentProgressAppsText', 'EnrollmentProgressCertificatesText',
                'EnrollmentProgressPolicyNotStartedText', 'EnrollmentProgressPolicyInProgressText', 'EnrollmentProgressPolicyFinishedText', 'EnrollmentProgressProfileNotStartedText', 'EnrollmentProgressProfileInProgressText', 
                'EnrollmentProgressProfileFinishedText', 'EnrollmentProgressApplicationNotStartedText', 'EnrollmentProgressApplicationInProgressText', 'EnrollmentProgressApplicationFinishedText',
                'EnrollmentProgressCertificateNotStartedText', 'EnrollmentProgressCertificateInProgressText', 'EnrollmentProgressCertificateFinishedText', 'EnrollmentProgressNotifyOfNotificationText',
                'UserNarratorText', 'ServerUrlNarratorText'];
            keyList.forEach(function (key) {
                var resourceId = '/unifiedEnrollment/' + key;
                unifiedEnrollmentResources[key] = WinJS.Resources.getString(resourceId).value;
            });
            return JSON.stringify(unifiedEnrollmentResources);
        }
        UnifiedEnroll.localizedStrings = localizedStrings;
        function localizedProvProgressStrings() {
            var unifiedEnrollmentResources = {};
            var keyList = ['BootstrapPageTitle', 'BootstrapPageRebootWarning', 'BootstrapPageDevicePrepTitle', 'BootstrapPageDeviceSetupTitle', 'BootstrapPageAccountSetupTitle', 'BootstrapPageShowDetailButton',
            'BootstrapPageGettingReady', 'BootstrapPageWaitingForPrevious', 'BootstrapPageComplete', 'BootstrapPageWorking', 'BootstrapPageStillWorking', 'BootstrapPageTPM', 'BootstrapPageAADJ', 'BootstrapPagePrepareMDM',
            'BootstrapPageMDM', 'BootstrapPageIdentifying', 'BootstrapPageAuthentication', 'BootstrapPageSecurityPolicies', 'BootstrapPageCertificates', 'BootstrapPageNetwork', 'BootstrapPageApps', 'BootstrapPagePolicyTrack',
            'BootstrapPageNetworkTrack', 'BootstrapPageAppTrack', 'BootstrapPageDontClose', 'BootstrapPagePatience', 'BootstrapPageFailed', 'BootstrapPageDefualtError', 'BootstrapPageCollectLogs',
            'BootstrapPageResetDevice', 'BootstrapPageTryAgain', 'BootstrapPageContinue', 'BootstrapPagePrevStepFailed', 'BootstrapPageContinueMessage', 'BootstrapPageSignInWait', 'BootstrapPageNotSetUp'];
            keyList.forEach(function (key) {
                var resourceId = '/unifiedEnrollment/' + key;
                unifiedEnrollmentResources[key] = WinJS.Resources.getString(resourceId).value;
            });
            return JSON.stringify(unifiedEnrollmentResources);
        }
        UnifiedEnroll.localizedProvProgressStrings = localizedProvProgressStrings;
    })(UnifiedEnroll = CloudExperienceHost.UnifiedEnroll || (CloudExperienceHost.UnifiedEnroll = {}));
})(CloudExperienceHost || (CloudExperienceHost = {}));