﻿/// --------------------------------------------------
/// mainScreen object
/// --------------------------------------------------
var worldwideScreen =
{
    worldwideModalExtender: null,           // modalExtender object on main page
    worldwideModalTitleSpan: null,          // title span object
    worldwideModalContentsDiv: null,         // div inside modal dialog
    controls: null
}

worldwideScreen.Init = function () {
    /// <summary>
    /// Initializes mainScreen variables
    /// </summary>
    this.worldwideModalExtender = $find('mbWorldWide');
    if (this.worldwideModalExtender == null) return;
    this.controls = new Array(4);
    var prefix = "ctl00_";
    if (this.worldwideModalExtender._PopupControlID.indexOf("_ctl00_WorldWidePanel") >= 0) {
        prefix += "ctl00_";
    }
    this.controls[0] = prefix + "ddlCountry";
    this.controls[1] = prefix + "ddlLanguage";
    this.controls[2] = prefix + "worldwideCancel";
    this.controls[3] = prefix + "worldwideOK";
};
worldwideScreen.ShowModal = function() {
    if (this.worldwideModalExtender == null) this.Init();
    if (this.worldwideModalExtender == null) return;
    isModalOpen = true;
    isLoginActive = false;
    wwModalOpen = true;
    _CURRENT_FORM_NAME = "WordWide";
    var countryList = $get(this.controls[0]);
    if (countryList != null) {
        var countryListIndex = 0;
        if (countryList.selectedIndex > 0) {
            countryListIndex = countryList.selectedIndex;
        }
        var selectedCountry = countryList[countryListIndex];
        if (selectedCountry.value != _COUNTRY_ID) {
            for (i = 0; i < countryList[0].length; i++) {
                if (ddlCountry[0][i].value == _COUNTRY_ID) {
                    ddlCountry[0][i].selected = true;
                    break;
                }
            }
        }
    }
    this.worldwideModalExtender.show();
    SetControlFocus(this.controls[0]);
};
worldwideScreen.CancelModal = function() {
    /// <summary>
    /// Hides modal dialog
    /// </summary>
    isModalOpen = false;
    isLoginActive = false;
    if (this.worldwideModalExtender == null) return;
    this.worldwideModalExtender.hide();
};


var loginScreen =
{
    loginModalExtender: null,           // modalExtender object on main page
    loginModalTitleSpan: null,          // title span object
    loginModalContentsDiv: null,         // div inside modal dialog
    controls: null
}


/// --------------------------------------------------
/// LoginScreen object
/// --------------------------------------------------

loginScreen.Init = function() {
    /// <summary>
    /// Initializes mainScreen variables
    /// </summary>
    this.loginModalExtender = $find('mbLogin');
    this.controls = new Array(6);
    var prefix = "ctl00_";
    if (this.loginModalExtender._PopupControlID.indexOf("_ctl00_loginModal") >= 0) {
        prefix += "ctl00_";
    }
    this.controls[0] = prefix + "loginModalID_lblLoginRegisterNow";
    this.controls[1] = prefix + "loginModalID_txtAgentUserName";
    this.controls[2] = prefix + "loginModalID_txtAgentPassword";
    this.controls[3] = prefix + "loginModalID_lblForgotPW";
    this.controls[4] = prefix + "loginModalID_loginCancel";
    this.controls[5] = prefix + "loginModalID_loginOK";

};
loginScreen.ShowModal = function() {
    isModalOpen = true;
    isLoginActive = true;
    this.loginModalExtender.show();
};
loginScreen.CancelModal = function() {
    /// <summary>
    /// Hides modal dialog
    /// </summary>
    isModalOpen = false;
    isLoginActive = false;
    this.loginModalExtender.hide();
};


/// --------------------------------------------------
/// Register object
/// --------------------------------------------------
var registerScreen =
{
    registerModalExtender: null           // modalExtender object on main page
}

registerScreen.Init = function() {
    /// <summary>
    /// Initializes mainScreen variables
    /// </summary>
    this.registerModalExtender = $find('mbRegister');
};
registerScreen.ShowModal = function() {
    isModalOpen = true;
    isLoginActive = false;
    this.registerModalExtender.show();
};
registerScreen.CancelModal = function() {
    /// <summary>
    /// Hides modal dialog
    /// </summary>
    isModalOpen = false;
    isLoginActive = false;
    this.registerModalExtender.hide();
};

/// --------------------------------------------------
/// ReceiptSample object
/// --------------------------------------------------
var receiptSampleScreen =
{
    receiptSampleModalExtender: null           // modalExtender object on main page
}

receiptSampleScreen.Init = function() {
    this.receiptSampleModalExtender = $find('mbReceiptSample');
};
receiptSampleScreen.ShowModal = function() {
    isModalOpen = true;
    isLoginActive = true;
    this.receiptSampleModalExtender.show();
};
receiptSampleScreen.CancelModal = function() {
    /// <summary>
    /// Hides modal dialog
    /// </summary>
    isModalOpen = false;
    isLoginActive = false;
    this.receiptSampleModalExtender.hide();
};

// End ///

/// --------------------------------------------------
/// NotifyModal object
/// --------------------------------------------------
var _notifyModalScreen =
{
    Extender: null           // modalExtender object on main page
}

_notifyModalScreen.Init = function() {
    this.Extender = $find('mbNotifyModal');
};
_notifyModalScreen.ShowModal = function() {
    isModalOpen = true;
    isLoginActive = false;
    this.Extender.show();
};
_notifyModalScreen.CancelModal = function() {
    /// <summary>
    /// Hides modal dialog
    /// </summary>
    isModalOpen = false;
    isLoginActive = false;
    this.Extender.hide();
};

// End ///

/// --------------------------------------------------
/// 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>
    worldwideScreen.Init();
    loginScreen.Init();
    registerScreen.Init();
    //brandLogoScreen.Init();
    receiptSampleScreen.Init();
    _notifyModalScreen.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
}

function getHtmlOption(text, value) {
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    return optn;
}

function isKeyPressed(e, code) {
    return (e.which && e.which == code) || (e.keyCode && e.keyCode == code);
}

function isEnterPressed(e) {
    return isKeyPressed(e, 13);
}


function ShowReceiptSample() {
    if (receiptSampleScreen != undefined &&
            receiptSampleScreen.receiptSampleModalExtender != undefined &&
            receiptSampleScreen.receiptSampleModalExtender != null) {
        isModalOpen = true;
        _CURRENT_FORM_NAME = "ReceiptSample";
        receiptSampleScreen.ShowModal();
    }
}
function ShowNotifyModal(_title, _content) {
    if (_notifyModalScreen != undefined &&
            _notifyModalScreen.Extender != undefined &&
            _notifyModalScreen.Extender != null) {
        var prefix = "ctl00_";
        if (_notifyModalScreen.Extender._PopupControlID.indexOf("_ctl00_notifyModalID") >= 0) {
            prefix += "ctl00_";
        }

        $get(prefix + "notifyModalID_lblTitle").innerHTML = _title;
        $get(prefix + "notifyModalID_lblContent").innerHTML = _content;
        $get(prefix + "notifyModalID_ID_Div_Button").style.display = "";
        _notifyModalScreen.ShowModal(); ;
    }
}

function ShowNotifyModalNoButton(_title, _content) {
    if (_notifyModalScreen != undefined &&
            _notifyModalScreen.Extender != undefined &&
            _notifyModalScreen.Extender != null) {
        var prefix = "ctl00_";
        if (_notifyModalScreen.Extender._PopupControlID.indexOf("_ctl00_notifyModalID") >= 0) {
            prefix += "ctl00_";
        }
        $get(prefix + "notifyModalID_lblTitle").innerHTML = _title;
        $get(prefix + "notifyModalID_lblContent").innerHTML = _content;
        $get(prefix + "notifyModalID_ID_Div_Button").style.display = "none";
        _notifyModalScreen.ShowModal(); ;
    }
}

function NotifyScreenClose() {
    _CURRENT_FORM_NAME = "NotifyModal";
    _notifyModalScreen.CancelModal();
    HomePage();
}

function NotifyScreenCloseNoRedirect() {
    _CURRENT_FORM_NAME = "NotifyModal";
    _notifyModalScreen.CancelModal();
}

function ShowLoginScreenModal() {
    _CURRENT_FORM_NAME = "LoginModal";
    loginScreen.ShowModal();
}
