function resetRental()
{
		// send reset flag to self
		document.fRental.action = 'broker_rental.aspx?reset=true';
		document.fRental.target='';
		// submit the form
		document.fRental.submit();	
}

function calculateRental(updateBasis)
{

	// validate the form
	if (validate_form())
	{
		// set form action and target
		if (updateBasis) {
		document.fRental.action = 'broker_rental.aspx?updateBasis=true';
		}
		else
		{
		document.fRental.action = 'broker_rental.aspx';
		}
		document.fRental.target='';
		// submit the form
		document.fRental.submit();
	}
	
}

function printRental()
{
	// validate the form
	if (validate_form())
	{
		// change the action for the form
		win=window.open('','myWin');
		document.fRental.target='myWin';
		document.fRental.action = 'broker_printrental.aspx';
		// submit the form
		document.fRental.submit();
	}
	
}


function validate_keystroke(e, sType)
{

	// only allow valid keystrokes into the fields

	var key;
	var keychar;
	var reg;
	
	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode; 
	}
	else if(e.which) {
		// netscape
		key = e.which; 
	}
	else {
		// no event, so pass through
		return true;
	}

	keychar = String.fromCharCode(key);

	if (sType == 'number')
	{
		reg = /(^[\d]?$)/;
	} 
	else if (sType == 'decimal')
	{
		reg = /(^[\d\.]?$)/;
	}
	else
	{
		reg = /(^[\d\.]?$)/;
	}

	var rtn = reg.test(keychar);

	return rtn;

}

function validate_form()
{

	// validate  RegExp on all fields here
	// at the time of form submittance

	// COST ex
	if (!is_valid(document.fRental.rental_cost_ex, "Cost ex.", false)) return false;
	
	// DEPOSIT PERCENT
	if (!is_valid(document.fRental.rental_depositpercent, "Deposit %", false)) return false;
	
	// ADVANCE RENTAL
	if (!is_valid(document.fRental.rental_advancerental_ex, "Advance Rental ex.", false)) return false;
	
	// COMMISSION PERCENT
	if (!is_valid(document.fRental.rental_commissionpercent, "Commission %", false)) return false;

	// COMMISSION
	if (!is_valid(document.fRental.rental_commissiontointro_ex, "Commission ex.", false)) return false;

	// NOMINAL RATE
	if (!is_valid(document.fRental.rental_nominalrate, "Nominal Rate", true)) return false;
	//if (!document.fRental.nominalrate.value > 0) return false;

	// NUMBER OF PAYMENTS
	if (!is_valid(document.fRental.rental_numberofpayments, "Number of Payments", true)) return false;
	//if (!document.fRental.rental_numberofpayments.value > 0) return false;

	// DEPOSIT TO SUPPLIER
	if (!is_valid(document.fRental.rental_deposittosupp_inc, "Deposit to Supplier inc.", false)) return false;

	// TRADE IN ALLOWANCE
	if (!is_valid(document.fRental.rental_tradeinallowance_inc, "Trade in Allowance inc.", false)) return false;
	
	return true;
	
}

function is_valid(objField, sName, bRequired)
{

	// this procedure uses regular expressions
	// to check for the decimal format
	// with optional decimal point.
	// if a decimal point exists then it
	// is required to have a numeral following it
	
	var reg;
	reg = /(^\d+(\.\d+)?$)/;
	
	var sValue;
	if (objField.value == null)
	{
		sValue = '';
	}
	else
	{
		sValue = objField.value;
	}
	
	if (!reg.test(sValue) && (sValue != ''))
	{
		alert(sName + " value is not a valid number,\nPlease correct this and try again.");
		objField.focus();
		objField.select();
		return false;
	}
	else if (bRequired && (sValue == '' || parseInt(sValue) == 0))
	{
		alert(sName + " value is required,\nPlease correct this and try again.");
		objField.focus();
		objField.select();
		return false;
	}
	else
	{
		return true;
	}
	
}