// JavaScript Document

var resultsShown=false;

function calculateCost() {
	var purchasePrice = document.getElementById('purchaseprice').value;
	var carAge = document.getElementById('age').value;
	var insurance = document.getElementById('insurance').value*1;
	var mileage = document.getElementById('mileage').value;
	var repairs = document.getElementById('repairs').value*1;
	
	var petrolRatio, tyreRatio, serviceRatio, partsRatio, depreciationRatio, roadTax, capital;
	
	switch(purchasePrice) {
		case '10000':
			petrolRatio = 916;
			tyreRatio = 78;
			serviceRatio = 292;
			partsRatio = 165;
			depreciationRatio = 1073;
			roadTax = 125;
			capital = 269;
			break;
		case '13000':
			petrolRatio = 1006;
			tyreRatio = 98;
			serviceRatio = 283;
			partsRatio = 209;
			depreciationRatio = 1674;
			roadTax = 150;
			capital = 392;
			break;
		case '20000':
			petrolRatio = 1288;
			tyreRatio = 112;
			serviceRatio = 288;
			partsRatio = 252;
			depreciationRatio = 2255;
			roadTax = 165;
			capital = 547;
			break;
		case '30000':
			petrolRatio = 1472;
			tyreRatio = 135;
			serviceRatio = 334;
			partsRatio = 303;
			depreciationRatio = 3207;
			roadTax = 165;
			capital = 803;
			break;
		case '30001':
			petrolRatio = 1718;
			tyreRatio = 185;
			serviceRatio = 376;
			partsRatio = 445;
			depreciationRatio = 5507;
			roadTax = 165;
			capital = 1295;
			break;
	}
	
	var mileageRatio = mileage/10000;
	
	var petrol = mileageRatio * petrolRatio;
	var tyres = mileageRatio * tyreRatio;
	var service = mileageRatio * serviceRatio;
	var parts = mileageRatio* partsRatio;
	var parking = mileageRatio * 180;
	var depreciation = mileageRatio * depreciationRatio;
	var breakdownCover = 40;
	
	document.getElementById('petrol').innerHTML = formatCurrency(petrol);
	document.getElementById('tyres').innerHTML = formatCurrency(tyres);
//	document.getElementById('service').innerHTML = formatCurrency(service);
//	document.getElementById('parts').innerHTML = formatCurrency(parts);
	document.getElementById('parking').innerHTML = formatCurrency(parking);
	document.getElementById('tax').innerHTML = formatCurrency(roadTax);
	document.getElementById('capital').innerHTML = formatCurrency(capital);
	document.getElementById('breakdowncover').innerHTML = formatCurrency(breakdownCover);
	document.getElementById('insurancecost').innerHTML = formatCurrency(insurance);
	document.getElementById('depreciation').innerHTML = formatCurrency(depreciation);
	document.getElementById('repairscost').innerHTML = formatCurrency(repairs);
	
	var total = petrol + tyres + service + parts + parking + roadTax + capital + breakdownCover + insurance + depreciation + repairs;

	document.getElementById('total').innerHTML = formatCurrency(total);
	
	//results = document.getElementById('results');
	if(!resultsShown) {
		new Effect.BlindDown('results');
		new Effect.ScrollTo('results', {offset: -280});
		resultsShown = true;
	}
	
}

function formatCurrency(pounds) {
	return '£' + pounds.toFixed(2);
}