﻿// Name: SendTipDialog.js
// Version: 1.0.0.0
// FileVersion: 1.0.0.0
// -----------------------------------------------------------------------
//  Copyright (C) Peter Bredenberg System. All rights reserved.
// -----------------------------------------------------------------------

// Key press handler
function sendTipOkButtonKeyPress(e, btn) {
    var kC = (window.event != null) ? event.keyCode : e.keyCode;
    if (kC == 13) {
        stopEventBubbling(e);
        btn.click();
    }
}

// Key press handler
function sendTipCancelButtonKeyPress(e, btn) {
    var kC = (window.event != null) ? event.keyCode : e.keyCode;
    if (kC == 13) {
        stopEventBubbling(e);
        btn.click();
    }
}

// Show the dialog
function showSendTipDialog(sender, senderEmail, receiver, receiverEmail) {
    closeAllDialogs();

    positionModalBackground(true);
    centerTipDialog(true);

    var senderTextBox = $get(sender);
    if (senderTextBox != null) {
        senderTextBox.value = '';
        senderTextBox.focus();
    }

    var senderEmailTextBox = $get(senderEmail);
    if (senderEmailTextBox != null) senderEmailTextBox.value = '';

    var receiverTextBox = $get(receiver);
    if (receiverTextBox != null) receiverTextBox.value = '';

    var receiverEmailTextBox = $get(receiverEmail);
    if (receiverEmailTextBox != null) receiverEmailTextBox.value = '';
}

// Center the dialog window
function centerTipDialog(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 tipDialog = $get('TipDialog');
    if (tipDialog != null)
        tipDialog.style.left = parseInt((width - 400) / 2) + 'px';

    if (show) {
        tipDialog.style.display = 'block';
    }
}

// Close the dialog
function closeTipDialog() {
    var dlg = $get('TipDialog');
    if (dlg != null)
        dlg.style.display = 'none';
    hideModalBackground();
}

// Notify ScriptManager that this is the end of the script
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

