
var offsetfromcursorX=0; 
var offsetfromcursorY=0; 

var offsetdivfrompointerX=235; 
var offsetdivfrompointerY=-10; 

document.write("<div id=\"dhtmltooltip\" style=\"position:absolute;\"></div>"); 
document.write("<img id=\"dhtmlpointer\" src=\"http://www.lautorite.qc.ca/images/arrow3.gif\">"); 

var ie=document.all;
var ns6=document.getElementById && !document.all;
var enabletip=false;
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : "";

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : "";
 

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

 

function ddrivetip(e,thetext, thewidth, thecolor)
{
	if (ns6||ie)
	{
		if (typeof thewidth!="undefined") 
			tipobj.style.width=thewidth+"px";
		if (typeof thecolor!="undefined" && thecolor!="") 
			tipobj.style.backgroundColor=thecolor;
		tipobj.innerHTML=thetext;
		enabletip=true;
		positiontip(e);
		return false;
	}	
}

function positiontip(e)
{
	if (! e)
		e = event;
	if (enabletip)
	{
		var nondefaultpos=false;
		var curX=(ns6)?e.pageX - 50: event.clientX+ietruebody().scrollLeft -50;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20;
		var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20;

		var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX;
		var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY;

		var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000;

		if ((rightedge+offsetdivfrompointerX)<tipobj.offsetWidth)
		{
			tipobj.style.left=curX-tipobj.offsetWidth+"px";
			nondefaultpos=true;
		}
		else if (curX<leftedge)
			tipobj.style.left="5px";
		else
		{
			tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px";
			pointerobj.style.left=curX+offsetfromcursorX+"px";
		}

		if (bottomedge<tipobj.offsetHeight)
		{
			tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px";
			nondefaultpos=true;
		}
		else
		{
			tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px";
			pointerobj.style.top=curY+offsetfromcursorY+"px";
		}
		tipobj.style.visibility="visible";
		if (!nondefaultpos)
			pointerobj.style.visibility="visible";
		else
			pointerobj.style.visibility="hidden";
	}
}

 

function hideddrivetip(){
if (ns6||ie){
enabletip=false;
tipobj.style.visibility="hidden";
pointerobj.style.visibility="hidden";
tipobj.style.left="-1000px";
tipobj.style.backgroundColor="";
tipobj.style.width="";
}
}

function jourCalClick(e,lng,ad,af,md,mf,jd,jf)
{
	getListEvenement(lng,ad,af,md,mf,jd,jf);
	ddrivetip(e,' ');
}

//document.onmousemove=positiontip;

// Fonction qui permet de récupérer 
// la liste des événements entre deux date
function getListEvenement(lng,ad,af,md,mf,jd,jf)
{ 
	// Créer une version texte de la date au format YYYY-MM-DD
	var strDate = ad.toString() + '-';
	var mdTmp = eval(md)+1;
	var jdTmp = eval(jd);
	strDate += (mdTmp < 10)?'0'+mdTmp.toString():mdTmp.toString();
	strDate += '-';
	strDate += (jdTmp < 10)?'0'+jdTmp.toString():jdTmp.toString();

	// Créer l'objet XMLHTTPREQUEST
    var xhr; 
    try 
    {  
    	xhr = new ActiveXObject('Msxml2.XMLHTTP');
    }
	catch (e) 
	{
	  	try 
	  	{   
	  		xhr = new ActiveXObject('Microsoft.XMLHTTP');
	  	}
		catch (e2) 
		{
			try 
			{  
				xhr = new XMLHttpRequest();
			}
		  	catch (e3) 
		  	{  
		  		xhr = false;  
		  	}
		}
	}
		
	xhr.onreadystatechange = function()
	{ 
		if(xhr.readyState  == 4)
		{
			var XMLdoc;
			if (window.ActiveXObject)
			{ // If IE Windows
				XMLdoc = new ActiveXObject("Microsoft.XMLDOM");
				XMLdoc.loadXML(xhr.responseText);
			} 
			else 
			{
				XMLdoc = xhr.responseXML;
			}
				
			vEvenements = XMLdoc.getElementsByTagName('evenement');
			var finalTable = '<table class="calendrier-popup" width="260" cellpadding="0" cellspacing="0" style="border:1px solid #000000;">';
			finalTable += '<tr><th width="5" style="padding:2px;margin:0px;color:#ffffff;background-color:#B68D0F;font-size:8pt;border:0px solid #ffffff;"><img src="http://www.lautorite.qc.ca/images/spacer.gif" width="5" height="20" /></th><th align="left" style="padding:2px;margin:0px;color:#ffffff;background-color:#B68D0F;font-size:8pt;border:0px solid #ffffff;">' + strDate + '</th><th align="right" style="padding:2px;margin:0px;color:#ffffff;background-color:#B68D0F;font-size:8pt;border:0px solid #ffffff;"><a href="javascript:hideddrivetip();" style="color:#ffffff;text-decoration:none;" >&nbsp;X</a>&nbsp;&nbsp;</th></tr>';
			for (var x=0;x<vEvenements.length;x++)
			{
				if (vEvenements[x].getElementsByTagName('titre')[0].firstChild != null)
				{
					strTitre = vEvenements[x].getElementsByTagName("titre")[0].firstChild.nodeValue;
					strCouleur = vEvenements[x].getElementsByTagName("couleur")[0].firstChild.nodeValue;
					strId = vEvenements[x].getElementsByTagName("id")[0].firstChild.nodeValue;
					finalTable += '<tr><td valign="top" style="border:0px solid #ffffff;padding:2px;margin:0px;background-color:#'+strCouleur+';"><img src="/images/puce-popup-calendrier.gif" style="margin-top:3px;" /></td><td colspan="2" style="background-color:#ffffff;padding:2px;font-size:8pt;border:0px solid #ffffff;"><a href="/calendrier-activite/liste-evenement.'+lng+'.html?a=' + ad + '&m=' + md +'#'+strId+'">' + strTitre + '</a></td></tr>';
					finalTable += '<tr><td colspan="3" style="background-color:#B68D0F;border:0px solid #ffffff;" height="1"><img src="http://www.lautorite.qc.ca/images/spacer.gif" width="1" height="1" alt=" " /></td></tr>';
				}
			}
			finalTable += '</table>';
			
			document.getElementById('dhtmltooltip').innerHTML = finalTable;
		}
	};

	var uri = "/fhtml/getListeEvenement.jsp?lng=" + lng + "&ad=" + ad + "&af=" + af + "&md=" + md + "&mf=" + mf + "&jd=" + jd + "&jf=" + jf;

	uri.concat(/\?/.test(uri)?"&":"?","noCache=",(new Date).getTime(),".",Math.random()*1234567)

	xhr.open( "GET", uri ,  true);
	
	xhr.send(null);	
} 


