﻿/*
Installation Notes: 
<asp:ScriptManager ID="ScriptManager1" runat="server" >
<Scripts>
<asp:ScriptReference Path="~/Utils/AJAX_ScriptManager_Scripts.js" />
</Scripts>
</asp:ScriptManager>
*/

Sys.Application.add_init(AppInit);

function AppInit(sender) {
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_initializeRequest(InitializeRequest);
    prm.add_beginRequest(BeginRequest);
    prm.add_endRequest(EndRequest);
}

function InitializeRequest(sender, args) {

    // Get a reference to the element that raised the postback,
    //   and disables it.
    $get(args._postBackElement.id).disabled = true;
}

function BeginRequest(sender, args) {
    // Clear the error if it's visible from a previous request.
    if ($get("Error")) {
        if ($get('Error').style.display == "none")
            CloseError();
    }

    if ($get("imgPagingProgressBar")) {
        $get("imgPagingProgressBar").style.display = "inline";
        self.scrollTo(0, 0);
    }
    if ($get("imgProgressBar")) {
        $get("imgProgressBar").style.display = "inline";
    }
    
}


function EndRequest(sender, args) {

    // Get a reference to the element that raised the postback
    //   which is completing, and enable it.
    $get(sender._postBackSettings.sourceElement.id).disabled = false;

    if ($get("imgPagingProgressBar")) {
        $get("imgPagingProgressBar").style.display = "none";
        self.scrollTo(0, 0);
    }

    // Check to see if there's an error on this request.
    if (args.get_error() != undefined) {
        // If there is, show the custom error.
        if ($get('Error')) {
            $get('Error').style.display = "block";

            // Let the framework know that the error is handled, 
            //  so it doesn't throw the JavaScript alert.
            args.set_errorHandled(true);
        }
    }

    
}

function CloseError() {
    // Hide the error span.
    $get('Error').style.display = "none";
}
