var glossaryWords = new Array();

function OnMouse(elem,word, definition)
{
//elem.style.cursor="help";
addGlossaryWord(word,definition);
}

function OffMouse(elem)
{
//elem.style.cursor="default";
hideToolTip()
}

function addGlossaryWord(word, definition)
{
	if(getGlossaryDefinition(word) == undefined) {
		var entry = new Array(word, unescape(definition));
		glossaryWords.push(entry);
	}
}

function getGlossaryDefinition(word)
{
	var def = undefined;

	if(glossaryWords != undefined) {
		for(i=0; i<glossaryWords.length; i++) {
			entry = glossaryWords[i];
			key = entry[0];
			if(key == word) {
				def = entry[1];
		    }
		}
	}
	
	return def;
}



var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;

var toolTipSTYLE = null;
var yCoordinate = 0;
var bubbleLength = 0;

initToolTips();


function initToolTips()
{
  if(ns4||ns6||ie4)
  {
    if(ns4) toolTipSTYLE = document.toolTipLayer;
    else if(ns6) toolTipSTYLE = document.getElementById("toolTipLayer").style;
    else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;
    if(ns4){
        document.captureEvents(Event.MOUSEMOVE);
    }
    else
    {
      toolTipSTYLE.visibility = "visible";
      toolTipSTYLE.display = "none";
    }
    document.onmousemove = moveToMouseLoc;
    //document.onclick = moveToMouseLoc;
    
  }
}

function toolTip(msg)
{
    var locationTop = 0;
    var content= '';

    if (ns4||ns6){
        if (yCoordinate < ((bubbleLength * 12) + 65)){
            locationTop = 1;
        }

    }
    else{
        if (event.clientY < ((bubbleLength * 12) + 65)){
            locationTop = 1;
        }
    }

    if (locationTop == 1) {
        content = '<table border="0" cellspacing="0" width="247" cellpadding="0">' +
        '<tr><td valign="bottom" width="247" colspan="6">' +
                '<table border="0" cellspacing="0" width="247" cellpadding="0">' +
                '<tr><td valign="bottom"><IMG SRC="images/bubble/bubble_top_inv_left.gif" WIDTH="19" HEIGHT="7"><br /></td>' +
                '<td valign="bottom"><IMG SRC="images/bubble/bubble_top_inv.gif" WIDTH="25" HEIGHT="25"><br /></td>' +
                '<td valign="bottom"><IMG SRC="images/bubble/bubble_top_inv_right.gif" WIDTH="203" HEIGHT="7"><br /></td></tr></table>' +
        '</td></tr>' +
        '<tr><td width="1" bgcolor="#666666"><IMG SRC="images/bubble/dark_grey_pixel.gif" width="1" height="1"><br /></td>' +
        '<td width="2" bgcolor="#FFFFFF">&nbsp;</td>' +
        '<td width="240" bgcolor="#FFFFFF">'+ msg + '&nbsp;</td>' +
        '<td width="2" bgcolor="#FFFFFF">&nbsp;</td>' +
        '<td width="1" bgcolor="#666666"><IMG SRC="images/bubble/dark_grey_pixel.gif" width="1" height="1"><br /></td>' +
        '<td width="1" bgcolor="#E0E0E0"><IMG SRC="images/bubble/light_grey_pixel.gif" width="1" height="1"><br /></td></tr>' +
        '<tr><td width="247" colspan="6"><IMG SRC="images/bubble/bubble_bottom_inv.gif" WIDTH="247" HEIGHT="5"><br /></td></tr>'+
        '</table>';
    }
    else{
        content = '<table border="0" cellspacing="0" width="247" cellpadding="0">' +
        '<tr><td width="247" colspan="6"><IMG SRC="images/bubble/bubble_top.gif" WIDTH="247" HEIGHT="5"><br /></td></tr>'+
        '<tr><td width="1" bgcolor="#666666"><IMG SRC="images/bubble/dark_grey_pixel.gif" width="1" height="1"><br /></td>' +
        '<td width="2" bgcolor="#FFFFFF">&nbsp;</td>' +
        '<td width="240" bgcolor="#FFFFFF">'+ msg + '&nbsp;</td>' +
        '<td width="2" bgcolor="#FFFFFF">&nbsp;</td>' +
        '<td width="1" bgcolor="#666666"><IMG SRC="images/bubble/dark_grey_pixel.gif" width="1" height="1"><br /></td>' +
        '<td width="1" bgcolor="#E0E0E0"><IMG SRC="images/bubble/light_grey_pixel.gif" width="1" height="1"><br /></td></tr>' +
        '<tr><td valign="top" width="247" colspan="6">' +
            '<table border="0" cellspacing="0" width="247" cellpadding="0">' +
                '<tr><td valign="top"><IMG SRC="images/bubble/bubble_bottom_left.gif" WIDTH="19" HEIGHT="7"><br /></td>' +
                '<td valign="top"><IMG SRC="images/bubble/bubble_bottom.gif" WIDTH="25" HEIGHT="25"><br /></td>' +
                '<td valign="top"><IMG SRC="images/bubble/bubble_bottom_right.gif" WIDTH="203" HEIGHT="7"><br /></td></tr></table>' +
        '</td></tr>' +
        '</table>';
    }
    
    if(ns4)
    {
      toolTipSTYLE.document.write(content);
      toolTipSTYLE.document.close();
      toolTipSTYLE.visibility = "visible";
    }
    if(ns6)
    {
      document.getElementById("toolTipLayer").innerHTML = content;
      toolTipSTYLE.display='block'
    }
    if(ie4)
    {
      document.all("toolTipLayer").innerHTML=content;
      toolTipSTYLE.display='block'
    }
}

function hideToolTip(){
    if(ns4) toolTipSTYLE.visibility = "hidden";
    else toolTipSTYLE.display = "none";
}

function moveToMouseLoc(e){
    
    if (ns4||ns6){
        yCoordinate = e.pageY - window.pageYOffset;
       
        if (yCoordinate < ((bubbleLength * 12) + 65)) {
            x = e.pageX;
            y = e.pageY + 30;
        }
        else{
            x = e.pageX;
            y = e.pageY - (bubbleLength * 12) - 50;
        }
    }
    else {
        if (event.clientY < ((bubbleLength * 12) + 65)) {
            x = event.clientX + document.body.scrollLeft;
            y = event.clientY + document.body.scrollTop + 30;
        }
        else{
            x = event.clientX + document.body.scrollLeft;
            y = event.clientY + document.body.scrollTop - (bubbleLength * 12) - 50;
        }
    }
    
    if (ns6) {
        document.getElementById("toolTipLayer").style.left = x + "px";
        document.getElementById("toolTipLayer").style.top =  y + "px";
    }
    else if (toolTipSTYLE) {
             toolTipSTYLE.left = x;
             toolTipSTYLE.top = y;
    }

    return true;
}

function glossaryToolTip(word,defLength) 
{
    bubbleLength = defLength /45;
    toolTip("<b>" + word + "</b><br />" + getGlossaryDefinition(word));
}

function glossaryToolTip1(word,defLength) 
{
    bubbleLength = defLength /45;
    toolTip(getGlossaryDefinition(word));
}


function popup(msg) {
    var content = '<html><head><title>Glossaire / Glossary</title></head>' +
    '<body><table align="center" valign="center" border=1 cellspacing=0 width="300" bgcolor="#FFDEAD" cellpadding="1">' +
    '<tr><td colspan="3"></td></tr>'+
    '<tr><td></td>' +
    '<td align="center">'+ msg + '&nbsp;</td>' +
    '<td></td></tr>' +
    '<tr><td colspan="3"></td></tr>' +
    '</table></body></html>';

	popupWin = window.open("", "glossaryPopup", "dependent=yes,width=350,height=200,menubar=no,location=no,toolbar=no,statusbar=no");
	popupWin.document.write(content);
}

function glossaryPopup(word) {
	popup("<b>" + word + "</b>:&nbsp;" + getGlossaryDefinition(word));
}

