﻿function uwLogIn(un, pw) {
    if (un == null) un = document.getElementById('uw_un').value;
    if (pw == null) pw = document.getElementById('uw_pw').value;
    UndyingWebServices.LogIn(un, pw, function() { window.location.reload(); });
}

function uwLogOut() {
    UndyingWebServices.LogOut(function() { window.location.reload(); });
}

function uwShowLogInForm() {
    UndyingWebServices.ShowLogInForm(uwShowLogInFormSuccess);
}

function uwShowLogInFormSuccess(results) {
    if(!results.match("@"))
        uwShowDialog('Log In', results, 320, 192);
    else
        uwShowDialog('Log In', results, 320, 192, 'uw_pw');
}

function uwShowDialog(title, content, width, height, focusElement) {
    var dialogBox = document.getElementById('uwModalDialog');
    dialogBox.innerHTML = content;
    //dialogBox.style.width = width;
    //dialogBox.style.height = height;
    $('#uwModalDialog').dialog('option', 'width', width);
    $('#uwModalDialog').dialog('option', 'height', height);
    $('#uwModalDialog').dialog('option', 'title', title);
    $('#uwModalDialog').dialog('option', 'button', {});
    $('#uwModalDialog').dialog('open');
    // Set focus to the
    if (focusElement != null)
        document.getElementById(focusElement).focus();
}