﻿GoodNites.Join = function(serverVars) {
	this.ServerVars = serverVars;
	this.Initialize();
};
GoodNites.Join.prototype = {
    Initialize: function() {
        $(document).ready(function() {
            UpdateForgotPassword();
            var first = $(serverVars.container + ' :text:first').focus();
            ShowToolTip(first);
        });

        $(serverVars.container + ' :text, :password').focus(function() {
            ShowToolTip(this);
        });

        $(serverVars.container + ' :text, :password').blur(function() {
            $('.RegistrationTooltip').addClass('Hidden');
        });

        $(serverVars.container + ' .EmailAddress').change(function() {
            UpdateForgotPassword();
        });

        $(serverVars.container + ' .EmailAddress').blur(function() {
            UpdateForgotPassword();
        });

        $(serverVars.container + ' .EmailAddress').keypress(function() {
            UpdateForgotPassword();
            return true;
        });

        function ShowToolTip(element) {
            var focusedSelector = '#' + $(element).attr('id');
            var tooltipSelector = '#' + $(focusedSelector).attr('class');
            $(tooltipSelector).removeClass('Hidden');
        }

        function UpdateForgotPassword() {
            if ($(serverVars.container + ' .EmailAddress').val() != null &&
                $(serverVars.container + ' .EmailAddress').val().length > 0)
            {
                ShowForgotPassword();
            } else {
                HideForgotPassword();
            }
        }

        function ShowForgotPassword() {
            $(serverVars.container + ' .KCGlobalRequestPassword a').show();
        }

        function HideForgotPassword() {
            $(serverVars.container + ' .KCGlobalRequestPassword a').hide();
        }
    }
};
GoodNites.Extend(GoodNites.Join, GoodNites.Core);
