function reset_form(){
  $('fuel_efficiency').value = '10';
  $('distance').value = '12000';
  $('fuel_gasoline').checked = true;
  $('system_of_measurement').selectedIndex = 0;
  $('volume').innerHTML = '0';
  $('pounds').innerHTML = '0';
  $('pri').innerHTML = '0';
  $('vehicle').innerHTML = "&nbsp;Emissions Calculator&nbsp;";
 //$('tier').innerHTML = "----";

  $('vm_year').selected = true;

  $('select_vehicle_model').innerHTML = "<span class=\"labelcell\">Model:</span> <select><option>---</option></select></div>";
  $('select_vehicle_make').innerHTML = "<span class=\"labelcell\">Make:</span> <select><option>---</option></select>";
  $('select_vehicle_complete').innerHTML = "";

  $('confirm1').checked = false;
  $('confirm1').disabled = true;
    $('add_to_cart').disabled = true;

  $('vehicle_model_id').value = '';
  $('tons').value = '';
  $('price').value = '';
  $('product').value = '';
}

function func_confirm() {
  if ($('confirm1').checked) {
    $('add_to_cart').disabled = false;
   
  } else {
    $('add_to_cart').disabled = true;
  }
}

function calculate() {
    //$('content_calculated').style.display = "none";
    $('indicator').style.display = "";
    calculateDrive("calculateDrive()",1500);
}

function milesToKm(distance){
  return (Number(distance) / 0.62136994949495);
}

function kmToMiles(distance){
  return (Number(distance)*0.62136994949495);
}

//////////////////////////////////
function calculateDrive(){
  if (!($('distance').value) || !($('fuel_efficiency').value) || ($('distance').value == 0) || ($('fuel_efficiency').value == 0)) {
    alert ("'Fuel efficiency' and 'Annual distance driven' should not be blank or zero");
    $('indicator').style.display = "none";
    return;
  }
  //0 for inche-pound, 1 for metric
  var efficiency_unit_selected = $('efficiency_unit').selectedIndex; 
  
  //0 for miles, 1 for kilometers
  var distance_unit_selected = $('distance_unit').selectedIndex; 
   
  $('distance').value = $('distance').value.replace(/,/g, '');
  $('distance').value = $('distance').value.split(',').join();

  //have the same distance unit 
  var default_distance = $('distance').value;  
  if (efficiency_unit_selected == 0 && distance_unit_selected == 1){    
    default_distance = kmToMiles(default_distance);
  }
  else if(efficiency_unit_selected == 1 && distance_unit_selected == 0){
    default_distance = milesToKm(default_distance);
  }

  var x = Number(default_distance)/Number($('fuel_efficiency').value);
  x = parseInt(x);
  
  var y=" ";
  var pri = document.getElementById("pri");
  var tier = document.getElementById("tier");

  if($('fuel_gasoline').checked == true){
    y=x;
  } else if($('fuel_diesel').checked == true){
    y=(x * 1.15);
  } else if(  $('fuel_cng').checked == true){
    y=(x * 0.77);
  } else if(  $('fuel_biodiesel').checked == true){
    y=(x * 0.25);
  }

  y=parseInt(y);

  //1 is for the smaller (pound/kilo) 2 is for larger(ton/tonne)
  var weight_1;
  var weight_2;
  
  weight_1=parseInt(weight_1);
    
  var t;
  var pp=0;
  var weight_unit_1;
  var weight_unit_2;
  var volume_unit;
  var product;

  //convert the volume of gas into weigth in C02 by 
  //multiplying by a factor of 2.32497
  // also some locale dependent math :)  
  
  weight_1 = parseInt(y*2.32497);
  if (efficiency_unit_selected == 0){
      weight_unit_1 = "pounds";
      weight_unit_2 = "tons";
      volume_unit="gallons"
      weight_1 = weight_1*8.3452;
      weight_2 = weight_1/2205;           
  }
  else  {
      weight_unit_1 = "kilos";
      weight_unit_2 = "metric tons";  
      volume_unit="liters"      
      weight_2 = weight_1/1000;
  }  
  weight_1 = Math.round(weight_1*100)/100
  weight_2 = Math.round(weight_2*10)/10
  
  
      
  if (weight_1 < 7717.5){
    pp='28'; t="One";
    product = 1;
  } else if(weight_1 >7717.5 && weight_1 <12127.5){
    pp='40';t="Two";
    product = 2;
  } else if(weight_1 >12127.5 && weight_1 <16537.5){
    pp='59';t="Three";
    product = 3;
  } else if(weight_1 >16537.5){
    pp=(59+(7.5*(weight_2-7.5))).toFixed(2);
    t="Four";
    product = 4;
  }
  


  if (efficiency_unit_selected == 0){
      weight_2 = weight_2*1.0160469;      
  }
  if (weight_2 <= 1){
        weight_2 = 1 
		}
      else
       weight_2 = Math.ceil(parseFloat(weight_2*2))/2;
	   
  weight_1= Math.round(weight_1)
  weight_2 = Math.round(weight_2*10)/10
  pp=  weight_2 * 7.5;
  $('tons').value = weight_2;   
  $('price').value = pp;
  $('product').value = product;
  $('indicator').style.display = "none";

  //add the results back to the HTML view
  document.getElementById("volume").innerHTML=' '+y+' '+volume_unit;
  document.getElementById("pri").innerHTML=pp;
  document.getElementById("weight_1").innerHTML=' '+weight_1 + ' ' + weight_unit_1;
  //document.getElementById("tier").innerHTML=' '+t+' ';
  document.getElementById("weight_2").innerHTML=' '+weight_2 + ' ' + weight_unit_2;

}