﻿var SessionCountdownSeconds = 31200;
function SessionTimeoutCountdown() {
    m = Math.floor(SessionCountdownSeconds / 60);
    s = SessionCountdownSeconds % 60;

    if (s < 10) { s = "0" + s; }

    if ((m == 0) && (s == 0)) {
        SessionExpired();
    }
    else {
        if (m < 2) {
            ShowSessionAboutToExpire();

            document.getElementById("ctl00_uxCounterLbl").innerHTML = m + ":" + s;

        }

        window.setTimeout('SessionTimeoutCountdown();', 1000);
    }

    SessionCountdownSeconds--;
}

function SessionExpired() {
    var url = document.location.href;

    if (url.indexOf('?') > -1) {
        if (url.indexOf('R=1') == -1) {
            window.location = GetRootURL() + "Common/Public/Logout.aspx?ReturnUrl=" + encodeURIComponent(document.location.href) + "&R=1";
        }
        else {
            window.location = GetRootURL() + "Common/Public/Logout.aspx?ReturnUrl=" + encodeURIComponent(document.location.href);
        }
    }
    else {
        window.location = GetRootURL() + "Common/Public/Logout.aspx?ReturnUrl=" + encodeURIComponent(document.location.href) + "&R=1";
    }
}

function ShowSessionAboutToExpire() {
    $find("ctl00_uxSessionExpireMdl").show();
}

function HideSessionExpired() {
    window.location.reload();

    $find("ctl00_uxSessionExpireMdl").hide();
}

function ShowProgressPopup(type) {
    var lbl = eval(document.getElementById("ctl00_uxUpdateProgressCntl_uxMessageLbl"));

    switch (type.toLowerCase()) {
        case "calculate":
            lbl.innerHTML = "Calculating Data";
            break;
        case "clear":
            lbl.innerHTML = "Clearing Data";
            break;
        case "delete":
            lbl.innerHTML = "Deleting Data";
            break;
        case "retrieve":
            lbl.innerHTML = "Retrieving Data";
            break;
        case "save":
            lbl.innerHTML = "Saving Data";
            break;
        case "sendemail":
            lbl.innerHTML = "Sending Email";
            break;
        case "undelete":
            lbl.innerHTML = "Undeleting Data";
            break;
        case "wait":
            lbl.innerHTML = "Please wait";
            break;
        case "upload":
            lbl.innerHTML = "Uploading Document";
            break;
        case "sendpassword":
            lbl.innerHTML = "Sending Password";
            break;
    }

    ShowPopup();
}

function ShowPopup() {
    var popup = $find("ctl00_uxUpdateProgressCntl_uxPopupMdl");

    popup.show();
}

function HidePopup() {
    var popup = $find("ctl00_uxUpdateProgressCntl_uxPopupMdl");

    popup.hide();
}

function ConfirmDeleteWithAJAX() {
    if (confirm("This entry will be deleted.  Are you sure?")) {
        ShowProgressPopup('delete');
        return true;
    }
    else {
        return false;
    }
}

function ConfirmUnDeleteWithAJAX() {
    if (confirm("This entry will be un-deleted.  Are you sure?")) {
        ShowProgressPopup('undelete');
        return true;
    }
    else {
        return false;
    }
}

function CustomConfirmDeleteWithAJAX(customMessage) {
    if (confirm(customMessage)) {
        ShowProgressPopup('delete');
        return true;
    }
    else {
        return false;
    }
}

function CustomConfirmUnDeleteWithAJAX(customMessage) {
    if (confirm(customMessage)) {
        ShowProgressPopup('undelete');
        return true;
    }
    else {
        return false;
    }
}

function BMEVoteConfirmation() {
    if (confirm('ATTENTION!\n\nOnce you cast your vote no changes can be made.  Are you sure you want to cast your vote?')) {
        ShowProgressPopup('wait');
        return true;
    }
    else {
        return false;
    }
}