Type.registerNamespace('eSecuritel');

eSecuritel.EscalationDetail = function(hidSubscriberHasAddress,
                                                faxTextBox,
                                                emailTextBox,
                                                isCurrentEscalationObsolete,
                                                administrationReasonCodeOptionList,
                                                logisticReasonCodeCheckList,
                                                claimNumberLink,
                                                uspsLink,
                                                escalationNumSpan,
                                                hidShowUSPSLink) {
    eSecuritel.EscalationDetail.initializeBase(this);

    this._HidSubscriberHasAddress = hidSubscriberHasAddress;
    this._FaxTextBox = faxTextBox;
    this._EmailTextBox = emailTextBox;
    this._IsCurrentEscalationObsolete = isCurrentEscalationObsolete;
    this._AdministrationReasonCodeOptionList = administrationReasonCodeOptionList;
    this._LogisticReasonCodeCheckList = logisticReasonCodeCheckList;
    this._ClaimNumberLink = claimNumberLink;
    this._MailLabelRequestCheckBox = null;
    this._MailLabelRequestOptionBox = null;
    this._MailLabelRequestOptionBoxSpan = null;
    this._MailLabelRequestLabel = null;
    this._FaxLabelRequestCheckBox = null;
    this._FaxLabelRequestOptionBox = null;
    this._FaxLabelRequestOptionBoxSpan = null;
    this._FaxLabelRequestLabel = null;
    this._EmailLabelRequestCheckbox = null;
    this._EmailLabelRequestOptionbox = null;
    this._EmailLabelRequestOptionboxSpan = null;
    this._EmailLabelRequestLabel = null;
    this._USPSLink = uspsLink;
    this._EscalationNumSpan = escalationNumSpan;
    this._HidShowUSPSLink = hidShowUSPSLink;

    this._FaxTextBoxChanged$Delegate = Function.createDelegate(this, this._FaxTextBoxChanged);
    this._EmailTextBoxChanged$Delegate = Function.createDelegate(this, this._EmailTextBoxChanged);
    this._BindEvents$Delegate = Function.createDelegate(this, this._bindEvents);
    this._CheckBoxChanged$Delegate = Function.createDelegate(this, this._CheckBoxChanged);
    
}

eSecuritel.EscalationDetail.prototype = {
    initialize: function() {
        eSecuritel.EscalationDetail.callBaseMethod(this, 'initialize');

        this._DisableOrEnableAll();

        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(this._BindEvents$Delegate);
        this._bindEvents(this, null);
    },
    _bindEvents: function(sender, args) {
        this._FaxTextBox.unbind('keyup', this._FaxTextBoxChanged$Delegate);
        this._FaxTextBox.bind('keyup', this._FaxTextBoxChanged$Delegate);

        this._EmailTextBox.unbind('keyup', this._EmailTextBoxChanged$Delegate);
        this._EmailTextBox.bind('keyup', this._EmailTextBoxChanged$Delegate);

        if (this._IsCurrentEscalationObsolete === 'True') {

            this._InitializeCheckBoxesWithJQuery();

            this._FaxLabelRequestCheckBox.bind('click', this._CheckBoxChanged$Delegate);
            this._EmailLabelRequestCheckbox.bind('click', this._CheckBoxChanged$Delegate);
            this._MailLabelRequestCheckBox.bind('click', this._CheckBoxChanged$Delegate);

            this._DisableOrEnableAll();

            if (this._MailLabelRequestCheckBox.attr('checked')) {
                this._DisableAppropriateCheckBoxes(this._MailLabelRequestCheckBox.get(0).id);
            } else if (this._FaxLabelRequestCheckBox.attr('checked')) {
                this._DisableAppropriateCheckBoxes(this._FaxLabelRequestCheckBox.get(0).id);
            } else if (this._EmailLabelRequestCheckbox.attr('checked')) {
                this._DisableAppropriateCheckBoxes(this._EmailLabelRequestCheckbox.get(0).id);
            }
            
        }

        if (this._IsCurrentEscalationObsolete === 'False') {
            this._InitializeOptionBoxesWithJQuery();
        }
            
        
    },
    get_HidShowUSPSLink: function() {
        return this._HidShowUSPSLink;
    },
    set_HidShowUSPSLink: function(value) {
        this._HidShowUSPSLink = value;
    },
    get_EscalationNumSpan: function() {
        return this._EscalationNumSpan;
    },
    set_EscalationNumSpan: function(value) {
        this._EscalationNumSpan = value;
    },
    get_USPSLink: function() {
        return this._USPSLink;
    },
    set_USPSLink: function(value) {
        this._USPSLink = value;
    },
    get_ClaimNumberLink: function() {
        return this._ClaimNumberLink;
    },
    set_ClaimNumberLink: function(value) {
        if (value !== this._ClaimNumberLink) {
            this._ClaimNumberLink = value;
            this.raisePropertyChanged('ClaimNumberLink');
        }
    },
    get_IsCurrentEscalationObsolete: function () {
        return this._IsCurrentEscalationObsolete;
    },
    set_IsCurrentEscalationObsolete: function (value) {
        if (this._IsCurrentEscalationObsolete !== value) {
            this._IsCurrentEscalationObsolete = value;
            this.raisePropertyChanged('IsCurrentEscalationObsolete');
        }
    },
    get_AdministrationReasonCodeOptionList: function () {
        return this._AdministrationReasonCodeOptionList;
    },
    set_AdministrationReasonCodeOptionList: function (value) {
        if (this._AdministrationReasonCodeOptionList !== value) {
            this._AdministrationReasonCodeOptionList = value;
            this.raisePropertyChanged('AdministrationReasonCodeOptionList');
            
            if (this._IsCurrentEscalationObsolete === 'False') {
                this._InitializeOptionBoxesWithJQuery();
            }
        }
    },
    get_LogisticReasonCodeCheckList: function() {
        return this._LogisticReasonCodeCheckList;
    },
    set_LogisticReasonCodeCheckList: function(value) {
        if (this._LogisticReasonCodeCheckList !== value) {
            this._LogisticReasonCodeCheckList = value;
            this.raisePropertyChanged('LogisticReasonCodeCheckList');

            if (this._IsCurrentEscalationObsolete === 'True') {
                this._InitializeCheckBoxesWithJQuery();
            }
        }
    },
    _InitializeCheckBoxesWithJQuery: function() {
        this._LogisticReasonCodeCheckList = $('#' + this._LogisticReasonCodeCheckList.get(0).id);
        this._MailLabelRequestLabel = $('label:contains(Mail Label Request)', this._LogisticReasonCodeCheckList);
        this._FaxLabelRequestLabel = $('label:contains(Fax Label Request)', this._LogisticReasonCodeCheckList); ;
        this._EmailLabelRequestLabel = $('label:contains(Email Label Request)', this._LogisticReasonCodeCheckList);
        this._MailLabelRequestCheckBox = $('td:has(label:contains(Mail Label Request)) :input', this._LogisticReasonCodeCheckList).eq(0);
        this._FaxLabelRequestCheckBox = $('td:has(label:contains(Fax Label Request)) :input', this._LogisticReasonCodeCheckList).eq(0);
        this._EmailLabelRequestCheckbox = $('td:has(label:contains(Email Label Request)) :input', this._LogisticReasonCodeCheckList).eq(0);
    },
    _InitializeOptionBoxesWithJQuery: function () {
        this._AdministrationReasonCodeOptionList = $('#' + this._AdministrationReasonCodeOptionList.get(0).id);
        this._MailLabelRequestLabel = $('label:contains(Mail Label Request)', this._AdministrationReasonCodeOptionList);
        this._FaxLabelRequestLabel = $('label:contains(Fax Label Request)', this._AdministrationReasonCodeOptionList);;
        this._EmailLabelRequestLabel = $('label:contains(Email Label Request)', this._AdministrationReasonCodeOptionList);
        this._MailLabelRequestOptionBox = $('td:has(label:contains(Mail Label Request)) :input', this._AdministrationReasonCodeOptionList).eq(0);
        this._MailLabelRequestOptionBoxSpan = $('td:has(label:contains(Mail Label Request)) span', this._AdministrationReasonCodeOptionList).eq(0);
        this._FaxLabelRequestOptionBox = $('td:has(label:contains(Fax Label Request)) :input', this._AdministrationReasonCodeOptionList).eq(0);
        this._FaxLabelRequestOptionBoxSpan = $('td:has(label:contains(Fax Label Request)) span', this._AdministrationReasonCodeOptionList).eq(0);
        this._EmailLabelRequestOptionbox = $('td:has(label:contains(Email Label Request)) :input', this._AdministrationReasonCodeOptionList).eq(0);
        this._EmailLabelRequestOptionboxSpan = $('td:has(label:contains(Email Label Request)) span', this._AdministrationReasonCodeOptionList).eq(0);
    },
    get_MailLabelRequestLabel: function() {
        return this._MailLabelRequestLabel;
    },
    get_FaxLabelRequestLabel: function() {
        return this._FaxLabelRequestLabel;
    },
    get_EmailLabelRequestLabel: function() {
        return this._EmailLabelRequestLabel;
    },
    get_MailLabelRequestCheckBox: function() {
        return this._MailLabelRequestCheckBox;
    },
    get_FaxLabelRequestCheckBox: function() {
        return this._FaxLabelRequestCheckBox;
    },
    get_EmailLabelRequestCheckbox: function() {
        return this._EmailLabelRequestCheckbox;
    },
    get_HidSubscriberHasAddress: function() {
        return this._HidSubscriberHasAddress;
    },
    set_HidSubscriberHasAddress: function(value) {
        if (this._HidSubscriberHasAddress !== value) {
            this._HidSubscriberHasAddress = value;
            this.raisePropertyChanged('HidSubscriberHasAddress');
        }
    },
    get_FaxTextBox: function() {
        return this._FaxTextBox;
    },
    set_FaxTextBox: function(value) {

        if (this._FaxTextBox !== value) {
            if ((typeof (this._FaxTextBox) != 'undefined')
                        && (this._FaxTextBox !== null)) {
                this._FaxTextBox.unbind('keyup', this._FaxTextBoxChanged$Delegate);
            }
            value.bind('keyup', this._FaxTextBoxChanged$Delegate);

            this._FaxTextBox = value;
            this.raisePropertyChanged('FaxTextBox');
        }
    },
    get_EmailTextBox: function() {
        return this._EmailTextBox;
    },
    set_EmailTextBox: function(value) {

        if (this._EmailTextBox !== value) {
            if ((typeof (this._EmailTextBox) != 'undefined')
                        && (this._FaxTextBox !== null)) {
                this._EmailTextBox.unbind('keyup', this._EmailTextBoxChanged$Delegate);
            }
            value.bind('keyup', this._EmailTextBoxChanged$Delegate);
            this._EmailTextBox = value;
            this.raisePropertyChanged('EmailTextBox');
        }
    },
    add_FaxTextBoxChange: function(handler) {
        this.get_events().addHandler('FaxTextBoxChange', handler);
    },
    remove_FaxTextBoxChange: function(handler) {
        this.get_events().removeHandler('FaxTextBoxChange', handler);
    },
    add_EmailTextBoxChange: function(handler) {
        this.get_events().addHandler('EmailTextBoxChange', handler);
    },
    remove_EmailTextBoxChange: function(handler) {
        this.get_events().removeHandler('EmailTextBoxChange', handler);
    },
    dispose: function() {
        if ((typeof (this._FaxTextBox) != 'undefined')
                        && (this._FaxTextBox !== null)) {
            this._FaxTextBox.unbind('keyup', this._FaxTextBoxChanged$Delegate);
        }
        if ((typeof (this._EmailTextBox) != 'undefined')
                        && (this._FaxTextBox !== null)) {
            this._EmailTextBox.unbind('keyup', this._EmailTextBoxChanged$Delegate);
        }

        if (this._IsCurrentEscalationObsolete === 'True') {

            if ((typeof(this._FaxLabelRequestCheckBox) != 'undefined')
                && (this._FaxLabelRequestCheckBox !== null)) {
                this._FaxLabelRequestCheckBox.unbind('click', this._CheckBoxChanged$Delegate);
            }
            if ((typeof(this._EmailLabelRequestCheckbox) != 'undefined')
                && (this._EmailLabelRequestCheckbox !== null)) {
                this._EmailLabelRequestCheckbox.unbind('click', this._CheckBoxChanged$Delegate);
            }
            if ((typeof(this._MailLabelRequestCheckBox) != 'undefined')
                && (this._MailLabelRequestCheckBox !== null)) {
                this._MailLabelRequestCheckBox.unbind('click', this._CheckBoxChanged$Delegate);
            }

        }
        
        eSecuritel.EscalationDetail.callBaseMethod(this, 'dispose');
    },
    _DisableOrEnableMailTextBox: function (specialFleag) {

        if (this._IsCurrentEscalationObsolete === 'True') {
            if ((this._ClaimNumberLink.text().length > 0)
                && ((this._HidSubscriberHasAddress.val() == 'True')
                    || (this._HidSubscriberHasAddress.val() == 'true'))
                && !this._EmailLabelRequestCheckbox.attr('checked')
                && !this._FaxLabelRequestCheckBox.attr('checked')) {

                this._EnableCheckBox(this._MailLabelRequestLabel, this._MailLabelRequestCheckBox);

            } else {

                this._DisableCheckBox(this._MailLabelRequestLabel, this._MailLabelRequestCheckBox);

            }
        }
        
        this._ToggleUSPSLinkVisibility();
    },
    _DisableOrEnableFaxTextBox: function (specialFleag) {

        if (this._IsCurrentEscalationObsolete === 'True') {

            if ((this._ClaimNumberLink.text().length > 0)
                && (this._FaxTextBox.val().length > 11)
                && !this._MailLabelRequestCheckBox.attr('checked')
                && !this._EmailLabelRequestCheckbox.attr('checked')) {

                this._EnableCheckBox(this._FaxLabelRequestLabel, this._FaxLabelRequestCheckBox);
            } else {

                this._DisableCheckBox(this._FaxLabelRequestLabel, this._FaxLabelRequestCheckBox);
                
            }
        }
        
        this._ToggleUSPSLinkVisibility();
    },
    _FaxTextBoxChanged: function () {

        this._DisableOrEnableFaxTextBox();
        this._DisableOrEnableEmailTextBox();
        this._DisableOrEnableMailTextBox();

        var handler = this.get_events().getHandler('FaxTextBoxChange');
        if (handler) {
            handler(this, Sys.EventArgs.Empty);
        }
    },
    _EnableCheckBox: function(label, checkbox) {
        checkbox.attr('disabled', false);
        label.attr('disabled', false);
    },
    _DisableCheckBox: function(label, checkbox) {
        label.attr('disabled', 'disabled');
        checkbox.attr('disabled', 'disabled');
        checkbox.removeAttr('checked');

        if (this._IsCurrentEscalationObsolete === 'True') {
            if (this._EscalationNumSpan.text().length <= 0) {
                checkbox.attr('checked', '');
            }
        }
    },
    _DisableOrEnableEmailTextBox: function (specialFleag) {
        var arpos = this._EmailTextBox.val().indexOf("@");
        var dopos = this._EmailTextBox.val().lastIndexOf(".");

        if (this._IsCurrentEscalationObsolete === 'True') {

            if ((this._ClaimNumberLink.text().length > 0)
                && (arpos > 0 && dopos > arpos + 2 && dopos)
                && !this._MailLabelRequestCheckBox.attr('checked')
                && !this._FaxLabelRequestCheckBox.attr('checked')) {

                    this._EnableCheckBox(this._EmailLabelRequestLabel, this._EmailLabelRequestCheckbox);

            } else {

                    this._DisableCheckBox(this._EmailLabelRequestLabel, this._EmailLabelRequestCheckbox);

            }

        }
        
        this._ToggleUSPSLinkVisibility();
    },
    _ToggleUSPSLinkVisibility: function () {

        if (this._IsCurrentEscalationObsolete === 'True') {

            if ((this._MailLabelRequestCheckBox.attr('checked') ||
                    this._FaxLabelRequestCheckBox.attr('checked') ||
                    this._EmailLabelRequestCheckbox.attr('checked')) &&
                (this._EscalationNumSpan.text().length > 0) &&
                (this._HidShowUSPSLink.val() == 'true')) {
                this._USPSLink.show();
                this._USPSLink.attr('disabled', false);

            } else {
                this._USPSLink.hide();
                this._USPSLink.attr('disabled', 'disabled');
            }

        }
        
        if (this._IsCurrentEscalationObsolete === 'False') {

            if ((this._MailLabelRequestOptionBox.attr('checked') ||
                    this._FaxLabelRequestOptionBox.attr('checked') ||
                    this._EmailLabelRequestOptionbox.attr('checked')) &&
                (this._EscalationNumSpan.text().length > 0) &&
                (this._HidShowUSPSLink.val() == 'true')) {
                this._USPSLink.show();
                this._USPSLink.attr('disabled', false);

            } else {
                this._USPSLink.hide();
                this._USPSLink.attr('disabled', 'disabled');
            }

        }

    },
    _EmailTextBoxChanged: function () {

        this._DisableOrEnableEmailTextBox();
        this._DisableOrEnableFaxTextBox();
        this._DisableOrEnableMailTextBox();

        var handler = this.get_events().getHandler('EmailTextBoxChange');
        if (handler) {
            handler(this, Sys.EventArgs.Empty);
        }
    },
    _DisableOrEnableAll: function(specialFleag) {
        this._DisableOrEnableEmailTextBox(specialFleag);
        this._DisableOrEnableFaxTextBox(specialFleag);
        this._DisableOrEnableMailTextBox(specialFleag);
    },
    _CheckBoxChanged: function(e) {
        this._DisableOrEnableAll();
        this._DisableAppropriateCheckBoxes(e.srcElement.id);
    },
    _DisableAppropriateCheckBoxes: function(checkedCheckBoxID) {
        if (checkedCheckBoxID == this._MailLabelRequestCheckBox.get(0).id) {

            this._DisableCheckBox(this._FaxLabelRequestLabel, this._FaxLabelRequestCheckBox);
            this._DisableCheckBox(this._EmailLabelRequestLabel, this._EmailLabelRequestCheckbox);

        } else if (checkedCheckBoxID == this._FaxLabelRequestCheckBox.get(0).id) {

            this._DisableCheckBox(this._MailLabelRequestLabel, this._MailLabelRequestCheckBox);
            this._DisableCheckBox(this._EmailLabelRequestLabel, this._EmailLabelRequestCheckbox);

        } else if (checkedCheckBoxID == this._EmailLabelRequestCheckbox.get(0).id) {

            this._DisableCheckBox(this._MailLabelRequestLabel, this._MailLabelRequestCheckBox);
            this._DisableCheckBox(this._FaxLabelRequestLabel, this._FaxLabelRequestCheckBox);
        }
    }
};

eSecuritel.EscalationDetail.registerClass('eSecuritel.EscalationDetail', Sys.Component);

// Since this script is not loaded by System.Web.Handlers.ScriptResourceHandler
// invoke Sys.Application.notifyScriptLoaded to notify ScriptManager 
// that this is the end of the script.
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();