﻿/// <reference name="MicrosoftAjax.debug.js" />
/// <reference name="MicrosoftAjaxTimer.debug.js" />
/// <reference name="MicrosoftAjaxWebForms.debug.js" />

/// <reference path="jquery-1.2.6-vsdoc.js"/>

SCOTT.CSC.ProfileFields = function(clientId) 
{
    this.ClientID = clientId;
    this.Selector = '#' + clientId;
    this.Initialize();
};

SCOTT.CSC.ProfileFields.prototype =
{
    Name : 'SCOTT.CSC.ProfileFields',
    __typeName : 'SCOTT.CSC.ProfileFields',
    __class : true,
    ShowCallout : function(name)
    {
        var __app = this;
        var timeout = 250;
        var selector = __app.Selector + ' .Callouts .' + name + 'Callout';
        var isHidden = ($(selector).css('display') == 'none');
        if (isHidden)
        {
            $(this.Selector + ' .Callouts > div').hide();
            $(selector).fadeIn(timeout);
        }
    },
    ComparePasswords : function()
    {
        var context = $(this.Selector);
        var p1 = $('input.Password', context).val();
        var p2 = $('input.Password2', context).val();
        if (p1 != '' && p1 == p2)
        {
            $('span.Match', context).fadeIn(300);
        }
        else
        {
            $('span.Match', context).fadeOut(150);
        }
    },
    AttachEvents : function()
    {
        var __app = this;
        var comparePasswords = function()
        {
            __app.ComparePasswords();
        };
        var context = $(this.Selector);
        $('input.Password', context).bind('blur', comparePasswords);
        $('input.Password2', context).bind('blur', comparePasswords);
        $('input.Password', context).bind('keyup', comparePasswords);
        $('input.Password2', context).bind('keyup', comparePasswords);
        
        // Callouts
        $('input.DisplayName', context).bind('focus', function(){__app.ShowCallout('DisplayName');});
        $('input.City', context).bind('focus', function(){__app.ShowCallout('City');});
        $('select.State', context).bind('focus', function(){__app.ShowCallout('State');});
        $('input.PostalCode', context).bind('focus', function(){__app.ShowCallout('PostalCode');});
        $('input.Password', context).bind('focus', function(){__app.ShowCallout('Password');});
        $('input.Password2', context).bind('focus', function(){__app.ShowCallout('Password2');});
        $('select.SecurityQuestion', context).bind('focus', function(){__app.ShowCallout('SecurityQuestion');});
        $('input.SecurityAnswer', context).bind('focus', function(){__app.ShowCallout('SecurityAnswer');});
    },
    Display : function()
    {
        $(this.Selector + ' input.AutoFocus').focus();
    }
};

SCOTT.CSC.Extend(SCOTT.CSC.ProfileFields, SCOTT.CSC.UserControl);
