/************************************************************
* estimate.js
* 02-May-2001
*
* Calculates the rental terms for a given equipment value.
*
* Modified for use in the UK.
* Completely modified to use common calculation functions and
* cater for warranty.
************************************************************/

document.write( '<SCRIPT SRC=\"/us/jvp/gen/calc/rs_product_calculator.js\" LANGUAGE=\"JAVASCRIPT\" TYPE=\"TEXT/JAVASCRIPT\"></SCRIPT>' );


function ValidateAndCalc()
{
	if (!document.rsform.Name.value)
	{
		alert( "Please enter your Name." );
		return false;
	}
	else if ((document.rsform.thardware.value <= 0) || isNaN( document.rsform.thardware.value ) || (document.rsform.thardware.value == ''))
	{
		alert( "Please enter a valid Amount." );
		return false;
	}
	else if (parseFloat( document.rsform.thardware.value ) < jvp_rental_lower_limit)
	{
		alert( 'The Amount Required must be at least ' + jvp_currency + jvp_rental_lower_limit )
		return false;
	}	
	else if (parseFloat( document.rsform.thardware.value ) > jvp_rental_upper_limit)
	{
		alert( 'For quotations above ' + jvp_currency + jvp_rental_upper_limit + ' please call us direct.' );
		return false;
	}
	
	CalculateQuote();
	document.rsform.submit();
}


function CalculateTax()
{
	var TaxRate = 0;
	if ((typeof document.rsform.TaxRate != 'undefined') && (document.rsform.TaxRate != null))
	{
		 TaxRate = document.rsform.TaxRate[document.rsform.TaxRate.selectedIndex].value;
	}
	var tm2 = document.rsform.tmonthly2.value;
	var tm3 = document.rsform.tmonthly3.value;

	document.rsform.ttotal2.value = FormatDecimals(tm2-(tm2*TaxRate/100));
	document.rsform.ttotal3.value = FormatDecimals(tm3-(tm3*TaxRate/100));
}


function CalculateQuote()
{
	SetRates();
	
	var TotalInvoiceAmount = parseFloat( document.rsform.thardware.value );
	
	// Set form results with the correct currency format
	document.rsform.thardware.value = FormatDecimals( TotalInvoiceAmount );
	
	document.rsform.tweekly2.value = FormatDecimals( RoundValue( ConvertMonthlyToWeekly( CalculateMonthlyInstalment( TotalInvoiceAmount, null, 36, document.rsform.Insurance[0].checked ) ) ) );
	document.rsform.tweekly3.value = FormatDecimals( RoundValue( ConvertMonthlyToWeekly( CalculateMonthlyInstalment( TotalInvoiceAmount, null, 48, document.rsform.Insurance[0].checked ) ) ) );

	document.rsform.tmonthly2.value = FormatDecimals( RoundValue( CalculateMonthlyInstalment( TotalInvoiceAmount, null, 36, document.rsform.Insurance[0].checked ) ) );
	document.rsform.tmonthly3.value = FormatDecimals( RoundValue( CalculateMonthlyInstalment( TotalInvoiceAmount, null, 48, document.rsform.Insurance[0].checked ) ) );
	
	CalculateTax();
}