var popUpOn = false;
var e;
var f;

window.onscroll = function()
{
    checkWindowSize();
}

function checkWindowSize()
{
    if(popUpOn == true)
        repositionPopup();
}

// Popup layer Function 1 of 4
function repositionPopup()
{
    e.style.width = "0px";    
    
    var frameWidth;
    var frameHeight;
    var marginTopY = getScrollCoordinates() + 50;
    
    if( window.innerHeight && window.scrollMaxY ) 
    {
        // Firefox 
        frameWidth = window.innerWidth + window.scrollMaxX;
        frameHeight = window.innerHeight + window.scrollMaxY;
    }
    else if( document.body.scrollHeight > document.body.offsetHeight ) 
    {
        // all but Explorer Mac
        frameWidth = document.body.scrollWidth;
        frameHeight = document.body.scrollHeight;
    }
    else 
    {
        // works in Explorer 6 Strict, Mozilla (not FF) and Safari
        frameWidth = document.body.offsetWidth + document.body.offsetLeft; 
        frameHeight = document.body.offsetHeight + document.body.offsetTop;
    }
    
    e.style.width= frameWidth+"px";
    e.style.height= frameHeight+"px";
    f.style.left = (frameWidth/2 - f.offsetWidth/2)+ "px";
    f.style.marginTop = marginTopY+ "px";
}

// Popup layer Function 2 of 4 
function getFrameWidth() {    
    return (document.width || document.body.offsetWidth);
}
// Popup layer Function 3 of 4 
function getFrameHeight() {
   return (document.height || document.body.offsetHeight);
}
// Popup layer Function 4 of 4 
function getScrollCoordinates() { 
    var frameWidth;
    var frameHeight;
    var windowHeight;
    var marginTopAmount;
    var scrollTop;
    var windowFrameRatio;

    frameWidth = getFrameWidth();
    frameHeight = getFrameHeight();
    
    if(frameWidth < 1)
        frameWidth =1;
    if(frameHeight < 1)
        frameHeight =1;
    
    scrollTop = window.pageYOffset || document.documentElement.scrollTop || 0; var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft || 0;
    if (window.innerHeight) //if browser supports window.innerWidth
        windowHeight = window.innerHeight;
    else if (document.all) //else if browser supports document.all (IE 4+)
        windowHeight = document.documentElement.clientHeight;
    
    windowFrameRatio = (windowHeight/frameHeight) * frameHeight;
    marginTopAmount = windowFrameRatio * (scrollTop/windowHeight);
    return marginTopAmount;
} 

function removePopup()
{
    popUpOn = false;
    var removePopupCont = document.getElementById('popupCont');
    removePopupCont.parentNode.removeChild(removePopupCont);
    
    e = null;
    f = null;
}