document.getElementById( "purchase_widget_container" ).style.display = "none";

/**
 * Calculator Object (slightly modded for mortgage news)
 *
 * This object handles all calculator interaction including assumption toggling,
 *
 * @namespace QL.quickenloans
 * @class Calculator
 * @constructor
 */
QL.application.Calculator = function()
{
    // for the loan amount feature. see updateLoanAmount()
    var la_la, la_big, la_sml;
    var la_numsToAdd;

    /**
     * Details for assumption toggling
     *
     * @property assumptionstoggleDetails
     * @static
     * @type Object[]
     */
    var assumptionstoggleDetails = {
        toggler: $D.get( 'trigger_assumptions' ),
        togglee: $D.get( 'assumptions' ),
        toggleEvent: 'click'
    };

    /**
     * Details for custom tax and insurance toggling
     *
     * @property customTaxesAndInsuranceDetails
     * @static
     * @type Object[]
     */
    var customTaxesAndInsuranceDetails = {
        container: $D.get( 'homeAfford_CustomTaxesAndInsurance_list' ),
        togglers: $S.query( 'dl dd ul li input' ),
        togglee: $D.get ( 'custom_taxes_and_insurance' )
    };

    /**
     * Details for second mortgage toggling
     *
     * @property secondMortgageDetails
     * @static
     * @type Object[]
     */
    var secondMortgageDetails = {
        container: $D.get( 'debtConsolidation_SecondMortgage_list' ),
        togglers: $S.query( 'dl dd ul li input' ),
        togglee: $D.get ( 'second_mortage_debt' )
    };

    /**
     * Details for home value explanation
     *
     * @property homeValueExplainedDetails
     * @static
     * @type Object[]
     */
    var homeValueExplainedDetails = {
        toggler: $D.get( 'trigger_explanation_home_value' ),
        togglee: $D.get ( 'explanation_home_value' ),
        toggleEvent: 'click'
    };


    /**
     * Details for interacting with the calculator form
     *
     * @property interactiveFormDetails
     * @static
     * @type Object[]
     */
    var interactiveFormDetails = {
        form: $D.getElementsByClassName( 'calculator' )[0],
        affectedFormElements: $S.query( 'form.calculator dl dd input, form.calculator dl dd select'  ),
        errorClass: 'fieldError',
        backgroundXPosition: {
            original: '0px',
            focus: '-43px',
            error: '-86px'
        },
        assistants: {
          querystring: 'form.calculator dl dt span.assistant_wrapper a',
          options: {
              toolbar: 0,
              location: 0,
              directories: 0,
              status: 0,
              menubar: 0,
              scrollbars: 1,
              resizable: 1,
              center: 1
          },
          dimensions: {
            home_value_assistant: {
                height: 500,
                width: 800
            },
            debt_assistant: {
                height: 500,
                width: 500
            },
            monthly_payment_assistant: {
                height: 500,
                width: 800
            },
            income_assistant: {
                height: 600,
                width: 800
            }
          }
        }
    };

    /**
     * Details for handling the purchase/refinance calculator
     *
     * @property loanPurposeSwapDetails
     * @static
     * @type Object[]
     */
    var loanPurposeSwapDetails = {
       toggler: $D.get( 'loan_purpose_swap_trigger' ),

       togglees: {
           refinance: $D.get( 'refinance_widget_container' ),
           purchase: $D.get( 'purchase_widget_container' )
       },

       toggleEvent: 'change',

       modeObserver: function( purpose ) {
           if ( purpose == 'refinance' ) {
                $D.setStyle( loanPurposeSwapDetails.togglees.refinance, 'display', 'block' );
                $D.setStyle( loanPurposeSwapDetails.togglees.purchase, 'display', 'none' );
                return;
           }
           $D.setStyle( loanPurposeSwapDetails.togglees.purchase, 'display', 'block' );
           $D.setStyle( loanPurposeSwapDetails.togglees.refinance, 'display', 'none' );
       },

       behavior: {
           load: function(toggler, togglee) {
               loanPurposeSwapDetails.modeObserver( toggler.value );
           },
           onActivate: function(toggler, togglee) {
               loanPurposeSwapDetails.modeObserver( toggler.value );
           },
           onDeactivate: function(toggler, togglee) {
               loanPurposeSwapDetails.modeObserver( toggler.value );
           }
       }
    };


    /**
     * Details for calculator results
     *
     * @property resultsDetails
     * @static
     * @type Object[]
     */
    var resultsDetails = {
       table: $D.get( 'calculator_results' )
    };

    /**
     * Details for calculator terms
     *
     * @property termDetails
     * @static
     * @type Object[]
     */
    var termDetails = {
       query: $S.query( 'table#calculator_results tbody tr th a.term' ),
       event: 'click',
       windowOptions: {
            toolbar: 0,
            location: 0,
            directories: 0,
            status: 0,
            menubar: 0,
            scrollbars: 1,
            resizable: 1,
            center: 1,
            width: 600,
            height: 300
        }
    };

    /**
     * Handles the swapping of the background-position property of an
     * element.
     *
     * @method swapBackgroundPosition
     * @param { Object } An HTML object.
     * @param { String } A string containing the new background-position-x value.
     * @param { String } A string containing the full background-position value to be replaced.
     * @static
     */
    var swapBackgroundPosition = function( element, replacement, replacee )
    {
        if ( document.all ) {
            $D.setStyle( element, 'background-position-x', replacement );
            return;
        }

        // IE and Safari get this right. Firefox, in its arrogant attempt to do
        // things 'correctly' by not admitting any of IE's virtues, gets this wrong.
        var regex = new RegExp( replacee+'{1}' );
            backgroundPosition = $D.getStyle( element, 'background-position' );

        $D.setStyle( element, 'background-position', backgroundPosition.replace( regex, replacement ) );
    };


    /**
     * Handles the interaction of calculator form elements receiving focus.
     *
     * @method interactiveFormFocus
     * @static
     */
    var interactiveFormFocus = function()
    {
        $E.on( interactiveFormDetails.affectedFormElements, 'focus', function( ev ) {
            var target = $E.getTarget( ev ),
                container = $D.getAncestorByTagName( target, 'dl' );

            $D.getElementsByClassName( 'step', 'span', container, function( el ) {

                if( $D.hasClass( target, interactiveFormDetails.errorClass ) ) {
                    $D.removeClass( target, interactiveFormDetails.errorClass );
                    swapBackgroundPosition( el, interactiveFormDetails.backgroundXPosition.focus, interactiveFormDetails.backgroundXPosition.error );
                    return;
                }

                swapBackgroundPosition( el, interactiveFormDetails.backgroundXPosition.focus, interactiveFormDetails.backgroundXPosition.original )
            } );
        } );
    };


    /**
     * Handles the interaction of calculator form elements losing focus.
     *
     * @method interactiveFormBlur
     * @static
     */
    var interactiveFormBlur = function()
    {
        $E.on( interactiveFormDetails.affectedFormElements, 'blur', function( ev ) {
            var target = $E.getTarget( ev ),
                container = $D.getAncestorByTagName( target, 'dl' );

            $D.getElementsByClassName( 'step', 'span', container, function( el ) {
                swapBackgroundPosition( el, interactiveFormDetails.backgroundXPosition.original, interactiveFormDetails.backgroundXPosition.focus );
            } );
        } );
    };


    /**
     * Handles the interaction of calculator form elements known to be errors.
     *
     * @method interactiveFormError
     * @static
     */
    var interactiveFormError = function()
    {
        $D.batch( interactiveFormDetails.affectedFormElements, function( el ) {
            if( $D.hasClass( el, interactiveFormDetails.errorClass ) ) {
                var container = $D.getAncestorByTagName( el, 'dl' );

                $D.getElementsByClassName( 'step', 'span', container, function( el ) {
                    swapBackgroundPosition( el, interactiveFormDetails.backgroundXPosition.error, interactiveFormDetails.backgroundXPosition.original );
                } );
            }
        } );
    };


    /**
     * Handles the interaction for assistants
     *
     * @method prepareAssistants
     * @static
     */
    var prepareAssistants = function()
    {
        var assistants = $S.query( interactiveFormDetails.assistants.querystring );

        if( assistants.length <= 0 ) return false;

        $E.on( assistants, 'click', function( ev ) {
            $E.preventDefault( ev );
            var target = $E.getTarget( ev );
            interactiveFormDetails.assistants.options[ 'height' ] = interactiveFormDetails.assistants.dimensions[ target.getAttribute( 'id' ) ].height;
            interactiveFormDetails.assistants.options[ 'width' ] = interactiveFormDetails.assistants.dimensions[ target.getAttribute( 'id' ) ].width;
            QL.utilities.Window.open( target.getAttribute( 'href' ), interactiveFormDetails.assistants.options );
        } );
    };


    /**
     * Handles the interaction for user adjusted taxes and insurance
     *
     * @method toggleCustomTaxesAndInsurance
     * @static
     */
    var toggleCustomTaxesAndInsurance = function()
    {
        if( !customTaxesAndInsuranceDetails.container ) {
            return false;
        }

        $E.on( customTaxesAndInsuranceDetails.togglers, 'click', function( ev ) {
            var target = $E.getTarget( ev );

            if ( target.value == 'false' ) {
                $D.setStyle( customTaxesAndInsuranceDetails.togglee, 'display', 'none' );
                return;
            }

            $D.setStyle( customTaxesAndInsuranceDetails.togglee, 'display', 'block' );
        } );
    };


    /**
     * Handles the interaction for second mortgages
     *
     * @method toggleSecondMortgage
     * @static
     */
    var toggleSecondMortgage = function()
    {
        if( !secondMortgageDetails.container ) {
            return false;
        }

        $E.on( secondMortgageDetails.togglers, 'click', function( ev ) {
            var target = $E.getTarget( ev );

            if ( target.value == 'false' ) {
                $D.setStyle( secondMortgageDetails.togglee, 'display', 'none' );
                return;
            }

            $D.setStyle( secondMortgageDetails.togglee, 'display', 'block' );
        } );
    };

    /**
     * Prepares terms for pop-up use.
     *
     * @method termLauncher
     * @static
     */
    var termLauncher = function()
    {
        if ( termDetails.query.length <= 0 ) return false;

        $E.on( termDetails.query, termDetails.event, function( ev ) {
            $E.preventDefault( ev );
            var target = $E.getTarget( ev );
            if (target.nodeName.toLowerCase() === 'img') {
                var parentAnchor = $D.getAncestorByTagName(target, "a");
                QL.utilities.Window.open( parentAnchor.getAttribute( 'href' ), termDetails.windowOptions );
            } else {
                QL.utilities.Window.open( target.getAttribute( 'href' ), termDetails.windowOptions );
            }
        });
    };

    /**
     * Pop Up Bubble for Estimated Taxes and Insurance.
     *
     * @method taxesAndInsuranceBubble
     * @static
     */
    var taxesAndInsuranceBubble = function()
    {
        var taxes_and_insurance = $D.get( 'taxes_and_insurance');

        if ( !taxes_and_insurance ) {
            return false;
        }

        $D.setStyle(taxes_and_insurance, 'display', 'inline');

        $E.on( taxes_and_insurance, 'mouseover', function( ev ) {
            if ( ! $D.get( 'tax_insurance_bubble' ) ) {
                var span = document.createElement( 'SPAN' ),
                    id = 'tax_insurance_bubble';

                span.setAttribute( 'id', id );

                document.body.appendChild( span );
            } else {
                var span = $D.get( 'tax_insurance_bubble' );
            }

            var target = $E.getTarget( ev ),
                 coords = $D.getXY( target );

            $D.setXY( span, [ coords[0] - 65, coords[1] - 140 ] );
            $D.setStyle( span, 'visibility', 'visible' );

            $E.on( span, 'mouseover', function( ev ) {
                var element = $E.getTarget( ev );
                $D.setStyle( span, 'visibility', 'visible' );
            } );

            $E.on( span, 'mouseout', function( ev ) {
                var element = $E.getTarget( ev );
                $D.setStyle( span, 'visibility', 'hidden' );
            } );
        } );

        $E.on( taxes_and_insurance, 'mouseout', function( ev ) {
            var target = $E.getTarget( ev );

            if ( $D.get( 'tax_insurance_bubble' ) && $D.getStyle( $D.get( 'tax_insurance_bubble' ), 'visibility' ) == 'visible' ) {
                $D.setStyle( $D.get( 'tax_insurance_bubble' ), 'visibility', 'hidden' );
            }
        } );
    };

    /**
     * Prepares assumptions toggler for use.
     *
     * @method toggleAssumptions
     * @static
     */
    var toggleAssumptions = function()
    {
        $E.toggle( assumptionstoggleDetails.toggler, assumptionstoggleDetails.togglee, assumptionstoggleDetails.toggleEvent, true );
    };

    /**
     * Prepares home value explanation toggler for use.
     *
     * @method toggleHomeValueExplanation
     * @static
     */
    var toggleHomeValueExplanation = function()
    {
        if ( ! homeValueExplainedDetails.toggler ) {
            return false;
        }

        $E.toggle( homeValueExplainedDetails.toggler, homeValueExplainedDetails.togglee, homeValueExplainedDetails.toggleEvent, true );
    };


    /**
     * Prepares a calculator form for use.
     *
     * @method interactiveFormPreparation
     * @static
     */
    var interactiveFormPreparation = function()
    {
        if( ! interactiveFormDetails.form ) return false;
        interactiveFormFocus();
        interactiveFormBlur();
        interactiveFormError();
        prepareAssistants();
        toggleCustomTaxesAndInsurance();
        toggleSecondMortgage();
        toggleHomeValueExplanation();
    };


    /**
     * Prepares calculator results for use.
     *
     * @method resultsPreparation
     * @static
     */
    var resultsPreparation = function()
    {
       if( ! resultsDetails.table ) return false;
       toggleAssumptions();
       termLauncher();
       taxesAndInsuranceBubble();
    };


    /**
     * Prepares purchase/refinance calculator
     *
     * @method resultsPreparation
     * @static
     */
    var combinationCalcPreparation = function()
    {
        if ( ! loanPurposeSwapDetails.toggler ) return false;
        $E.toggle( loanPurposeSwapDetails.toggler, loanPurposeSwapDetails.togglees, loanPurposeSwapDetails.toggleEvent, false, loanPurposeSwapDetails.behavior );
    };

    /**
     * Handles the Calculate v. Save and Close buttons on
     * assistants built with the workflow builder.
     *
     * @method assistantPreparation
     * @static
     */
    var assistantPreparation = function()
    {
        if ( ! $D.get( 'home_value_button' ) ) return false;

        var querystringObject = QL.utilities.Window.queryStringToObject(),
            errorCollection = $S.query( 'dd.error' );

        if ( querystringObject[ 'homeValue%5Bcalculate%5D.x' ] && errorCollection.length == 0 ) {
            window.opener.$S.query( 'dl.home_value dd input' )[0].value = Math.ceil( $D.get( 'calculation_result' ).firstChild.nodeValue.substr(1).replace( /\,/g, "" ) );
            self.close();
        }
    };

    var promoPreparation = function()
    {
        if ( $D.getElementsByClassName( 'tooltip_promo', 'A' ).length <= 0 || $D.get( 'calculator_mortgage_payment' ) || $D.get( 'calculator_prequalification' ) || $D.get( 'calculator_home_afford' ) ) {
            return false;
        }

        $D.batch( $D.getElementsByClassName( 'tooltip_promo', 'A' ), function( el ) {
            $D.setStyle( el, 'display', 'block' );
        } )

        $E.on( $D.getElementsByClassName( 'tooltip_promo', 'A' ), 'mouseover', function( ev ) {
            if ( ! $D.get( 'promo_banner' ) ) {
                var a = document.createElement( 'A' ),
                    id = 'promo_banner',
                    href = '/mortgage-options/fha-streamline';

                a.setAttribute( 'id', id );
                a.setAttribute( 'href', href );

                document.body.appendChild( a );
            } else {
                var a = $D.get( 'promo_banner' );
            }

            var target = $E.getTarget( ev ),
                 coords = $D.getXY( target );

            $D.setXY( a, [ coords[0] - 65, coords[1] - 140 ] );
            $D.setStyle( a, 'visibility', 'visible' );

            $E.on( a, 'mouseover', function( ev ) {
                var promo = $E.getTarget( ev );
                $D.setStyle( a, 'visibility', 'visible' );
            } );

            $E.on( a, 'mouseout', function( ev ) {
                var promo = $E.getTarget( ev );
                $D.setStyle( a, 'visibility', 'hidden' );
            } );
        } );

        $E.on( $D.getElementsByClassName( 'tooltip_promo', 'A' ), 'mouseout', function( ev ) {
            var target = $E.getTarget( ev );

            if ( $D.get( 'promo_banner' ) && $D.getStyle( $D.get( 'promo_banner' ), 'visibility' ) == 'visible' ) {
                $D.setStyle( $D.get( 'promo_banner' ), 'visibility', 'hidden' );
            }
        } );

    };

    var updateLoanAmount = function updateLoanAmount() {
        var value;
        var balance2 = $D.get('debtConsolidation_SecondMortgageBalance');
        if (la_numsToAdd) {
            var total = 0;
            for (var i=0; i<la_numsToAdd.length; i++) {
                if (la_numsToAdd[i] == balance2
                  && !$D.get('debtConsolidation_SecondMortgage_true').checked
                ) {
                    // we're on the debt consolidation calculator, about to add the second mortgage balance, but
                    // hey! -- they haven't selected "Yes" to indicate that they "have a secondary mortgage"
                    continue;
                }
                total += parseInt(la_numsToAdd[i].value.replace(/,/g, ''), 10) || 0;
            }
            value = total;
        } else if (la_big && la_sml) {
            value = parseInt(la_big.value.replace(/,/g, '') || 0, 10) - parseInt(la_sml.value.replace(/,/g, '') || 0, 10);
        }
        la_la.innerHTML = '$' + value.toString().formatCurrency(false, true);
    };

    /**
     * This details elements critical to the setup of numeric
     * input formatting.
     */

    var numericInputDetails = {
        classTrigger: 'numeric_input',
        tagTrigger: 'INPUT',
        numericErrorStyling: {
            position: 'absolute',
            background: 'url(/resources/application/calculator/background_numeric_input_warning.png) no-repeat 0px 0px',
            color: '#ffffff',
            padding: '7px 0px 0px 35px',
            width: '187px',
            height: '34px'
        }
    };

    var numericInputErrorHandling = function ( eventKeycode, inputElementValue ) {
        switch ( eventKeycode ) {
            case 37:
                return; // left arrow
            break;
            case 39:
                return; // right arrow
            break;
            default:
                if ( inputElementValue.match( /\./ ) ) {
                    cmCreatePageElementTag('User attempted to format with a decimal', 'Numeric Formatter Summary');
                    return 'Please do not enter decimals.';
                } else {
                    cmCreatePageElementTag('User entered a non-currency formatted entry', 'Numeric Formatter Summary');
                    return 'Please enter numbers only.'; // everything else
                }
            break;
        }
    };

    var numericInputHandling = function ( inputElement, inputElementValue, eventKeycode ) {
        if ( inputElementValue == '' ) {
            // Hide an error if we have it
            if ( $D.get( 'numeric_input_warning' + '_' + inputElement.getAttribute( 'id' ) ) ) {
                $D.setStyle( $D.get( 'numeric_input_warning' + '_' + inputElement.getAttribute( 'id' ) ), 'display', 'none' );
            }
            return inputElementValue;
        }
        if ( eventKeycode == 188 ) {
            cmCreatePageElementTag('User attempted to format with comma', 'Numeric Formatter Summary');
            return inputElementValue;
        }
        if ( ! inputElementValue.match( /[^\d?^,]/gi ) ) {
            // All is well with the input
            var inputElementValueFormatted = inputElementValue.replace( /[^\d]/gi, '' );

            // Hide an error if we have it
            if ( $D.get( 'numeric_input_warning' + '_' + inputElement.getAttribute( 'id' ) ) ) {
                $D.setStyle( $D.get( 'numeric_input_warning' + '_' + inputElement.getAttribute( 'id' ) ), 'display', 'none' );
            }

            // Format the data to act like an ATM and auto-insert comma separated numerals
            return QL.util.Number.format( inputElementValueFormatted, {
                   prefix: '',
                   decimalPlaces: 0,
                   decimalSeparator: '.',
                   thousandsSeparator: ','
                } );
        }

        // We have a problem with the input - but which one?
        var errorMessage = numericInputErrorHandling( eventKeycode, inputElementValue );

        // Have we already had a problem or is this the first time?
        if ( $D.get( 'numeric_input_warning' + '_' + inputElement.getAttribute( 'id' ) ) ) {
            var errorContainer = $D.get( 'numeric_input_warning' + '_' + inputElement.getAttribute( 'id' ) );
            errorContainer.lastChild.nodeValue = ( errorMessage ) ? errorMessage : errorContainer.lastChild.nodeValue;
            $D.setStyle( $D.get( 'numeric_input_warning' + '_' + inputElement.getAttribute( 'id' ) ), 'display', 'block' );
        } else {
            // Create the error message, id it, style it, attach the appropriate warning
            var errorContainer = document.createElement( 'P' );
            errorContainer.setAttribute( 'id', 'numeric_input_warning' + '_' + inputElement.getAttribute( 'id' ) );
            for ( property in numericInputDetails.numericErrorStyling ) {
                $D.setStyle( errorContainer, property, numericInputDetails.numericErrorStyling[property] );
            }
            errorMessage = document.createTextNode( errorMessage );
            errorContainer.appendChild( errorMessage );
            document.body.appendChild( errorContainer );
        }

        // Determine Placement of warning in context of inputElement location
        var errorContainerRegion = $D.getRegion( errorContainer ),
            errorContainerRegionHalf = ( ( errorContainerRegion.right - errorContainerRegion.left ) / 2 ) ,
            errorContainerRegionCenter = errorContainerRegion.left + errorContainerRegionHalf,
            inputElementRegion = $D.getRegion( inputElement ),
            inputElementRegionHalf = ( ( inputElementRegion.right - inputElementRegion.left ) / 2 ),
            inputElementRegionCenter = inputElementRegion.left + inputElementRegionHalf,
            y = inputElementRegion.bottom - ( ( inputElementRegion.bottom - inputElementRegion.top ) / 7 ),
            x = inputElementRegionCenter - errorContainerRegionHalf,
            coords = [ x, y ];
        $D.setXY( errorContainer, coords );
        return inputElementValue;
    };

    var collectAndPrepareNumericFormatters = function() {

        $E.on( $D.getElementsByClassName( numericInputDetails.classTrigger, numericInputDetails.tagTrigger ), 'keyup', function( ev ) {
            var target = $E.getTarget( ev );
            target.value = numericInputHandling( target, target.value, ev.keyCode );
        });
    }

    // Public methods
    return {
        init: function()
        {
            $E.onDOMReady(function() {
                interactiveFormPreparation();
                combinationCalcPreparation();
                resultsPreparation();
                assistantPreparation();
                promoPreparation();

                // Only running the test on THIS PAGE
                if ( location.pathname == '/mortgage-calculator/should-you-refinance' ) {
                    collectAndPrepareNumericFormatters();
                }

                // check to see if fields are on the page
                if ($D.get('mortgage_LoanAmount_field')) {
                    la_la  = $D.get('mortgage_LoanAmount_field');
                    la_big = $D.get('mortgage_PurchasePrice');
                    la_sml = $D.get('mortgage_DownPayment');
                } else if ($D.get('preQualification_LoanAmount_field')) {
                    la_la  = $D.get('preQualification_LoanAmount_field');
                    la_big = $D.get('preQualification_PurchasePrice');
                    la_sml = $D.get('preQualification_DownPayment');
                } else if ($D.get('debtConsolidation_LoanAmount_field')) {
                    la_la  = $D.get('debtConsolidation_LoanAmount_field');
                    la_numsToAdd = [$D.get('debtConsolidation_MortgageBalance'),
                                    $D.get('debtConsolidation_SecondMortgageBalance'),
                                    $D.get('debtConsolidation_OtherDebt')];
                } else if ($D.get('homeEquity_LoanAmount_field')) {
                    la_la  = $D.get('homeEquity_LoanAmount_field');
                    la_numsToAdd = [$D.get('homeEquity_MortgageBalance'), $D.get('homeEquity_CashOut')];
                }

                // set up the listeners to update Loan Amount automatically
                if (la_la) {
                    if (la_big && la_sml) {
                        $E.addListener(la_big, YAHOO.util.KeyListener.KEYUP, function() { updateLoanAmount(); });
                        $E.addListener(la_sml, YAHOO.util.KeyListener.KEYUP, function() { updateLoanAmount(); });
                    } else if (la_numsToAdd) {
                        for (var i=0; i<la_numsToAdd.length; i++) {
                            if (la_numsToAdd[i] == $D.get('debtConsolidation_SecondMortgageBalance')) {
                                // we're setting up listeners for the debt consolidation calc. make sure we hook
                                // the yes/no, "do you have a secondary mortgage" ratio buttons.
                                $E.addListener($D.get('debtConsolidation_SecondMortgage_true'),
                                    'click', function() { updateLoanAmount(); });
                                $E.addListener($D.get('debtConsolidation_SecondMortgage_false'),
                                    'click', function() { updateLoanAmount(); });
                            }
                            $E.addListener(la_numsToAdd[i], YAHOO.util.KeyListener.KEYUP,
                                function() { updateLoanAmount(); });
                        }
                    }
                    updateLoanAmount();
                }
            });
        }
    };
}().init();
