/* http://www.w3schools.com/jS/tryit.asp?filename=tryjs_timing_clock */
// This function formats numbers by adding commas
function numberFormat(nStr){
  nStr += '';
  x = nStr.split('.');
  x1 = x[0];
  x2 = x.length > 1 ? '.' + x[1] : '';
  var rgx = /(\d+)(\d{3})/;
  while (rgx.test(x1))
    x1 = x1.replace(rgx, '$1' + ',' + '$2');
  return x1 + x2;
}

function startTime()
{
 var today = new Date();
 //var h=today.getHours();
 //var m=today.getMinutes();
 //var s=today.getSeconds();
 // add a zero in front of numbers<10
 //m=checkTime(m);
 //s=checkTime(s);

 var start=new Date(2010, 3, 20, 0, 0, 0, 0);
// var gallonsLeaked = Math.round((today.getTime()/1000 - start.getTime()/1000) * 31.6); 
 var gallonsLeaked = 206000000;
 //document.getElementById('clock').innerHTML=h+":"+m+":"+s;
 //document.clock.face.value=h + ":" + m + ":" + s; 
 document.clock.face.value=numberFormat(gallonsLeaked) + " gallons";
 t=setTimeout('startTime()',1000);
}

window.onload=startTime;

function checkTime(i)
{
 if (i<10)
 {
   i="0" + i;
 }
 return i;
}
