//DOES NOT NEED JQUERY TO WORK. jQuery = awesome, heavy, intrusive and slow...
	
var calc = {
		
	'payment': Number ( 0 ),
	
	//check the fields
	'checkFields': function ( parent ) {
		var inputs = this.el ( parent ).getElementsByTagName ( 'input' );
		for ( var i = 0; i < inputs.length; i++ ) {
			inputs[i].style.border = 'none';//reset error borders
			if ( inputs[i].value == '' ) {
				inputs[i].style.border = '1px solid #E23500';
				inputs[i].focus ( );//put focus to empty element
				return false;
				break;//in case return is out of context and doesn't halt exectution
			}
		}
		this.math( this.el ( 'amount' ).value, this.el ( 'period' ).value, this.el ( 'rate' ).value );
		this.animateHeight( 'results', 80 );
		this.changeHTML ( );
		return false;
	},
	
	//TODO: This was originally using replaceChild and appendChild but different browsers didn't like it.. not enough time.
	'changeHTML': function ( ) {
		//add the total
		//this.el ( 'result1' ).innerHTML = Number ( Number ( this.el ( 'amount' ).value ) / 100 * Number ( this.el ( 'rate' ).value ) / Number ( this.el ( 'period' ).value ) ).toFixed ( 2 );
		//add the monthly
		this.el( 'result1' ).innerHTML = Number ( this.payment ).toFixed( 2 );
		//return false
		return false;
	},
	
	'el': function ( id ) {
		return document.getElementById( id );
	},
	
	//do not change otherwise the math will be incorrect
	'math': function ( amount, period, rate ) {
		var addition = amount / 100 * rate / 1200;
		this.payment = amount * rate / ( 1 - ( Math.pow ( 1 / ( 1 + ( rate / 1200 ) ), ( period * 12 ) ) ) ) / 1200 + addition;
		return this.payment;
	},
	
	'animateHeight': function ( id, newheight ) {
		clearTimeout();
		if( Number ( this.el ( id ).style.height.replace ( 'px', '' ) ) <= Number ( newheight ) ) {
			this.el ( id ).style.height = Number ( this.el ( id ).style.height.replace ( 'px', '' ) ) + Number ( 3 ) + 'px';
			setTimeout ( function ( ) { calc.animateHeight ( id, newheight ); }, 1 );
		}
	}
	
};
