<?php
$page_name = "The True Cost of Owning a Car";
$menu_type = "bad math";
$menu_name = "Real Car Cost";
$blog_num = 52;
$page_rate = 7;
$page_tags = array();
$page_date = "Nivember 27, 2011";
include_once("./files/head.php");

$part = $_POST['part'];
$o_price = $_POST['o_price'];
$p_price = $_POST['p_price'];
$e_price = $_POST['e_price'];
$o_age = $_POST['o_age'];
$f_age = $_POST['f_age'];
$y_dist = $_POST['y_dist'];
$gas_dist = $_POST['gas_dist'];
$gas_dist_100 = $_POST['gas_dist_100'];
$gas_price = $_POST['gas_price'];
$insurance = $_POST['insurance'];

echo "<p>This page will roughly calculate the cost of your car (in theory).  Input welcome.</p>\n";

echo "<form enctype=\"multipart/form-data\" name=\"page_print\" action=\"./car_cost.php" . $admin_link . "\" method=\"POST\">\n";
echo "<input type=\"hidden\" name=\"part\" id=\"part\" value=\"1\" />\n";

echo "<p>Original value of the car (when it was shiny new on the lot): $ <input type=\"text\" name=\"o_price\" id=\"o_price\" value=\"" . $o_price . "\" size=\"10\" />\n";
echo "<br />*What you paid for the car: $ <input type=\"text\" name=\"p_price\" id=\"p_price\" value=\"" . $p_price . "\" size=\"10\" />\n";
echo "<br />What you paid for the extras (winter tires, betty boop bling, unforseen issues): $ <input type=\"text\" name=\"e_price\" id=\"e_price\" value=\"" . $e_price . "\" size=\"10\" />\n";
  
echo "<br /><br />Age of the car when you got it (0=new): <input type=\"text\" name=\"o_age\" id=\"o_age\" value=\"" . $o_age . "\" size=\"3\" /> years\n";
echo "<br />Age of the car when you sold/want to sell it (<30): <input type=\"text\" name=\"f_age\" id=\"f_age\" value=\"" . $f_age . "\" size=\"3\" /> years\n";

echo "<br /><br />Distance you drive in a year: <input type=\"text\" name=\"y_dist\" id=\"y_dist\" value=\"" . $y_dist . "\" size=\"10\" /> Km\n";
echo "<br />**Average cost of gas over your ownership: $ <input type=\"text\" name=\"gas_price\" id=\"gas_price\" value=\"" . $gas_price . "\" size=\"5\" /> /L\n";
echo "<br />Efficiency (Km/L): <input type=\"text\" name=\"gas_dist\" id=\"gas_dist\" value=\"" . $gas_dist . "\" size=\"3\" />";
  echo " or (L/100Km): <input type=\"text\" name=\"gas_dist_100\" id=\"gas_dist_100\" value=\"" . $gas_dist_100 . "\" size=\"3\" />\n";

echo "<br /><br />Average monthly insurance cost: $ <input type=\"text\" name=\"insurance\" id=\"insurance\" value=\"" . $insurance . "\" size=\"7\" /> /month\n";

echo "<br /><br /><input type=\"submit\" value=\"CALCULATE\" tabindex=500 /></p>\n";
echo "</form>\n";

if ($part == 1) {
  //Calculations
  $years_owned = $f_age - $o_age;
  $total_dist = ($y_dist * $years_owned == 0 ? 1 : $y_dist * $years_owned);
  $total_gas = ($gas_dist > 0) ? $total_dist / $gas_dist : $total_dist * $gas_dist_100 / 100;
  $repairs = array(1, 1, 1, 1, 1, 2, 3, 5, 8, 12, 15, 17, 18, 17, 15, 12, 8, 5, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
  $total_repairs = 0;
  for ($i>=$o_age; $i <= $f_age; $i++) {
    $total_repairs += ($o_price * $repairs[$i] / 100);  
  }
  $total_insurance = $insurance * $years_owned * 12;
  $total_cost = $p_price + $e_price + $total_gas + $total_repairs + $total_insurance;
  $total_per_km = $total_cost / $total_dist;
  $sex_appeal = ($total_per_km <= 0.20 ? "none" : "yes");
  
  //display
  echo "<p>Total Km: " . number_format($total_dist, 2, ".", " ") . "Km\n";
  echo "<br />Total Gas: $" . number_format($total_gas, 2, ".", " ") . "\n";
  echo "<br />**Total Repairs: $" . number_format($total_repairs, 2, ".", " ") . "\n";
  echo "<br />Total Insurance: $" . number_format($total_insurance, 2, ".", " ") . "\n";
  echo "<br /><br />Total Cost of Your Car: <strong>$" . number_format($total_cost, 2, ".", " ") . "</strong>\n";
  echo "<br />Total Cost per Km: <strong>$" . number_format($total_per_km, 2, ".", " ") . "</strong>\n";
  echo "<br />\n";
  if ($sex_appeal == "none") {
    echo "<br />Sex Appeal: <strong><big>NONE!! You're a cheapskate!</big></strong><br />\n";
  }
  echo "<br /></p>\n";
}

echo "<h3>Notes</h3\n";
echo "<p>*Remember to include your inspection and initial repairs (the repairs you had to do in the first week of getting the car) in the purchase price.\n";
echo "<p>**Oh gas prices, how we hate you...\n";
  echo "<ul>\n";
	echo "<li>~60 cents per liter in 2000</li>\n";
	echo "<li>~70 cents per liter in 2002</li>\n";
    echo "<li>~80 cents per liter in 2004</li\n";
    echo "<li>~90-100 cents per liter in 2008</li\n";
    echo "<li>~100-120 cents per liter in 2010</li\n";
    echo "<li>~120 cents per liter in 2011</li\n";
  echo "</ul>\n";
echo "***Repair costs are based on the following ideas:\n";
  echo "<ul>\n";
	echo "<li>Brand new cars cost you virtually nothing in repairs and yearly maintenance for the first 5-7 years</li>\n";
	echo "<li>You will refuse to spend lots of money on repairs for a car over 18-20 years old.</li>\n";
    echo "<li>Major repairs come at the 10-15 year range once warranties run out.</li\n";
  echo "</ul>\n";
  echo "This works out to a nice bell curve centering on 18% of your car value at year 12.\n";
  echo "<br />If the car is older than 30 years, it's probably a classic or something and your going to be putting in more than average to keep it going and look shiny, so don't expect this to be at all accurate.\n";
echo "</p>\n";

include_once("./files/close.php");
?>