var secs
var timerID = null
var timerRunning = false
var newLocation = ""


function InitializeTimer(wait)
{
    // Set the length of the timer, in seconds
    secs = wait
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
        window.location.replace(newLocation)
    }
    else
    {
        self.status = "Redirection in " + secs + " seconds"
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", 1000)
    }
}

function redirect(wait, newurl)
{
  // wait <wait> seconds, then redirect browser window to <newurl>
  InitializeTimer(wait)
  newLocation = newurl
  StartTheTimer()
}


