
/*
 Determines commision level

	It is assumed that PlanType is 0 for Gold, 1 for Silver, 2 for Bronze
	
	TODO: Error checking to determine whether terms and cost are within limits.
*/
function getDealerCommissionLevel( PlanType, Term, Cost) {

	var i;
	var row;
	var col;
	
	for ( i = 0; i < InsuranceTerms.length; i++ ) {
		if ( Term <= InsuranceTerms[i] ) {
			row = i;
			i = InsuranceTerms.length + 1;	
		}
	}
	
	for ( i = 0; i < InsuranceCosts.length; i++ ) {
		if ( Cost <= InsuranceCosts[i] ) {
			col = i;
			i = InsuranceCosts.length + 1;	
		}
	}
	
	// alert( row + " " + col + " " + GoldPlan[row][col]  + " " + SilverPlan[row][col] + " " + BronzePlan[row][col] );
	
	switch ( PlanType ) {
		case 0 : return GoldPlan[row][col];
		case 1 : return SilverPlan[row][col];
		case 2 : return BronzePlan[row][col];
	}
}

var InsuranceTerms = [ 12,24,36,48,60,72,84,96,108,120 ];
var InsuranceCosts = [ 0, 5, 10,15,20,25,30,35,40,45,50 ];

var GoldPlan = [											
	[ 5.0,	6.0,    7.0,	8.0,	9.0,	9.5,	10.0,	10.5,	11.0,	11.5,	12.0 ],
	[ 7.0,	8.0,	9.0,	10.0,	13.0,	13.5,	14.0,	14.5,	15.0,	15.5,	16.0 ],
	[ 9.0,	10.0,	11.0,	13.0,	16.0,	16.5,	17.0,	17.5,	18.0,	19.0,	20.0 ],
	[ 11.0,	12.0,	13.0,	15.0,	19.0,	19.5,	21.0,	22.0,	23.0,	24.0,	25.0 ],
	[ 13.0,	14.0,	15.0,	17.0,	21.0,	23.0,	25.0,	27.0,	28.0,	29.0,	30.0 ],
	[ 13.0,	14.0,	15.0,	17.0,	22.0,	24.0,	27.0,	28.0,	29.0,	30.0,	31.0 ],
	[ 13.0,	14.0,	15.0,	17.0,	24.0,	26.0,	28.0,	29.0,	30.0,	31.0,	32.0 ],
	[ 13.0,	14.0,	15.0,	17.0,	24.0,	26.0,	28.0,	29.0,	30.0,	31.0,	32.0 ],
	[ 13.0,	14.0,	15.0,	17.0,	24.0,	26.0,	28.0,	29.0,	30.0,	31.0,	32.0 ],
	[ 13.0,	14.0,	15.0,	17.0,	24.0,	26.0,	28.0,	29.0,	30.0,	31.0,	32.0 ]
];
	
var SilverPlan = [											
	[ 3.5,	4.0,	4.5,	5.0,	5.5,	5.8,	6.0,	6.3,	6.5,	6.8,	7.0 ],
	[ 5.5,	6.0,	6.5,	7.0,	7.5,	7.8,	8.0,	8.3,	8.5,	8.8,	9.0 ],
	[ 7.5,	8.0,	8.5,	9.0,	9.5,	10.0,	10.5,	11.0,	11.5,	12.0,	12.5 ],
	[ 9.5,	10.0,	10.5,	11.0,	12.0,	12.5,	13.0,	14.0,	14.5,	15.5,	16.5 ],
	[ 11.5,	12.0,	12.5,	13.0,	14.5,	15.5,	16.5,	18.0,	19.5,	20.5,	21.5 ],
	[ 11.5,	12.0,	12.5,	13.0,	16.0,	16.5,	17.5,	18.5,	20.5,	21.5,	22.5 ],
	[ 11.5,	12.0,	12.5,	13.0,	17.0,	17.5,	18.5,	19.5,	21.5,	22.5,	23.5 ],
	[ 11.5,	12.0,	12.5,	13.0,	17.0,	18.5,	19.5,	20.5,	21.5,	22.5,	23.5 ],
	[ 11.5,	12.0,	12.5,	13.0,	17.0,	18.5,	19.5,	20.5,	21.5,	22.5,	23.5 ],
	[ 11.5,	12.0,	12.5,	13.0,	17.0,	18.5,	19.5,	20.5,	21.5,	22.5,	23.5 ]
];

											
var BronzePlan = [											
	[ 3.5,	3.7,	3.8,	3.9,	4.0,	4.3,	4.5,	4.8,	4.0,	5.3,	5.5 ],	
	[ 5.0,	5.2,	5.3,	5.4,	5.5,	5.8,	6.0,	6.3,	6.5,	6.8,	7.0 ],
	[ 7.0,	7.2,	7.3,	7.4,	7.5,	7.8,	8.0,	8.3,	8.5,	8.8,	9.0 ],
	[ 9.0,	9.3,	9.5,	9.8,	10.0,	10.5,	11.0,	11.3,	11.5,	11.8,	12.0 ],
	[ 10.0,	10.5,	11.0,	11.3,	11.5,	12.0,	12.5,	13.0,	13.5,	14.0,	15.0 ],
	[ 10.5,	11.0,	11.5,	11.8,	12.0,	12.5,	13.0,	13.5,	14.0,	14.5,	15.5 ],
	[ 11.0,	11.5,	12.0,	12.3,	12.5,	13.0,	13.5,	14.0,	14.5,	15.0,	16.0 ],
	[ 11.0,	11.5,	12.0,	12.3,	12.5,	13.0,	13.5,	14.0,	14.5,	15.0,	16.0 ],
	[ 11.0,	11.5,	12.0,	12.3,	12.5,	13.0,	13.5,	14.0,	14.5,	15.0,	16.0 ],
	[ 11.0,	11.5,	12.0,	12.3,	12.5,	13.0,	13.5,	14.0,	14.5,	15.0,	16.0 ]

];
