// NL Versie


function MM_swapImgRestore() { //v2.0
  if (document.MM_swapImgData != null)
    for (var i=0; i<(document.MM_swapImgData.length-1); i+=2)
      document.MM_swapImgData[i].src = document.MM_swapImgData[i+1];
}

function MM_preloadImages() { //v2.0
  if (document.images) {
    var imgFiles = MM_preloadImages.arguments;
    if (document.preloadArray==null) document.preloadArray = new Array();
    var i = document.preloadArray.length;
    with (document) for (var j=0; j<imgFiles.length; j++) if (imgFiles[j].charAt(0)!="#"){
      preloadArray[i] = new Image;
      preloadArray[i++].src = imgFiles[j];
  } }
}

function MM_swapImage() { //v2.0
  var i,j=0,objStr,obj,swapArray=new Array,oldArray=document.MM_swapImgData;
  for (i=0; i < (MM_swapImage.arguments.length-2); i+=3) {
    objStr = MM_swapImage.arguments[(navigator.appName == 'Netscape')?i:i+1];
    if ((objStr.indexOf('document.layers[')==0 && document.layers==null) ||
        (objStr.indexOf('document.all[')   ==0 && document.all   ==null))
      objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);
    obj = eval(objStr);
    if (obj != null) {
      swapArray[j++] = obj;
      swapArray[j++] = (oldArray==null || oldArray[j-1]!=obj)?obj.src:oldArray[j];
      obj.src = MM_swapImage.arguments[i+2];
  } }
  document.MM_swapImgData = swapArray; //used for restore
}

function Lien() {
 i = document.Choix.Liste.selectedIndex;
 url = document.Choix.Liste.options[i].value;
 parent.location.href = url;
}

function removeSpaces(string) {
 return string.split(' ').join('');
}

function CheckValidUrl(strUrl)
{
        var RegexUrl = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
        return RegexUrl.test(strUrl);
}

function Instr(str,substr,start){
var oStr = new String(str);
return oStr.indexOf(substr,start);
}

function buildlink()
      {
        var newlink ;
	var lverset ;
	var currlocation;
	var instrphp

	//newlink = oform.elements["verset"].value;
	currlocation = document.location.href;
	//alert (currlocation);
	lverset = document.Choix.txtFirstNumber.value;

	//alert(">"+lverset+"<");
	if (lverset == " " )
		{ alert("Geef het boek aan, gevolgd door een komma en het vers, in cijfers.");
		  return false ;}
	if (lverset == "" )
		{ alert("Geef het boek aan, gevolgd door een komma en het vers, in cijfers.");
		  return false ;}

	//	currentadress = document.location.href;
	//alert(currentadress);
	//alert(lverset);
	lverset = lverset.replace(";",",");
	lverset = lverset.replace(" ",",");
	lverset = lverset.replace(".",",");	
	lverset = lverset.replace("_",",");
	lverset = lverset.replace("-",",");
	lverset = removeSpaces(lverset.replace("+",","));
	lverset = lverset.replace(",,",",");
	//var newlink = "document.location.href='Livre_04_.htm#20'";
	//alert(lverset);
	//alert (lverset.substr(2,1));
	if (lverset.substr(2,1)==",")
		{ newlink='Boek_' +lverset.substr(0,2)+'_.htm#'+lverset.substr(3);
		  nlivre = lverset.substr(0,2); }
	else    { newlink='Boek_0' +lverset.substr(0,1)+'_.htm#'+lverset.substr(2);
		  nlivre = lverset.substr(0,1); }
	//alert(">"+nlivre+"<");
	nnlivre = parseInt(nlivre);
	if (lverset = "")
		{ alert("Geef het boek aan, gevolgd door een komma en het vers, in cijfers.");
		  return false ;}
	
	if (Instr(currlocation,"htm",1)> 0) 
		{;}
	else
		 {	newlink = newlink.replace("Boek_","DeHervondenBoodschap.php?Boek=");
			newlink = newlink.replace("_.htm",""); 	}

	//alert(CheckValidUrl("http://www.geekpedia.com"));
	if (nnlivre>41)
		{ alert("Het boeknummer moet tussen 1 en 40 liggen!");
		  return false ;}
	else	{ 
	document.location.href=newlink;
	          return true; }
      }
      
      


function TirerVerset(){

var Livre = 0;
Livre = Math.round(Math.random()*40)+1;
var Livres = Livre + "";
//Alert (Livres);
//nombre de versets maximum pour chaque livre;
var nverset=new Array;
nverset[0]=6;
nverset[1]=74;
nverset[2]=91;
nverset[3]=71;
nverset[4]=98;
nverset[5]=95;
nverset[6]=62;
nverset[7]=64;
nverset[8]=63;
nverset[9]=61;
nverset[10]=65;
nverset[11]=72;
nverset[12]=77;
nverset[13]=60;
nverset[14]=66;
nverset[15]=70;
nverset[16]=61;
nverset[17]=67;
nverset[18]=71;
nverset[19]=68;
nverset[20]=73;
nverset[21]=75;
nverset[22]=76;
nverset[23]=79;
nverset[24]=56;
nverset[25]=58;
nverset[26]=59;
nverset[27]=57;
nverset[28]=54;
nverset[29]=53;
nverset[30]=50;
nverset[31]=55;
nverset[32]=52;
nverset[33]=51;
nverset[34]=78;
nverset[35]=80;
nverset[36]=108;
nverset[37]=69;
nverset[38]=69;
nverset[39]=54;
nverset[40]=22;
nverset[41]=111;


MaxLivre = nverset[Livre];
verset =   Math.round(Math.random()*MaxLivre)+1;
if (verset > MaxLivre) { verset = MaxLivre ; }
var oStr = new String(Livre+","+verset);
document.Choix.txtFirstNumber.value = oStr;

comp=(setTimeout("buildlink()",600));

}
function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}



// Création : Dustin Diaz
//Site : http://www.dustindiaz.com/getelementsbyclass
function getElementsByClass(searchClass, node, tag) { 
var classElements = new Array(); 
if ( node == null ) 
node = document; 
if ( tag == null ) 
tag = '*'; 
var els = node.getElementsByTagName(tag); 
var elsLen = els.length; 
var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); 
for (i = 0, j = 0; i < elsLen; i++) { 
if ( pattern.test(els[i].className) ) { 
classElements[j] = els[i]; 
j++; 
} 
} 
return classElements; 
} 

function tailleFonte(classe, taille) { 
//alert(taille);
cibles = getElementsByClass(classe); 
for (i = 0; i < cibles.length; i++) { 
        cibles[i].style.fontSize = taille; 
        } 
    
    } 
    
function GettailleFonte(classe) { 
cibles = getElementsByClass(classe); 
for (i = 0; i < cibles.length; i++) { 
        taille = cibles[i].style.fontSize  ; 
        } 
return taille;
    } 


// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			//alert (cookie_value);
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function taille_initiale() {
  //alert("taille_initiale_1") ;
  taille_s = Get_Cookie('mr_verset_font_size');
  //alert(taille_s) ;
  if (taille_s == null) {taille_s = "90"};
  if (taille_s == "NaN") {taille_s = "90"};
  taille = parseInt(taille_s);
  //alert(taille) ;
  Set_Cookie( 'mr_verset_font_size', taille_s, 30, '/', '', '' )
  taille_s = taille+"%";
  //si on ajuste ici ne pas oublier openingPrintWindow() ci-dessous !!!
  tailleFonte('text2',taille_s);
  tailleFonte('text21',taille_s);
  taille_Titre = taille + 10 ;
  taille_Titre_s = taille_Titre +"%";
  tailleFonte('TITOL',taille_Titre_s );
  tailleFonte('text1',taille_Titre_s);
  tailleFonte('num',taille_s);
  }
  
function taille_changer(delta) {
  taille_s = Get_Cookie('mr_verset_font_size');
// alert("taille_s changer init>"+taille_s+"<");
  if (taille_s == null ) {
  	//cas ou on tourne sur une machine locale, pas de cookies disponibles
	   gottaille = GettailleFonte('text2');
	   if (gottaille == "100%") { gottaille = "90%" ; }
  	   taille_s = gottaille.substring(0,2);
	   }
  taille = parseInt(taille_s);
  taille = taille + delta;
  if (taille < 60) {taille = 60;}
  if (taille > 100) {taille = 100;}
//  alert("taille changer mid>"+taille+"<");
  Set_Cookie( 'mr_verset_font_size', taille, 30, '/', '', '' );
  taille_s = taille+"%";
  tailleFonte('text2',taille_s);
  tailleFonte('num',taille_s);
  taille_Titre = taille + 10 ;
  taille_Titre_s = taille_Titre +"%";
  tailleFonte('TITOL',taille_Titre_s );
  tailleFonte('text1',taille_Titre_s);
  tailleFonte('text21',taille_s);
  //alert(taille_s) ;	
  }

function taille_etoile() {
   document.getElementById('testBot').value="imNotBot";
   }
  
function Imprimer_Resultat() {
document.getElementById("print").style.visibility = 'hidden';
document.getElementById("aide").style.visibility = 'hidden';
document.getElementById("augmenter").style.visibility = 'hidden';
document.getElementById("diminuer").style.visibility = 'hidden';
document.getElementById("partager").style.visibility = 'hidden';
document.getElementById("recherchesimple").style.visibility = 'hidden';
document.getElementById("rechercheavancee").style.visibility = 'hidden';
document.getElementById("back").style.visibility = 'hidden';
document.getElementById("Remarques").style.visibility = 'hidden';
document.getElementById("Retour").style.visibility = 'hidden';
document.getElementById("main_table").style.width = '100%';
window.print();
}

function Add_TopRight_Buttons() {
if ( document.getElementById("print").style.visibility == 'hidden' ) 
    {
	document.getElementById("print").style.visibility = 'visible';
	document.getElementById("aide").style.visibility = 'visible';
	document.getElementById("augmenter").style.visibility = 'visible';
	document.getElementById("diminuer").style.visibility = 'visible';
	document.getElementById("partager").style.visibility = 'visible';
	document.getElementById("recherchesimple").style.visibility = 'visible';
	document.getElementById("rechercheavancee").style.visibility = 'visible';	
	document.getElementById("back").style.visibility = 'visible';
	document.getElementById("Remarques").style.visibility = 'visible';
	document.getElementById("Retour").style.visibility = 'visible';
	document.getElementById("main_table").style.width = '72%';
    }
}
 
//function Imprimer_Livre() {
//alert("function Imprimer_Resultat");
//document.getElementById("entete").remove();
//window.print();
//}

function CopyToClipboard(textToCopy) {
var CurrentLocation = document.URL ;
var TargetLink = CurrentLocation.replace("Result","Advanced") + textToCopy 

navigator.clipboard
.writeText(TargetLink)
.then(() => {
alert("Link succesvol gekopieerd naar klembord");
})
.catch(() => {
alert("Er is een probleem opgetreden bij het kopiëren van de link naar het klembord");
});

} 

function choisir_mot(MaxMot){

var NumMot = 0;
NumMot = Math.round(Math.random()*MaxMot)+1;
var IdMot = new String("mot"+NumMot);
var Mot = new String(document.getElementById(IdMot).childNodes[0].textContent);
var NewLink = new String("Concordance.php?mot="+Mot+"&source=hasard");
document.location.href=NewLink;
return true;

}


function openPrintWindow(Target) {
     b = GettailleFonte('text2');
    var  url = Target + "?size=" + b;
    document.location.href = url;
}

function openingPrintWindow() {
 var url = document.location.href,
        params = url.split('?')[1].split('&'),
        data = {}, tmp;
    for (var i = 0, l = params.length; i < l; i++) {
         tmp = params[i].split('=');
         data[tmp[0]] = tmp[1];
    }
    if (typeof data.size !== 'undefined') {
    //alert("size= >"+ data.size +"<");
    taille_s = data.size ;
    taille = parseInt(taille_s);
   //alert(taille) ;
    taille_s = taille+"%";
   tailleFonte('text2',taille_s);
   tailleFonte('text21',taille_s);
   taille_Titre = taille + 10 ;
   taille_Titre_s = taille_Titre +"%";
   tailleFonte('TITOL',taille_Titre_s );
   tailleFonte('text1',taille_Titre_s);
   tailleFonte('num',taille_s);
    
    }
    else
    { alert("taille_s undified");}
}
	
function RefreshCaptcha() {
     // alert("RefreshCaptach") ;
     document.getElementById("captcha-image").src = 'Captcha.php?' + Date.now();
}	
