/***********************************************
* Popup Window script
***********************************************/

/***********************************************
* External variables that must be set in HTML page using popup
*
* popupName // Name to be given to popup window
***********************************************/

var popupWin   = null;
var popupPage  = "detail_popup.htm" ;    // HTML file for popup window
var lastTarget = "nothing";

function myHeight()
{
    if ('number' == typeof(window.innerHeight))
    {
        return window.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    {
        return document.documentElement.clientHeight;
    }
    else if (document.body && document.body.clientHeight)
    {
        return document.body.clientHeight;
    }

    return 480;
}

function myWidth()
{
    if ('number' == typeof(window.innerWidth))
    {
        return window.innerWidth;
    }
    else if (document.documentElement && document.documentElement.clientWidth)
    {
        return document.documentElement.clientWidth;
    }
    else if (document.body && document.body.clientWidth)
    {
        return document.body.clientWidth;
    }

    return 640;
}

function urlFromTarget(newTarget, newWidth, newHeight)
{
        if (!newWidth)
        {
            newWidth = eval(myWidth()) - 48;
        }
 
        if (!newHeight)
        {
            newHeight = eval(myHeight()) - 124;
        }

        return (popupPage                     + '?' +
                encodeURIComponent(newTarget) + '&' +
                newWidth                      + '&' +
                newHeight);
}

function openPopup(newTarget, newWidth, newHeight)
{
    if (lastTarget.valueOf() != newTarget.valueOf())
    {
        lastTarget = newTarget;

        var newUrl = urlFromTarget(newTarget, newWidth, newHeight);

        if (popupWin && !popupWin.closed)
        {
            popupWin.location.href = newUrl;
        }
        else
        {
            popupWin = window.open(newUrl,
                                   popupName,
                                   'width=' + newWidth
                                   + ', height=' + newHeight
                                   + ', location=yes'
                                   + ', menubar=no '
                                   + ', status=no '
                                   + ', toolbar=yes '
                                   + ', scrollbars=yes '
                                   + ', resizable=yes');
        }
    }

    popupWin.focus();
}

function loadPopup(newTarget, newWidth, newHeight)
{
    if ((lastTarget.valueOf() != newTarget.valueOf()) &&
        popupWin                                      &&
        !popupWin.closed                                )
    {
        lastTarget = newTarget;

        var newUrl = urlFromTarget(newTarget, newWidth, newHeight);

        popupWin.location.href = newUrl;
    }
}

function closePopup()
{
    if (popupWin && !popupWin.closed)
    {
        popupWin.close();
    }
    
    popupWin = null;
}

/***********************************************
* End of popup Window script
***********************************************/
