﻿
var __escToAdmin = {
    msgA: "'Are you sure you want to leave this page\nand enter the Admin Section?'",
    msgB: "A Popup blocker might have blocked the new window.\nDo you want to open the Admin in this window?",
    simpleMode: false,
    targetPage: ""
};

var __escToAdmingCount = 0;
var __escToAdmingTO = null;

document.onkeyup = JumpToAdmin;

function JumpToAdmin(e) {
    var KeyID = (window.event) ? event.keyCode : e.keyCode;
    if (KeyID == 27) {

        __escToAdmingCount++;

        if (__escToAdmingCount < 2) {
            __escToAdmingTO = setTimeout(function() {
                __escToAdmingCount = 0;
            }, 250);
            return;
        }
        clearTimeout(__escToAdmingTO);
        __escToAdmingCount = 0;


        // THE FOLLOWING CHECK IS TO AVOID TRAPPING THE ESC KEY WHEN THE USER IS
        // EDITING A FIELD. IF THE USER IS EDITING A FIELD, THE ESC KEY IS THE STANDARD TO
        // CLEAR THE FIELD, THAT'S WHY WE DON'T WANT TO TRAP IT THERE.
        //
        // BUT NOW WE ARE USING DOUBLE ESC KEY. SO THIS LOGIC WOULD NO LONGER BE APPLYING.
        //

        // if (nn != "INPUT" && nn != "TEXTAREA") {
        
        if (__escToAdmin.simpleMode) {
            if (confirm(__escToAdmin.msgA)) {
                var nuWin = window.open("/admin/" + __escToAdmin.targetPage);
                if (nuWin == null) {
                    if (confirm(__escToAdmin.msgB))
                        location.href = "/admin/" + __escToAdmin.targetPage;
                }
            }
        } else {
            jConfirm(__escToAdmin.msgA, 'Jump to Admin', function(r) {
                if (r) {
                    var nuWin = window.open("/admin/" + __escToAdmin.targetPage);
                    if (nuWin == null) {
                        jConfirm(__escToAdmin.msgB, 'Popup Blocked', function(r) {
                            if (r) location.href = "/admin/" + __escToAdmin.targetPage;
                        });

                    }

                }
            });
        }
        
        //}
    }
}

