function init() {

    (document.getElementById('submit_button')).onclick = function() {

        var final_quote_value = parseFloat((document.getElementById('final_quote')).value);

        (document.getElementById('secluder')).style.display = 'none';

        var last_visible_quote_value = parseFloat((document.getElementById( 'last_visible_quote_text')).innerHTML);
            
        var quote_change = final_quote_value - last_visible_quote_value;
        quote_change = ( quote_change < 0 ? '-$' : '+$' ) + (new String(quote_change)).replace(/^-/,'');
        quote_change = (new String(quote_change)).replace(/\.(\d\d).*$/, '.$1');
        
        var quote_changeNode = document.createElement('span');
        quote_changeNode.appendChild( document.createTextNode( quote_change ) );
        quote_changeNode.style.color = quote_change.match(/^-/) ? '#fb0000' : '#00fb00';
        quote_changeNode.style.fontWeight = 'bold';
        quote_changeNode.style.marginLeft = '10px';
        (document.getElementById( 'last_visible_quote_text')).parentNode.appendChild( quote_changeNode );
        (document.getElementById( 'last_visible_quote_text')).innerHTML = final_quote_value;

        var invest_credits_select = document.getElementById( 'invest_credits' );
        var invested_credits = parseInt(invest_credits_select[invest_credits_select.selectedIndex].innerHTML);
        if ( invested_credits > 0 ) {
            var user_credits = (document.getElementById( 'user_credits' )).value;
            var start_credits = user_credits;
            user_credits -= invested_credits;
            var number_shares_owned = invested_credits / last_visible_quote_value;
            var current_value = number_shares_owned * final_quote_value;
            user_credits += current_value;
            var end_credits = user_credits;
            (document.getElementById( 'user_credits' )).value = user_credits;
            user_credits = (new String(user_credits)).replace(/\.(\d\d).*$/, '.$1');
            (document.getElementById( 'user_credits_text')).innerHTML = user_credits + ' ';
            var change = end_credits - start_credits;
            change = ( change < 0 ? '-$' : '+$' ) + (new String(change)).replace(/^-/,'');
            change = (new String(change)).replace(/\.(\d\d).*$/, '.$1');

            var changeNode = document.createElement('span');
            changeNode.appendChild( document.createTextNode( change ) );
            changeNode.style.color = change.match(/^-/) ? '#fb0000' : '#00fb00';
            changeNode.style.fontWeight = 'bold';
            changeNode.style.marginLeft = '10px';
            (document.getElementById( 'user_credits_text')).parentNode.appendChild( changeNode );
        }

        var company_name = (document.getElementById('company_name')).value;
        var symbol = (document.getElementById('symbol')).value;
        var investment_td = document.getElementById('investment_td');
        while ( investment_td.firstChild ) {
            investment_td.removeChild(investment_td.firstChild);
        }
        investment_td.appendChild(document.createTextNode( company_name + ' (' ));
        var quote_anchor = document.createElement( 'a' );
        quote_anchor.href = 'http://finance.yahoo.com/q?s=' + symbol;
        quote_anchor.target = '_Blank';
        quote_anchor.appendChild( document.createTextNode( symbol ) );
        investment_td.appendChild( quote_anchor );
        investment_td.appendChild(document.createTextNode( ')' ));
        investment_td.style.textAlign  = 'center';
        investment_td.style.fontWeight = 'bold';

        (document.getElementById('submit_button')).onclick = function() {

            (document.getElementById('marketguesser_form')).submit();
        };

        (document.getElementById('submit_button')).value = 'next >>';

        return;
    };
}

function log(txt) {
    document.body.appendChild( document.createTextNode( txt ) );
    document.body.appendChild( document.createElement( 'br' ) );
    return;
}
