// Global variables
var xMousePos = 0; // Horizontal position of the mouse on the screen
var yMousePos = 0; // Vertical position of the mouse on the screen

// Add a listener for browsers other than Internet Explorer
if (!document.all) document.addEventListener("mousemove", captureMousePosition, true)

// Initialize the mouse move event.
document.onmousemove = captureMousePosition;

// -------------------------------------------------------------------------------------------------------//

//JH
function DelGmnoprint() {
    var sd = document.getElementsByTagName('svg');

        for (var n = 0 ; n < sd.length ; n++ ) {
            if (sd[n].parentNode.className == 'gmnoprint') {
                sd[n].parentNode.className = '';
            }
        }
    setTimeout("DelGmnoprint();",100);
}

function initializePage()
{
    // Initialize the page.
    document.getElementById("btnGenerateReport").disabled = (objChartArray.length == 0);

    // Position the loading animation.
    document.getElementById("loadingDivMap").style.left = ((document.getElementById("map").offsetWidth - 220) / 2) + "px";
    document.getElementById("loadingDivMap").style.top = ((document.getElementById("map").offsetHeight - 19) / 2) + "px";

    // Initialize Google Maps.
    initializeGoogleMaps();
}

function captureMousePosition(e)
{
    if (!e)
        var e = window.event;

    // Capture the mouse position.
    if (e.pageX || e.pageY)
    {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
    }
    else if (e.clientX || e.clientY)
    {
        xMousePos = e.clientX + document.documentElement.scrollLeft;
        yMousePos = e.clientY + document.documentElement.scrollTop;
    }

    // Show mouse position in browser status bar.
    //window.status = "xMousePos=" + xMousePos + ", yMousePos=" + yMousePos;
}

function processKeyPress(pEvent, pStrFunction)
{
    var strKeyCode;

    if (window.event) // IE
        strKeyCode = pEvent.keyCode;
    else if (pEvent.which) // Netscape/Firefox/Opera
        strKeyCode = pEvent.which;

    if ((strKeyCode == 13) && (pStrFunction))
        eval(pStrFunction);
}

function removeDiv(pDivName)
{
    // Remove the div if exists.
    if (document.getElementById(pDivName))
        document.body.removeChild(document.getElementById(pDivName));
}

// Creates the help window
function showHelpDiv(pID, pHtml, pLeft, pTop)
{
    // Create a new div.
    var oHelpDiv = document.createElement("div");

    // Assign an ID to the div.
    oHelpDiv.id = pID;
    oHelpDiv.name = pID;

    // Assign a class style to the div object.
    oHelpDiv.className = "help";

    oHelpDiv.style.left = pLeft + "px";
    oHelpDiv.style.top = pTop + "px";

    oHelpDiv.innerHTML = pHtml;

    document.body.appendChild(oHelpDiv);
}

function changeButtonText(pButton, pText)
{
    pButton.value = pText;
}

function existsInArray(pContentKey, pArray)
{
    var intArrayLength = pArray.length;
    var intCounter = 0;
    var boolFound = false;

    // Loop through the array to see if pContentKey already exists.
    while ((boolFound == false) && (intCounter < intArrayLength))
    {
        if (pArray[intCounter] == pContentKey)
            boolFound = true;

        intCounter ++;
    }

    return boolFound;
}