(function() {
    window.frameElement.style.width = "100vw";
    window.frameElement.style.height = "100vh";
    window.frameElement.style.minWidth = "100vw";
    window.frameElement.style.minHeight = "100vh";
    window.frameElement.style.maxWidth = "100vw";
    window.frameElement.style.maxHeight = "100vh";

    function findParent(element, styles) {
        while (element) {
            var i = 0;
            var contains = true;
            while (contains && i < styles.length) {
                contains = element.classList && element.classList.contains(styles[i++]);
            };
            if (contains)
                return element;
            element = element.parentElement;
        };
    };

    function findChildByClassNames(element, styles) {
        var e = 0;
        while (e < element.childNodes.length) {
            var i = 0, elem = element.childNodes[e];
            var contains = true;
            while (contains && i < styles.length) {
                contains = elem.classList && elem.classList.contains(styles[i++]);
            };
            if (contains)
                return elem;
            e++;
        };
    };

    function findChildByTagName(element, tag) {
        for (var i = 0; i < element.childNodes.length; i++)
            if (element.childNodes[i].tagName.toUpperCase() === tag.toUpperCase())
                return element.childNodes[i];
    };

    var msNavContent = findParent(window.frameElement.parentElement, ["ms-nav-content", "ms-nav-scrollable"]);
    if (msNavContent) {
        // Tablet client
        msNavContent.style.padding = "0";
        msNavContent.style.margin = "0";
        msNavContent.style.height = "100vh";
        msNavContent.style.width = "100vw";
        msNavContent.style.overflow = "hidden";
        for (var i = 0, child; (child = msNavContent.parentElement.childNodes[i]), i < msNavContent.parentElement.childNodes.length; i++) {
            (child.classList.contains("topbar-container") || child.classList.contains("ms-nav-navigation")) && (child.style.display = "none");
        };
    } else {
        // Web client
        window.frameElement.parentElement.style.height = "calc(100% - 500px)";

        var msNavScrollable = findParent(window.frameElement.parentElement, ["ms-nav-scrollable"]);
        if (msNavScrollable) {
            msNavScrollable.parentElement.style.padding = "0";
            msNavScrollable.style.overflow = "hidden";
            var h1 = findChildByTagName(msNavScrollable, "h1");
            h1 && (h1.style.display = "none");
            msNavScrollable.style.padding = "0";

            var contentHeader = findChildByClassNames(msNavScrollable.parentElement, ["content-header"]);
            contentHeader && (contentHeader.style.display = "none");

            var spaView = findParent(msNavScrollable.parentElement, ["spa-view", "spa-normal"]);
            spaView && (spaView.style.left = "0", spaView.style.width = "100vw");
        };

        var navBar = window.top.document.getElementById("product-menu-bar");
        navBar && (navBar.style.display = "none");
        var spa = findChildByClassNames(window.top.document.body, ["spa-container"]);
        if (spa) {
            spa.style.top = 0;
            spa.style.height = "100vh";
        };
    };
});