﻿// JScript File
// Globals
var currentPostBackElem;

function pageLoad() {
    var manager = Sys.WebForms.PageRequestManager.getInstance();
    manager.add_initializeRequest(OnInitializeRequest);
    manager.add_beginRequest(OnBeginRequest);
    manager.add_endRequest(OnEndRequest);
}

// Aborts the command currently executing
// function abortTask() {
//    var obj = Sys.WebForms.PageRequestManager.getInstance();
//    if (obj.get_isInAsyncPostBack())
//        $get("ctl00_ContentPlaceHolder1_UpdatePanel1").style.backgroundColor = "CornflowerBlue";
//        obj.abortPostBack();
//}

// Prevents the command action from being executed multiple times
function OnInitializeRequest(sender, args) {
    var manager = Sys.WebForms.PageRequestManager.getInstance();
    
    // Check if we're posting back because of the Command buttons
    if (manager.get_isInAsyncPostBack() &&
        (args.get_postBackElement().id == "ctl00_ctl00_Main_main_prcsOrdrNow") || (args.get_postBackElement().id == "ctl00_ctl00_Main_main_imgEditPlans")) {
            if ($get("ctl00_ctl00_Main_main_lblErr") != null)
            {
            $get("ctl00_ctl00_Main_main_lblErr").innerHTML = "Still working on previous request. Please, be patient ...";
            args.set_cancel(true);
            }
        }
}

function OnBeginRequest(sender, args) {
    currentPostBackElem = args.get_postBackElement();
    if (typeof(currentPostBackElem) === "undefined")
        return;
    if ((currentPostBackElem.id == "ctl00_ctl00_Main_main_prcsOrdrNow") || (currentPostBackElem == "ctl00_ctl00_Main_main_imgEditPlans"))  {
        // Disable the Submit button on order2 page 
        document.getElementById('ctl00_ctl00_Main_main_prcsOrdrNow').style.display = 'none';
        document.getElementById("ctl00_ctl00_Main_main_imgEditPlans").style.display = 'none';
        var updPR = document.getElementById('ctl00_ctl00_Main_main_UpdateProgress1');
        if (updPR != null)
        {
            document.getElementById('ctl00_ctl00_Main_main_UpdateProgress1').style.display = 'block';
        }
        else
            {
            document.getElementById('ctl00_ctl00_Main_main_imgWorking').style.display = 'block'; 
            document.getElementById('ctl00_ctl00_Main_main_txtFinalize').style.display = 'block'; 
            }
    }
}
function OnEndRequest(sender, args) {
   // debugger;
    if (typeof(currentPostBackElem) === "undefined")
        return;
    if ((currentPostBackElem.id == "ctl00_ctl00_Main_main_prcsOrdrNow") || (currentPostBackElem.id == "ctl00_ctl00_Main_main_imgEditPlans")) {
        // Enable the Submit button on Order2 page
        document.getElementById('ctl00_ctl00_Main_main_prcsOrdrNow').style.display = 'block';
        document.getElementById("ctl00_ctl00_Main_main_imgEditPlans").style.display = 'block';
        //$get("btnAbort").disabled = false;
        // Set the color of the UpdatePanel back
        //$get("ctl00_ContentPlaceHolder1_UpdatePanel1").style.backgroundColor = "CornflowerBlue";
    }
}
 
 function endRequest(sender,e){
     if(e.get_error()!=null){
        //an error has occurred
        alert("An error has occurred. Please re-submit your query.");
        //alert(e.get_error().message);
        //window.location="/ErrorPage.htm";
        e.set_errorHandled(true);//supresses the framework error message handling. 
     }
 }
 
 