Hey all... I have been working on creating a game, and have come across a timer issue.

I have this code below, but not sure how to actually get the timer to keep its current countdown upon page refresh. I also need to update the database upon completion of the countdown to zero. I've been told I needed Javascript and possibly ajax, so I'm posting here for any help. I don't know much about javascript or ajax; only php. So if I can find a way to use php for changes in my database, but also have it work with the code I currently have, that would be great as well. Any ideas or any help please?

What I am basically looking for is:

1. Timer does not restart/clear upon page refresh
2. After timer runs to zero, then a field in the database is set to either "yes" or "1" to indicate that they now own the object.
3. After timer runs to zero, have another button show for an upgrade button, and repeat the process after upgrade is done.

Thank you for any and all help. Here is my current code with a working timer.

Code:
<html>
<head>
<script type="text/javascript">
var x=2700;
var m=x/60;
var   h=m/60;
var   m=(h-Math.floor(h))*60;
var s= Math.round((m-Math.floor(m))*60);
var m = Math.floor(m);
var h = Math.floor(h);
if(h<10){
   h = '0'+h;
}
if(m<10){
   m = '0'+m;
}
if(s<10){
   s = '0'+s;
}
var c = h+':'+m+':'+s;
var t;
var timer_is_on=0;

function timedCount()
{
document.getElementById('txt').value=c;
if(x>0){
   x=x-1;
   m=x/60;
   h=m/60;
   m=(h-Math.floor(h))*60;
   s= Math.round((m-Math.floor(m))*60);
   m = Math.floor(m);
   h = Math.floor(h);
   if(h<10){
   h = '0'+h;
   }
   if(m<10){
      m = '0'+m;
   }
   if(s<10){
      s = '0'+s;
   }
   c = h+':'+m+':'+s;
}else{
   c='Ready';
}
t=setTimeout("timedCount()",1000);
}

function doTimer()
{
if (!timer_is_on)
  {
  timer_is_on=1;
  timedCount();
  }
}
</script> 
</head>

<body>
<form>
<input type="button" value="Build" onclick="doTimer()">
<input type="text" id="txt">
</form>
<p>My Example</p>
</body>
</html>