/* SVN FILE: $Id: comopound-calculator.js 178 2007-12-14 02:10:43Z ryan.blunden $ */
/**
 * Compound Calculator for Presentation
 *
 * Requires calculators.js
 *
 * Copyright 2007, FreemanFox Ltd
 * Level 11, 1 Eagle St Brisbane, QLD, Australia 4000
 *
 * Licensed under The Creative Commons License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright		Copyright 2007, FreemanFox Ltd
 * @version			$Revision: 178 $
 * @modifiedby		$LastChangedBy: ryan.blunden $
 * @lastmodified	$Date: 2007-12-14 12:10:43 +1000 (Fri, 14 Dec 2007) $
 * @license			http://creativecommons.org/licenses/by/3.0/ The Creative Commons License
 */

$(document).ready(function()
{
	$('#calcDisplay').hide();
	
	$('#current_principle').bind('change', function()
	{
		$(this).attr('value', Calculator.formatNumber($(this).attr('value'), 2, 0));
	});
	
	$('#weekly_addition').bind('change', function()
	{
		$(this).attr('value', Calculator.formatNumber($(this).attr('value'), 2, 0));
	});
	
	$('#years').bind('change', function()
	{
		$(this).attr('value', Calculator.numval($(this).attr('value'), 2, 1));
	});
	
	$('#interest_rate').bind('change', function()
	{
		$(this).attr('value', Calculator.numval($(this).attr('value'), 2, 0));
	});
	
	$('#compound_times').bind('change', function()
	{
		$(this).attr('value', Calculator.numval($(this).attr('value'), 2, 0));
	});
	
	$('#calcForm').bind('submit', function()
	{
		$('#current_principle, #weekly_addition, #years, #interest_rate, #compound_times').trigger('change');
		var args = {};
		$('#calcForm input, #calcForm select').each(function()
		{
			if($(this).attr('value') === '' || $(this).attr('value') === undefined)
			{
				args[$(this).attr('id')] = 0;
			}
			else
			{
				args[$(this).attr('id')] = Calculator.numval($(this).attr('value'));
			}
		});
		$('#slide8 p').hide();
		$('#calcDisplay').hide();
		$('#calcDisplay').html('After '+ $('#years').attr('value') + ' years, you would have <span id="amount">$' + Calculator.formatNumber(Calculator.compound(args), 2) + '</span>');
		$('#calcDisplay').fadeIn();
		return false;
	});
});