<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Routing</title>
</head>
<body>
<br>
  <a href="http://www.trekescapes.com/">
<img src="images/trek.jpg" width="280" height="111" border="0" /></a>
<br>

<?php session_start(); 
      echo "Distance emission";
      echo "<br/>";
	  echo "<br/>";
      /*info from the from*/
	  $passengers = $_POST["passengers"] ;
	  //$temp = is_int( $_POST["passengers"] );
	  
	  if ($passengers == '0')
	  {
	      echo "Passengers entry is not a valid number. Please change the input.<br>";
		  return;
	  }
	  echo $passengers . " Passenger(s)<br>";
	  
  
	  /*Check if the Dist is not NULL*/
	  if(!empty($_POST["dist"]))
	  {
	   					
						$dist = $_POST["dist"];
						if($_POST["distradio"]=='m')
						{
						  	echo round($dist) . " Miles<br>";
						   $dist = $dist * 1.61 ;
						  
						}
						else 
						{
						   echo round($dist) . " Kilometer<br>";
						}
						if ($dist == '0')
	  					{
						     echo "Distance entry is not a valid number. Please change the input.<br>";
							 return;
						}
					
						$total = emissiondist( $dist );
						echo round($total) . " kilograms<br>";
						$cton = round($total/1000,3);
						echo $cton . " tonne<br>";
						echo "<hr>";
						echo "Total : <br>";
						echo "$ ". ( $passengers * $cton * 16 ). " <br>";
		}
       $_SESSION['emission'] = number_format($rout * $cton, 1, '.', '');
        $_SESSION['distance'] = $totaldist * $rout ; 
		$_SESSION['cost'] = number_format($number, 2, '.', '');
       	echo '<form action="confirm.php?'. SID .'" method="post">';
		echo '<label> Transaction ID: <br />';
		echo '<input name="transaction" type="text" />';
		echo '</label><br/>';
		echo '<label> Agent Code: <br />';
		echo '<input name="agent" type="text" />';
		echo '</label><br/>';
		echo '<label> Enter Traveler Name(optional): <br />';
		echo '<input name="name" type="text" />';
		echo '</label><br/>';
        echo '<input name="confirmsave" type="submit" value="Confirm" />';
		echo '</form>';
			
 ?>


 <br/>
<a href="index.php" title="New" accesskey="n" target="_self">New calculation</a>
<br/>
<br/>

  <a href="http://www.offsetters.ca">
<img src="http://www.trekescapes.com/offsetting/images/ofsetters-logo.gif" width="250" height="98" border="0" /></a>

<?php

//return emission in kgr
function emissiondist($dist) { 
  $metric = 2;
  //freight allocation
  $freight = 0.10;
  if($dist <= 500)
  {
      $haul = 0.15; 
  }
   if($dist <= 1600 && $dist > 500)
  {
      $haul = 0.11;
  }
   if($dist > 1600)
  {
      $haul = 0.11;
  }
   
   $temission = $dist * $haul;
   //echo $temission."<br>";
   $falloc = $temission * $freight;
   //echo $falloc."<br>";
   $emission = ($temission - $falloc)*$metric;   
   return $emission;
}



//echo distance(32.9697, -96.80322, 29.46786, -98.53506, "m") . " miles<br>";
//echo distance(  49.1138,-123.1104, 43.4038,-79.3750,  "k") . " kilometers<br>";
//echo distance(  49.2500,-123.1333, 43.6667,-79.4167,  "k") . " kilometers<br>";
//echo distance(32.9697, -96.80322, 29.46786, -98.53506, "n") . " nautical miles<br>";

?>
 
</body>
</html>




