// Connaitre la position du curseur en temps reel.
var $curseur_pos_x=0;
var $curseur_pos_y=0;
document.onmousemove=getCurseurPos;
function getCurseurPos(e) {
  if (navigator.appName!="Microsoft Internet Explorer") {
    $curseur_pos_x=e.pageX;
    $curseur_pos_y=e.pageY;
  }
  else {
    if (document.documentElement.clientWidth>0) {
	  $curseur_pos_x=event.x+document.documentElement.scrollLeft;
	  $curseur_pos_y=event.y+document.documentElement.scrollTop;
    } else {
	  $curseur_pos_x=event.x+document.body.scrollLeft;
	  $curseur_pos_y=event.y+document.body.scrollTop;
	}
  }
  //window.alert("X : "+$curseur_pos_x+" Y : "+$curseur_pos_y);
}
// -----------------------------------------------------------------------------
// Afficher un element au niveau de la souris sans sortir de l ecran.
// Input : $nom (string) Nom de l element.
// Input : $taille_x (int) Largeur de l element.
// Input : $taille_y (int) Hauteur de l element.
function postOnCurseur($nom,$taille_x,$taille_y) {
  var $pos_x=$curseur_pos_x; var $marge_x=0;
  var $pos_y=$curseur_pos_y; var $marge_y=10;
  if (($pos_x+$taille_x+$marge_x)>screen.availWidth) {$pos_x=($pos_x-$taille_x-$marge_x);}
  {$pos_x=($pos_x+$marge_x);}
  if (($pos_y+$taille_y+$marge_y)>screen.availHeight) {$pos_y=($pos_y-$taille_y-($marge_y*2));}
  {$pos_y=($pos_y+$marge_y);}
  getChamp($nom).style.left=$pos_x+'px';
  getChamp($nom).style.top=$pos_y+'px';
  postElement($nom);
}










// -----------------------------------------------------------------------------
// Remplacer les caracteres indesirables dans les champs textes.
// Input : $liste (array[string]) Noms des champs a verifier
function verifTexte($liste) {
  for (var $nav=0; $nav<$liste.length; $nav++) {
	document.getElementById($liste[$nav]).value=document.getElementById($liste[$nav]).value.replace(new RegExp("&","g"),"et");
	document.getElementById($liste[$nav]).value=document.getElementById($liste[$nav]).value.replace(new RegExp('"','g'),'::');
  while (document.getElementById($liste[$nav]).value.indexOf("+")!=(-1)) {
	  document.getElementById($liste[$nav]).value=document.getElementById($liste[$nav]).value.replace("+","plus");
	}
	/*
	while (document.getElementById($liste[$nav]).value.indexOf("\\ ")!=(-1)) {
	  document.getElementById($liste[$nav]).value=document.getElementById($liste[$nav]).value.replace("\\ ",">");
	}
	*/
  }
}
// -----------------------------------------------------------------------------
// Retourner la reference d un champ.
// Input : $nom (string) Nom du champ.
function getChamp($nom) {
  return(document.getElementById($nom));
}
// -----------------------------------------------------------------------------
// Mettre a jour la valeur d un champ.
// Input : $nom (string) Nom du champ.
// Input : $valeur (string) Valeur a enregistrer.
function updateChamp($nom,$valeur) {
  getChamp($nom).value=$valeur;
}
// -----------------------------------------------------------------------------
// Mettre a jour la valeur de plusieurs champs.
// Input : $noms (array[string]) Noms des champs.
// Input : $valeurs (array[string]) Valeurs a enregistrer.
function updateChamps($noms,$valeurs) {
  for(var $nav=0;$nav<$noms.length;$nav++) {
    updateChamp($noms[$nav],$valeurs[$nav]);
  }
}
// -----------------------------------------------------------------------------
// Mettre a jour la valeur d un element.
// Input : $nom (string) Nom de l element.
// Input : $valeur (string) Valeur a enregistrer.
function updateElement($nom,$valeur) {
  getChamp($nom).innerHTML=$valeur;
}
// -----------------------------------------------------------------------------
// Mettre a jour la valeur de plusieurs elements.
// Input : $noms (array[string]) Noms des elements
// Input : $valeurs (array[string]) Valeurs a enregistrer.
function updateElements($noms,$valeurs) {
  for(var $nav=0;$nav<$noms.length;$nav++) {
    updateElement($noms[$nav],$valeurs[$nav]);
  }
}
// -----------------------------------------------------------------------------
// Remplacer du texte par un autre dans un champ.
// Input : $nom (string) Nom du champ.
// Input : $source (string) Texte a remplacer.
// Input : $cible (string) Texte a de remplacement.
function replaceChamp($nom,$source,$cible) {
  var $tmp=getChamp($nom).value;
  while ($tmp.indexOf($source)>-1) {
    alert($tmp.indexOf($source));
    $tmp=$tmp.replace($source,$cible);
  }
  updateChamp($nom,$tmp);
}
// -----------------------------------------------------------------------------
// Remplacer du texte par un autre dans plusieurs champs.
// Input : $noms ([string]) Noms des champs.
// Input : $source (string) Texte a remplacer.
// Input : $cible (string) Texte a de remplacement.
function replaceChamps($noms,$source,$cible) {
  for(var $nav=0;$nav<$noms.length;$nav++) {
    replaceChamp($noms[$nav],$source,$cible);
  }
}
// -----------------------------------------------------------------------------
// Activer la lecture seule d un champ.
// Input : $nom (string) Nom du champ.
function readonlyChamp($nom) {
  getChamp($noms[$nav]).readonly=true;
}
// -----------------------------------------------------------------------------
// Activer la lecture seule de plusieurs champs.
// Input : $noms (array(string)) Noms des champs.
function readonlyChamps($noms) {
  for(var $nav=0;$nav<$noms.length;$nav++) {
    readonlyChamp($noms[$nav]);
  }
}
// -----------------------------------------------------------------------------
// Activer la lecture ecriture d un champ.
// Input : $nom (string) Nom du champ.
function readwriteChamp($nom) {
  getChamp($noms[$nav]).readonly=false;
}
// -----------------------------------------------------------------------------
// Activer la lecture ecriture de plusieurs champs.
// Input : $noms (array(string)) Noms des champs.
function readwriteChamps($noms) {
  for(var $nav=0;$nav<$noms.length;$nav++) {
    readwriteChamp($noms[$nav]);
  }
}
// -----------------------------------------------------------------------------
// Activer un champ.
// Input : $nom (string) Nom du champ.
function enableChamp($nom){
  getChamp($nom).disabled=false;
}
// -----------------------------------------------------------------------------
// Activer plusieurs champs.
// Input : $noms (array[string]) Noms des champs.
function enableChamps($noms){
  for(var $nav=0;$nav<$noms.length;$nav++) {
    enableChamp($noms[$nav]);
  }
}
// -----------------------------------------------------------------------------
// Desactiver un champ.
// Input : $nom (string) Nom du champ.
function disableChamp($nom){
  getChamp($nom).disabled=true;
}
// -----------------------------------------------------------------------------
// Desactiver plusieurs champs.
// Input : $noms (array[string]) Noms des champs.
function disableChamps($noms){
  for(var $nav=0;$nav<$noms.length;$nav++) {
    disableChamp($noms[$nav]);
  }
}
// -----------------------------------------------------------------------------
// Cocher une case a cocher.
// Input : $nom (string) Nom de la case.
function checkCase($nom) {
    getChamp($nom).checked=true;
}
// -----------------------------------------------------------------------------
// Cocher plusieurs cases a cocher.
// Input : $noms (array[string]) Noms des cases.
function checkCases($noms){
  for(var $nav=0;$nav<$noms.length;$nav++) {
    checkCase($noms[$nav]);
  }
}
// -----------------------------------------------------------------------------
// Decocher une case a cocher.
// Input : $nom (array[string]) Nom de la case.
function uncheckCase($nom) {
    getChamp($nom).checked=false;
}
// -----------------------------------------------------------------------------
// Decocher plusieurs cases a cocher.
// Input : $noms (array[string]) Noms des cases.
function uncheckCases($noms){
  for(var $nav=0;$nav<$noms.length;$nav++) {
    uncheckCase($noms[$nav]);
  }
}
// -----------------------------------------------------------------------------
// Inverser l etat du cochage d une case.
// Input : $nom (string) Nom de la case.
function reverseCase($nom) {
  if (getChamp($nom).checked==false) {checkCase($nom);}
  else {uncheckCase($nom);}
}
// -----------------------------------------------------------------------------
// Inverser l etat du cochage de plusieurs cases.
// Input : $noms (array[string]) Noms des cases.
function reverseCases($noms){
  for(var $nav=0;$nav<$noms.length;$nav++) {
    reverseCase($noms[$nav]);
  }
}
// -----------------------------------------------------------------------------
// Retourner la date du jour au format US de MySQL.
// Output : Date (YYYY-MM-JJ)
function getDateUS() {
  var $date_jour=new Date();
  var $date_us=$date_jour.getFullYear();
  if (($date_jour.getMonth()+1)<10) {
    $date_us+="-0"+($date_jour.getMonth()+1);
  } else {
    $date_us+="-"+($date_jour.getMonth()+1);
  }
  if (($date_jour.getDate())<10) {
    $date_us+="-0"+($date_jour.getDate());
  } else {
    $date_us+="-"+($date_jour.getDate());
  }
  return($date_us);
}
// -----------------------------------------------------------------------------
// Convertir une date US en date FRA.
// Input : $dateUS (string) AAAA-MM-JJ.
// Output : (string) JJ-MM-AAAA.
function convertDate2Fra($dateUS) {
  var $annee=$dateUS.substr(0,4);
  var $mois=$dateUS.substr(5,2);
  var $jour=$dateUS.substr(8,2);
  var $dateFRA=$jour+"-"+$mois+"-"+$annee;
  return($dateFRA);
}
// -----------------------------------------------------------------------------
// Afficher un lien.
// Input : $nom (string) Nom du lien.
function postLien($nom) {
  getChamp($nom).style.visibility="visible";
}
// -----------------------------------------------------------------------------
// Afficher plusieurs liens.
// Input : $noms (array[string]) Noms des liens.
function postLiens($noms) {
  for(var $nav=0;$nav<$noms.length;$nav++) {
    postLien($noms[$nav]);
  }
}
// -----------------------------------------------------------------------------
// Cacher un lien.
// Input : $nom (string) Nom du lien.
function hideLien($nom) {
  getChamp($nom).style.visibility="hidden";
}
// -----------------------------------------------------------------------------
// Cacher plusieurs liens.
// Input : $noms (array[string]) Noms des liens.
function hideLiens($noms) {
  for(var $nav=0;$nav<$noms.length;$nav++) {
    hideLien($noms[$nav]);
  }
}
// -----------------------------------------------------------------------------
// Afficher un element.
// Input : $nom (string) Nom de l element.
function postElement($nom) {
  if (navigator.appName=="Microsoft Internet Explorer") {
    //getChamp($nom).style.filter="blendTrans(duration=1)";
    //getChamp($nom).filters.blendTrans.Apply();
  }
  getChamp($nom).style.visibility="visible";
  getChamp($nom).style.display="block";
  if (navigator.appName=="Microsoft Internet Explorer") {
    //getChamp($nom).filters.blendTrans.Play();
  }
}
// -----------------------------------------------------------------------------
// Afficher plusieurs elements.
// Input : $noms (array[string]) Noms des elements.
function postElements($noms) {
  for(var $nav=0;$nav<$noms.length;$nav++) {
    postElement($noms[$nav]);
  }
}
// -----------------------------------------------------------------------------
// Cacher un element.
// Input : $nom (string) Nom de l element.
function hideElement($nom) {
  if (navigator.appName=="Microsoft Internet Explorer") {
    //getChamp($nom).style.filter="blendTrans(duration=1)";
    //getChamp($nom).filters.blendTrans.Apply();
  }
  getChamp($nom).style.visibility="hidden";
  getChamp($nom).style.display="none";
  if (navigator.appName=="Microsoft Internet Explorer") {
    //getChamp($nom).filters.blendTrans.Play();
  }
}
// -----------------------------------------------------------------------------
// Cacher plusieurs elements.
// Input : $noms (array[string]) Noms des elements.
function hideElements($noms) {
  for(var $nav=0;$nav<$noms.length;$nav++) {
    hideElement($noms[$nav]);
  }
}
// -----------------------------------------------------------------------------
// Inverser l etat d affichage d un element.
// Input : $nom (string) Nom de l element.
function reverseElement($nom) {
  if (getChamp($nom).style.visibility=="hidden") {postElement($nom);}
  else {hideElement($nom);}
}
// -----------------------------------------------------------------------------
// Inverser l etat d affichage de plusieurs elements.
// Input : $noms (array[string]) Noms des elements.
function reverseElements($noms) {
  for(var $nav=0;$nav<$noms.length;$nav++) {
    reverseElement($noms[$nav]);
  }
}
// -----------------------------------------------------------------------------
// Inserer une ligne a la fin d une liste de selection.
// Input : $nom (string) Nom de la liste.
// Input : $valeur (string) Valeur a ajouter.
// Input : $texte (string) Texte associe a l option ajoutee.
function insertSelect($nom,$valeur,$texte) {
  getChamp($nom).options[getChamp($nom).options.length]=new Option($texte,$valeur);
}
// -----------------------------------------------------------------------------
// Vider une liste de selection.
// Input : $nom (string) Nom de la liste.
function eraseSelect($nom) {
  var $nav;
  for($nav=(getChamp($nom).options.length-1);$nav>=0;$nav--){
    getChamp($nom).options[$nav]=null;
  }
}
// -----------------------------------------------------------------------------
// Rechercher si une valeur existe dans une liste de selection.
// Input : $nom (string) Nom de la liste.
// Input : $valeur (string) Valeur a trouver.
// Output : Reponse (bool).
function existInSelect($nom,$valeur) {
  var $nav; var $trouve=false;
  for($nav=(getChamp($nom).options.length-1);$nav>=0;$nav--){
    if (getChamp($nom).options[$nav].value==$valeur) {$trouve=true;}
  }
  return($trouve);
}
// -----------------------------------------------------------------------------
// Selectionner une valeur dans une liste si elle existe.
// Input : $nom (string) Nom de la liste.
// Input : $valeur (string) Valeur a selectionner.
function selectInSelect($nom,$valeur) {
  if (existInSelect($nom,$valeur)==true) {
    updateChamp($nom,$valeur);
  }
}
// -----------------------------------------------------------------------------
