//this function retrieves the number of pixels from a CSS value, "343px" will be converted to "343"

function getPixels(id) {

    pixels = id.split("p");

    return parseInt(pixels[0]);

}



//displays the tooltip with name and message once the mouse is positioned above the smiley

function showtip(id,name,message) {

    tooltip = document.getElementById('tip');



    //tooltip.style.top = document.getElementById('branche_' + id).style.top;

    //tooltip.style.left = document.getElementById('branche_' + id).style.left;

    tooltip.innerHTML = "<center><strong>" + name + "</strong></center>" + message;

    tooltip.style.visibility = "visible";

    tooltip.style.zIndex = 100;

}



//get the cursor location

function cursorLocation() {

    //needed for other browsers then MSIE

    if(!document.all) {

        document.captureEvents(Event.MOUSEMOVE);

    }

    document.getElementById('MapImage').onmousemove = showMousePosition;

}



//getting the cursor location works different in MSIE and Gecko (Mozilla/Netscape) browers

function showMousePosition(e) {

    var posY;

    var posX;



    if(!document.all) {

        posY = e.pageY;

        posX = e.pageX;

    } else {

        //MSIE needs some correction, especially when scrolling

        posX = window.event.x + document.body.scrollLeft - 1 + getPixels(document.getElementById('MapDiv').style.left) + 176;

        posY = window.event.y + document.body.scrollTop - 2 + getPixels(document.getElementById('MapDiv').style.top) + 110;

    }

    //insert the values in the hidden fields after compensating the map position

    //document.getElementById('tempY').value = (posY - getPixels(document.getElementById('MapDiv').style.top));

    //document.getElementById('tempX').value = (posX - getPixels(document.getElementById('MapDiv').style.left));

    document.getElementById('tempY').value = (posY - 110);

    document.getElementById('tempX').value = (posX - 176);

}



//once called, this function will insert the coordinates in the form

function storeCursorLocation() {

    var icon = document.getElementById('icon').style;



    icon.visibility = "visible";

    icon.zIndex = 99;

    icon.left = document.getElementById('tempX').value + "px";

    icon.top = document.getElementById('tempY').value + "px";



    // set click position

    document.getElementById('realX').value = document.getElementById('tempX').value;

    document.getElementById('realY').value = document.getElementById('tempY').value;

} 



//hides any element depending on the id argument

function hide(id) {

    document.getElementById(id).style.visibility = "hidden";

    document.getElementById(id).style.zIndex = 0;

}

