//configure refresh interval (in seconds)
var iCountDownInterval = 15;
var iCountDownTime = iCountDownInterval + 1;
var autoRefresh = false;
var bRefresh = true;

function CountDown()
{
    if (bRefresh)
    {
        iCountDownTime--;
        if (iCountDownTime <= 0)
        {
            iCountDownTime = iCountDownInterval;
            clearTimeout(iCounter);
            window.location.reload();
            return;
        }
        
        if (document.all) //if IE 4+
            document.all.countDownText.innerText = iCountDownTime + " ";
        else if (document.getElementById) //else if NS6+
            document.getElementById("countDownText").innerHTML = iCountDownTime + " ";
        
        iCounter = setTimeout("CountDown()", 1000);
    }
}

function StopRefresh()
{
    bRefresh = false;
    createCookie("vkpirefresh", 0);
    ctl00_CellRefresh.innerHTML = "<a href='javascript:window.location.reload()'>Refresh</a> stopped <a href='javascript:StartRefresh();'>(Start)</a>";
}

function StartRefresh()
{
    bRefresh = true;
    createCookie("vkpirefresh", 1);
    ctl00_CellRefresh.innerHTML = "<a href='javascript:window.location.reload()'>Refresh</a> in <b id='countDownText'>" + iCountDownTime + "</b> seconds <a href='javascript:StopRefresh();'>(Stop)</a>";
    CountDown()
}

function StartIt()
{
    iCountDownInterval = parseInt(ctl00_hdCount.value); 
    iCountDownTime = iCountDownInterval + 1;
    
    if (parseInt(ctl00_hdAutoStartRefresh.value) == 1)
    {
        autoRefresh = true;
    }
    
    var refreshCookie = readCookie("vkpirefresh");
    
    if (iCountDownInterval > 0)
    {
        if (refreshCookie == "1" || (refreshCookie == null && autoRefresh))
        {
            ctl00_CellRefresh.innerHTML = "<a href='javascript:window.location.reload()'>Refresh</a> in <b id='countDownText'>" + iCountDownTime + "</b> seconds <a href='javascript:StopRefresh();'>(Stop)</a>";
            CountDown()
        }
        else
        {
            ctl00_CellRefresh.innerHTML = "<a href='javascript:window.location.reload()'>Refresh</a> stopped <a href='javascript:StartRefresh();'>(Start)</a>";
        }
    }
    try {
        if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
            window.scrollTo(0, 1);
        }
    }
    catch (err) { }
    
}