﻿function loginToolsObj()
{
    var _this = this;
    this.loginPanel = document.getElementById("loginPanel");
    this.newUserPanel = document.getElementById("createAccountPanel");
    this.forgotPasswordPanel = document.getElementById("forgotPasswordPanel");
    this.accountTools = document.getElementById("wc-accountTools");
    
    this.position = function(e)
    {
        var logo = document.getElementById("wc-logo");
        _this.accountTools.style.top = "105px";
        _this.accountTools.style.left = (getOffsetLeft(logo) + 630) + "px";
    };
    this.showTool = function(tool)
    {
        toggleSelects("hide");
        toggleOverflowsOnClass("dropContent", document.body, "hide");
        
        for(var i = 0; i < 2; i++)
        {
            if(!showGenericErr)
                document.getElementById("error").style.display = "none";
                
            clearTree(login_valSummary);
            login_valSummary.style.display = "none";
            clearTree(new_valSummary);
            new_valSummary.style.display = "none";
            clearTree(forgot_valSummary);
            forgot_valSummary.style.display = "none";
            login_valUsername.style.display = "none";
            login_valPassword.style.display = "none";
            new_valUsername.style.display = "none";
            new_valEmail.style.display = "none";
            new_valRegEmail.style.display = "none";
            new_valPassword.style.display = "none";
            new_valConfirmPassword.style.display = "none";
            forgot_valUsername.style.display = "none";
        
            this.accountTools.className = "";
            
            this.loginPanel.className = (tool == "login") ? "" : "hide";
            this.newUserPanel.className = (tool == "new") ? "" : "hide";
            this.forgotPasswordPanel.className = (tool == "forgot") ? "" : "hide";
            
            this.position();
        }
        
        showGenericErr = false;
        
        addEvent(window, "resize", loginTools.position);
    };
    this.close = function()
    {
        _this.accountTools.className = "hide";
        
        toggleSelects("show");
        toggleOverflowsOnClass("dropContent", document.body, "show");
        
        removeEvent(window, "resize", loginTools.position);
        
        return false;
    };       
    this.showLogin = function(btn)        
    {
        if(login_ready)
        {
            btn.blur();
            this.showTool("login");
            loginTitle.innerHTML = "Sign-In";
            login_txtUsername.focus();
        }
        return false;        
    };
    this.showNewUser = function(btn)
    {
        if(login_ready)
        {
            btn.blur();
            this.showTool("new");
            loginTitle.innerHTML = "New Member?";
            new_txtUsername.focus();
        }        
        return false;
    };
    this.showForgotPassword = function(btn)
    {
        if(login_ready)
        {
            btn.blur();
            this.showTool("forgot");
            loginTitle.innerHTML = "Forgot Password?";
            forgot_txtUsername.focus();
        }
        return false;
    };
}

var loginTools = new loginToolsObj();

var showGenericErr = false;

function checkForLoginErr()
{
    if(getQueryVariable("err") != null || (getQueryVariable("ReturnUrl") != null) || (getQueryVariable("showlogin") != null))
    {
        if(getQueryVariable("err") != null)
        {
            document.getElementById("error").innerHTML = unescape(getQueryVariable("err"));
            showGenericErr = true;
        }
        
        if(getQueryVariable("form") != null)
        {
            if(getQueryVariable("form") == "forgot")
                loginTools.showForgotPassword(document.getElementById("ctl00_twcTopNav_ctlLoginStatus"));
            else if(getQueryVariable("form") == "new")
                loginTools.showNewUser(document.getElementById("ctl00_twcTopNav_ctlLoginStatus"));        
            else
                loginTools.showLogin(document.getElementById("ctl00_twcTopNav_ctlLoginStatus"));
        }
        else
        {
            loginTools.showLogin(document.getElementById("ctl00_twcTopNav_ctlLoginStatus"));
        }
    }
}