// LT
// 12-12-2007
// Fonctions de gestion d'affichage

function openWindow(strUrl, strWindowName, intWindowWidth, intWindowHeight, bFollowLink)
// Ouvre une nouvelle fenêtre avec les dimensions, le nom et l'adresse demandés
{

  /**
   * Largeur ou hauteur a -1 signifie toute la place possible
   * PM
   */
  if( intWindowHeight==-1 ){
    intWindowHeight = screen.height;
  }  
  if( intWindowWidth==-1 ){
      intWindowWidth = screen.width;
  }

  // Définition de la position de la nouvelle fenêtre
  var intWindowLeft = screen.width - intWindowWidth;
  var intWindowTop = screen.height - intWindowHeight;

  // Définition de l'URL
  if(strUrl == ""){
    strUrl = "about:blank";}

  // Ouverture de la fenêtre
  oWindow = window.open(strUrl, strWindowName, 'toolbar=0,menubar=0,location=0,resizable=1,directories=0,scrollbars=1,width=' + intWindowWidth + ',height=' + intWindowHeight + ',left=' + intWindowLeft + ',top=' + intWindowTop);
  oWindow.focus();

  // Indique si on doit suivre le lien ou non
  return bFollowLink;
}

function openCloseDiv(strDivId, bFollowLink)
// Ouvre ou ferme le div dont l'ID est strDivId
{
  // Si le div est ouvert, on le ferme
  if(document.getElementById(strDivId).style.display == "block"){
    document.getElementById(strDivId).style.display = "none";}

  // Si le div est fermé, on l'ouvre
  else{
    document.getElementById(strDivId).style.display = "block";}

  // Indique si on doit suivre le lien ou non
  return bFollowLink;
}

// POSITON SOURIS - PM
var mouse_x=0;
var mouse_y=0;

if (navigator.appName.substring(0,3) == "Net") document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = function (e) {
        mouse_x = (navigator.appName.substring(0,3) == "Net") ? e.pageX : event.x+(document.documentElement ? document.documentElement : document.body).scrollLeft;
        mouse_y = (navigator.appName.substring(0,3) == "Net") ? e.pageY : event.y+(document.documentElement ? document.documentElement : document.body).scrollTop;
};


function openPopup(strDivId){
// Affiche le div dont l'ID est strDivId, et adapte les dimensions à l'écran si nécessaire

 // Définition du div à traiter
  var oDiv = document.getElementById(strDivId);
  if( !oDiv ){
    return;
  }
  
  var BODY = document.documentElement ? document.documentElement : document.body;
  
  // Paramétrage
  
  var intBottomMargin = 20;
  
  var intOffset = 25; //Décalage à droite du curseur
  var intMargin = 10; //Marge à droite du div
  var intDivWidth = 500 // Largeur max du div
  var intDivWidthMin = 200; // Largeur minimum du div
  
  var intDivHeightMax = 250; // Hauteur max du div (cf feuille de style)
  
  
  var intDivTopMax = BODY.scrollTop + BODY.clientHeight - intDivHeightMax - intBottomMargin; //position 'Top' max du div
  
  
  
  
  
  // Positionnement et affichage du div
  oDiv.style.top =(
  	mouse_y-10 > intDivTopMax ?
	  intDivTopMax :
	  mouse_y-10
	)+'px';

  /*alert( (mouse_y-10)+' '+intDivTopMax+'='+BODY.scrollTop+'+' + BODY.clientHeight+'-'+ intDivHeightMax +'-'+5 );
  if( mouse_y-10 > intDivTopMax )alert('restricted ' + (mouse_y-10) + ' to ' +intDivTopMax+' : ' + oDiv.style.top  )
  */

  oDiv.style.left = mouse_x+60+'px';
    

  /*oDiv.style.width = (
  	parseInt(oDiv.style.left)-BODY.scrollLeft + parseInt(intDivWidth) > BODY.clientWidth ?
		// Si nécessaire, réduction de la largeur du div
		Math.max((BODY.clientWidth - parseInt(oDiv.style.left)+BODY.scrollLeft) - intMargin, intDivWidthMin) :
		intDivWidth
  	)+'px';*/
	 
	//affichage du div
  oDiv.style.display = "block";

}

function closePopup(strDivId){
// Masque le div dont l'ID est strDivId
  if( document.getElementById(strDivId) ){
        document.getElementById(strDivId).style.display = "none";
  }
}

function sendToUrl(strUrl){
// Renvoie à strUrl en gérant la fenêtre appelante éventuelle

  // Si on a une fenetre appelante
  if(this.opener){
    this.opener.location = strUrl;
    this.close();}

  // Si on n'a pas de fenetre appelante
  else{
    this.location = strUrl;}
}

