﻿
var mainScreen =
{
    mainModalExtender : null,           // modalExtender object on main page
    mainModalTitleSpan : null,          // title span object
    mainModalContentsDiv : null         // div inside modal dialog  
}
var mainModalRedirect = "";
mainScreen.Init = function() {   
    this.mainModalExtender = $find('mbMain');
    this.mainModalTitleSpan = $get("spanTitle");
    this.mainModalContentsDiv = $get("mainModalContents");
};
mainScreen.ShowModal = function (_title, _html) {
    var ErrorMessage = "Astro warning";
    var ConfirmMessage = "Astro Confirmation";
    if (_title == "error") {
        this.mainModalTitleSpan.innerHTML = ErrorMessage;       
        mainModalRedirect = "";
    }
    else if (_title == "confirm") {
        this.mainModalTitleSpan.innerHTML = ConfirmMessage;
        mainModalRedirect = "";
    }
    else {
        this.mainModalTitleSpan.innerHTML = ConfirmMessage;
        mainModalRedirect = _title;
    }
    this.mainModalContentsDiv.innerHTML = _html;
    this.mainModalExtender.show();
};
mainScreen.CancelModal = function () {   
    this.mainModalExtender.hide();   
    if (mainModalRedirect != "") {
        window.location = mainModalRedirect;
        mainModalRedirect == "";
    }
};


/// --------------------------------------------------
/// Page events processing
/// --------------------------------------------------

if (typeof (Sys) !== 'undefined') {
    Sys.Application.notifyScriptLoaded();
    //set up a handler for the application start
    Sys.Application.add_load(ApplicationLoadHandler)
}

function ApplicationLoadHandler(sender, args) {
    if (args.get_isPartialLoad()) return;
    //find out when new pages are loaded. 
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandler);
    mainScreen.Init();
}


//Sys.Application.add_load(
//    applicationLoadHandler
//    );
//Sys.WebForms.PageRequestManager.getInstance().add_endRequest(
//    endRequestHandler
//    );
//Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(
//    beginRequestHandler
//    );

//function applicationLoadHandler() {
//    /// <summary>
//    /// Raised after all scripts have been loaded and 
//    /// the objects in the application have been created 
//    /// and initialized.
//    /// </summary>
//    mainScreen.Init()
//}

function endRequestHandler() {
    /// <summary>
    /// Raised before processing of an asynchronous 
    /// postback starts and the postback request is 
    /// sent to the server.
    /// </summary>
    
    // TODO: Add your custom processing for event
}

function beginRequestHandler() {
    /// <summary>
    /// Raised after an asynchronous postback is 
    /// finished and control has been returned 
    /// to the browser.
    /// </summary>

    // TODO: Add your custom processing for event
}


