/************************************************************
* 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=\"/calc/rs_product_calculator.js\" LANGUAGE=\"JAVASCRIPT\" TYPE=\"TEXT/JAVASCRIPT\"></SCRIPT>' );


function ValidateAndCalc()
{
	if (!document.rsform.Name.value)
	{
		alert( "Por favor escriba su nombre." );
		return false;
	}
	else if ((document.rsform.thardware.value <= 0) || isNaN( document.rsform.thardware.value ) || (document.rsform.thardware.value == ''))
	{
		alert( "Por favor rellene una cantidad válida." );
		return false;
	}
	else if (parseFloat( document.rsform.thardware.value ) < jvp_rental_lower_limit)
	{
		alert( 'La cantidad exigida debe ser por lo menos ' + jvp_rental_lower_limit + ' Euros.' )
		return false;
	}	
	else if (parseFloat( document.rsform.thardware.value ) > jvp_rental_upper_limit)
	{
		alert( 'Para presupuestos de más de ' + jvp_rental_upper_limit + ' Euros por favor llámenos directamente.' );
		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;
	}

	document.rsform.ttotal2.value = FormatDecimals( (document.rsform.tmonthly2.value - FormatDecimals( document.rsform.tmonthly2.value * (TaxRate / 100) )) * 36 );
	document.rsform.ttotal3.value = FormatDecimals( (document.rsform.tmonthly3.value - FormatDecimals( document.rsform.tmonthly3.value * (TaxRate / 100) )) * 48 );
}


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, false ) ) ) );
	document.rsform.tweekly3.value = FormatDecimals( RoundValue( ConvertMonthlyToWeekly( CalculateMonthlyInstalment( TotalInvoiceAmount, null, 48, false ) ) ) );

	document.rsform.tmonthly2.value = FormatDecimals( RoundValue( CalculateMonthlyInstalment( TotalInvoiceAmount, null, 36, false ) ) );
	document.rsform.tmonthly3.value = FormatDecimals( RoundValue( CalculateMonthlyInstalment( TotalInvoiceAmount, null, 48, false ) ) );
	
	CalculateTax();
}
