﻿// Name: MyAccountDialog.js
// Version: 1.0.0.0
// FileVersion: 1.0.0.0
// -----------------------------------------------------------------------
//  Copyright (C) Peter Bredenberg System. All rights reserved.
// -----------------------------------------------------------------------

// Key press handler
function changePwButtonKeyPress(e) {
    var kC = (window.event != null) ? event.keyCode : e.charCode;
    if (kC == 13) {
        stopEventBubbling(e);
        changePwButton.click();
    }
}

// Key press handler
function myAccountCancelButtonKeyPress(e) {
    var kC = (window.event != null) ? event.keyCode : e.charCode;
    if (kC == 13) {
        stopEventBubbling(e);
        myAccountCancelButton.click();
    }
}

// Show the dialog window
function showMyAccountDialog() {
    closeAllDialogs();

    positionModalBackground(true);
    var width = 350;

    var dlg = $get('MyAccountDialog');
    if (dlg != null) {
        enableCtrls($get('MyAccountTable').childNodes);
        currentPwTextBox.value = '';
        newPwTextBox.value = '';
        confirmPwTextBox.value = '';
        dlg.style.left = ((getWindowWidth() - width) / 2) + 'px';
        dlg.style.display = 'block';
        currentPwTextBox.focus();
    }
}

// Change the password
function changePassword() {
    if (Page_ClientValidate('MyAccount')) {
        disableCtrls($get('MyAccountTable').childNodes);
        Onyx.Web.Services.OnyxWebService.ChangePassword(currentPwTextBox.value, newPwTextBox.value, OnChangePwComplete, OnChangePwError, OnChangePwTimeOut);
        return false;
    }
}

// Success
function OnChangePwComplete(result) {
    alert('Ditt lösenord har nu ändrats.');
    closeMyAccountDialog();
}

function OnChangePwError(result) {
    alert(result.get_message());
    enableCtrls($get('MyAccountTable').childNodes);
    currentPwTextBox.value = '';
    newPwTextBox.value = '';
    confirmPwTextBox.value = '';
    currentPwTextBox.focus();
}

function OnChangePwTimeOut(result) {
    showUnexpectedErrorMsg(result);
    enableCtrls($get('MyAccountTable').childNodes);
}

// Close the dialog window
function closeMyAccountDialog() {
    var dlg = $get('MyAccountDialog');
    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();

