﻿logInAjax_spinsLogIn_working = false; 

function logInAjax_spinsLogIn(userNameTextBox, passwordTextBox, logInButton, buttonToClick, statusImage, resultLabel)
{
    if (logInAjax_spinsLogIn_working) return; 
    // Set working flag to true
    logInAjax_spinsLogIn_working = true; 
    
    logInButton.disabled = true; 
    logInButton.value = "Working..."; 

    if (statusImage != null) $(statusImage).fadeIn(250); 
    $(resultLabel).slideUp(250); 
    
    // If the textboxes exist and also either of them has a value
    try 
    {
       // Do the ajax request
        $.ajax({
            type: "POST", 
            url: "AjaxFunctions/member-functions.aspx", 
            data: "mode=validateMember&userName=" + escape(userNameTextBox.value) + "&password=" + escape(passwordTextBox.value), 
            success: function(msg) { logInAjax_spinsLogIn_Success(msg, logInButton, buttonToClick, resultLabel); }, 
            error: function(req, stat, err) { logInAjax_spinsLogIn_Error(req, stat, err, resultLabel); }, 
            complete: function(req) { logInAjax_spinsLogIn_Complete(req, logInButton, statusImage); }
        }); 
    }
    catch (e)
    {
        logInAjax_spinsLogIn_working = false; 
    }

    return false; 
}
function logInAjax_spinsLogIn_Success(msg, logInButton, buttonToClick, resultLabel)
{
    if (msg == "OK")
    {
        $(resultLabel).slideUp(250); 
        buttonToClick.click(); 
        //__doPostBack(logInButton.name, "OnClick")
    }
    else
    {
        resultLabel.innerHTML = msg; 
        $(resultLabel).slideDown(250); 
    }
}
function logInAjax_spinsLogIn_Error(req, stat, err, resultLabel)
{
    message.innerHTML = "An error prevented you from logging in, if the problem persists please contact support."; 
    $(resultLabel).slideDown(250); 
}
function logInAjax_spinsLogIn_Complete(req, logInButton, statusImage)
{
    if (statusImage != null) $(document.getElementById("logInStatus")).fadeOut(250); 
    logInButton.disabled = false; 
    logInButton.value = "Log in"; 
    logInAjax_spinsLogIn_working = false; 
}


// For the log in panel 
function logInPanel_userNameFocus(defaultText, elmTextBox)
{
    if (elmTextBox.value == defaultText)
    {
        elmTextBox.value = ""; 
    }
}
function logInPanel_userNameBlur(defaultText, elmTextBox)
{
    if (elmTextBox.value == null || elmTextBox.value == "")
    {
        elmTextBox.value = defaultText; 
    }
}

function logInPanel_passwordFocus(defaultText, elmPasswordMask, elmPassword)
{
    elmPasswordMask.style.display = "none"; 
    elmPassword.style.display = "inline-block"; 
    elmPassword.focus(); 
}
function logInPanel_passwordBlur(defaultText, elmPasswordMask, elmPassword)
{
}

