var popUpWin=0;

function popUpWindow(URLStr, left, top, width, height) {
  if(popUpWin) {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

var running = false;
var endTime = null;
var timerID = null;
var totalMinutes = 30;

function startTimer() {
    running = true;
    now = new Date();
    now = now.getTime();
    endTime = now + (1000 * 60 * totalMinutes);
    showCountDown();
}

function showCountDown() {
    var now = new Date();
    now = now.getTime();
    if (endTime - now <= 0) {
       clearTimeout(timerID);
       running = false;
       alert("Die Zeit für den Test ist abgelaufen.");
       document.getElementById('SessionTimeCount').innerHTML = " Zeit abgelaufen";
       window.location.replace("/riskolleg_v2/index.php") ;
    } else {
        var delta = new Date(endTime - now);
        var theMin = delta.getMinutes();
        var theSec = delta.getSeconds();
        var theTime = theMin;
        theTime += ((theSec < 10) ? ":0" : ":") + theSec;
        document.getElementById('SessionTimeCount').innerHTML = "Verbleibende Zeit für den Test<br><b>" + theTime + " Minuten</b>";
        if (running) {
            timerID = setTimeout("showCountDown()",900);
        }
    }
}
