/* ----------- */
function isSecuredInvestmentLoan( v )
	{
	if( v == "true" )
		return true;
			else
				return false;
	}
/* ----------- */



/* ----------- */
function form_setSecuredInvestmentLoan( f, secured )
	{

	for( var i = 0; i < f.securedInvestmentLoan.length; i++ ) 
		if( isSecuredInvestmentLoan(f.securedInvestmentLoan.options[i].value) == secured )
			f.securedInvestmentLoan.options[i].selected = true;
	}
/* ----------- */




/* ----------- */
function getPotentialSavingsPerMonth( lAmount, interestR )
	{
	if( lAmount > 0 )
		return ( ( lAmount / 12) * (interestR * .01)).toFixed(2);

	return 0;
	}
/* ----------- */




/* ----------- */
function loadDefaultMortgageValues( f )
	{
	var len = global_historyArr.length-1

	global_mortgageInfo = new mortgageInfo( global_historyArr[0][s_INDEX_mAmount], global_historyArr[0][s_INDEX_anualInterestRate], global_historyArr[0][s_INDEX_termYears], global_scenarios.next.mortgage.normal.payment, global_historyArr[0][s_INDEX_numPayments], global_scenarios.next.mortgage.normal.cumInterestAmount, global_scenarios.next.mortgage.normal.cumPrincipalPaid )	
	f.mAmount.value = global_historyArr[len][s_INDEX_mAmount];
	f.anualInterestRate.value = global_historyArr[len][s_INDEX_anualInterestRate];
	f.termYears.value = global_historyArr[len][s_INDEX_termYears];
	f.monthlyPayment.value = global_mortgageInfo.monthlyPayment;
	f.numPayments.value = global_historyArr[len][s_INDEX_numPayments];
	f.ttlPaymentWithInterest.value = global_mortgageInfo.ttlPaymentsAndInterest;
	}
/* ----------- */




/* ----------- */
function loadDefaultInvestmentLoanValues( f )
	{
	var len = global_historyArr.length-1

	global_investmentInfo = new investmentInfo( global_historyArr[0][ s_INDEX_loanPrincipal ], global_historyArr[0][ s_INDEX_securedInvestmentLoan ], global_historyArr[0][ s_INDEX_rateOfReturn ], global_Lookups.attributes.primeInterestRate )

	f.lAmount.value = global_historyArr[len][ s_INDEX_loanPrincipal ]//global_investmentInfo.loanPrincipal;
	form_setSecuredInvestmentLoan( f, global_historyArr[len][ s_INDEX_securedInvestmentLoan ] )
	f.rateOfReturn.value = global_historyArr[len][ s_INDEX_rateOfReturn ];//global_investmentInfo.rateOfReturn;
	f.prime.value = global_investmentInfo.primeRate;
	}
/* ----------- */




/* ----------- */
function loadDefaultPersonalInformationValues( f )
	{
	var len = global_historyArr.length-1;
	global_personalInfo = new personalInfo( global_historyArr[0][ s_INDEX_annualIncome ], global_historyArr[0][ s_INDEX_potentialSavingsPerMonth ], global_historyArr[0][ s_INDEX_propertyValue ] )		

	f.annualIncome.value =	global_historyArr[len][ s_INDEX_annualIncome ];
	f.potentialSavingsPerMonth.value = global_historyArr[len][ s_INDEX_potentialSavingsPerMonth ];
	f.propertyValue.value = global_historyArr[len][ s_INDEX_propertyValue ];

	}
/* ----------- */




/* ----------- */
function loadDefaultPortfolio( f )
	{
	global_Portfolio = new portfolio( "portfolio_content", global_pFunds, global_historyArr[0][ s_INDEX_loanPrincipal ] );
	loadPortfolio( f, global_Portfolio );
	}
/* ----------- */




/* ----------- */
function loadDefaultLookups( f )
	{
	global_Lookups = new lookUps( "lookup_content", global_lMarginalTRA, global_historyArr[0][ s_INDEX_annualIncome ], global_historyArr[0][ s_INDEX_defaultInvestmentPrincipal ], global_historyArr[0][ s_INDEX_housingGrowthRate ], global_historyArr[0][ s_INDEX_primeRate ], global_historyArr[0][ s_INDEX_primeRate_Plus ], global_historyArr[0][ s_INDEX_securedInvestmentLoan ], global_historyArr[0][ s_INDEX_filtersArr ], global_historyArr[0][ s_INDEX_enableMortgageAccelerator ] );


	loadLookups( f, global_Lookups );
	}
/* ----------- */




/* ----------- */
function loadDefaultScenarios( )
	{

	var msNormal = new msNormalAttributes( eval(global_historyArr[0][s_INDEX_mAmount]) );
	var msAccelerator = new msAcceleratorAttrs( eval(global_historyArr[0][s_INDEX_mAmount]) );
	var mortgageScenarios = new mortgageScenariosAttrs( msNormal, msAccelerator, global_historyArr[0][s_INDEX_anualInterestRate], global_historyArr[0][s_INDEX_mAmount] );
	var investmentLoan = new investmentLoanAttrs( global_Portfolio.getMonthlyDistributionCompoundFactor(), global_historyArr[0][ s_INDEX_rateOfReturn ], global_historyArr[0][ s_INDEX_loanPrincipal ], global_Portfolio.getMonthlyDistributionTotal(), global_Lookups.attributes.adjustedAnnalInterestRate, global_Lookups.attributes.marginalTaxRate );
	var initalScenario = new scenario( mortgageScenarios, investmentLoan, global_historyArr[0][ s_INDEX_propertyValue ], global_historyArr[0][s_INDEX_numPayments], global_historyArr[0][s_INDEX_anualInterestRate], global_Lookups.attributes.housingGrowthRate, global_historyArr[0][ s_INDEX_potentialSavingsPerMonth ], null );

	global_scenarios = new scenarios( initalScenario, global_historyArr );	
	}
/* ----------- */



/* ----------- */
function init( fid )
	{
	// these method must be in the following order.
	testURL();	
	
	loadInitalValues( fid );
	loadDefaultLookups( document.lookup );
	loadDefaultPortfolio( document.portfolio );
	loadScenarios( global_ScenarioView, global_scenarios_lineOpen );
	loadDashBoard( document.calculator )
	loadDefaultMortgageValues( document.calculator );
	loadDefaultInvestmentLoanValues( document.calculator );
	loadDefaultPersonalInformationValues( document.calculator );
	document.calculator.mAmount.focus();
	}
/* ----------- */



/* ----------- */
function reloadSummary()
	{
	loadDefaultLookups( document.lookup );
	loadDefaultPortfolio( document.portfolio );
	loadScenarios( global_ScenarioView, global_scenarios_lineOpen )
	loadDashBoard( document.calculator )
	loadDefaultMortgageValues( document.calculator )
	loadDefaultInvestmentLoanValues( document.calculator )
	loadDefaultPersonalInformationValues( document.calculator )	
	}
/* ----------- */
