﻿// Name: AccountApplicationDialog.js
// Version: 1.0.0.0
// FileVersion: 1.0.0.0
// -----------------------------------------------------------------------
//  Copyright (C) Peter Bredenberg System. All rights reserved.
// -----------------------------------------------------------------------

// Key press handler
function sendButtonKeyPress(e) {
    var kC = (window.event != null) ? event.keyCode : e.charCode;
    if (kC == 13) {
        stopEventBubbling(e);
        sendButton.click();
    }
}

// Key press handler
function cancelButtonKeyPress(e) {
    var kC = (window.event != null) ? event.keyCode : e.charCode;
    if (kC == 13) {
        stopEventBubbling(e);
        cancelButton.click();
    }
}

// Show the dialog window
function showAccountDialog() {
    closeAllDialogs();

    positionModalBackground(true);
    var width = 350;

    if (isLoggedIn()) {
        showMyAccountDialog();
    }
    else {

        var dlg = $get('AccountApplicationDialog');
        if (dlg != null) {
            enableCtrls($get('ApplicationTable').childNodes);
            appNameTextBox.value = '';
            appPhoneTextBox.value = '';
            appEmailTextBox.value = '';
            appCompanyTextBox.value = '';
            appOrgNoNameTextBox.value = '';
            dlg.style.left = ((getWindowWidth() - width) / 2) + 'px';
            dlg.style.display = 'block';
            appNameTextBox.focus();
        }
    }
}

// Close the dialog window
function closeAccountApplicationDialog() {
    var dlg = $get('AccountApplicationDialog');
    if (dlg != null)
        dlg.style.display = 'none';
    hideModalBackground();
}

// Send the application
function sendApplication() {
    if (Page_ClientValidate('Application')) {
        disableCtrls($get('ApplicationTable').childNodes);
        var appData = new Array();
        appData[0] = appNameTextBox.value;
        appData[1] = appPhoneTextBox.value;
        appData[2] = appEmailTextBox.value;
        appData[3] = appCompanyTextBox.value;
        appData[4] = appOrgNoNameTextBox.value;
        Onyx.Web.Services.OnyxWebService.SendApplication(appData, OnSendAppComplete, OnSendAppError, OnSendAppTimeOut);
        return false;
    }
}

// Success
function OnSendAppComplete(result) {
    alert('Tack för din kontoansökan! Vi kommer att kontakta dig inom kort.');
    closeAccountApplicationDialog();
}

function OnSendAppError(result) {
    showUnexpectedErrorMsg(result);
}

function OnSendAppTimeOut(result) {
    showUnexpectedErrorMsg(result);
}

// Notify ScriptManager that this is the end of the script
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

