/* (c) Scientec Internet Applications + Media GmbH - www.scientec.de */

window.name="index-";
window.onerror=catchError;
if(self!=top ) {top.location=self.location}

var dom=(document.getElementById)?1:0;
var ie=(document.all && dom)?1:0;
var tag=(document.getElementsByTagName)?1:0;
var lay=(document.layers)?1:0;

function catchError(Nachricht,Datei,Zeile){return true}

function init(){
  if (dom){
    modifyEmails();
    modifyExternalLinks();
    highlightNavigation();
    searchStringHighlight();
  }
}

function highlightNavigation(){
  if(document.getElementById('navigation')){
    var obj=document.getElementById('navigation');
    var length=obj.getElementsByTagName("a").length;
    var url=document.location.href.replace(/_\d/gi,"");
    if(document.getElementById("pfad")){
      var link2="";
      if(document.getElementById("pfad").getElementsByTagName("a").length>2){
        var link2=document.getElementById("pfad").getElementsByTagName("a")[2].href;
      }
      for (var i=0; i<length; i++){
        var A=obj.getElementsByTagName("a")[i];
        if (A.href==url || (A.href==link2)){
          A.parentNode.style.backgroundColor="#fff";
          A.style.color="#505050";
          A.style.textDecoration="none";
        }
  	  else {
          A.parentNode.style.backgroundColor="";
          A.style.color="";
          A.style.textDecoration="";
        }
      }
    }
  }
}

function modifyExternalLinks(){
  for (var i=0; i<document.links.length;i++){
    var o=document.links[i];
    if((o.target=="link" || o.className.indexOf("ext")!=-1) && o.href.indexOf("dmoz.org")==-1){		
      o.onclick=function(){
        var HREF=escape(this.href).replace(/\%25/gi,"%").replace(/\%3A/gi,":");
        link=window.open("/onTEAM/exit.shtml?"+HREF,"link",'');
        return false
      }
	}
    if(o.href.indexOf("wiktionary.org")!=-1){		
      o.title="WIKTIONARY > "+o.title;
    }
  }
}


function modifyEmails() {
  for(var i=document.getElementsByName("a").length-1; i>=0;i--){
    str=document.getElementsByName("a")[i].parentNode.innerHTML.replace(/<img.+?>/ig,"\@").replace(/<.+?>/ig,"");
    document.getElementsByName("a")[i].parentNode.innerHTML="<a href='mailto:"+str+"'>"+str+"</a>";
  }
}

function highlightWord(node,word) {
  if (node.hasChildNodes){
    var hi_cn;
    for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++){
      highlightWord(node.childNodes[hi_cn],word);
    }
  }
  if (node.nodeType == 3 && node.parentNode.tagName!="TEXTAREA") {
    tempNodeVal = node.nodeValue.toLowerCase();
    tempWordVal = word.toLowerCase();
    if (tempNodeVal.indexOf(tempWordVal) != -1) {
      pn = node.parentNode;
      if (pn.className != "searchword") {
        nv = node.nodeValue;
        ni = tempNodeVal.indexOf(tempWordVal);
        before = document.createTextNode(nv.substr(0,ni));
        docWordVal = nv.substr(ni,word.length);
        after = document.createTextNode(nv.substr(ni+word.length));
        hiwordtext = document.createTextNode(docWordVal);
        hiword = document.createElement("span");
        hiword.className = "searchword";
        hiword.title = "Suchtreffer";
        hiword.appendChild(hiwordtext);
        pn.insertBefore(before,node);
        pn.insertBefore(hiword,node);
        pn.insertBefore(after,node);
        pn.removeChild(node);
      }
    }
  }
}

function searchStringHighlight() {
  if (!document.createElement || !document.getElementsByTagName) return;
  ref = document.referrer;
  if (ref.indexOf('?') == -1 || ref.indexOf('google') == -1 || ref.indexOf('search') == -1) return;
  qs = ref.substr(ref.indexOf('?')+1);
  qsa = qs.split('&');
  for (i=0;i<qsa.length;i++) {
    qsip = qsa[i].split('=');
    if (qsip.length == 1) continue;
    if (qsip[0] == 'q' || qsip[0] == 'as_q') { /* q= for Google, p= for Yahoo*/
      words = unescape(qsip[1].replace(/\+/g,' ')).replace(/\"/g,'').split(/\s+/);
      highlightedWords="";
      for (var w=0;w<words.length;w++) {
        if(words[w].length>3) {
          highlightWord(document.getElementById("inhalt"),words[w]);
          highlightedWords+="<span class=searchword>"+words[w]+"</span> "
        }
      }
    }
  }
  if(highlightedWords!="" && document.getElementById("seitentools")){document.getElementById("seitentools").innerHTML+="<div id=suchtrefferliste>Found: "+highlightedWords+"</div>"}
}



