<div id="time" style="display:none">Осталось времени: <span></span></div>
var init, inis;
document.onmousemove = onInit;
document.onkeydown = onInit;
function onInit()
{
var a = document.getElementById('time'), b = 5, c = a.getElementsByTagName('span')[0]
a.style.display = 'none';
if(init)
{
clearTimeout(init);
if(inis) clearInterval(inis);
init = 0;
inis = 0;
}
init = setTimeout(function()
{
a.style.display = '';
inis = setInterval(function()
{
c.innerHTML = b;
b--;
if(b < 0) document.location = 'test.php';
}, 1000);
}, 5000);
}