Stopwatch
http://knowpapa.com/js-stopwatch/
by Adam Calihman
HTML
<input class="stopwatch" id="stopwatch" type="text" value="0:0:0"><br>
<input class="button" id="startandstopbutton" type="button" value="Start/Stop" onclick="startandstop();"><br>
<input class="button" id="marklapbutton" type="button" value="Split/Mark Lap" onclick="marklap();"><br>
<input class="button" id="resetbutton" type="button" value="Reset Stopwatch" onclick="resetstopwatch();"><br>
<textarea class="lap" id="lapdetails"></textarea>
CSS
.stopwatch { color: red; padding: 5px; border:none; width: 220px; margin:15px 0; float:center; }
.lap { color: red; padding: 1px; border:none; height:75%; width: 220px; margin:15px 0;}
.button { width: 220px; margin:2px; }
JavaScript
var stopwatch;
var runningstate = 0; // 1 means the timecounter is running 0 means counter stopped
var stoptime = 0;
var lapcounter = 0;
var currenttime;
var lapdate = '';
var lapdetails;
function timecounter(starttime)
{
currentdate = new Date();
lapdetails = document.getElementById('lapdetails');
stopwatch = document.getElementById('stopwatch');
var timediff = currentdate.getTime() - starttime;
if(runningstate == 0)
{
timediff = timediff + stoptime
}
if(runningstate == 1)
{
stopwatch.value = formattedtime(timediff);
refresh = setTimeout('timecounter(' + starttime + ');',10);
}
else
{
window.clearTimeout(refresh);
stoptime = timediff;
}
}
function marklap()
{
if(runningstate == 1)
{
if(lapdate != '')
{
var lapold = lapdate.split(':');
var lapnow = stopwatch.value.split(':');
var lapcount = new Array();
var x = 0
for(x; x < lapold.length; x++)
{
lapcount[x] = new Array();
lapcount[x][0] = lapold[x]*1;
lapcount[x][1] = lapnow[x]*1;
}
if(lapcount[1][1] < lapcount[1][0])
{
lapcount[1][1] += 60;
lapcount[0][1] -= 1;
}
if(lapcount[2][1] < lapcount[2][0])
{
lapcount[2][1] += 10;
lapcount[1][1] -= 1;
}
var mzeros = (lapcount[0][1] - lapcount[0][0]) < 10?'0':'';
var szeros = (lapcount[1][1] - lapcount[1][0]) < 10?'0':'';
lapdetails.value += '\t+' + mzeros + (lapcount[0][1] - lapcount[0][0]) + ':'
+ szeros + (lapcount[1][1] -...