
// Copyright (C) 2004 Knuddels.com

function doTabs() // colors the <tr> alternatingly
{ for (t = 0; t < document.getElementsByTagName("table").length; t++)
  { if (document.getElementsByTagName("table")[t].className != "blind") for (r  = 0; r < document.getElementsByTagName("table")[t].getElementsByTagName("tr").length; r++)
    { for (d = 0; d < document.getElementsByTagName("table")[t].getElementsByTagName("tr")[r].getElementsByTagName("th").length; d++)
        document.getElementsByTagName("table")[t].getElementsByTagName("tr")[r].getElementsByTagName("th")[d].className = ((d%2)?'even':'odd');
      for (d = 0; d < document.getElementsByTagName("table")[t].getElementsByTagName("tr")[r].getElementsByTagName("td").length; d++)
        document.getElementsByTagName("table")[t].getElementsByTagName("tr")[r].getElementsByTagName("td")[d].className = ((r%2)?'even':'odd')+((d%2)?'Even':'Odd')
    }
  }
}

var sensiTime = 0; // object for sensi-Blinking timeouts
var sensiLast = ''; // name of anchor in last blinking DIV

function installSensi(orig) // used to install onclick-Handlers to certain anchorlinks
{ return function foo() {
    a = this.href.replace(/.+#/g,'');
    document.getElementsByName(a).item(0).parentNode.className='sensia';
//    if (sensiTime) clearTimeout(sensiTime);
//    if (sensiLast != '') document.getElementsByName(sensiLast).item(0).parentNode.className='sensi';
    s = 'document.getElementsByName("'+a+'").item(0).parentNode.className="sensi';
//    sensiTime = setTimeout(s+'";sensiTime = setTimeout(\''+s+'a"\',1400)',1000);
    setTimeout(s+'";',1000);
    setTimeout(s+'a";',1400);
    setTimeout(s+'";',1800);
    setTimeout(s+'a";',2200);
    setTimeout(s+'";',2600);
    setTimeout(s+'a";',3000);
    setTimeout(s+'";',3400);
//    sensiLast = a;
    if (orig) x = eval(orig); else x = function x() {};
    x();
  }
}

function doLinks() // attaches the tooltips to the links and attaches onclicks to anchorlinks, if anchor´s parent div has class="sensi". also replaces " " to "&nbsp;" (if not class="blind")
{ for (n=0; n < document.links.length; n++)
    with(document.links[n]) {
    if (className != "blind") innerHTML = innerHTML.replace(/ +/g,'&nbsp;');
      if (target == '_blank') title = 'Link öffnet in neuem Fenster';
      else if (target == '') {
        if (href.indexOf('#') != -1) {
	  anc = document.getElementsByName(href.replace(/.+#/g,'')).item(0);
          if (anc) {
	    if (anc.parentNode.tagName.toLowerCase() == 'div') // checking if anchor is in a div
              if (anc.parentNode.className.indexOf('sensi') != -1) { // checking if div has class=sensi
                document.links[n].onclick = installSensi(document.links[n].onclick); // install onclick-hndl. on corresp. link
              }
            z = anc.innerHTML.replace(/<.+?>/g,'');
	    if (z == '') if (anc.nextSibling) z = anc.nextSibling.innerHTML.replace(/<.+?>/g,'');
	  }
	  else z = '';
          title = ((z)?('Gehe zu "'+z+'"'):'Anzeigen')
	}
	else title = 'Link öffnet in diesem Fenster';
      }
      else title = 'Link öffnen';
      if (typeof(onclick) != 'undefined') if ((String(onclick).indexOf('window.open') != -1) || (String(onclick).toLowerCase().indexOf('pop')!= -1)) title = 'Link öffnet im Popup';
    }
}

function doKbds() // attaches the tooltips to kdb-Elements
{ for (n = 0; n < document.getElementsByTagName("kbd").length; n++)
    with(document.getElementsByTagName("kbd")[n]) {
      if (!title) title = 'Dieser Text wird im Chat eingegeben.'; else title += ' (dieser Text wird im Chat eingegeben)'
    }
}


function installSensiH(orig, a) // used to install hover-effectd (onmouseover/out) to divs having class="sensi"
{ return function foo() {
    this.className = 'sensi' + a;
    if (orig) x = eval(orig); else x = function x() {};
    x();
  }
}


function doSensis(orig) // attaches the hover-effect to all divs with class="sensi"
{ for (n=0; n < document.getElementsByTagName("div").length; n++)
    with(document.getElementsByTagName("div")[n]) {
      if (className.indexOf('sensi') != -1) {
        document.getElementsByTagName("div")[n].onmouseover = installSensiH(document.getElementsByTagName("div")[n].onmouseover,'a');
        document.getElementsByTagName("div")[n].onmouseout = installSensiH(document.getElementsByTagName("div")[n].onmouseout,'');
      }
    }
}

function checkAnchor() // is called onload and checks if there's a sensi-DIV to blink because of '#' in URL
{
}

function s0init()
{
  doTabs();
  doLinks();
  doSensis();
  doKbds();
  checkAnchor();
}
