﻿// var ModalPopupExtenderSession - is a variable that is set up in ModalSessionReminderPopup.ascx.cs - is a reference to the ModalPopupExtenderSession ModalPopupExtender ClientId
// var ModalPopupExtenderSession - is a variable that is set up in ModalSessionReminderPopup.ascx.cs - is a reference to the ModalPopupExtenderSession ModalPopupExtender ClientId



// Session Reminder Popup Methods
function showUserMessage(_mins, _secs) {
    $find(ModalPopupExtenderSession).show(); // show modal session reminder popup
    dc(_mins.toString(), _secs.toString()); // start visual countdown
}

function hideUserMessage() {
    $find(ModalPopupExtenderSession).hide();
}


// Client Visual Count-Down Methods ====================================================================
var mins
var secs;

function dc(_mins, _secs){
    mins = 1 * m(_mins);
    secs = 0 + s(":" + _secs);
    redo();
}

function m(obj){
    for (var i = 0; i < obj.length; i++) {
        if (obj.substring(i, i + 1) == ":") {
            break;
        }
    }
    return (obj.substring(0, i));
}

function s(obj){
    for (var i = 0; i < obj.length; i++) {
        if (obj.substring(i, i + 1) == ":") {
            break;
        }
    }
    return (obj.substring(i + 1, obj.length));
}

function dis(mins, secs){
    var disp;

    if (mins <= 9) {
        disp = " 0";
    } else {
        disp = " ";
    }

    disp += mins + ":";

    if (secs <= 9) {
        disp += "0" + secs;
    } else {
        disp += secs;
    }

    return (disp);
}

function redo(){
    secs--;

    if (secs == -1) {
        secs = 59;
        mins--;
    }

    // checkW3C DOM, then MSIE 4, then NN 4.
    var item;
    if (document.getElementById && document.getElementById('txtCountDown')) {
        item = document.getElementById('txtCountDown');
    } else if (document.all && document.all('txtCountDown')) {
        item = document.all('txtCountDown');
    } else if (document.layers && document.layers['txtCountDown']) {
        item = document.layers['txtCountDown'];
    }

    // update diplayed value
    item.value = dis(mins, secs);

    if ((mins == 0) && (secs == 0)) {
        // do not take action based on the end of this timer. 
        // This is handled by the generated script in ModalSessionReminderPopup.ascx.cs
    } else {
        cd = setTimeout("redo()", 1000);
    }
}

