function ValidateForm() {
	if ((isEmpty(document.getElementById('finPayment').value)) || (!isNumeric(document.getElementById('finPayment').value)) || document.getElementById('finPayment').value == 0) {
		alert('Please specify the monthly payment amount.');
		document.getElementById('finPayment').focus();
		return false;
	} else if ((isEmpty(document.getElementById('finTerm').value)) || (!isNumeric(document.getElementById('finTerm').value)) || (document.getElementById('finTerm').value == 0) || (document.getElementById('finTerm').value > 72)) {
		alert('Please specify a valid term. The maximum term is 72 months.');
		document.getElementById('finTerm').focus();
		return false;
	} else {
		CalculateLoanAmt();
	}
}

// ##############################################################################
// ##############################################################################
// ##############################################################################

function CalculateLoanAmt() {
	var getBalloonAmt = document.getElementById('finBalloonAmt').value;
	var getDeposit = document.getElementById('finDeposit').value;
	var getTerm = document.getElementById('finTerm').value;
	var getRate = document.getElementById('finRate').value;
	var getPayments = FormatString(document.getElementById('finPayment').value);
	var userMessage = '';
	var i = getRate;
	if (i > 1.0) {
		i = i / 100.0;
	}
	i /= 12;
	var pow = 1;
	for (var j = 0; j < getTerm; j++) pow = pow * (1 + i);
	getFinalLoan = getLoan -  getBalloonAmt/ pow;
	var getLoan = (getPayments * (1 - Math.pow(1 + i, - getTerm)) / i) + parseFloat(getDeposit);
	document.getElementById('finLoan').value = FormatString(getLoan);
	var getLoanWithBalloon = (getLoan +  getBalloonAmt / pow)
	document.getElementById('finBalloonFV').value = FormatString(getLoanWithBalloon);
	document.getElementById('finBalloonPerc').value = FormatString(((getBalloonAmt / getLoanWithBalloon)*100));
	if (parseFloat(document.getElementById('finBalloonAmt').value) > parseFloat(document.getElementById('finLoan').value)) {
		alert('The balloon amount cannot be larger than the loan amount.');
		document.getElementById('finBalloonAmt').focus();
	}
	if (parseFloat(document.getElementById('finBalloonPerc').value) > 50) {
		alert('The balloon percentage cannot be more than 50%.');
		document.getElementById('finBalloonAmt').focus();
	}
	if (getBalloonAmt > 0) {
		userMessage += '<p>The Balloon amount of <b>R' + getBalloonAmt + '</b> will be payable at the end of the contract period.</p>';
	} else {
		userMessage += '';
	}
	document.getElementById('message').innerHTML = userMessage;
}

// ##############################################################################
// ##############################################################################
// ##############################################################################

function ClickToPrint() {
	var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,scrollbars=yes,width=650,height=600,left=100,top=25";
	var screenUserMessage = document.getElementById('message').innerHTML;
	var printUserMessage = screenUserMessage.replace(/<HR SIZE=1>/g, "<br>");
	var content_value = "<table border=1 bordercolor=#e6e6e6 cellpadding=4 cellspacing=0>";
	content_value += "<tr><td colspan=2><b>Vehicle Purchase Price Calculator</td></tr>";
	content_value += "<tr><td colspan=2 bgcolor=#e6e6e6><b>Vehicle Finance Inputs</td>";
	content_value += "<tr><td width=30%>Monthly repayment:</td><td width=70%>R" + FormatString(document.getElementById('finPayment').value) + "</td></tr>";
	content_value += "<tr><td>Deposit:</td><td>R" + FormatString(document.getElementById('finDeposit').value) + " </td></tr>";
	content_value += "<tr><td>Term:</td><td>" + document.getElementById('finTerm').value + " months </td></tr>";
	content_value += "<tr><td>Interest rate:</td><td>" + document.getElementById('finRate').value + "%</td></tr>";
	content_value += "<tr><td>Balloon amount:</td><td>R" + FormatString(document.getElementById('finBalloonAmt').value) + "</td></tr>";
	content_value += "<tr><td>Loan amount:</td><td>R" + FormatString(document.getElementById('finLoan').value) + "</td></tr>";
	content_value += "<tr><td>Loan including Balloon:</td><td>R" + FormatString(document.getElementById('finBalloonFV').value) + "</td></tr>";
	content_value += "<tr><td>Balloon %:</td><td>" + document.getElementById('finBalloonPerc').value + "%</td></tr>";
	content_value += "<tr><td colspan=2>" + printUserMessage + "</td></tr>";
	content_value += "<tr><td colspan=2><b>Disclaimer:</b> All calculations made on calculators supplied on this site, together with rates quoted, are guidelines only and are subject to confirmation at the time of finalising any transactions. All information regarding the products, fees, interest and/or costs which are included in and form a fundamental basis of the calculations are subject to change at any time prior to a final pre-agreement quote being handed to the User. The User indemnifies " + document.getElementById('form1:sitename').value + " against any loss or liability, which the User may suffer as a result of the use of any calculator. The site and all information provided on this site and the services provided on this site, are provided ''as is''. The information provided on this site should not be treated as professional advice of any kind.</td></tr>";
	content_value += "<table>";
	var docprint=window.open("","",disp_setting);
	docprint.document.open();
	docprint.document.write('<html><head><title>Vehicle Purchase Price Calculator</title>');
	docprint.document.write('<style type="text/css">td {font-family: tahoma; font-size: 11px; color: #000000; }</style></head>');
	docprint.document.write('<body onLoad="self.print()">');
	docprint.document.write(content_value);
	docprint.document.write('</body></html>');
	docprint.document.close();
	docprint.focus();
}

var A_TPL = {
	'b_vertical' : false,
	'b_watch': true,
	'n_controlWidth': 200,
	'n_controlHeight': 16,
	'n_sliderWidth': 15,
	'n_sliderHeight': 17,
	'n_pathLeft' : 0,
	'n_pathTop' : 0,
	'n_pathLength' : 185,
	's_imgControl': '/images/explore/slider_bkg.gif',
	's_imgSlider': '/images/explore/slider_vw.gif',
	'n_zIndex': 1
}
var A_INIT = {
	's_form' : 0,
	's_name': 'finPayment',
	'n_minValue' : 0,
	'n_maxValue' : 20000,
	'n_value' : 3000,
	'n_step' : 100
}
var B_TPL = {
	'b_vertical' : false,
	'b_watch': true,
	'n_controlWidth': 200,
	'n_controlHeight': 16,
	'n_sliderWidth': 15,
	'n_sliderHeight': 17,
	'n_pathLeft' : 0,
	'n_pathTop' : 0,
	'n_pathLength' : 185,
	's_imgControl': '/images/explore/slider_bkg.gif',
	's_imgSlider': '/images/explore/slider_vw.gif',
	'n_zIndex': 1
}
var B_INIT = {
	's_form' : 0,
	's_name': 'finTerm',
	'n_minValue' : 0,
	'n_maxValue' : 72,
	'n_value' : 54,
	'n_step' : 6
}
var C_TPL = {
	'b_vertical' : false,
	'b_watch': true,
	'n_controlWidth': 200,
	'n_controlHeight': 16,
	'n_sliderWidth': 15,
	'n_sliderHeight': 17,
	'n_pathLeft' : 0,
	'n_pathTop' : 0,
	'n_pathLength' : 185,
	's_imgControl': '/images/explore/slider_bkg.gif',
	's_imgSlider': '/images/explore/slider_vw.gif',
	'n_zIndex': 1
}
var C_INIT = {
	's_form' : 0,
	's_name': 'finRate',
	'n_minValue' : 8,
	'n_maxValue' : 20,
	'n_value' : 10.5,
	'n_step' : 0.25
}
var D_TPL = {
	'b_vertical' : false,
	'b_watch': true,
	'n_controlWidth': 200,
	'n_controlHeight': 16,
	'n_sliderWidth': 15,
	'n_sliderHeight': 17,
	'n_pathLeft' : 0,
	'n_pathTop' : 0,
	'n_pathLength' : 185,
	's_imgControl': '/images/explore/slider_bkg.gif',
	's_imgSlider': '/images/explore/slider_vw.gif',
	'n_zIndex': 1
}
var D_INIT = {
	's_form' : 0,
	's_name': 'finBalloonAmt',
	'n_minValue' : 0,
	'n_maxValue' : 100000,
	'n_value' : 0,
	'n_step' : 1000
}
var E_TPL = {
	'b_vertical' : false,
	'b_watch': true,
	'n_controlWidth': 200,
	'n_controlHeight': 16,
	'n_sliderWidth': 15,
	'n_sliderHeight': 17,
	'n_pathLeft' : 0,
	'n_pathTop' : 0,
	'n_pathLength' : 185,
	's_imgControl': '/images/explore/slider_bkg.gif',
	's_imgSlider': '/images/explore/slider_vw.gif',
	'n_zIndex': 1
}
var E_INIT = {
	's_form' : 0,
	's_name': 'finDeposit',
	'n_minValue' : 0,
	'n_maxValue' : 100000,
	'n_value' : 0,
	'n_step' : 1000
}