function insert() {

  form = document.forms[0];
  word=form.elements['word'].value;
  
   if (word=="") {
	   form.elements['word'].value="Suchbegriff eingeben";
	}
}

window.setTimeout('insert()',500);

function autocomplete() {

  form = document.forms[0];
  file = form.elements['file'].value;
  word = form.elements['word'].value;
  
  if(word=="Suchbegriff eingeben") {
    form.elements['word'].value="";
  }
  //file= window.location.href;
  //alert(file);
	url = "../../cgi-bin/search/alphanum_extract.php?uri="+file+"&word="+word;
  
  // Versuch AJAX mit xmlhttp:
  try { 
  	if(document.all) {
    		xmlhttp.open("GET",url,true);
    }
  	xmlhttp.onreadystatechange=function() {
  	 	if (xmlhttp.readyState==4 && xmlhttp.responseText) {
   	 		document.getElementById('select').innerHTML = xmlhttp.responseText;
   		}
  	}
		if(!document.all && !window.opera) {
  		xmlhttp.open("GET",url,true);
  	}
 		xmlhttp.send();
 		
 	// Alternative mit iframe:
	} catch (e) { 
		if(!window.frames[0]) {
		
			iframe= '<iframe frameborder="0" src="about:blank"></iframe>';
   	 	document.getElementById('select').innerHTML = iframe;	
		}
 		window.frames[0].location.href=url+"&iframe=1";
	}
	finally {
  	window.document.getElementById('select').style.display="block";
	}
	tempvar = window.setTimeout('autocomplete()',2000);
	return false;
 
}

function copy (e) {

	var elem = e;
	form = parent.document.forms[0];
	form.elements['word'].value=e.innerHTML; 
	window.document.getElementById('select').style.display="none";
  if(window.tempvar) window.clearTimeout(tempvar);
}

function form_submit() {

  parent.document.forms[0].submit();
  
}

function string_highlight_words (string, word) {

	newword ="<span class=\"search\">"+word+"<\/span>";
	myRegExp = new RegExp(word,"g");
	string = string.replace(myRegExp,newword);

  return string;
  
} // Highlighting der Suchtreffer

function search (elem, word) {
	
	word = word || document.forms[0].elements['word'].value;
	elem = elem || document.getElementById("container");
	
	remove_className (elem, "search");
	string = elem.innerHTML;
	
	if(word!="") {
		elem.innerHTML = string_highlight_words(string,word);
	}
}

function remove_className (elem, name) {
	
	span = elem.getElementsByTagName("span");
	for(i=0;i<span.length;i++) {
		if(span[i].className == name ) {
			span[i].className = "";
		}
	}
	
} // Highlighting der Suchtreffer aufheben

