﻿/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: onUpdating                                                                                      ***/
/***                                                                                                        ***/
/// <summary>
/// Called when the update panel is updating, i.e. while the server is processing
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function onUpdating(updateProgressDivID, disabledBackgroundDivID, gridViewID)
{
    // get the update progress div
    var updateProgressDiv = $get(updateProgressDivID); 
    var backgroundDiv = $get(disabledBackgroundDivID); 
                
    // make it visible
    updateProgressDiv.style.display = '';
    backgroundDiv.style.display = '';
    
    //  get the gridview element     
    var gridView = $get(gridViewID);
    
    // get the bounds of both the gridview and the progress div
    var gridViewBounds = Sys.UI.DomElement.getBounds(gridView);
    var updateProgressDivBounds = Sys.UI.DomElement.getBounds(updateProgressDiv);
    
    //	do the math to figure out where to position the element (the center of the gridview)
    var x = gridViewBounds.x + Math.round(gridViewBounds.width / 2) - Math.round(updateProgressDivBounds.width / 2);
    //var y = gridViewBounds.y + Math.round(gridViewBounds.height / 2) - Math.round(updateProgressDivBounds.height / 2);
    var y = gridViewBounds.y + 5;
    
    //	set the progress element to this position
    Sys.UI.DomElement.setLocation(updateProgressDiv, x, y);
    
    //  set the dimensions of the background div to the same as the body    
    var bodyBounds = Sys.UI.DomElement.getBounds(document.body);
    
    backgroundDiv.style.width = bodyBounds.width + 'px';
    backgroundDiv.style.height = bodyBounds.height + 'px';
    
    //  place the div over the gridview
    Sys.UI.DomElement.setLocation(backgroundDiv, bodyBounds.x, bodyBounds.y);
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: onUpdating                                                                                      ***/
/***                                                                                                        ***/
/// <summary>
/// Called when the update panel is updating, i.e. while the server is processing
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function onUpdatingCentreY(updateProgressDivID, disabledBackgroundDivID, gridViewID)
{
    // get the update progress div
    var updateProgressDiv = $get(updateProgressDivID); 
    var backgroundDiv = $get(disabledBackgroundDivID); 
                
    //  get the gridview element     
    var gridView = $get(gridViewID);
    
    // get the bounds of both the gridview and the progress div
    var gridViewBounds = Sys.UI.DomElement.getBounds(gridView);
    var updateProgressDivBounds = Sys.UI.DomElement.getBounds(updateProgressDiv);
    
    //	do the math to figure out where to position the element (the center of the gridview)
    var x = gridViewBounds.x + Math.round(gridViewBounds.width / 2) - Math.round(updateProgressDivBounds.width / 2);
    var y = gridViewBounds.y + Math.round(gridViewBounds.height / 2) - Math.round(updateProgressDivBounds.height / 2);    
    //var y = gridViewBounds.y + 5;
    
    //	set the progress element to this position
    Sys.UI.DomElement.setLocation(updateProgressDiv, x, y);
    
    //  set the dimensions of the background div to the same as the body    
    var bodyBounds = Sys.UI.DomElement.getBounds(document.body);
    
    backgroundDiv.style.width = bodyBounds.width + 'px';
    backgroundDiv.style.height = bodyBounds.height + 'px';
    
    //  place the div over the gridview
    Sys.UI.DomElement.setLocation(backgroundDiv, bodyBounds.x, bodyBounds.y);
    
    // make it visible
    updateProgressDiv.style.display = '';
    backgroundDiv.style.display = '';    
}


/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: onUpdated                                                                                       ***/
/***                                                                                                        ***/
/// <summary>
/// Called when the update panel is updated, i.e. when the server has finished processing and the control 
/// is rendered back to the browser
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function onUpdated(updateProgressDivID, disabledBackgroundDivID, gridViewID)
{
    // get the update progress div
    var updateProgressDiv = $get(updateProgressDivID); 
    var backgroundDiv = $get(disabledBackgroundDivID); 
    
    // make it invisible
    updateProgressDiv.style.display = 'none';
    backgroundDiv.style.display = 'none';
    
}

/**************************************************************************************************************/
/***                                                                                                        ***/
/***  Name: onAbort                                                                                         ***/
/***                                                                                                        ***/
/// <summary>
/// Called when we want to abort the updating of the update panel
/// </summary>
/***                                                                                                        ***/
/**************************************************************************************************************/

function onAbort(animationBehaviourID)
{
    if(Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack())
    {
        //  abort the postback
        Sys.WebForms.PageRequestManager.getInstance().abortPostBack();
        
        //  get the reference to the animation for the gridview
        var gvAnimation = $find(animationBehaviourID);
        
        //  simulate stopping by replaying the animation
        gvAnimation._postBackPending = false;
        gvAnimation.get_OnUpdatingBehavior().quit();
        gvAnimation.get_OnUpdatedBehavior().play();
    }
}