var stime, ntime;
var min, sec, cen, xmin, xsec, xcen;
var fStart, active, interval , fStop;
xmin=0; xsec=0; xcen=0; fStop=1;
function timerstart(){
 if (fStop==1) {
    fStart=new Date();
    stime=fStart.getTime()-(xmin*60000+xsec*1000+xcen*10);
    count();
    fStop=0;
  }
 }
function count() {
 interval=setTimeout("count()",10);
 active=new Date();
 ntime=active.getTime();
 min=Math.floor((ntime-stime)/60000);
 sec=Math.floor(((ntime-stime)%60000)/1000);
 cen=Math.floor((((ntime-stime)%60000)%1000)/10);
 document.timer.m.value=min;
 document.timer.s.value=sec;
 document.timer.c.value=cen;
 }
function timerstop(x) {
 clearTimeout(interval);
 xmin=eval(x.m.value);
 xsec=eval(x.s.value);
 xcen=eval(x.c.value);
 fStop=1;
 }
function timerclear() {
 clearTimeout(interval);
 xmin=0; xsec=0; xcen=0;
 document.timer.m.value="0";
 document.timer.s.value="0";
 document.timer.c.value="0";
 fStop=1;
 }
window.onload=timerclear;

document.write("<ul><li>ボタンが押されている間、ストップウォッチが作動します</li><li>ボタンからフォーカスが失われると計測がそこで止まります</li></ul><form name=\"timer\">");
document.write("<p><input type=\"button\" value=\"Start&amp;Stop\"");
document.write(" onmousedown=\"timerstart()\" onmouseup=\"timerstop(this.form)\" />");
document.write("</p><p>");
document.write("<input name=\"m\" value=\"0\" style=\"font-size:300%; width:2.1em; text-align:center;\" />分");
document.write("\n<input name=\"s\" value=\"0\" style=\"font-size:300%; width:2.1em; text-align:center;\" />秒");
document.write("\n<input name=\"c\" value=\"0\" style=\"font-size:300%; width:2.1em; text-align:center;\" />");
document.write("</p>");
document.write("</form>");
