
function addValues (value) {
var myForm = document.timeCalculator;

if(myForm.total_time.value.length > 0){
var the_hours = parseInt(myForm.total_time.value.substring(0,myForm.total_time.value.indexOf(":")));
var the_minutes = parseInt(myForm.total_time.value.substring(myForm.total_time.value.indexOf(":")+1,myForm.total_time.value.lastIndexOf(":")));
var the_seconds = parseInt(myForm.total_time.value.substring(myForm.total_time.value.lastIndexOf(":")+1,myForm.total_time.value.length));
}
else{
var the_hours = 0;
var the_minutes = 0;
var the_seconds = 0;
}

var form_hours = parseFloat(myForm.frm_hours.value);
var form_minutes = parseFloat(myForm.frm_minutes.value);
var form_seconds = parseFloat(myForm.frm_seconds.value);
if (isNaN(form_hours)) {form_hours = 0;}
if (isNaN(form_minutes)) {form_minutes = 0;}
if (isNaN(form_seconds)) {form_seconds = 0;}
myForm.frm_hours.value = form_hours;
myForm.frm_minutes.value = form_minutes;
myForm.frm_seconds.value = form_seconds;

form_seconds = (form_hours * 60 * 60) + (form_minutes * 60) + form_seconds;
form_hours = 0; form_minutes = 0;
while(form_seconds >= 60){form_seconds = form_seconds - 60;form_minutes++;}
while(form_minutes >= 60){form_minutes = form_minutes - 60;form_hours++;}

the_hours = value * form_hours + the_hours;
the_minutes = value * form_minutes + the_minutes;
the_seconds = value * form_seconds + the_seconds;

while(the_seconds >= 60){the_seconds = the_seconds - 60;the_minutes++;}
while(the_minutes >= 60){the_minutes = the_minutes - 60;the_hours++;}
while(the_seconds < 0){the_seconds += 60;the_minutes--;}
while(the_minutes < 0){the_minutes += 60;the_hours--;}

the_seconds = Math.round(the_seconds *10000)/10000;

myForm.total_time.value = "" + the_hours + ":" + the_minutes + ":" + the_seconds;

var tempDecimal = the_hours + (the_minutes / 60) + (the_seconds / 60 / 60);
tempDecimal = Math.round(tempDecimal *10000)/10000;
myForm.total_time_decimal.value = "" + tempDecimal + " hours";
}

function resetValues(){
var myForm = document.timeCalculator;

myForm.frm_hours.value = "";
myForm.frm_minutes.value = "";
myForm.frm_seconds.value = "";

myForm.total_time.value = "0:0:0";
myForm.total_time_decimal.value = "0 hours";
}
