﻿
/*
* Shows progress bar while the google maps gets loaded.
*/
function ShowLoader(input, layer) {
    try {
        var imageLocation = "images/misc/loadingbar.gif";
        var str = "<p>";
        var img = "<img src='" + imageLocation + "' />";
        switch (input) {
            case 1:
                str += "Receiving Data<br/>";
                break;
            case 2:
                str += "Loading " + layer + " Data<br/>";
                break;
            case 3:
                str += "Unloading " + layer + " Data<br/>";
                break;
            case 4:
                str += "Updating Map<br/>";
                break;
            default:
                break;
        }

        var updatingElement = GetElementByID('dvUpdating');
        var theMapDiv = GetElementByID('map');

        // Retrieve the x position of the map.
        var horizontalPosition = getX(theMapDiv);

        // Calculate the position to center the image over the map. The image is 220 pixels wide. 110 is half of that.
        var horizontalOffset = horizontalPosition + (theMapDiv.offsetWidth / 2) - 110;

        // Get the y-axis position of the top of the map.
        var topOfMap = getY(theMapDiv);
        updatingElement.style.position = 'absolute';

        // Place the loading control 10 pixels below the top of the map.
        updatingElement.style.top = topOfMap + 10 + 'px';
        updatingElement.style.left = horizontalOffset + 'px';

        // Ensure that the map is on top of the map.
        updatingElement.style.zIndex = '50000';

        GetElementByID('dvUpdating').style.display = 'inline';
        GetElementByID('dvUpdating').innerHTML = str + img + "</p>";
    }
    catch (e) {
        alert(e.message);
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Purpose:
//      This will get the y offset position of an element.
//
//  Parameters:
//      oElement: This is the element that the y-axis position will be retrieved for.
//
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
function getY(oElement) {
    var iReturnValue = 0;
    while (oElement != null) {
        iReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Purpose:
//      This will get the x offset position of an element.
//
//  Parameters:
//      oElement: This is the element that the x-axis position will be retrieved for.
//
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
function getX(oElement) {
    var iReturnValue = 0;
    while (oElement != null) {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}


/*
* Hides progress bar that is loaded by ShowLoader function.
*/
function HideLoader() {
    try {
        GetElementByID('dvUpdating').innerHTML = "";
        GetElementByID('dvUpdating').style.display = 'none';
    }
    catch (e) {
        alert(e.message);
    }
}