function showPopupBackground() {

    var isIE = false;

    if (navigator.userAgent) {
        if (navigator.userAgent.indexOf('MSIE') > -1)
            isIE = true;
        else
            isIE = false;
    }

    document.getElementById("popupBackground").style.display = 'block';
    document.getElementById("popupBackground").style.height = document.body.clientHeight + "px";
    document.getElementById("popupBackground").style.Width = pageWidth();

    if (!isIE)
    {
        document.getElementsByTagName('body')[0].style.overflow = 'hidden';
        document.getElementsByTagName('body')[0].style.marginRight = '17px';
    }
}

function hidePopupBackground() {

    document.getElementById("popupBackground").style.display = 'none';
    
    var isIE = false;
    
    if (navigator.userAgent) {
        if (navigator.userAgent.indexOf('MSIE') > -1)
            isIE = true;
        else
            isIE = false;
    }

    if (!isIE)
    {
        document.getElementsByTagName('body')[0].style.overflow = 'scroll';
        document.getElementsByTagName('body')[0].style.marginRight = '0px';
    }
    
    
}

var CurrentPopup;
function showPopup(PopupId) {
    if (document.getElementById("banner_place_yatay")) { 
        document.getElementById("banner_place_yatay").style.display = "none"
    }

    var container = document.getElementById("container");

    if (container)
    {
        container.style.display = 'none';
    }

    CurrentPopup = document.getElementById(PopupId);
    CurrentPopup.style.display = 'block';

    var margTop = posTop();
    var margLeft = 0;
    
    if (CurrentPopup.offsetHeight)
    if (CurrentPopup.offsetHeight < pageHeight())
    {
        margTop = posTop() + (pageHeight() - CurrentPopup.offsetHeight) / 2;
    }

    if (CurrentPopup.offsetWidth)
    if (CurrentPopup.offsetWidth < pageWidth())
    {
        margLeft = (pageWidth() - CurrentPopup.offsetWidth) / 2;
    }
    
    CurrentPopup.style.top = margTop + "px";
    CurrentPopup.style.left = margLeft + "px";
    
    showPopupBackground();

    window.onresize += resizePopup;

    if (PopupId == "loginWindow")
    {
        TXT_Login_Email.select();
    }
}

function hidePopup() {
    if (document.getElementById("banner_place_yatay")) {
        document.getElementById("banner_place_yatay").style.display = ""
    }

    CurrentPopup.style.display = 'none';
    hidePopupBackground();

    var container = document.getElementById("container");

    if (container) {
        container.style.display = 'block';
    }
}

function resizePopup()
{
    if (CurrentPopup)
    {
        if (CurrentPopup.style.display == 'block')
        {
            repositionPopup();
        }
    }
}

function repositionPopup()
{
    if (CurrentPopup.offsetHeight)
        if (CurrentPopup.offsetHeight < pageHeight()) {
        margTop = posTop() + (pageHeight() - CurrentPopup.offsetHeight) / 2;
    }

    if (CurrentPopup.offsetWidth)
        if (CurrentPopup.offsetWidth < pageWidth()) {
        margLeft = (pageWidth() - CurrentPopup.offsetWidth) / 2;
    }

    CurrentPopup.style.top = margTop + "px";
    CurrentPopup.style.left = margLeft + "px";
}
