
function checkNum(value,required)
{
		vLen = value.length;
		// check for required
		if( required && vLen == 0) return false;
		
		if( isNaN( value ) ) return false;

	return true;
}

function preedit( value )
{
	s = new String( value );

	while( s.match(',') ) { s = s.replace(',',''); }
	
	s = s.replace('%','');
	return s;
}

function computePayment()
{
  
	
 	document.calc.price.value = preedit( document.calc.price.value );
	document.calc.downpay.value = preedit( document.calc.downpay.value );
	
	if( !checkNum(document.calc.price.value,true))
	{
		alert("Price must be a numeric value.");
		document.calc.price.focus()
		return false;
	}
	
	if( !checkNum(document.calc.downpay.value,true) )
	{
		alert("Down payment must be a numeric value.");
		document.calc.downpay.focus()
		return false;
	}

	price = document.calc.price.value - document.calc.downpay.value ;
	i = document.calc.rate.value  / 100.0;
	
	index = document.calc.months.selectedIndex ;
		
	months = document.calc.months.options[index].value ;
	
	numPaymentsPerYear = 12;
	
	i = i / numPaymentsPerYear;
	payment = Math.round(price * i / (1.0 - Math.pow(1.0 + i, -months)) * 100)/100;
	Lease = Math.round(((price * i / (1.0 - Math.pow(1.0 + i, -months))*100)) * .7)/100;

	document.calc.payment.value = "" + payment;
	document.calc.lease.value = "" + Lease;
  
}