// JavaScript Document
function montre_menu_niv1(id) 
{
	for (var i=1; i<=24; i++) 
  {
		if (document.getElementById('smenu'+i)) 
    {
    document.getElementById('smenu'+i).style.display='none';
    }
	}
  
  if (document.getElementById(id)) 
  {
  document.getElementById(id).style.display='block';
  }
}

function montre_menu_niv2(id) 
{
  for (var i=5; i<=24; i++)
  {
		if (document.getElementById('smenu'+i)) 
    {
    document.getElementById('smenu'+i).style.display='none';
    }
	}
	
	if (document.getElementById(id)) 
  {
  document.getElementById(id).style.display='block';
  }
}
//--------------------------------------------------------------------------------------------------
//La variable dans le onchange="n=0;" est bien réinitialisée sous ie. Elle permet sous ie de
//faire partir la recherche en haut de page si en cours de recherche sur un mot on en choisit un autre.
//Sous FF la recherche part là où le dernier mot a été sélectionné.
var n= 0;
var id0;


function chercherDansLaPage()
{
var txt, x, found;
var string = document.getElementById(id0).options[document.getElementById(id0).selectedIndex].value;

 if (string != "")
 {

   if (document.all) 
   {
   
     //i.e
     txt = window.document.body.createTextRange();
     for (x = 0; x <= n && (found = txt.findText(string)) != false; x++) 
     {
     //moveStart(String mode, Integer n)
     //Définit l'unité à utiliser. Déclenche une erreur "Argument non valide" dans le cas où l'unité est inconnue
     //Définit le nombre d'unités que le curseur de départ doit se déplacer, relativement à sa position d'origine.
     txt.moveStart("character", 1);
     //moveEnd()
     //Moves the end position of a text to a new location
     //textedit = start or end of the text range
     txt.moveEnd("textedit");
     }
     
     if (found) 
     {
     //Si texte trouvé, le sélectionner et faire défiler la page pour qu'il soit visible
     txt.moveStart("character", -1);
     txt.findText(string);
     txt.select();//crée une sélection active sur le texte
     txt.scrollIntoView();//fait défiler jusqu'au texte
     n++;
     document.onkeypress=touche;
     }
     else 
     {
     //Si plus de texte trouvé alors recherche terminée. Réinitialisation du compteur.
     document.onkeypress="";
     alert("La recherche est terminée.");
     n = 0;
     }
   }
   else
   {
     //autres navigateurs. Utilisation de window.find() au lieu de createTextRange()
     //Si texte trouvé, le sélectionner et faire défiler la page pour qu'il soit visible  
     if (window.find(string))
     {
     n++;
     document.onkeypress=touche;
     }
     else
     {
     //while(window.find(string, false, true)); 
     //n++;
     }  
   }
 }    
 return false;	
}

function touche(e)
{
  if (document.all)
  {
    if (event.keyCode==13) 
    {
    chercherDansLaPage();
    }
  } 
  else 
  {
    if (e.which==13)
    { 
    chercherDansLaPage();
    }
  }
}

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

function ouvrirPopup(page,x,y)
{
window.open(page,'','resizable=no, location=no, menubar=no, status=no, scrollbars=yes, directories=no, width=' + x + ', height=' + y + ', left=' + ((screen.width - x)/2) + ', top=' + ((screen.height - y)/2));
}

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

function ouvrirPopup0(page,x,y)
{
window.open(page,'','resizable=yes, location=no, menubar=no, status=no, scrollbars=yes, directories=no, width=' + x + ', height=' + y + ', left=' + ((screen.width - x)/2) + ', top=' + ((screen.height - y)/2));
}

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

//popup page archives de st barthelemy : biographie
function ouvrirPopup1(page)
{
window.open(page,'','resizable=no, location=no, menubar=no, status=no, scrollbars=yes, directories=no, width=500, height=150, left=' + ((screen.width - 500)/2) + ', top=' + ((screen.height - 150)/2));
}

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

//popup page archives de st barthelemy : recensements
function ouvrirPopup2(page)
{
window.open(page,'','resizable=yes, location=no, menubar=no, status=no, scrollbars=yes, directories=no, width=700, height=525, left=' + ((screen.width - 700)/2) + ', top=' + ((screen.height - 525)/2));
}

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

function insertionsource()
{
    var mySource= "'Comité de Liaison et d'Application des Sources Historiques', Saint-Barthélemy. URL : " + document.location; 
    
    
  //Creates a TextRange object from the current text selection
    var selObj=document.selection.createRange().text;
    
  //Si pas de sélection, pas d'action
    if (selObj.length<1)
    {
    }
    //Si sélection > 20 caractères
    else if (selObj.length<20) 
    {
    //nettoyage du presse-papier(clipboarddata)
    window.clipboardData.clearData();
    //Insertion de la sélection dans le presse-papier. mySource n'est pas inséré à la séléction.
    window.clipboardData.setData("Text",selObj);
    //Après copie, la sélection n'apparait plus en bleu. 
    document.selection.empty();
    }
    else
    {
    window.clipboardData.clearData();
    window.clipboardData.setData("Text",selObj + '\r\rSource: ' + mySource); 
    document.selection.empty();
    }
}
//--------------------------------------------------------------------------------------------------

function affichedetails(id)
{
 for (var i=1; i<=100; i++) 
 {
	if (document.getElementById('details'+i)) 
  {
  document.getElementById('details'+i).style.display='none';
  }
 }
  
 if (document.getElementById(id)) 
 {
 document.getElementById(id).style.display='block';
 }
}
  
