//
// Scripts for various ajax popup controls.
//

// Global variable for details popup timeout instance.
var popupDetailsTimeoutID = 0;

function ShowPopupDetails(pce)
{
    if (pce != null)
    {
        pce.showPopup();
    }
}
  
// Check the popup details client cursor position and render up/downward popup style
function CheckPopupDetails(e, popupID, behaviorID)
{
    var windowY = GetWindowHeight();    // windows y size
    var availSpace = 230;     // available bottom gap
    //var yScroll = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;

    if (e != null)
    {
        var popupObj = $get(popupID);
        var pce = $find(behaviorID);
        if ((popupObj == null) || (pce == null)) return;
        
        if (windowY - e.clientY > availSpace)
        {
            popupObj.className = 'ProdMiniPopupOuterLineDown';            // set the downward styles
            pce._offsetY = 0;     
        }
        else
        {
            popupObj.className = 'ProdMiniPopupOuterLineUp';
            pce._offsetY = -290;     
        }
        $find(behaviorID + 'PopupBehavior').set_positioningMode(0);   // aboslute positioning
    }
}

// Check popup screen position for oem machine fitment.
function CheckPopupOemFit(e, behaviorID, popupHeight)
{
    if (e != null) 
    {
        var pce = $find(behaviorID);  
        if (pce == null)
        {
            return;
        }

        // windowY is the window client-area height.
        // e.clientY is the position of the event from the top of windowY.
        var windowY = GetWindowHeight();
        if (windowY - e.clientY > popupHeight)    
        {
            pce._offsetY = 0;     
        } 
        else
        {
            // This pops it upward from the click point, even if there's some room below, just to keep it simple.
            pce._offsetY = -popupHeight;  
        }

        $find(behaviorID + 'PopupBehavior').set_positioningMode(0);   // absolute positioning
    }
}

// Get window height depending on browser.
//  This is the client-area height.
function GetWindowHeight()
{
    var windowY = 0;
    
    if (parseInt(navigator.appVersion) > 3)
    {
        if ((navigator.appName == "Microsoft Internet Explorer") && document.body)
        {
            windowY = document.documentElement.clientHeight;
        }
        else if (navigator.appName == "Netscape")
        {
            windowY = window.innerHeight;
        }
    }
    
    return windowY;
}
