// round for percent decimal of 3 places
var win = null;
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
}

function perRound(num) {
   result=Math.floor(num)+"." 
   var percents=1000*(num-Math.floor(num))+0.05
   result += Math.floor(percents/100)
   result += Math.floor(percents%100)
   return(result)
}
// send the value in as "num" in a variable

// clears field of default value
function clear_field(field) {
		if (field.value==field.defaultValue) {
			field.value=''
		}
	}

// Takes a string in the form h:m:s.s and converts to seconds
    function stringToSeconds (timeString) {
if (timeString == "") return 0;
if (timeString <= 0) return 0; //no negatives, leave entry on the line, do not accumulate any buckets
var hr = 0;
var mn = 0;
var sec = 0;
var timeArray = timeString.split(":");
switch (timeArray.length) {
case 1:
sec = Number(timeArray[0])
break;
case 2:
mn = Number(timeArray[0])
sec = Number(timeArray[1])
break;
case 3:
hr  = Number(timeArray[0])
mn = Number(timeArray[1])
sec = Number(timeArray[2])
break;
}
//alert(hr + ", " + mn + ", " + sec)
return hr*3600 + mn*60 + sec
    }
 
 // Takes an hr string, mn string, and sec string and converts to seconds
    function stringToSeconds3 (hrString, minString, secString) {
 return Number(hrString)*3600 + Number(minString)*60 + Number(secString)
    }

 // Takes seconds and converts to h:m:s.s
    function secondsToString (seconds) {
var hr = Math.floor(seconds/3600);
var mn = Math.floor((seconds%3600)/60);
//var mn = Math.floor(seconds/60)%60
var sec = round2(seconds%60);

var timeString = "" + sec;
if (hr > 0) {
if (mn > 9) timeString = hr + ":" + mn + ":"
else timeString = hr + ":0" + mn + ":"
if (sec > 9) timeString = timeString + sec
else timeString = timeString + "0" + sec
}
else if (mn > 0) {
if (sec > 9) timeString = mn + ":" + sec
else timeString = mn + ":0" + sec
}
return timeString
}

 function showTime (seconds) {
var hr = Math.floor(seconds/3600);
var mn = Math.floor((seconds%3600)/60);
//var mn = Math.floor(seconds/60)%60
var sec = round2(seconds%60);

var timeString = "" + sec + "s. ";
if (hr > 0) {
if (mn > 9) timeString = hr + "h. " + mn + "m. "
else timeString = hr + "h. 0" + mn + "m. "
if (sec > 9) timeString = timeString + sec+ "s. "
else timeString = timeString + "0" + sec+ "s. "
}
else if (mn > 0) {
if (sec > 9) timeString = mn + "m. " + sec+ "s. "
else timeString = mn + "m. 0" + sec+ "s. "
}
return timeString
}
    
    function round2(myNumber) {
        return Math.floor(Math.round(myNumber * 100)) / 100
    }
    
    function round3(myNumber) {
        return Math.floor(Math.round(myNumber * 1000)) / 1000
    }
    

    
function addTimes(ftime,stime ) {
var ftime;
var stime;
var seconds = stringToSeconds(ftime)
var totalTime = seconds
var minsec = seconds
var maxsec = seconds
var count = 0
if (seconds > 0) {
secondsToString(totalTime)
count = count + 1
} 


seconds = stringToSeconds(stime)
seconds
totalTime = totalTime + seconds
if (seconds > 0) {
secondsToString(totalTime)
minsec = Math.min(minsec, seconds)
maxsec = Math.max(maxsec, seconds)
count = count + 1
} 

if (count > 0) {
return showTime((maxsec) - (minsec));
} 

}

function secToMins(sec) {
return sec/60.0
}

function secToHours(sec) {
return sec/3600.0
}

function minsToSec(mn) {
return mn*60.0
}

function hoursToSec(hr) {
return hr*3600.0
}

