/* routines voor de zoekmachine en de keuzelijsten op de Zinhoud */

//Zinhoud: geselecteerde webpagina tonen
function Keuze(j)
	{
	if (j==1)
	 {var x = document.Znederls.keuze.selectedIndex;
	 if (x==0) return;
	 if (x!=0)
	   {window.location.href=document.Znederls.keuze.options[x].value;
	 } }
	if (j==2)
	 {var y = document.Zenglish.choice.selectedIndex;
	 if (y==0) return;
	 if (y!=0)
	   {window.location.href=document.Zenglish.choice.options[y].value;
	 } }
	}

//Zinhoud: link naar zoekmachine
function searchPage(j)
	{
	if (j==1)
	 {if ((document.searchpage1.keyword.value.length == 0)
	 || (document.searchpage1.keyword.value == " ")) 
	  {alert("Geef eerst een woord om naar te zoeken.");
	  } else
	  {var sel = document.searchpage1.and_or.selectedIndex;
	  location.href = xy1 + "?"
	   + escape(document.searchpage1.keyword.value)
	   + (sel==0?"&and":(sel==2?"&exact":"&or"));
	  }
	 }
	if (j==2)
	 {if ((document.searchpage2.keyword.value.length == 0)
	 || (document.searchpage2.keyword.value == " ")) 
	  {alert("First you must enter a keyword to search for.");
	  } else
	  {var sel = document.searchpage2.and_or.selectedIndex;
	  location.href = xy2 + "?"
	   + escape(document.searchpage2.keyword.value)
	   + (sel==0?"&and":(sel==2?"&exact":"&or"));
	  }
	 }
	  return true;
}

//patronen, structuur-lijn: genummerde plaatjes wisselen
var tdl="";
function changer(j)
      	{
	//#9 nu via DYNpage.js
	if (j=="draaiing"){min=0;
		max=4;
		name="images/6tijd"};
	if (j=="ecliptica"){min=0;
		max=5;
		name="images/6bol0"};
	if (j=="4D"){min=0;
		max=5;
		name="images/6fourD0"};
	if (j=="4D2"){min=0;
		max=5;
		name="images/6fourD2"};
	//#13 nu via DYNpage.js
	map="animate/img13/";
	if (j=="tilt"){min=1;
		max=13;
		name=map+"13tilt";
		};
	if (j=="ascend"){min=1;
		max=13;
		name=map+"13asc";
		};
	if (j=="ecliptic"){min=1;
		max=8;
		name=map+"13ecl";
		};
	if (j=="kaart"){min=1;
		max=13;
		name=map+"13krt";
		};
	//#19 nu via DYNpage.js
	if (j=="proces"){min=0;
		max=5;
		name="images/19draai";
		};
      	counter += 1;	
      	if (counter==max){counter=min};
	if (j!=tdl){counter=min+1};
      	document.images[j].src=name+counter+".gif";
	tdl=j;
      	}

// 5 routines voor zoekmachine
function Page(url,title,keywords,description) {
 while ((url.length > 0) && (url.charAt(0) == " ")) {
  url = url.substring(1,url.length);
 }
 this.url = url;
 while ((title.length > 0) && (title.charAt(0) == " ")) {
  title = title.substring(1,title.length);
 }
 this.title = title;
 this.keywords = keywords;
 this.description = description;
 return this;
}

function Database() {
 var pos = 0, pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
 while ((pos1 = amorphous.indexOf("~",pos)) != -1) {
  pos2 = amorphous.indexOf("|",pos1+1);
  pos3 = amorphous.indexOf("^",pos2+1);
  pos4 = amorphous.indexOf("*",pos3+1);
  if ((pos2 != -1)
  && (pos2 < pos3) && (pos3 < pos4)
  && (pos4 <= amorphous.indexOf("*",pos))) {
   this[database_length++] = new Page(amorphous.substring(pos,pos1),
   amorphous.substring(pos1+1,pos2),
   amorphous.substring(pos2+1,pos3),
   amorphous.substring(pos3+1,pos4));
   pos = pos4+1;
  } else { // error reading amorphous database
   if (pos+30 <= amorphous.length)
    alert('Error reading in amorphous database around "'
     + amorphous.substring(pos,pos+30) + '"');
   pos = amorphous.indexOf("*",pos) + 1;
  }
 }
 return this;
}

function search(str) {
 menu_length = 0;
 temp = new Object();
 temp_length = 0;
 words_length = 0;
 words = new Object();
 pos = 0;
 while ((pos = str.indexOf(" ")) != -1
 && and_search != "exact") {
  words[words_length] = str.substring(0,pos);
  if (words[words_length].length > 0)
   words_length++;
  if (str.length == 1)
   str="";
  else
   str = str.substring(pos+1,str.length);
 }
 if (str.length > 0)
  words[words_length++] = str;
 for (var q=0;q<words_length;q++) {
  temp_length = 0;
  str = words[q].toLowerCase();
  len = (and_search=="and"&&q>0?menu_length:database_length);
  for (n=0; n<len; n++) { 
  // forward search: (n=0; n<len; n++) // (n=len-1; n>0; n--)
   if (and_search=="and"&&q>0) {
    combo = (menu[n].title + " " + menu[n].description
     + " " + menu[n].keywords).toLowerCase();
   } else {
    combo = (database[n].title + " " + database[n].description
     + " " + database[n].keywords).toLowerCase();
   }
   if (combo.indexOf(str) != -1) // found
    temp[temp_length++] = (and_search=="and"&&q>0?menu[n]:database[n]);
  }
  if (and_search!="and" && q>0) {
   added = 0;
   for (i=0;i<temp_length;i++) {
    duplicate = false;
    for (j=0;j<menu_length&&!duplicate;j++) {
     if (menu[j] == temp[i]) {
      duplicate = true;
     }
    }
    if (!duplicate)
     menu[menu_length+(added++)] = temp[i];
   }
   menu_length += added; return added;
  } else {
   for(h=0;h<temp_length;h++)
    menu[h] = temp[h];
   menu_length = temp_length;
  }
 }
  return true; 
}

function entry() {
 if ((document.entryform.keyword.value.length == 0)
 || (document.entryform.keyword.value == " ")) {
  alert("First you must enter a keyword to search for.");
  return false;
 }
 and_search = (document.entryform.and_or.selectedIndex == 0?"and":"or");
 if (document.entryform.and_or.selectedIndex == 2)
  and_search = "exact";
 location.href = location.pathname + "?"
  + escape(document.entryform.keyword.value)
  + (and_search != "or"?"&"+and_search:"");
 return false;
}

function redWord(str) {
 for(r=0; r<words_length; r++) {
  pos = -3;
  word = words[r].toLowerCase();
  while ((pos = str.toLowerCase().indexOf(word,pos+3)) != -1) {
   val = pos+word.length;
   str = str.substring(0,pos) + "*"
    + str.substring(pos,val) + "|"
    + str.substring(val,str.length);
  }
 }
 pos = -16;
 while ((pos = str.toLowerCase().indexOf("*",pos+16)) != -1)
  str = str.substring(0,pos) + "<font color=red>"
   + str.substring(pos+1,str.length);
 pos = -7;
 while ((pos = str.toLowerCase().indexOf("|",pos+7)) != -1)
  str = str.substring(0,pos) + "</font>"
   + str.substring(pos+1,str.length);
 return str;
}

//genummerde teksten tonen in apart venster
function meertxt(i)
	{
	alert(item[i]);
	}
// -->
