﻿	function calcCash() {
		
		var tmpPrice = 0;
		
		
		for (i = 1; i <= document.form1.tot.value; i++){
			if (document.form1.item('price'+i).checked) {
				tmpPrice += parseInt(document.form1.item('price'+i).value);
			}
		}
		document.form1.cash.value = parseInt(document.form1.stdPrice.value) + tmpPrice;
	}  	


	function monthsTot()
	{
		if (document.form1.deposit.value=='')
		d = 0
		else
		d = eval (document.form1.deposit.value)
		
		p = eval (document.form1.cash.value) - d
		mm = eval (document.form1.monthsPeriod.value)
		r = 15.5 / 100 //Interest rate!!!!!
		topTot = p * (r / 12)
		
		totBottom = 1 - Math.pow(1 + (r / 12),-mm)
		
		t = topTot / totBottom

		document.form1.monthlyTot.value = custRound(t,2);
		
	}


	function custRound(x,places) {

		return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places)
	}


	function getbc(region,locationID)
	{
		size=locationID.length;
		for (x=0;x<size;x++)
			{locationID.options[0] = null;}
			
		locationID.length+=1; //add 1 to the length of array
		locationID.options[locationID.length-1].value='';
		locationID.options[locationID.length-1].text='Please select...';

		for (x=0;x<locationcomp.length;x++) {
			if (regioncomp[x]==document.forms[0].region[document.forms[0].region.selectedIndex].value)
				{
					locationID.length+=1;
					locationID.options[locationID.length-1].value=locationcomp[x];
					locationID.options[locationID.length-1].text=locname[x];
				}
		}
	}


	function pre_chk() 
	{
		if(document.forms[0].derivative.selectedIndex == 0) 
		{
			alert('Please select vehicle model.');
			document.forms[0].derivative.focus();
			return false;
		}
		else
		{
			return true;
		}
	}

	function post_chk()
	{
		if (document.form1.fname.value=='')
		{
			alert("Please supply your first name.");
			document.form1.fname.focus();
			return false;
		}
		else if	(document.form1.email.value=='')
		{
			alert("Please supply your email address.");
			document.form1.email.focus();
			return false;
		}
		else if (document.forms[0].contact.value=='' || document.forms[0].contact.value.length<10)
		{
			alert('Please fill in your 10 digit office number, including area code, with no spaces, eg: 0111234567.');
			document.forms[0].contact.focus();
			return false;
		}
		else if (document.forms[0].cell.value=='' || document.forms[0].cell.value.length<10)
		{
			alert('Please fill in your 10 digit cell phone number with no spaces, eg: 0821234567.');
			document.forms[0].cell.focus();
			return false;
		}
		else if (document.form1.region.selectedIndex==0)
		{
			alert("Please select your region.");
			document.form1.region.focus();
			return false;
		}
		else if (document.form1.locationID.selectedIndex==0)
		{
	 		alert("Please select your local dealership.");
	 		document.form1.locationID.focus();
			return false;
		}
		else if (document.form1.derivative.selectedIndex==0)
		{
		    alert('Please select the model of your vehicle');
		    document.forms[0].derivative.focus();
		    return false;
		}
		else if ( (document.getElementById("tradein_yes").checked) && (document.getElementById("tradein_year").selectedIndex==0) )
		{
			alert('Please select the year of your trade-in vehicle.');
			document.forms[0].tradein_year.focus();
			return false;
		}
		else if ( (document.getElementById("tradein_yes").checked)  && (document.getElementById("tradein_brand").selectedIndex==0) )
		{
			alert('Please select the make of your trade-in vehicle.');
			document.forms[0].tradein_brand.focus();
			return false;
		}
		else if ( (document.getElementById("tradein_yes").checked)  && (document.getElementById("tradein_model").value=="") ) 
		{
			alert('Please specify the model of your trade-in vehicle.');
			document.forms[0].tradein_model.focus();
			return false;
		}
		else if ( (document.getElementById("tradein_yes").checked)  && (isNaN(parseInt(document.getElementById("tradein_value").value))) )
		{
			
			alert('Please fill in the estimated numerical value of your trade-in. (No spaces or commas!)');
			document.forms[0].tradein_value.focus();
			return false;
		}
		else
		{
			return true;
		}
	}
	
	function ShowHideTradein(strValue)
	{
		tr_Tradein.style.display=strValue;
	}

