// -*- C++ -*-
// -----------------------------------------------------------------
//
//  Copyright 2002 Nordsites.com, All rights reserved
//
// -----------------------------------------------------------------


var ns4 = (document.layers);
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);


function get_objet(id) {
  if(ns4){
    return document.layers[id];
  }
  // Explorer 4
  else if(ie4){
    return document.all[id];
  }
  // W3C - Explorer 5+ and Netscape 6+
  else if(ie5 || ns6){
    return document.getElementById(id);
  }
}


function show(id){
  // Netscape 4
  if(ns4){
    document.layers[id].visibility = "show";
  }
  // Explorer 4
  else if(ie4){
    document.all[id].style.visibility = "visible";
  }
  // W3C - Explorer 5+ and Netscape 6+
  else if(ie5 || ns6){
    document.getElementById(id).style.visibility = "visible";
  }
}

function hide(id){
  // Netscape 4
  if(ns4){
    document.layers[id].visibility = "hide";
  }
  // Explorer 4
  else if(ie4){
    document.all[id].style.visibility = "hidden";
  }
  // W3C - Explorer 5+ and Netscape 6+
  else if(ie5 || ns6){
    document.getElementById(id).style.visibility = "hidden";
  }
}

//ne marche que pour IE5 et+ ou NS6 et +
function swap_display(Id) {
  //récupère l'element en fonction de l'Id
  var current=document.getElementById(Id);
  
  var state=current.style.display;
  if (state == "none") {
    //il faut afficher ce détail
    current.style.display="";
  } 
  else {
    //maintenant il faut le cacher
    current.style.display="none";
  }
  
}

function border_error(objet) {
  if (objet.type!="radio") {
    objet.className="error";
    objet.focus();
    //if (objet.type!="select")
    //  objet.select();
  }
}

function border_restore(objet) {
  if (objet.type!="radio") {
    if (objet.type=="checkbox") {
      objet.className="noborder";
    } else {
      objet.className="";
    }
  }
}


// source, destination et texte si vide (mettre "") si on laisse vide
var ajout=1;
var retrait=2;
function Deplace(source, dest, empty, contenu, sens) {
  
  var newElem;
  var flagRemovePeuImporte = 0;
  var fin=dest;
  
  if ((sens!=ajout) && (sens!=retrait)) {
    return false;
  }
  
  if (sens==retrait) {
    var tmp=source;
	source=dest;
	dest=tmp;
  } else {
    empty="";
  }
  
  //pour chaque éléments, ordre décroissant important
  for (i=source.options.length-1; i>=0; i--) {
    if (source.options[i].selected == true) {
      if (source.options[i].value == '') {
        //option non valide, on la supprime
	    source.options[i] = null;
      }
      else {
        //nouvelle option
	    newElem = new Option(source.options[i].text, source.options[i].value, '', '');
	    //on l'ajoute en fin
	    dest.options[dest.options.length] = newElem;
	    //on supprime l'option de la source
	    source.options[i] = null;
	    //on peut supprimer "-peu importe-"
	    flagRemovePeuImporte = 1;
      }
    }
  }
  
  ispeuimporte = (empty.length>0);

  if ((ispeuimporte == 0) && (flagRemovePeuImporte)) {
    if ((dest.options.length >= 2) && (dest.options[0].value == '')) dest.options[0] = null;
  }
  
  //on sélectionne par défaut le premier élément de la source
  if (source.options.length > 0) source.options[0].selected = true;
  
  if ((source.options.length == 0) && (ispeuimporte)) {
    newElem = new Option(empty, '', '', '');
    source.options[source.options.length] = newElem;
  }
  
  //on place tout les éléments dans contenu
  var tableau= new Array();
  for (i=fin.options.length-1; i>=0; i--) {
    tableau[tableau.length]=fin.options[i].value;
  }
  contenu.value=tableau.join(',');


  return (true);
}


//
// ouvre un popup
//
var popUpWin=0;
function popup(URLStr, width, height)
{
  if(popUpWin) {
    if(!popUpWin.closed)
	  popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height);
}

//affiche une fiche
function popupfiche(URLStr)
{
  width = 400;
  height = 400;

  if (window.screen) {
   w = parseInt(window.screen.availWidth * 0.80);
   h = parseInt(window.screen.availHeight * 0.80);
  }

  open(URLStr, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+w+',height='+h);
}

// screenX=400,screenY=400,top=400,left=400'

/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object   the table row
 * @param   string   the action calling this script (over, out or click)
 * @param   string   the default background color
 * @param   string   the color to use for mouseover
 * @param   string   the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
        if (theAction == 'out') {
            newColor = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor = (thePointerColor != '')
                     ? thePointerColor
                     : theDefaultColor;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

// ------------------------------------------------------------------------------------------

var aide_active=false;
var aide_pos='';
var aide_show=false;
var aide_size=0;


//affiche une aide
function aff_bulle(texte,alignement,taille) {
  var objet=get_objet('bulle');
  //mémorise l'id de l'objet à afficher
  aide_active=true;
  aide_pos=alignement;
  //affichera l'objet au prochain mouvement de la souris
  aide_show=true; 
  if (ie5||ns6) {
    //modifie le contenu
    objet.innerHTML=texte;
  }
  objet.style.width=taille+'px';
  aide_size=taille;
}

function cache_bulle() {
  if (aide_active) {
    var objet=get_objet('bulle');
    aide_active=false;
	aide_size=0;
    //cache affichage
    if (ns4) {  objet.visibility = "hide";  } 
    else {  objet.style.visibility = "hidden"; }
  }
}


function deplace_bulle(e) {
  if (aide_active) {
    var x = (ns4||ns6) ? e.pageX : event.x+document.body.scrollLeft;
    var y = (ns4||ns6) ? e.pageY : event.y+document.body.scrollTop;
    var objet = get_objet('bulle');
	if (aide_pos=='right') {
	   //alignement à droite
	   objet.style.left = x - aide_size + 12;
	}
	else {
	   //alignement à gauche
       objet.style.left = x;
	}
    objet.style.top  = y+22;
	if (aide_show) {
	  //affichage
      if (ns4) {  objet.visibility = "show";  } 
      else {  objet.style.visibility = "visible"; }
	  aide_show=false; 
	}
  }
}

//on attache une action à l'événement MOUSEMOVE
if (ie5||ns6) {
  if (ns6) document.captureEvents(Event.MOUSEMOVE);
  document.onmousemove = deplace_bulle;
}


