

function getEarnings(theForm)
{
 l1 = parseInt(theForm.l1.value);
 l2 = parseInt(theForm.l2.value);
 l3 = parseInt(theForm.l3.value);
 
 theForm.l1_total.value = l1;
 theForm.l2_total.value = l1 * l2;
 theForm.l3_total.value = l1 * l2 * l3; 
 total_num = (l1 + (l1 * l2) + (l1 * l2 * l3));
 
 theForm.total_num.value = total_num;
 
 total1 = parseInt(theForm.l1_total.value) * l1fee;
 total2 = parseInt(theForm.l2_total.value) * l2fee;
 total3 = parseInt(theForm.l3_total.value) * l3fee;
 total = total1 + total2 + total3;
 
 theForm.l1_total_earnings.value = total1;
 theForm.l2_total_earnings.value = total2;
 theForm.l3_total_earnings.value = total3; 
 theForm.total_earnings.value = total;
}

function getPayout(theForm)
{
	// fees array defined outside of function
	
	levels = fees.length;
	
	earnings = 0;
	payout = 0;
	total = 0;	
	fee = 0;
	refs = 0;
	total_refs = 0;
	last = 1;
	
	level = 1;
	for(i=0;i<levels;i++)
	{
		fee = fees[i];
		refs = parseInt(theForm.elements['l'+level].value);
		total_refs = refs * last;
		last = total_refs;
		earnings = fee * total_refs;		
		payout += earnings;
		
		theForm.elements['l'+level+'_total'].value = total_refs + ' x ' + fee;
		theForm.elements['l'+level+'_total_earnings'].value = earnings;
		
		total += total_refs;
		level++;
	}
	
	theForm.total_num.value = total;
	theForm.total_earnings.value = payout;
}
