<html>
<head>
<title>Herbal's Timecard Calculator</title>
<body bgcolor=#FFFFFF onLoad="document.hours.from1.focus()">
<script language="Javascript">
<!--
var colon=":";
// sumrhr() figures out all the hours worked for all days
function sumrhr()
{
calchours(document.forms["hours"].elements["from1"], document.forms["hours"].elements["to1"], document.forms["hours"].elements["total1"]);
calchours(document.forms["hours"].elements["from2"], document.forms["hours"].elements["to2"], document.forms["hours"].elements["total2"]);
calchours(document.forms["hours"].elements["from3"], document.forms["hours"].elements["to3"], document.forms["hours"].elements["total3"]);
calchours(document.forms["hours"].elements["from4"], document.forms["hours"].elements["to4"], document.forms["hours"].elements["total4"]);
calchours(document.forms["hours"].elements["from5"], document.forms["hours"].elements["to5"], document.forms["hours"].elements["total5"]);
calchours(document.forms["hours"].elements["from6"], document.forms["hours"].elements["to6"], document.forms["hours"].elements["total6"]);
calchours(document.forms["hours"].elements["from7"], document.forms["hours"].elements["to7"], document.forms["hours"].elements["total7"]);
calchours(document.forms["hours"].elements["from1b"], document.forms["hours"].elements["to1b"], document.forms["hours"].elements["total1b"]);
calchours(document.forms["hours"].elements["from2b"], document.forms["hours"].elements["to2b"], document.forms["hours"].elements["total2b"]);
calchours(document.forms["hours"].elements["from3b"], document.forms["hours"].elements["to3b"], document.forms["hours"].elements["total3b"]);
calchours(document.forms["hours"].elements["from4b"], document.forms["hours"].elements["to4b"], document.forms["hours"].elements["total4b"]);
calchours(document.forms["hours"].elements["from5b"], document.forms["hours"].elements["to5b"], document.forms["hours"].elements["total5b"]);
calchours(document.forms["hours"].elements["from6b"], document.forms["hours"].elements["to6b"], document.forms["hours"].elements["total6b"]);
calchours(document.forms["hours"].elements["from7b"], document.forms["hours"].elements["to7b"], document.forms["hours"].elements["total7b"]);
}
// calchours() does all the time math
function calchours(intime, outtime, dest)
{
inarray = intime.value.split(colon);
inhour = Number(inarray[0]);
inmin = Number(inarray[1]);
outarray = outtime.value.split(colon);
outhour = Number(outarray[0]);
outmin = Number(outarray[1]);
// Adjust for the case where no minutes are given
if (isNaN(inmin)) {
inmin = 00;
}
if (isNaN(outmin)) {
outmin = 00;
}
if (isNaN(inhour)) {
inhour = 00;
}
if (isNaN(outhour)) {
outhour = 00;
}
// Special time-math limitations
if (outmin < inmin) {
outmin = outmin + 60;
outhour = outhour - 1;
}
if (outhour < inhour) {
outhour = outhour + 12;
}
var totalhour = outhour - inhour;
var totalmin = outmin - inmin;
/*
// Take 0 minute fields out
if (totalmin == 0) {
dest.value = totalhour;
} else {
dest.value = totalhour + colon + convert(totalmin);
}
*/
dest.value = totalhour + convert(totalmin);
}
// convert() changes the minutes from 0-59 to 0-98
function convert(min)
{
return (min / 60).toFixed(2);
}
// sumot() figures out all overtime for all days
function sumot()
{
overtime(document.forms["hours"].elements["total1"], document.forms["hours"].elements["total1ot)"];
overtime(document.forms["hours"].elements["total2"], document.forms["hours"].elements["total2ot)"];
overtime(document.forms["hours"].elements["total3"], document.forms["hours"].elements["total3ot)"];
overtime(document.forms["hours"].elements["total4"], document.forms["hours"].elements["total4ot)"];
overtime(document.forms["hours"].elements["total5"], document.forms["hours"].elements["total5ot)"];
overtime(document.forms["hours"].elements["total6"], document.forms["hours"].elements["total6ot)"];
overtime(document.forms["hours"].elements["total7"], document.forms["hours"].elements["total7ot)"];
overtime(document.forms["hours"].elements["total1b"], document.forms["hours"].elements["total1otb)"];
overtime(document.forms["hours"].elements["total2b"], document.forms["hours"].elements["total2otb)"];
overtime(document.forms["hours"].elements["total3b"], document.forms["hours"].elements["total3otb)"];
overtime(document.forms["hours"].elements["total4b"], document.forms["hours"].elements["total4otb)"];
overtime(document.forms["hours"].elements["total5b"], document.forms["hours"].elements["total5otb)"];
overtime(document.forms["hours"].elements["total6b"], document.forms["hours"].elements["total6otb)"];
overtime(document.forms["hours"].elements["total7b"], document.forms["hours"].elements["total7otb)"];
}
// overtime() figures out the overtime done in a day
function overtime(rtime, dest)
{
rtime = rtime.value
if (rtime <= 8)
dest.value = 0
else
dest.value = (rtime - 8)
}
// totalregtime() figures out all the regular hours all days
function totalregtime()
{
regtime(document.forms["hours"].elements["total1"], document.forms["hours"].elements["total1)"];
regtime(document.forms["hours"].elements["total2"], document.forms["hours"].elements["total2)"];
regtime(document.forms["hours"].elements["total3"], document.forms["hours"].elements["total3)"];
regtime(document.forms["hours"].elements["total4"], document.forms["hours"].elements["total4)"];
regtime(document.forms["hours"].elements["total5"], document.forms["hours"].elements["total5)"];
regtime(document.forms["hours"].elements["total6"], document.forms["hours"].elements["total6)"];
regtime(document.forms["hours"].elements["total7"], document.forms["hours"].elements["total7)"];
regtime(document.forms["hours"].elements["total1b"], document.forms["hours"].elements["total1b)"];
regtime(document.forms["hours"].elements["total2b"], document.forms["hours"].elements["total2b)"];
regtime(document.forms["hours"].elements["total3b"], document.forms["hours"].elements["total3b)"];
regtime(document.forms["hours"].elements["total4b"], document.forms["hours"].elements["total4b)"];
regtime(document.forms["hours"].elements["total5b"], document.forms["hours"].elements["total5b)"];
regtime(document.forms["hours"].elements["total6b"], document.forms["hours"].elements["total6b)"];
regtime(document.forms["hours"].elements["total7b"], document.forms["hours"].elements["total7b)"];
}
// regtime() keeps regular hours <=8
function regtime(regtime, dest)
{
regtime = regtime.value
if (regtime <= 8)
dest.value = regtime
else
dest.value = 8
}
// totweek() provides the variables for add()
function totweek()
{
add(document.forms["hours"].elements["total1"],
document.forms["hours"].elements["total2"],
document.forms["hours"].elements["total3"],
document.forms["hours"].elements["total4"],
document.forms["hours"].elements["total5"],
document.forms["hours"].elements["total6"],
document.forms["hours"].elements["total7"],
document.forms["hours"].elements["reg1"]);
add(document.forms["hours"].elements["total1ot"],
document.forms["hours"].elements["total2ot"],
document.forms["hours"].elements["total3ot"],
document.forms["hours"].elements["total4ot"],
document.forms["hours"].elements["total5ot"],
document.forms["hours"].elements["total6ot"],
document.forms["hours"].elements["total7ot"],
document.forms["hours"].elements["ot1"]);
add(document.forms["hours"].elements["total1b"],
document.forms["hours"].elements["total2b"],
document.forms["hours"].elements["total3b"],
document.forms["hours"].elements["total4b"],
document.forms["hours"].elements["total5b"],
document.forms["hours"].elements["total6b"],
document.forms["hours"].elements["total7b"],
document.forms["hours"].elements["reg2"]);
add(document.forms["hours"].elements["total1otb"],
document.forms["hours"].elements["total2otb"],
document.forms["hours"].elements["total3otb"],
document.forms["hours"].elements["total4otb"],
document.forms["hours"].elements["total5otb"],
document.forms["hours"].elements["total6otb"],
document.forms["hours"].elements["total7otb"],
document.forms["hours"].elements["ot2"]);
}
// add() adds up all the time in a column
function add(box1, box2, box3, box4, box5, box6, box7, dest)
{
dest.value = ((box1.value * 1) + (box2.value * 1) + (box3.value * 1) + (box4.value * 1) + (box5.value * 1) + (box6.value * 1) + (box7.value * 1))
}
// weekot() keeps all hours >40 as ot from reg
function weekot()
{
totot(document.forms["hours"].elements["reg1"], document.forms["hours"].elements["ot1"], document.forms["hours"].elements["ot1"]);
totot(document.forms["hours"].elements["reg2"], document.forms["hours"].elements["ot2"], document.forms["hours"].elements["ot2"]);
totreg(document.forms["hours"].elements["reg1"], document.forms["hours"].elements["reg1"]);
totreg(document.forms["hours"].elements["reg2"], document.forms["hours"].elements["reg2"]);
}
// totot() kicks reg 40< into ot
function totot(rtime, otime, dest)
{
rtime2 = rtime.value
otime2 = otime.value
if (rtime2 <=40)
dest.value = otime2
else
dest.value = (rtime2 + otime2 - 40)
}
// totreg() keeps reg total <=40
function totreg(reg, dest)
{
reg = reg.value
if (reg <= 40)
dest.value = reg
else
dest.value = 40
}
// final() adds up Weeks 1 & 2
function final()
{
totalsheethr(document.forms["hours"].elements["reg1"], document.forms["hours"].elements["reg2"], document.forms["hours"].elements["regtot"]);
totalsheethr(document.forms["hours"].elements["ot1"], document.forms["hours"].elements["ot2"], document.forms["hours"].elements["ottot"]);
}
// totalsheethr() adds up weeks 1 & 2 hours
function totalsheethr(var1, var2, dest)
{
var1 = var1.value
var2 = var2.value
dest.value = (var1 + var2)
}
//total() does all the math functions in order to figure out time
function total()
{
sumrhr();
sumot();
totalregtime();
totweek();
weekot();
totreg();
final();
}
-->
</script>
</head>
<form name=hours>
<table border=1 cellspacing=1>
<tr bgcolor=#54C571>
<td colspan=4 align=Center><b>Week 1</b></td></tr>
<tr bgcolor=#8CC4A8>
<td><b>From:</b></td>
<td><b>To:</b></td>
<td><b>Regular:</b></td>
<td><b>Overtime:</b></td>
</tr>
<tr bgcolor=#70A8A8>
<td><input type=text size=6 name=from1></td>
<td><input type=text size=6 name=to1></td>
<td><input type=text size=6 name=total1></td>
<td><input type=text size=6 name=total1ot></td>
</tr>
<tr bgcolor=#8CC4A8>
<td><input type=text size=6 name=from2</td>
<td><input type=text size=6 name=to2></td>
<td><input type=text size=6 name=total2></td>
<td><input type=text size=6 name=total2ot></td>
</tr>
<tr bgcolor=#70A8A8>
<td><input type=text size=6 name=from3></td>
<td><input type=text size=6 name=to3></td>
<td><input type=text size=6 name=total3></td>
<td><input type=text size=6 name=total3ot></td>
</tr>
<tr bgcolor=#8CC4A8>
<td><input type=text size=6 name=from4></td>
<td><input type=text size=6 name=to4></td>
<td><input type=text size=6 name=total4></td>
<td><input type=text size=6 name=total4ot></td>
</tr>
<tr bgcolor=#70A8A8>
<td><input type=text size=6 name=from5></td>
<td><input type=text size=6 name=to5></td>
<td><input type=text size=6 name=total5></td>
<td><input type=text size=6 name=total5ot></td>
</tr>
<tr bgcolor=#8CC4A8>
<td><input type=text size=6 name=from6></td>
<td><input type=text size=6 name=to6></td>
<td><input type=text size=6 name=total6></td>
<td><input type=text size=6 name=total6ot></td>
</tr>
<tr bgcolor=#70A8A8>
<td><input type=text size=6 name=from7></td>
<td><input type=text size=6 name=to7></td>
<td><input type=text size=6 name=total7></td>
<td><input type=text size=6 name=total7ot></td>
</tr>
</table>
<p>
<p>
<table border=1 cellspacing=1>
<tr bgcolor=#54C571>
<td colspan=4 align=Center><b>Week 2</b></td></tr>
<tr bgcolor=#8CC4A8>
<td><b>From:</b></td>
<td><b>To:</b></td>
<td><b>Regular:</b></td>
<td><b>Overtime:</b></td>
</tr>
<tr bgcolor=#70A8A8>
<td><input type=text size=6 name=from1b></td>
<td><input type=text size=6 name=to1b></td>
<td><input type=text size=6 name=total1b></td>
<td><input type=text size=6 name=total1otb></td>
</tr>
<tr bgcolor=#8CC4A8>
<td><input type=text size=6 name=from2b></td>
<td><input type=text size=6 name=to2b></td>
<td><input type=text size=6 name=total2b></td>
<td><input type=text size=6 name=total2otb></td>
</tr>
<tr bgcolor=#70A8A8>
<td><input type=text size=6 name=from3b</td>
<td><input type=text size=6 name=to3b></td>
<td><input type=text size=6 name=total3b></td>
<td><input type=text size=6 name=total3otb></td>
</tr>
<tr bgcolor=#8CC4A8>
<td><input type=text size=6 name=from4b</td>
<td><input type=text size=6 name=to4b></td>
<td><input type=text size=6 name=total4b></td>
<td><input type=text size=6 name=total4otb></td>
</tr>
<tr bgcolor=#70A8A8>
<td><input type=text size=6 name=from5b></td>
<td><input type=text size=6 name=to5b></td>
<td><input type=text size=6 name=total5b></td>
<td><input type=text size=6 name=total5otb></td>
</tr>
<tr bgcolor=#8CC4A8>
<td><input type=text size=6 name=from6b></td>
<td><input type=text size=6 name=to6b></td>
<td><input type=text size=6 name=total6b></td>
<td><input type=text size=6 name=total6otb></td>
</tr>
<tr bgcolor=#70A8A8>
<td><input type=text size=6 name=from7b></td>
<td><input type=text size=6 name=to7b></td>
<td><input type=text size=6 name=total7b></td>
<td><input type=text size=6 name=total7otb></td>
</tr>
</table>
<p>
<p>
<td valign=top width=500>
<table>
<tr bgcolor=#54C571>
<td><b>Totals</b></td>
<td><b>Regular:</b></td>
<td><b>Overtime:</b></td>
</tr>
<tr bgcolor=#8CC4A8>
<td><b>Week 1:</b></td>
<td><input type=text size=6 name=reg1></td>
<td><input type=text size=6 name=ot1></td>
</tr>
<tr bgcolor=#70A8A8>
<td><b>Week2:</b></td>
<td><input type=text size=6 name=reg2></td>
<td><input type=text size=6 name=ot2></td>
</tr>
<tr bgcolor=#8CC4A8>
<td><b>Total:</b></td>
<td><input type=text size=6 name=regtot></td>
<td><input type=text size=6 name=ottot></td>
</tr>
</table>
<p>
<p>
<input type="button" value="Total Hours" onclick="total()"/>
<input type=reset name="Clear form" onClick="document.hours.from1.focus()"/>
</form>
</body>
</html>