var pnlOverlay;
var pnlPopUp;

function displayModal( backgroundPanel, popupPanel )
{
    pnlOverlay = document.getElementById(backgroundPanel);
    pnlPopUp = document.getElementById(popupPanel);
    pnlOverlay.style.display = 'block';
    pnlPopUp.style.display = 'block';
    pnlPopUp.style.visibility = 'visible';
    document.documentElement.style.overflow = 'auto';
    placeModal();
    
}

function cancelModal( backgroundPanel, popupPanel )
{
    document.getElementById(backgroundPanel).style.display = 'none';
    document.getElementById(popupPanel).style.display = 'none';
    document.documentElement.style.overflow = 'auto';
    window.onresize = null;
}

function placeModal()
{
    if (!pnlPopUp || pnlPopUp.style.display == 'none')
        return;

    var clientHeight = document.documentElement.clientHeight;
    var clientWidth = document.documentElement.clientWidth;
    var totalHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
    var totalWidth = document.documentElement.scrollWidth || document.body.scrollWidth;
    var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;

    totalHeight = clientHeight > totalHeight ? clientHeight : totalHeight;
    totalWidth = clientWidth > totalWidth ? clientWidth : totalWidth;

    pnlOverlay.style.height = totalHeight + 'px';
    pnlOverlay.style.width = totalWidth + 'px';

    pnlPopUp.style.top = (scrollTop + ((clientHeight-pnlPopUp.clientHeight)/2)) < 1 ? '1px' : scrollTop + ((clientHeight-pnlPopUp.clientHeight)/2) + 'px';
    pnlPopUp.style.left = (scrollLeft + ((clientWidth-pnlPopUp.clientWidth)/2)) < 1 ? '1px' : scrollLeft + ((clientWidth-pnlPopUp.clientWidth)/2) + 'px';

    window.onresize = function(){placeModal()};
}

function getIndex ( dObject, sValue )
{
    for (  var x = 0; x < dObject.length; x++ )
    {
        if ( dObject.options[x].value == sValue )
            return x;
    }
    
    return -1;
}
