﻿function GetId(id)
{
    return document.getElementById(id);
}

var AsyncPostbackControlId = "";    // controle utilisé pour l'appel ajax
var KeywordIdControlId = "";        // controle contenant l'id du keyword survolé
var UpdatePanelDiv = "";            // id client de l'updatePanel

var idVisible = null; 
var idSouris = null;
var idProchainAffiche = null;


function mouseoverdiv(){
    idSouris = "1";
}
function mouseover(idWord){
    idSouris = idWord;
    GetId(KeywordIdControlId).value = idWord;
    if (idVisible==null){
        GetId(UpdatePanelDiv).innerHTML = "Loading...";
        __doPostBack(AsyncPostbackControlId,'');
        demanderAffichage();
    }
}
function mouseout(){
    idSouris = null;
    
    // On annule la demande d'affichage si le div n'est pas encore apparu
    if (idVisible==null && idTimeoutAffiche!=null){
        clearTimeout(idTimeoutAffiche);
        idProchainAffiche=null;
    }
}
function mouseclick(){
    if (idVisible!=null && idSouris != idVisible){
        masque();
    }
    if (idSouris != idVisible) {
        GetId("curseur").style.left = posLeft;
        GetId("curseur").style.top = posTop;
        affiche();
    }
}

function affiche(){
    if (GetId(UpdatePanelDiv).innerHTML == "") {
        GetId(UpdatePanelDiv).innerHTML = "Loading...";
        __doPostBack(AsyncPostbackControlId,'');
    }
    GetId("curseur").style.display="block";
    idVisible=idSouris;
    idTimeoutAffiche=null;
        //debug
    AfficherValeurs();
}
function masque(){
    GetId(UpdatePanelDiv).innerHTML = "";
    GetId("curseur").style.display="none";
    idVisible=null;
    idProchainAffiche=null;
    idTimeoutMasque=null;
        //debug
    AfficherValeurs();
}



function demanderAffichage(){
    if (idSouris != null && idSouris != idProchainAffiche)
    { 
        // on annule toute tentative d'affichage ou de masquage
        if (idTimeoutAffiche!=null) 
            clearTimeout(idTimeoutAffiche);
//        if (idTimeoutMasque!=null)
//            clearTimeout(idTimeoutMasque);
            
        // on relance l'affichage
        GetId("curseur").style.left = posLeft;
        GetId("curseur").style.top = posTop;
        idTimeoutAffiche = setTimeout("affiche()",500);
        idProchainAffiche = idSouris;
    }
}


//var idTimeoutMasque = null;
var idTimeoutAffiche = null;


var posLeft, posTop;



function move(e) 
{
    // récupération de la position de la souris
    if (navigator.appName!="Microsoft Internet Explorer")  
    {
        posLeft=e.pageX ;
        posTop=e.pageY + 15;
    }
    else  
    {
        if(document.documentElement.clientWidth>0) 
        {
            posLeft=15+event.x+document.documentElement.scrollLeft;
            posTop=15+event.y+document.documentElement.scrollTop;
        }
        else 
        {
            posLeft=15+event.x+document.body.scrollLeft;
            posTop=15+event.y+document.body.scrollTop;
        }
    }
    // décalage gauche de la page à corriger
    if (document.body!=null)
        posLeft = posLeft - document.body.clientWidth/2 + 480;
    
    
    posLeft = posLeft + "px";
    posTop = posTop + "px";
    
        //debug
    AfficherValeurs();
} 

document.onmousemove=move; // dès que la souris bouge, on appelle la fonction move pour mettre à jour la position de la bulle.




function AfficherValeurs(){
/* Décommenter pour le debug 
    GetId('spVisible').innerHTML = idVisible;
    GetId('spSouris').innerHTML = idSouris;
    GetId('spProchain').innerHTML = idProchainAffiche;
    */
}






// Masquage différé : n'est plus utilisé

/*
function demanderMasquage(){
    if (idTimeoutAffiche!=null) 
        clearTimeout(idTimeoutAffiche);
        
    idTimeoutMasque = setTimeout("masque()",2000);
    idProchainAffiche=null;
}
function annulerMasquage(){
    if (idTimeoutMasque!=null)
        clearTimeout(idTimeoutMasque);
}
*/



/*
function ShowHide() 
{    
    if (idSouris==null)     // Il ne faut pas afficher le div
    {
        demanderMasquage();
    }
    else if (idSouris==1 || idSouris==idVisible)
    {
        annulerMasquage();
    }
    else
    {
        demanderAffichage();
    }
        //debug
    AfficherValeurs();
}
*/