function getById(id, mount) {
    if(mount)
        return document.getElementById('requirementsForm:includeRequirements:' + id);
    else
        return document.getElementById(id);
}

function show(id, mount) {
    getById(id, mount).style.display = "block";
}

function hide(id, mount) {
    getById(id, mount).style.display = "none";
}

function testAll() {
    testFlashPlayer();
    testCookies();
    testPopupBlocker();
}

function testFlashPlayer() {
    show('testFlashPlayerLoadingImage', true);
    if(gwaUtility != null) {
        if(gwaUtility.testFlashPlayer()) {
            hide('testFlashPlayerDefaultImage', true);
            hide('testFlashPlayerFalseImage', true);
            show('testFlashPlayerTrueImage', true);
            hide('testFlashPlayerErrorDetailLink');
        } else {
            hide('testFlashPlayerDefaultImage', true);
            show('testFlashPlayerFalseImage', true);
            hide('testFlashPlayerTrueImage', true);
            show('testFlashPlayerErrorDetailLink');
        }
    } else {
        alert('não encontrou script gwaUtility');
    }
    hide('testFlashPlayerLoadingImage', true);
}

function testCookies() {
    show('testCookiesLoadingImage', true);
    if(gwaCookieManager != null) {
        if(gwaCookieManager.isSupported()) {
            hide('testCookiesDefaultImage', true);
            hide('testCookiesFalseImage', true);
            show('testCookiesTrueImage', true);
            hide('testCookiesErrorDetailLink');
        } else {
            hide('testCookiesDefaultImage', true);
            show('testCookiesFalseImage', true);
            hide('testCookiesTrueImage', true);
            show('testCookiesErrorDetailLink');
        }
    } else {
        alert('não encontrou script gwaCookieManager');
    }
    hide('testCookiesLoadingImage', true);
}

function testPopupBlocker_callback(pop) {
    show('testPopUpLoadingImage', true);
    if(pop==null) {
        hide('testPopUpDefaultImage', true);
        show('testPopUpFalseImage', true);
        hide('testPopUpTrueImage', true);
        show('testPopUpErrorDetailLink');
    } else {
        pop.close();
        hide('testPopUpDefaultImage', true);
        hide('testPopUpFalseImage', true);
        show('testPopUpTrueImage', true);
        hide('testPopUpErrorDetailLink');
    }
    hide('testPopUpLoadingImage', true);
    var iframe = getById("popup_frame");
    iframe.style.display = "none";
}

function testPopupBlocker()
{
    var iframe;
    if(is.IE)
        iframe=document.createElement('<iframe name="popup_frame" id="popup_frame" src="" style="visibility: hidden;width:1px;height:1px;"></iframe>');
    else if(is.NS) {
        iframe=document.createElement('iframe');
        iframe.setAttribute("name", "popup_frame");
        iframe.setAttribute("id", "popup_frame");
        iframe.setAttribute("style", "visibility: hidden;width:1px;height:1px;");
    }
    document.body.appendChild(iframe);
    iframe = window.frames["popup_frame"];

    var script = "<script type='text/javascript'>var framePop; function test() { framePop = window.open('about:blank','', 'width=1, height=1'); } </script>";
    var html = "<html><head>"+script+"</head><body><script>setTimeout(function() {test(); parent.testPopupBlocker_callback(framePop)}, 2000);</script></body></html>";
    iframe = window.frames["popup_frame"];
    iframe.document.write(html)
}

function renderDetail(test) {
    if(test == 'flash') {
        hide('testCookiesErrorDetailBlockIE', true);
        hide('testCookiesErrorDetailBlockFF', true);
        hide('testPopUpErrorDetailBlockIE', true);
        hide('testPopUpErrorDetailBlockFF', true);
        show('testFlashPlayerErrorDetailBlock', true);
    } else {
        if(test == 'cookie') {
            if(is.IE)
            {
                hide('testFlashPlayerErrorDetailBlock', true);
                hide('testPopUpErrorDetailBlockIE', true);
                hide('testPopUpErrorDetailBlockFF', true);
                hide('testCookiesErrorDetailBlockFF', true);
                show('testCookiesErrorDetailBlockIE', true);
            }
            else
                if(is.NS)
                {
                    hide('testFlashPlayerErrorDetailBlock', true);
                    hide('testPopUpErrorDetailBlockIE', true);
                    hide('testPopUpErrorDetailBlockFF', true);
                    hide('testCookiesErrorDetailBlockIE', true);
                    show('testCookiesErrorDetailBlockFF', true);
                }
        } else {
            if(is.IE)
            {
                hide('testFlashPlayerErrorDetailBlock', true);
                hide('testCookiesErrorDetailBlockIE', true);
                hide('testCookiesErrorDetailBlockFF', true);
                hide('testPopUpErrorDetailBlockFF', true);
                show('testPopUpErrorDetailBlockIE', true);
            }
            else
                if(is.NS)
                {
                    hide('testFlashPlayerErrorDetailBlock', true);
                    hide('testCookiesErrorDetailBlockIE', true);
                    hide('testCookiesErrorDetailBlockFF', true);
                    hide('testPopUpErrorDetailBlockIE', true);
                    show('testPopUpErrorDetailBlockFF', true);
                }
        }
    }
}

function setDefaultStatus()
{
    hide('testFlashPlayerTrueImage', true);
    hide('testFlashPlayerFalseImage', true);
    hide('testFlashPlayerErrorDetailLink');
    show('testFlashPlayerDefaultImage', true);

    hide('testCookiesTrueImage', true);
    hide('testCookiesFalseImage', true);
    hide('testCookiesErrorDetailLink');
    show('testCookiesDefaultImage', true);

    hide('testPopUpTrueImage', true);
    hide('testPopUpFalseImage', true);
    hide('testPopUpErrorDetailLink');
    show('testPopUpDefaultImage', true);
}

function adjustDetailPositionModal(item)
{
    var widthVisibility, leftModal, eleModal;
    widthVisibility = getWidthVisibilityArea();
    eleModal = document.getElementById(item);
    eleModal.width = "370px";
    leftModal = (widthVisibility-370)/2;
    eleModal.style.left = leftModal + "px";

    if(is.IE) {
        //getDiffScroll()= retorna a diferença da área visivel com o tamanho da rolagem. quando vem 0 é pq não tem rolagem.
        if(getDiffScroll()>0) {
            eleModal.style.top = (getPositionHeightScroll()+10) + "px";
        } else {
            eleModal.style.top = "10px";
        }
    } else {
        if(getDiffScroll()>0) {
            eleModal.style.top = (getPositionHeightScroll()+10) + "px";
        } else {
            eleModal.style.top = "10px";
        }
    }
}
