﻿


function compute(form)
{
    //
    // Compute the minutes per mile.
    //

    // First thing to do is set everything that might have been correctly
    // left off by the invoker of this script.
    //
    // Sure ... they could leave off the hour.  We'll fix it for them.
    if (form.hour.value==null || form.hour.value.length==0)
    {
      form.hour.value=0;
    } 
    //
    // Sure ... they could leave off the minute.  We'll fix it for them.
    if (form.minute.value==null || form.minute.value.length==0)
    {
      form.minute.value=0;
    }
    //
    // Sure ... they could leave off the second.  We'll fix it for them.
    if (form.second.value==null || form.second.value.length==0)
    {
      form.second.value=0;
    }

    //
    // Next, put these various measurements of time into the least common
    // denominator ... seconds ... for our calculations.
    //
    // It's an easy computation based upon an earthling's point of view.
    var tot_time = (form.hour.value*3600) + (form.minute.value*60) + (form.second.value*1);

    //
    // Finally, check on the integrity of the data.  When things are not
    // nice, make note of it.  Otherwise, we can figure out the mpm.
    if (tot_time==0)
    {
      alert("Recheck your hour/minute/second values.")
    }
    else
    {
      if (form.distance.value.length==0)
      {
        alert("Recheck your distance value.")
      }
      else
      {
        var secs_mile = tot_time/form.distance.value; 
        var sec_part = secs_mile%60;
        var whole_part = secs_mile - sec_part;
        var min_part = whole_part/60;
        if (sec_part==0)
        {
          form.results.value= min_part + ":00." + sec_part;
        }
        else
        {
          if (sec_part < 1)
          {
            form.results.value= min_part + ":00" + sec_part; 
          }
          else
          {
            if (sec_part < 10)
            {
              form.results.value= min_part + ":0" + sec_part; 
            }
            else
            {
              form.results.value= min_part + ":" + sec_part; 
            }
          }
        }
      }
    }

    return;

}

function clear(form)
{
    //
    // Clear the values for the minutes per mile form.
    //
    form.distance.value = "";
    form.hour.value = "";
    form.minute.value = "";
    form.second.value = "";
    form.results.value = "";
}

function marcompute(form)

{
// Compute the minutes per mile.

// First thing to do is set everything that might have been correctly
// left off by the invoker of this script.

// Sure ... they could leave off the hour.  We'll fix it for them.
if (form.marhour.value==null || form.marhour.value.length==0)
{
  form.marhour.value=0;
} 
// Sure ... they could leave off the minute.  We'll fix it for them.
if (form.marminute.value==null || form.marminute.value.length==0)
{
  form.marminute.value=0;
}
// Sure ... they could leave off the second.  We'll fix it for them.
if (form.marsecond.value==null || form.marsecond.value.length==0)
{
  form.marsecond.value=0;
}

// Next, put these various measurements of time into the least common
// denominator ... seconds ... for our calculations.

// It's an easy computation based upon an earthling's point of view.
var tot_time = (form.marhour.value*3600) + (form.marminute.value*60) + (form.marsecond.value*1);

// Finally, check on the integrity of the data.  When things are not
// nice, make note of it.  Otherwise, we can figure out the mpm.
if (tot_time==0)
{
  alert("Recheck your hour/minute/second values.")
}
else
{
  var secs_mile = tot_time/26.2; 
  var sec_part = secs_mile%60;
  var whole_part = secs_mile - sec_part;
  var min_part = whole_part/60;
  if (sec_part < .1 )
  {
    form.marresults.value= min_part + ":00." + sec_part;
  }
  else
  {
    if (sec_part < 1)
    {
      form.marresults.value= min_part + ":00" + sec_part; 
    }
    else
    {
      if (sec_part < 10)
      {
        form.marresults.value= min_part + ":0" + sec_part; 
      }
      else
      {
        form.marresults.value= min_part + ":" + sec_part; 
      }
    }
  }
}

return;

}

function marclear(form)
{
//
// Clear the values for the minutes per mile form.
//
form.marhour.value = "";
form.marminute.value = "";
form.marsecond.value = "";
form.marresults.value = "";
}
