﻿// Name: LoginDialog.js
// Version: 1.0.0.0
// FileVersion: 1.0.0.0
// -----------------------------------------------------------------------
//  Copyright (C) Peter Bredenberg System. All rights reserved.
// -----------------------------------------------------------------------

// Key press handler
function loginOkButtonKeyPress(e) {
    var kC = (window.event != null) ? event.keyCode : e.charCode;
    if (kC == 13) {
        stopEventBubbling(e);
        loginOkButton.click();
    }
}

// Key press handler
function loginCancelButtonKeyPress(e) {
    var kC = (window.event != null) ? event.keyCode : e.charCode;
    if (kC == 13) {
        stopEventBubbling(e);
        loginCancelButton.click();
    }
}

// Login dialog
function showLoginDialog(userName, password) {
    closeAllDialogs();

    if (isLoggedIn()) {
        onClickLogout();
    }
    else {
        positionModalBackground(true);
        centerLoginDialog(true);

        var userNameTextBox = $get(userName);

        if (userNameTextBox != null) {
            userNameTextBox.value = '';
            userNameTextBox.focus();
        }

        var passwordTextBox = $get(password);
        if (passwordTextBox != null) {
            passwordTextBox.value = '';
        }
    }
}

// Center the login dialog window
function centerLoginDialog(show) {
    var clientWidth = 0, bodyWidth = 0;

    if (navigator.appName.indexOf("Microsoft") != -1) {
        clientWidth = document.documentElement.clientWidth;
    }

    bodyWidth = document.body.offsetWidth;

    var width = clientWidth > bodyWidth ? clientWidth : bodyWidth;

    var loginDialog = $get('LoginDialog');
    if (loginDialog != null)
        loginDialog.style.left = parseInt((width - 350) / 2) + 'px';

    if (show) {
        loginDialog.style.display = 'block';
    }
}

// Close login dialog
function closeLoginDialog() {
    var loginError = $get('LoginError');
    loginError.style.display = 'none';

    var dlg = $get('LoginDialog');
    dlg.style.display = 'none';

    hideModalBackground();
}

// Notify ScriptManager that this is the end of the script
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

