var timeout_timer;

function initSessionCountdownTimer(iTimeout, bWarning) {  

}

function display() {
    rtime = etime - ctime;
    if (rtime > 60)
        m = parseInt(rtime / 60);
    else {
        m = 0;
    }

    s = parseInt(rtime - m * 60);

    if (s < 10)
        s = "0" + s    
}

function settimes(strSec) {
    var time = new Date();
    hours = time.getHours();
    mins = time.getMinutes();
    secs = time.getSeconds();
    etime = hours * 3600 + mins * 60 + secs;
    etime += parseInt(strSec);  //(420 = 7 λεπτά * 60 δεύτερα)
    //(1200 = 20 λεπτά * 60 δεύτερα)
    etimewarning = hours * 3600 + mins * 60 + secs;
    etimewarning += (parseInt(strSec) * (2 / 3));  //((420 = 7 λεπτά * 60 δεύτερα)/3) = 140    
    timeout_timer = window.setInterval(checktime, 1000);
}

function checktime() {
    var time = new Date();
    hours = time.getHours();
    mins = time.getMinutes();
    secs = time.getSeconds();
    ctime = hours * 3600 + mins * 60 + secs
    
    if (ctime >= etime) {
        expired();
    }
    else if (ctime > etimewarning && warning == false) {        
        warning = true;
        var obj = document.getElementById("CDown");
        obj.className = ("CDiv_Red");
        display();
    }
    else {
        display();
        percent = parseInt(((etime - ctime) * 100) / timeout);
        var obj = document.getElementById("CDown");
        obj.style.width = percent + "%";
        var objtxt = document.getElementById("strCount");        
        objtxt.value = m + ":" + s;
    }
}

function warning() {
    alert("warning");
}

function expired() {   
    fnUserlogoutGeneric(0);
}

function restart() {
    //location.reload();
	document.location.href = document.location.href;
}

function fnForgotPassword(nCase) {
    if (nCase == 1) {
        document.location.href = 'http://www.epicos.com/Portal/Main/Home/Pages/ForgotMyPassword.aspx';
    } else { 
        var oTopRightLoginAction = fnGetDomObjectWithingArea('dvHiddenUserLoginFields', 'hdTopRightLoginAction');
        var oTopRightUserLoginButton = fnGetDomObjectWithingArea('dvHiddenUserLoginFields', 'btnTopRightUserLogin');
        if (oTopRightLoginAction) {
            oTopRightLoginAction.value = 3;
            if (oTopRightUserLoginButton) {
                var bFullPostBack = false;
                if (navigator.appName.toLowerCase() == 'netscape') {
                    var sHomePageUrl = 'http://www.epicos.com/portal/main/home/pages/default.aspx';
                    if (window.location.href.toLowerCase() == sHomePageUrl.toLowerCase()) {
                        bFullPostBack = true;
                    }
                }
                if (bFullPostBack) {
                    document.forms[0].submit();
                }
                else {
                    oTopRightUserLoginButton.click();
                }
            }
        }
    }
}