function showFinanceInfo(obj) 
{
	pid = obj.value;
	if (pid == 0) return;
	
	url = 'tractorOffers.php?p_ID=' + pid
	
	var page_request = getXMLHttpRequest()
	
	page_request.onreadystatechange=function()
	{
		if ((page_request.readyState == 4) && (page_request.status==200))
		{
			document.getElementById('specificFinance').innerHTML=page_request.responseText
		}
	}
	bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	page_request.open('GET', url+bustcacheparameter, true)
	page_request.send(null)
	
/////////////////////////////////////////////
// set which div to display, either View All or specific
	if (pid == 999)
	{
		document.getElementById('specificFinance').style.display = 'none';
		document.getElementById('defaultFinanceInfo').style.display = 'block';
	}
	else
	{
		document.getElementById('specificFinance').style.display = 'block';
		document.getElementById('specificFinance').style.backgroundColor = '#FFFFE8';
		document.getElementById('defaultFinanceInfo').style.display = 'none';
	}
/////////////////////////////////////////////
}

var rates = new Array();
rates['24@0.00'] = 0.041665;
rates['36@0.00'] = 0.027777;
rates['48@0.00'] = 0.020833;
rates['36@1.99'] = 0.028638;
rates['36@2.99'] = 0.029077;
rates['36@3.49'] = 0.029298;
rates['48@1.99'] = 0.021691;
rates['48@2.99'] = 0.022013;
rates['48@3.99'] = 0.022575;
rates['48@3.49'] = 0.022352;
rates['48@4.49'] = 0.022799;
rates['60@0.00'] = 0.016666;
rates['60@1.99'] = 0.017523;
rates['60@2.99'] = 0.017964;
rates['60@3.99'] = 0.018412;
rates['60@5.49'] = 0.019097;
rates['72@2.99'] = 0.015189;
rates['72@4.99'] = 0.016100;
rates['72@5.99'] = 0.016568;
rates['84@2.99'] = 0.013209;
rates['84@3.99'] = 0.013664;
rates['84@4.99'] = 0.014129;
rates['84@5.99'] = 0.014604;
rates['84@5.49'] = 0.014365;
rates['84@6.49'] = 0.014971;

rates['60@4.49'] = 0.018638;

function calculatePayment()
{
	var amount = document.getElementById('txtAmount').value;
	amount = amount.replace(/,/g, '')
	amount = amount.replace(/\$/g, '')
	var a = document.getElementsByTagName('input');
	for (var i=0; i<a.length; i++)
	{
		var obj = document.getElementById(a[i].id);
		if (obj.id.indexOf('@') == -1) continue;  // only process input elements with '@' in their id
		
		var val = rates[obj.id.substring(3)] * amount;
		val = Math.round(val*100)/100
		if (isNaN(val)) 
		{
			alert ('There is an error in the dollar amount you entered.')
			return false
		}
		else
		{
			val = val.toFixed(2);
			obj.value = '$' + val;  // set the values of the form elements
		}
	} 
}

function handleSubmit()
{
	// enables pressing Return to calculate payments
	calculatePayment();
	document.getElementById('txt24@0.00').focus();    // take focus away from txtAmount, then
	document.getElementById('txtAmount').focus();     // put it back, to overcome a Firefox bug of dropping down a select menu
	document.getElementById('txtAmount').select();    // select the Amount to make it easy to enter a new amount
	return false;  // don't actually process the form submission
}
