﻿/// --------------------------------------------------
/// mainScreen object
/// --------------------------------------------------
var mainScreen =
{
    mainModalExtender: null,           // modalExtender object on main page
    mainModalTitleSpan: null,          // title span object
    mainModalContentsDiv: null        // div inside modal dialog
}

mainScreen.Init = function() {
    try {
        /// <summary>
        /// Initializes mainScreen variables
        /// </summary>
        this.mainModalExtender = $find('mbMain');
        this.mainModalTitleSpan = $get("spanTitle");
        this.mainModalContentsDiv = $get("mainModalContents");
    }
    catch (e) { }
};
mainScreen.ShowConfirm = function(_button, _title, _html) {
    try {
        /// <summary>
        /// Shows modal dialog with contents equal to _html
        /// </summary>
        /// <param name="_button">Button object</param>
        /// <param name="_title">Title of modal popup</param>
        /// <param name="_html">HTML that should be shown inside popup</param>
        this.currentButtonUID = _button.name
        this.mainModalTitleSpan.innerHTML = _title;
        this.mainModalContentsDiv.innerHTML = _html;
        this.mainModalExtender.show();
    }
    catch (e) { }
};
mainScreen.CancelConfirm = function() {
    /// <summary>
    /// Hides modal dialog 
    /// </summary>
    this.mainModalExtender.hide();
    this.currentButtonUID = null;
};
mainScreen.SubmitConfirm = function() {
    /// <summary>
    /// Hides modal dialog 
    /// </summary>
    if (this.currentButtonUID) {
        __doPostBack(this.currentButtonUID, "");
    }
    this.mainModalExtender.hide();
    this.currentButtonUID = null;
};
mainScreen.OKConfirm = function() {
    /// <summary>
    /// Hides modal dialog
    /// </summary>
    this.mainModalExtender.hide();
    this.currentButtonUID = null;
    try { AlertWasClosed(); }
    catch (e) { }
};


/// --------------------------------------------------
/// Page events processing
/// --------------------------------------------------

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>
    if ($get("resultDiv") != null)
        $get("resultDiv").innerHTML = "<img src='images/activity_small.gif'/>";
}