// JavaScript Document
// This JavaScript contains general functions that are used throughout FAAdmin pages

/*****************************************/
/* Change List                           */
/*****************************************/
// ID				Date			Author				Description
// N/A				2013/Mar/04		Jeyong				Moved setCookie and getCookie from general JS page to current JS page
// N/A				2013/Mar/04		Jeyong				Created initPage function to contain all common operation need to be done for all pages.
//														This function is supposed to contain original function being called in settingsApp page:
//                                                      initRedirectMask.
// N/A				2013/Mar/04		Jeyong				Created createRedirectMaskLayer. This function replaces initial function initRedirectMask.
//														The function was re-named to describe what the function actually does.
// N/A				2013/Mar/04		Jeyong				Created showWindow and hideWindow functions. This function replaces showMessage and hideMessage.
//														In the application, there was already a function about show{xxx}Message and hide{xxx}Message,
// 														and the functionality was very different from current function.
// 														In order to better define what the function was about (which is about creating a modal window
// 														on a separate layer), the showWindow name was chosen.
// N/A              2013/JUN/25     Jeyong              Added confirmation window to have custom button text
// 54549420         2013/OCT/02     Jeyong              Collapsed/expanded state of instructions and headings not maintained
// AX-4481.2         Oct 28, 2020   arr   Changes to an iForm can be lost with no warning message - Back button 

/*****************************************/
/* Global Variables                      */
/*****************************************/
var gLayers = new Array();

/*****************************************/
/* Initial functions                     */
/*****************************************/

// Initialize common behaviours for all pages
function initPage() {

}

/*****************************************/
/* General functions                     */
/*****************************************/

// Add additional function call to existing window.onload event listener
// - this function is cross browser compatible with switch between addEventListener and window.attachEvent
function addOnLoad(func) {
    if (window.addEventListener) // W3C standard
        window.addEventListener('load', func, false); // NB **not** 'onload'

    else if (window.attachEvent) // Microsoft
        window.attachEvent('onload', func);
}

// Creates or updates a cookie.
// - this function creates a cookie with session exipry
// - code reference from: http://www.w3schools.com/js/js_cookies.asp
function setCookie(key, value) {

    // "expires=0" does not work in IE, and terminates the cookie immediately
    // got rid of the condition to make cross browser compatible
    // [Original] document.cookie = escape(key) + "=" + escape(value) + "; expires=0; path=/";
    document.cookie = escape(key) + "=" + escape(value) + "; path=/";
}

// Retrieve value stored in a cookie set by setCookie
// - code reference from: http://www.w3schools.com/js/js_cookies.asp
function getCookie(key) {
    var i, x, y, arrCookies = document.cookie.split(";");
    for (i = 0; i < arrCookies.length; i++) {
        x = arrCookies[i].substr(0, arrCookies[i].indexOf("="));
        y = arrCookies[i].substr(arrCookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == key)
            return unescape(y);
    }

    return "";
}

// Get current width and height of a window browser
// - code reference from: http://www.java-samples.com/showtutorial.php?tutorialid=1015
function getBrowserDimension() {
    var intH = 0;
    var intW = 0;

    if (typeof window.innerWidth == 'number') {
        // Non IE
        intH = window.innerHeight;
        intW = window.innerWidth;
    }
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        // IE 6+ in 'standards compliant mode'
        intH = document.documentElement.clientHeight;
        intW = document.documentElement.clientWidth;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        // IE 4 compatible
        intH = document.body.clientHeight;
        intW = document.body.clientWidth;
    }

    return { width: parseInt(intW), height: parseInt(intH) };
}

// Get current width and height of current content
// - Gets maximum dimension of all known method used to retrieve body content size for cross browser compatibility.
function getContentDimension() {
    var winW = Math.max(document.body.scrollWidth, document.body.offsetWidth, document.documentElement.clientWidth, document.documentElement.scrollWidth, document.documentElement.offsetWidth);
    var winH = Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);

    return { width: parseInt(winW), height: parseInt(winH) };
}

// Disable enter when an keypress event is triggered
function disableEnter(e) {
    // disable keyCode 13 - enter
    if (e.which == 13) e.preventDefault();
}

// Set selection to text field
function setSelection(field, start, length) {
    if (field.createTextRange) {
        var selRange = field.createTextRange();
        selRange.collapse(true);
        selRange.moveStart('character', start);
        selRange.moveEnd('character', length);
        selRange.select();
    } else if (field.setSelectionRange) {
        field.setSelectionRange(start, start + length);
    } else if (field.selectionStart) {
        field.selectionStart = start;
        field.selectionEnd = start + length;
    }
    //field.focus();
}

// Get current selection
function getSelection(field) {
    var s = $(this).prop("selectionStart");
    var e = $(this).prop("selectionEnd");

    // IE
    if (s == undefined || e == undefined) {
        if ("selectionStart" in field && document.activeElement == field) {
            return {
                start: field.selectionStart,
                end: field.selectionEnd
            };
        }
        else if (field.createTextRange) {
            var sel = document.selection.createRange();
            if (sel.parentElement() === field) {
                var rng = field.createTextRange();
                rng.moveToBookmark(sel.getBookmark());
                for (var len = 0;
                     rng.compareEndPoints("EndToStart", rng) > 0;
                     rng.moveEnd("character", -1)) {
                    len++;
                }
                rng.setEndPoint("StartToStart", field.createTextRange());
                for (var pos = { start: 0, end: len };
                     rng.compareEndPoints("EndToStart", rng) > 0;
                     rng.moveEnd("character", -1)) {
                    pos.start++;
                    pos.end++;
                }
                return pos;
            }
        }
        return -1;
    }

    return {
        start: s,
        end: e
    };
}

/*****************************************/
/* Layer functions                       */
/*****************************************/

// Disable all content below masked area for current page
// - Creates a layer in current page for all contents (moved from document.body into the new layer)
// - Disables the layer
// - Note that is function needs to be called before creating a separate layer, otherwise, the new layer will also be disabled
function disablePage() {
    //Container ID that holds default content - to be disabled 
    var contentLayerId = "genContentLayer";

    //Disable actions done in container
    var elmt = document.getElementById(contentLayerId);
    if (elmt != null) {
        //Disable tab to prevent user from tabbing to masked fields
        elmt.onkeydown = function () { return false; };
    }
}

// Enable all contents of current page disabled by disablePage function
function enablePage() {
    //Container ID that holds default content - to be enabled 
    var contentLayerId = "genContentLayer";

    //Enable actions done in container
    var elmt = document.getElementById(contentLayerId);
    if (elmt != null) {
        //Remove keyboard restriction
        elmt.onkeydown = function () { return true; };
    }
}

// Function to create layer
function createLayer(id, className, isVisible) {
    var elmt = document.getElementById(id);
    if (elmt)
        return elmt;

    if (gLayers[id] == undefined) {
        //latest entry
        var maxLayer = 0;
        for (var i = 0; i < gLayers.length; i++) {
            if (maxLayer < gLayers[i][1])
                maxLayer = gLayers[i][1];
        }

        gLayers.push([id, maxLayer + 1]);
    }

    //Create div
    var div = document.createElement("div");
    div.className = className;
    div.id = id;
    div.style.display = "none";

    //Add new div to html body
    document.body.appendChild(div);

    //JQuery animation to prevent from page flickering if the loading time is too short
    //If set to visible, the content will fade in with delay of 0.4
    //If set to hidden, the content will be loaded, but hidden initially
    if (isVisible) {
        $("#" + id).fadeIn(400);
    } else {
        $("#" + id).hide();
    }

    return div;
}

// Delete layer with specified id from current page
function deleteLayer(id) {
    var elmt = document.getElementById(id);
    if (elmt)
        document.body.removeChild(elmt);

    var indexToRemove = -1;
    for (var i = 0; i < gLayers.length; i++) {
        if (gLayers[i][0] == id) {
            indexToRemove = i;
        }
    }

    gLayers.splice(indexToRemove, 1);
}

function createContent(containerId, id, className) {
    var elmt = document.getElementById(id);
    if (elmt)
        return elmt;

    //Create div
    var div = document.createElement("div");
    div.id = id;
    div.className = className;

    //Add new div to container
    var container = document.getElementById(containerId);
    if (container != null)
        container.appendChild(div);

    return div;
}

// Create iframe
function createIframe(containerId, id, className, src) {
    var elmt = document.getElementById(id);
    if (elmt)
        return elmt;

    var iframe = document.createElement("iframe");
    iframe.className = className + " PAiFrame";                     // 52498835 Add class PaiFrame to all the frame created by PA to avoid issue using resizeParentIframe function
    iframe.id = id;
    iframe.src = src;
    iframe.title = "frm_" + id;         // AX-18948
    //iframe.scrolling = false; // this does not work in IE

    //Add new iframe to container
    var container = document.getElementById(containerId);
    if (container != null)
        container.appendChild(iframe);

    return iframe;
}

// Create button
function createCloseButton(containerId, id, className) {
    var elmt = document.getElementById(id);
    if (elmt)
        return elmt;

    var btn = document.createElement("a");
    btn.id = id;
    btn.className = className;
    btn.innerHTML = "&nbsp;";
    btn.title = "Close";

    //Add new button to container
    var container = document.getElementById(containerId);
    if (container != null)
        container.appendChild(btn);

    return btn;
}

// Create Span
function createSpan(containerId, id, className, text) {
    var elmt = document.getElementById(id);
    if (elmt)
        return elmt;

    var span = document.createElement("span");
    span.id = id;
    span.className = className;
    span.innerHTML = text;

    //Add new span to container
    var container = document.getElementById(containerId);
    if (container != null)
        container.appendChild(span);

    return span;
}

// Create checkbox (input type = "chekbox")
function createCheckbox(containerId, id, className, value) {
    var elmt = document.getElementById(id);
    if (elmt)
        return elmt;

    var chkBox = document.createElement("input");
    chkBox.type = "checkbox";
    chkBox.id = id;
    chkBox.className = className;
    chkBox.value = value;

    //Add new span to container
    var container = document.getElementById(containerId);
    if (container != null)
        container.appendChild(chkBox);

    return chkBox;
}

// Function to resize indicated layer:
// - maximum size of current browser/content dimension
function resizeLayer(id) {
    var elmt = document.getElementById(id);
    if (elmt) {
        var bws = getBrowserDimension();
        var con = getContentDimension();

        elmt.style.width = Math.max(bws.width, con.width) + "px";
        elmt.style.height = Math.max(bws.height, con.height) + "px";
    }
}

// Function to get current layer index
function getLayerIndex(id) {
    for (var i = 0; i < gLayers.length; i++) {
        if (gLayers[i][0] == id) {
            return gLayers[i][1];
        }
    }

    return 0;
}

//Popup windows
function createConfirmWindow(title, message, cancelButtonText, okButtonText, action) {
    var dialogWindow = "confirmWindow";

    if ($("#" + dialogWindow).length == 0) {
        var div = document.createElement("div");
        div.id = dialogWindow;
        document.body.appendChild(div);
    }

    $("#" + dialogWindow).html(message);
    $("#" + dialogWindow).dialog({
        dialogClass: dialogWindow,
        title: title,
        autoOpen: true, // set this to false so we can manually open it
        closeOnEscape: false,
        draggable: false,
        resizable: false,
        width: 460,
        minHeight: 50,
        modal: true, // defines current window to be modal (disables all previous layers)
        position: { my: "center", at: "top+30%", of: window },  // AX-24898.24919.4 ['middle', 70],
        buttons:
        [
            {
                text: (cancelButtonText == "" || cancelButtonText == null) ? "Cancel" : cancelButtonText,
                "class": "normalBtn",
                click: function () {
                    $(this).dialog("close");
                }
            },
            {
                text: (okButtonText == "" || okButtonText == null) ? "OK" : okButtonText,
                "class": "mainBtn",
                click: function () {
                    $(this).dialog("close");
                    if (action != null)
                        action();
                }
            }
        ],
        open: function () {
            $('*:focus').trigger('blur');					// AX-24898.24919.2 .blur();

            // IE fix for scroll bar issue
            // ---
            // May 17, 2013 - could not produce issue with the scroll bar on IE 9 + compatibility mode
            // We found an issue with dropdown list appearing in offset position after opening/closing a modal window.
            // ---
            // This can be reproduced with:
            // 1. Partially scroll a page in FireFox 20.0
            // 2. Trigger open a modal window
            // 3. Close the modal window
            // 4. Select a dropdown list (IMPORTANT: do not scroll after closing the modal window )
            // OBSERVE: the list selction panel is displayed in incorrect location
            // ---
            // $('body').css('overflow', 'hidden');

           $('.ui-widget-overlay').css('width', '100%');
           $('.ui-widget-overlay').css('height', '100%');      // AX-24898.24919.4
           $('.ui-widget-overlay').css('z-index', '1010');     // AX-24898.24919.4
           $("." + dialogWindow).css('z-index', '1020');       // AX-24898.24919.4
           $('.ui-dialog-titlebar-close').hide();              // AX-24898.24919.4
        },
        close: function () {

            // Pairing operation for IE scroll bar issue
            // ---
            // May 17, 2013 - Error found in FireFox 20.0 with dropdown list
            // modal window will no longer trigger a scroll lock
            // ---
            // $('body').css('overflow', 'auto');
        }
    });
}

function createWarningWindow(title, message, cancelButtonText, okButtonText, action) {
    var dialogWindow = "confirmWindow";

    var icon = "<span class=\"warning\">&nbsp;</span>";

    if ($("#" + dialogWindow).length == 0) {
        var div = document.createElement("div");
        div.id = dialogWindow;
        document.body.appendChild(div);
    }

    $("#" + dialogWindow).html(message);
    $("#" + dialogWindow).dialog({
        dialogClass: dialogWindow,
        title: icon + title,
        autoOpen: true, // set this to false so we can manually open it
        closeOnEscape: false,
        draggable: false,
        resizable: false,
        width: 460,
        minHeight: 50,
        modal: true, // defines current window to be modal (disables all previous layers)
        position: { my: "center", at: "top+20%", of: window },  // AX-24898.24919.4 ['middle', 70],
        buttons:
        [
            {
                text: (cancelButtonText == "" || cancelButtonText == null) ? "Cancel" : cancelButtonText,
                "class": "normalBtn",
                click: function () {
                    $(this).dialog("close");
                }
            },
            {
                text: (okButtonText == "" || okButtonText == null) ? "OK" : okButtonText,
                "class": "mainBtn",
                click: function () {
                    $(this).dialog("close");
                    if (action != null)
                        action();
                }
            }
        ],
        open: function () {
            $('*:focus').trigger('blur');					// AX-24898.24919.2 .blur();
            $('.ui-widget-overlay').css('width', '100%');
            $('.ui-widget-overlay').css('height', '100%');      // AX-24898.24919.4
            $('.ui-widget-overlay').css('z-index', '1010');     // AX-24898.24919.4
            $("." + dialogWindow).css('z-index', '1020');       // AX-24898.24919.4
            $('.ui-dialog-titlebar-close').hide();              // AX-24898.24919.4
        },
        close: function () { }
    });
}

function createErrorWindow(title, message, action) {
    var dialogWindow = "errorWindow";

    if ($("#" + dialogWindow).length == 0) {
        var div = document.createElement("div");
        div.id = dialogWindow;
        document.body.appendChild(div);
    }

    $("#" + dialogWindow).html(message);
    $("#" + dialogWindow).dialog({
        dialogClass: dialogWindow,
        title: title,
        autoOpen: true, // set this to false so we can manually open it
        closeOnEscape: false,
        draggable: false,
        resizable: false,
        width: 460,
        minHeight: 50,
        modal: true, // defines current window to be modal (disables all previous layers)
        position: { my: "center", at:"top+20%", of: window },  // AX-24898.24919.4 ['middle', 70],
        buttons:
        [
            {
                text: "OK",
                "class": "mainBtn",
                click: function () {
                    $(this).dialog('close');
                }
            }
        ],
        open: function () {
           $('*:focus').trigger('blur');					// AX-24898.24919.2 .blur();

            // IE fix for scroll bar issue
            // ---
            // May 17, 2013 - could not produce issue with the scroll bar on IE 9 + compatibility mode
            // We found an issue with dropdown list appearing in offset position after opening/closing a modal window.
            // ---
            // This can be reproduced with:
            // 1. Partially scroll a page in FireFox 20.0
            // 2. Trigger open a modal window
            // 3. Close the modal window
            // 4. Select a dropdown list (IMPORTANT: do not scroll after closing the modal window )
            // OBSERVE: the list selction panel is displayed in incorrect location
            // ---
            // $('body').css('overflow', 'hidden');

           $('.ui-widget-overlay').css('width', '100%');
           $('.ui-widget-overlay').css('height', '100%');      // AX-24898.24919.4
           $('.ui-widget-overlay').css('z-index', '1010');     // AX-24898.24919.4
           $("." + dialogWindow).css('z-index', '1020');       // AX-24898.24919.4
           $('.ui-dialog-titlebar-close').hide();              // AX-24898.24919.4
        },
        close: function () {

            // Pairing operation for IE scroll bar issue
            // ---
            // May 17, 2013 - Error found in FireFox 20.0 with dropdown list
            // modal window will no longer trigger a scroll lock
            // ---
            // $('body').css('overflow', 'auto');

            if (action != null)
                action();
        }
    });
}

function createSuccessWindow(title, message) {
    var dialogWindow = "successWindow";

    if ($("#" + dialogWindow).length == 0) {
        var div = document.createElement("div");
        div.id = dialogWindow;
        document.body.appendChild(div);
    }

    $("#" + dialogWindow).html(message);
    $("#" + dialogWindow).dialog({
        dialogClass: dialogWindow,
        title: title,
        autoOpen: true, // set this to false so we can manually open it
        closeOnEscape: false,
        draggable: false,
        resizable: false,
        width: 460,
        minHeight: 50,
        modal: false, // defines current window to be modal (disables all previous layers)
        position: { my: "center", at: "top+20%", of: window }, // AX-24898.24919.4 ['middle', 70],
        buttons:
        [
            {
                text: "OK",
                "class": "mainBtn",
                click: function () {
                    $(this).dialog('close');
                }
            }
        ],
        open: function () {
            $('*:focus').trigger('blur');					// AX-24898.24919.2 .blur();
        },
        close: function () {
        }
    });
}

function isErrorWindowOpened() {
    if ($("#errorWindow:visible").length > 0)
        return true;

    return false;
}

function isConfirmWindowOpened() {
    if ($("#confirmWindow:visible").length > 0)
        return true;

    return false;
}

// AX-4481.2
function isSuccessWindowOpened() {
   if ($("#successWindow:visible").length > 0)
      return true;

   return false;
}

// AX-4481.2
function removeSuccessWindow() {
   $(".successWindow").remove();
}


/*****************************************/
/* Validation functions                  */
/*****************************************/

// Helper function to validate if field is empty or not
function validateRequired(value) {
    if (value == "") {
        return false;
    }

    return true;
}

// Helper function to validate if field exceeds allowed character count
function validateLength(value, maxLength) {
    var lineBreakCount = (value.match(/\n/g) || []).length;
    if (value.length + lineBreakCount > maxLength) {
        return false;
    }

    return true;
}

// Helper function to validate if field contains any character not allowed
function validateText(value) {
    var illegalChars = ["<", ">"];
    if (!isValidFormat(value, null, illegalChars)) {
        return false;
    }

    return true;
}

// Helper function to validate if field contains non-numeric characters
function validateInteger(value) {
    var pattern = /^-?[0-9]*$/;
    if (!pattern.test(value)) {
        return false;
    }

    return true;
}

// Helper function to validate if field is in numeric format (including decimal)
function validateDecimal(value) {
    var pattern = /^-?[0-9]*[.]?[0-9]+$/;
    if (!pattern.test(value)) {
        return false;
    }

    return true;
}

// Helper function to validate if field is a positive number
function validatePositive(value) {
    if (value < 0) {
        return false;
    }

    return true;
}

// Helper function to validate if field contains out of range values
function validateRange(value, begin, end, increment) {
    if (value == "" || undefined === begin || undefined === end || undefined === increment || null === begin || null === end || null === increment) {
        return true;
    }

    value = parseFloat(value);
    begin = parseFloat(begin);
    end = parseFloat(end);
    increment = parseFloat(increment);

    if (begin > end || value > end || value < begin) {
        return false;
    }

    if (Math.abs(Math.round(value * 100) - (value * 100)) >= 0.00000001) {
        return false;
    }

    var n = Math.round(value * 100);
    var min = Math.round(begin * 100);
    var inc = Math.round(increment * 100);

    if ((n - min) % inc == 0)
        return true;

    return false;
}

// Helper function to validate if field contains valid date
// Not yet implemented
// function validateDate() {
// Not yet implemented...
// Refer to settings.js with 2/27/2013 or older for example in: 
// FAAdmin/js/settings.js
// validateEnteringDate - validation of keyCode while entering value
// validateDate - validate field when entered
// getMonthAsNumber - helper function to get month
// isDate - check if value is actually a date
// alert("Not yet implemented");
// return false;
// }

// Helper function to check if input value matches whitelist and blacklist criteria
// whitelist - only character that are allowed for the input (ignored if null)
// blacklist - any character not allowed to be part of the input (ignored if null)
function isValidFormat(value, whitelist, blacklist) {
    // whitelist - only character that are allowed for the value (ignored if null)
    if (whitelist != null) {
        var chars = value.split('');
        for (var i = 0; i < chars.length; i++) {
            if (whitelist.indexOf(chars[i]) == -1)
                return false;
        }
    }

    // blacklist - any character not allowed to be part of the value (ignored if null)
    if (blacklist != null) {
        for (var j = 0; j < blacklist.length; j++) {
            if (value.indexOf(blacklist[j]) != -1)
                return false;
        }
    }

    return true;
}

/// general function to trigger click with id
function clickButtonWithId(id) {
    if ($("#" + id).length > 0)
        $("#" + id).trigger('click');	        // AX-24898.24919.2 $("#" + id).click();
}

/// general function to trigger click with className
function clickButtonWithClassName(className) {
    if ($("." + className).length > 0)
        $("." + className).trigger('click');	        // AX-24898.24919.2 $("." + className).click();
}

// 1stAccess
//-----------------------------------------------------------------------------
$(document).ready(function() {
    window.addEventListener('message', reply, false);

    function reply(e) {

        if (e.data === 'loaded') {
            window.parent.postMessage('loaded', '*');
        }

        if (e.data === 'closeParent') {
            window.parent.postMessage('closeParent', '*');
        }

        if (e.data && typeof e.data === 'object') {
            var iframeEl = $('#loginIfrmId').get(0);
            if (iframeEl) {
                var contentWindow = iframeEl.contentWindow;
                contentWindow.postMessage(e.data, '*');
            }
        }

    }
});

// Ping parent...
$(document).on('active.idleTimer', function () {      // AX-24898.24919.2 $(document).bind('active.idleTimer', function () {
    window.parent.postMessage('ping','*');
});
$(document).ready(function () {
    $(this).on('mousemove keypress', function () {    // AX-24898.24919.2 $(this).bind('mousemove keypress', function () {
        window.parent.postMessage('ping', '*');
    });
});
//-----------------------------------------------------------------------------



// PA Again
// AX-8776 Show spinner in PA
// ----------------------------------------------------------------------------
 
var opts = {
    color: '#428BCA', // #rgb or #rrggbb or array of colors
    lines: 13, // The number of lines to draw
    length: 29, // The length of each line
    width: 8, // The line thickness
    radius: 23, // The radius of the inner circle
    corners: 1, // Corner roundness (0..1)
    rotate: 0, // The rotation offset
    direction: 1, // 1: clockwise, -1: counterclockwise
    speed: 1, // Rounds per second
    trail: 60, // Afterglow percentage
    shadow: false, // Whether to render a shadow
    hwaccel: false, // Whether to use hardware acceleration
    className: 'spinner', // The CSS class to assign to the spinner
    zIndex: 2e9, // The z-index (defaults to 2000000000)
    top: 'auto', // Top position relative to parent in px
    left: 'auto' // Left position relative to parent in px
};
var spinner = new Spinner(opts);
function showSpinner() { //, framework, msg) {
    try {
        var spinnerArea = "spinner";
        var spinnerCenter = "spinner_center";

        if ($("#" + spinnerArea).length === 0) {
            var div = document.createElement("div");
            div.id = spinnerArea;
            var divCenter = document.createElement("div");
            divCenter.id = spinnerCenter;
            div.appendChild(divCenter);
            document.body.appendChild(div);
        }

        var $spinner = $("#" + spinnerArea);
        var $spinner_center = $("#" + spinnerCenter);
        spinner.spin($spinner_center.get(0));
        $spinner.show();
        $spinner_center.show();
    } catch (ex) {
    }
}

function hideSpinner() {
    try {
        var spinnerArea = "spinner";
        var spinnerCenter = "spinner_center";
        if ($("#" + spinnerArea).length > 0) {
            var $spinner = $("#" + spinnerArea);
            var $spinner_center = $("#" + spinnerCenter);
            $spinner.hide();
            $spinner_center.hide();
            spinner.stop($spinner_center.get(0));
        }

       // AX-4481.2
       if (isSuccessWindowOpened()) {
          removeSuccessWindow();
       }

    } catch (ex) {
    }
}


// AX-4481
function isSpinnerShowing() {
   try {
      var spinnerArea = "spinner";
      if ($("#" + spinnerArea).length > 0) {
         return true;
      }
   } catch (ex) {
   }
   return false;
}