﻿// SCOTT.CSC.Submission

/// <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.Submission = function(clientId, authenticationRequired) 
{
    this.ClientID = clientId;
    this.AuthenticationRequired = authenticationRequired;
    this.Selector = '#' + clientId;
    this.Initialize();
};

SCOTT.CSC.Submission.prototype =
{
    Name: 'SCOTT.CSC.Submission',
    __typeName: 'SCOTT.CSC.Submission',
    __class: true,
    _maskId: undefined,
    AttachEvents: function() {
        var __app = this;
        var context = $(this.Selector);

        var csc = SCOTT.CSC.GetApplication();
        var isUserAuthenticated = csc.IsUserAuthenticated();

        if (this.AuthenticationRequired && !isUserAuthenticated) {
            var handleStep1Button = function() {
                isUserAuthenticated = csc.IsUserAuthenticated();

                if (!isUserAuthenticated) {
                    csc.ShowAutoLogin();
                    return false;
                }
            };
            $('input.Step1Button', context).click(handleStep1Button);
        }

        $('textarea', context).charCounter(750, {
            container: '<span style="color: #555; font-size: 0.9em;"></span>',
            format: '(%1 remaining)'
        });
    },
    ChangeLoginStatus: function(isAuthenticated) {
        if (isAuthenticated && this._maskId !== undefined) {
            $('#' + this._maskId).remove();
            this._maskId = undefined;
        }
    }
};

SCOTT.CSC.Extend(SCOTT.CSC.Submission, SCOTT.CSC.UserControl);
