var popupResponse = "";
function showHorizontalAJAXLoader(show) {
    var pathwayRight = document.getElementById("loading");
    if (show) {
        document.body.style.cursor = 'wait';
        pathwayRight.innerHTML = "<img src=\"./templates/VeteransMATES/images/ajax-loading-line.gif\" border=\"0\">";
    } else {
        pathwayRight.innerHTML = "";
        document.body.style.cursor = 'default';
    }
}

function getPreLoader() {
    return "<img src=\"./templates/VeteransMATES/images/ajax-loading.gif\" border=\"0\">";
}

function preloadImage() {
    preload_image = new Image(25,25); 
      preload_image.src="../images/ajax-loading-line.gif"; 
}

/**
* Checks for logged in LMO and inspects whether specific flags have been set
* @param None
* @return If check is true, proceeds to fade in pop-up frame with actions to be completed - fadeInFade();
*/
function checkForIncomplete() { 
    var ajaxRequest = initialiseAJAXRequest();
    var processURL = uncacheurl("./modules/requiredDataChecks/AJAX/checkForIncomplete.jsp");
    ajaxRequest.onreadystatechange = function() {
        if (ajaxRequest.readyState == 4) {
            if (ajaxRequest.status == 200) {
                var theResponse = ajaxRequest.responseText.trim();
                if (theResponse.substr(0, 2)=="i:") {
                    document.getElementById('contentDivvo').style.display="block";
                    popupResponse = theResponse.substr(2, theResponse.length).trim();
                    //fadeInFade(5, 'incomplete', theResponse);
                    fadeInFade(5, 'incomplete');
                }
            } else {
            }
        }
    };
    ajaxRequest.open("GET", processURL, true);
    ajaxRequest.send(null);
}

function fadeInFade(x, action) {
    if (x==5)  document.getElementById('fadeContainer').style.display="block";
    
    if (x<71) {
        var decimalX = x / 100;
        document.getElementById('overlay').style.opacity= (decimalX);
        document.getElementById('overlay').style.filter  = "alpha(opacity=" + x + ")"; 
        x = x+5;
        setTimeout("fadeInFade(" + x + ",'" + action + "')", 10);
    } else {
        if (action=="incomplete") {
            document.getElementById('popupContent').innerHTML=popupResponse +"<br><br><center><a href='' class='blueRed' onclick=\"fadeOutFade(70);return(false);\">(close)</a></center>";
            var popupHeight = document.getElementById('popupContent').offsetHeight+10;
            var winInnerHeight = document.body.clientHeight;
            if (winInnerHeight < popupHeight) document.getElementById('popupContent').style.height = (winInnerHeight-30) + "px";
        }
    }
    
}


function fadeOutFade(y) {
    if (y==70)  document.getElementById('contentDivvo').style.display="none";
    
    if (y>5) {
        var decimalY = y / 100;
        document.getElementById('overlay').style.opacity= (decimalY);
        document.getElementById('overlay').style.filter  = "alpha(opacity=" + y + ")"; 
        y = y-5;
        setTimeout("fadeOutFade(" + y + ")", 10);
    } else {
        document.getElementById('fadeContainer').style.display="none";
    }
    
}
