 function roundToNearest( n, val )
 {
	var tmpNo = new Number();
	tmpNo = (val / n);
	tmpNo = tmpNo.toFixed(0);
	return( tmpNo * n);	
 }


// calculate the maxiumum secured loan rounded to nearest 1k
function calcMaxSecuredLoan( propertyValue, outstanding )
{
	// max = (propDetails_value - propDetails_otherLoans_balanceOutstanding) * 1.25
	var maxLoan = new Number();
	maxLoan = (propertyValue - outstanding ) * 1.25;
	maxLoan = maxLoan.toFixed(0); // ensure no. is rounded to pounds. eg. 785. -> 1k?
	
	if( (maxLoan % 1000 ) == 0 ) 
	{
		// no action required.
	}
	else 
	{
		maxLoan = roundToNearest( 1000, maxLoan );
	}
	return ( maxLoan );
}


function getULoanAmountSelectArray()
{
	var maxLoan = Number(25000);
	sAr = [500];
	x=1;
	for( i = 1000; i<=maxLoan; i=i+1000 )
	{
		sAr[x] = i;
		x++;
	}
	return sAr;
}

function getSLoanAmountSelectArray( propVal, outstanding )
{
	// unsecured: 500.00, 1000, 2000, 3000... 25000. 
	// secured: 0 -> calcMaxSecuredLoan() (in thousands)
	var minLoan = new Number();
	var maxLoan = new Number();		
	minLoan = 0;
	maxLoan = calcMaxSecuredLoan( propVal, outstanding );
	x = 0;
	var sAr = new Array();
	for( i=minLoan; i <= maxLoan; i = i + 1000)
	{
		
		sAr[x] = i;
		x++;		
		if( x > 1000 ) break;
	}
	return( sAr );
}

