// Functions for the recent vehicle hover.

function hideRecentVehHover()
{
    hideDIV("recentPopUp");
    
    hideDIV("recentPopUpLowerLeft");
    hideDIV("recentPopUpLowerMid");
    hideDIV("recentPopUpLowerRight");
}

// When the page loads, the detail section has the Wait content
var g_recentWaitHTML = $get("recentPopUpDetail").innerHTML;
var g_callCount = 0;
var g_hoverSource = null;
var g_vehicleId;
var g_vehicles = new Object();
function showRecentVehHover(control, vehId, column)
{
//debugger; 
    g_hoverSource = control;
    var elm;   
    
    elm = $get("recentPopUpDetail");
    if(null != g_recentWaitHTML)
    {
        elm.innerHTML = g_recentWaitHTML;
        fixPNG();
    }

    // un-hide the lower section (callout wedge)
    showDIV("recentPopUpLower" + column);

    // unhide the main hover popup div.
    showDIV("recentPopUp");
    
    // position the hover
    positionHover();
    
    if(g_vehicles[vehId] && ("" != g_vehicles[vehId]))
    {
        g_callCount += 1;    
        fillHover(g_vehicles[vehId]);
    }
    else
    {
        // Call the webservice.
        g_callCount += 1;
        g_vehicles[vehId] = "";
        g_vehicleId = vehId;
        Reynolds.CL.Web.WebServices.VehicleFunctions.GetRecentVehicleHover(vehId, WSKey, recentVehicleSuccess, recentVehicleFailure, g_callCount);
    }
}

function positionHover()
{
    if(null != g_hoverSource)
    {
        // position the hover
        var controlLoc = Sys.UI.DomElement.getLocation(g_hoverSource);
        elm = $get("recentPopUp");
        var hoverBnds = Sys.UI.DomElement.getBounds(elm);
        Sys.UI.DomElement.setLocation(elm, 367, controlLoc.y - hoverBnds.height);
    }
}

function fillHover(content)
{
    elm = $get("recentPopUp");
    if(elm.style.display != "none")
    {
        elm = $get("recentPopUpDetail");
        elm.innerHTML = content; 
        positionHover();
        fixPNG();
    }
}

function recentVehicleSuccess(result, eventArgs)
{
    // Only process the result of the most recent web service call.
    if(eventArgs == g_callCount)
    {
        fillHover(result);
        g_vehicles[g_vehicleId] = result;
    }
} 

function recentVehicleFailure(err)
{
    hideRecentVehHover();
}
// END - Functions for the recent vehicle hover.