/* copyright by Sigrist Consulting GmbH, 17.04.2000 */
/*if (top.frames.length != 0)  {
  top.location = document.URL
}*/
var flip = 1;  // Initialisierung für flip_flop()
OK =
  (((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 3 )) ||
  ((navigator.appName == "Microsoft Internet Explorer") &&
  (parseInt(navigator.appVersion) >= 4 )));

var d = document;   // abbreviation
var NS = document.layers ? true : false;
var IE = document.getElementById ? true : false; // also for NS6

if(OK) {
// main_nav: array of image-names like 'n_index_1.gif' and 'n_index_2.gif':
// var main_nav = new array; main_nav[0] = "index"; ......
  var n = new Array();
  var o = new Array();
  var x;
//  for(i=0;i<main_nav.length-1;i++) {
  for(i=0;i<main_nav.length;i++) {
    var img1 = "/images/navi/_" + i + "_1.gif";
    var img2 = "/images/navi/_" + i + "_2.gif";
    n[i] = preload(img1);
    o[i] = preload(img2);
  }
}
/* extrahiere fname (ohne .ext) und chap (2. Zahl im '_1_2.html')  */
var datei_name = d.location.pathname + "";  // mache einen String
var fname = "";
var chap = "";
datei_name.match(/(\w+)\.[^.]+$/);
fname = RegExp.$1;
fname.match(/^_(\d+)/);
chap = RegExp.$1;  // Kapitel

var counter_name;
/* ------------------------------- */
function sitemap() {
  var s = "<ul>\n";
  var len,txt;
  for(i=0;i<main_nav.length;i++) {
    if(main_nav[i] == "" || main_nav[i] == null) continue;
    s += "<li><a href=\"/_" + i + ".html\">" + main_nav[i] + "</a>\n";
    len = eval("kapitel" + i + ".length");
    s += "<ul>\n";
    for(j=0;j<len;j++) {
      txt = eval("kapitel" + i + "[" + j + "]");
      if(txt == "") continue;
      s += "<li><a href=\"_" + i + "_" + j + ".html\">" + txt + "</a>\n";
    }
    s += "</ul>\n";
  }
  s += "</ul>\n";
  d.writeln(s);
}

function rechts_links(kap,mein_i) {  // erstellt automatisch Navigationspfeile
  if(kap == null) var kap = chap;
  var len = eval("kapitel" + kap + ".length");
  for(i=0;i<len;i++) {
    if(fname == "_" + kap + "_" + i) break;
  }
  if(mein_i != null) i = mein_i;
  var titel = eval("kapitel" + kap + "[" + i + "]");
  counter_name = eval("counter" + kap + "[" + i + "]");
  var s = "<div align=\"center\"><table border=0 cellpadding=0 cellspacing=0 width=\"92%\"><tr>";
  if(i > 0) s += "<td><a href=\"/_" + kap + "_" + (i-1) + ".html\"><img src=\"/images/left.gif\" width=35 height=20 border=0 alt=\"zurück\"></a></td>";
  if(i < len-1) s += "<td align=right><a href=\"/_" + kap + "_" + (i+1) + ".html\"><img src=\"/images/right.gif\" width=35 height=20 border=0 alt=\"weiter\"></a>&nbsp;</td>";
  s += "</tr></table></div>";
  s += "<h1>" + titel + "</h1>";
  d.title = "DST - " + titel;
  d.writeln(s);
}

/* erstelle eine Kapitelliste mit <ul> */
function kapitel(titel) {
  if(titel == null) {
    var titel = main_nav[chap];
    counter_name = counter[chap];
  }
  var s = "<h1>" + titel + "</h1>";
  s += "<ul>";
  var t;
  var len = eval("kapitel" + chap + ".length");
  for(i=0;i<len;i++) {
    t = eval("kapitel" + chap + "[" + i + "]");
    s += "<li class=gross><a href=\"_" + chap + "_" + i + ".html\">" + t + "</a>";
  }
  s += "</ul>";
  d.title = "DST - " + titel;
  d.writeln(s);
}

function uml(s) {  // Umlaute und _ ersetzen
  s = s.replace(/_/g," ");
  s = s.replace(/ae/g,"ä");
  s = s.replace(/oe/g,"ö");
  s = s.replace(/ue/g,"ü");
  s = unescape(s);
  return s;
}

function top_code() {  // benötigt in navi()
  return("<table border=0 cellpadding=0 cellspacing=0>" +
  "<tr><td colspan=2 height=80 valign=top>" +
  "<a href=\"/\"><img src=\"/images/navi/logo160.gif\" width=160 height=61 border=0 alt=DST></a>" +
  "</td></tr>" +
  "<tr><td width=30></td>" +
  "<td>");
}

function bot_code() {  // benötigt in navi()
  return("</td></tr></table>");
}

function navi() {  /* write navigation - requires main_nav: array of link- and
  image-names like 'Home_1.gif', 'Home_2.gif'
  images and documents must have identical 'root-name' eg 'Home' */
  var s0 = "<a href=\"/";
  var s1 = ".html\"";
  var s2 = " onMouseOver=\"";
  var s3 = "show_it(";
  var s4 = ",'headline'); ";
  var s5 = "s_img('i";
  var s6 = "','o')\" onMouseOut=\"";
  var s7 = "hide_it('headline'); ";
  var s8 = "','n')\""
  var s9 = "><img name=\"i";
  var s10 = "\" src=\"/images/navi/";
  var s11 = "_1.gif\" width=" + nav_width + " height=" + nav_height + " alt=\"";
  var s11a = "_2.gif\" width=" + nav_width + " height=" + nav_height + " alt=\"";
  var s12 = "\" border=0></a><br>";

  txt = top_code();
  var fn;
  max = reihenfolge.length;
  var i,j;

  for(j=0;j<max;j++) {
    i = reihenfolge[j] + "";
    if(i == "") {  // Leerraum inder Grösse eines Navi-Knopfes wird eingefügt
      txt += "<img src=\"/images/transp.gif\" width=" + nav_width + " height=" + nav_height + " alt=\"\"><br>";
    } else {
      fn = "_" + i;
      if(fname == "") {  // wir sind auf der Homepage --> show_it()
        txt += (s0+fn+s1+s2+s3+i+s4+s5+i+s6+s7+s5+i+s8+s9+i+s10+fn+s11+main_nav[i]+s12);
      } else {  // wir sind NICHT auf der Homepage
        if(i == chap)
          txt += (s0+fn+s1+s9+i+s10+fn+s11a+main_nav[i]+s12);
        else
          txt += (s0+fn+s1+s2+s5+i+s6+s5+i+s8+s9+i+s10+fn+s11+main_nav[i]+s12);
      }
    }
  }

  txt += bot_code();
  d.write(txt);
}

function OpenBox(text,x,y,ele) {
  if(NS) {
    var m = document[ele];
    m.left=x;
    m.top=y;
    m.visibility="visible";
    m.document.write(text);
    m.document.close();
  }
  if(IE) {
    var m = document.getElementById(ele) ;
    m.style.pixelLeft=x;
    m.style.pixelTop=y;
    m.style.visibility="visible";
    m.innerHTML=(text);
  }
}

function CloseBox(ele) {
  if(NS) {
    if (sm) {
      document.mysubmenu.visibility='hidden';
      if (sm == 2) document.mymenu.visibility='hidden';
    } else {
      document.mymenu.visibility='hidden';
    }
  }
  if(IE) {
    if (sm) {
      document.all.mysubmenu.style.visibility='hidden';
      if (sm == 2) document.all.mymenu.style.visibility='hidden';
    } else {
      document.all.mymenu.style.visibility='hidden';
    }
  }
}

function hide_it(ele) {
  if(IE) {
    var m = document.getElementById(ele) ;
    m.style.visibility="hidden";
  }
  if(NS) {
    var m = document[ele] ;
    m.visibility="hidden";
  }
}

function show_hide(ele,what) {
  if(IE) {
    var m = document.getElementById(ele) ;
    m.style.visibility=what;
  }
  if(NS) {
    var m = document[ele] ;
    m.visibility=what;
  }
}

function show_it(id,ele) {
  /* sample use:
  <a href="..." onMouseOver="show_it(0)" ....>
  <div id="headline" style="position:absolute; visibility:hidden;">
  'id' is index of array used in 'navi()' - see above */
  var table_start = "<table background=\""  + headline_background + "\" border=0 cellpadding=12 cellspacing=0 bgcolor='" + headline_bgcolor
   + "' width=" + headline_width + "><tr><td class=headline height=" + headline_height + ">";
  var table_end = "</td></tr></table>";
  var what = "visible";
  if(messages[id] != "") {
    if(IE) {
      var m = document.getElementById(ele) ;
      m.style.left=headline_left;
      m.style.top=headline_top+4;
      m.innerHTML=table_start + messages[id] + table_end;
      m.style.visibility=what;
    }
    if(NS) {
      var m = document[ele] ;
      m.left=headline_left;
      m.top=headline_top+4;
      m.document.write(table_start + messages[id] + table_end);
      m.document.close();
      m.visibility=what;
    }
  }
}

function slide_down(ele,from,to) {
  if (from < to) {
    ele.top = (from += 10);
    setTimeout('slideLogo('+ ele + ',' + from + ',' + to + ')', 75);
  }
}

function flip_flop(nam) {
  document.images[nam].src = "/images/" + nam + "_" + flip + ".jpg";
  flip = flip % 2 + 1;
}

/*function show_right_not_used(id) {
  var table_start = "<table border=0 cellpadding=5 cellspacing=0 width=" +
    right_width + "><tr><td height=" + right_height +
    "><p align=center><span class=\"right" + myfont + "\">";
  var table_end = "</span></td></tr></table>";
  var what = "visible";
  if(messages[id] != "") {
    if(NS6 || IE) {
      var m = document.getElementById("headline") ;
      m.style.left=right_left;
      m.style.top=right_top;
      m.innerHTML=table_start + messages[id] + table_end;
      m.style.visibility=what;
    }
    if(NS) {
      var m = document["headline"] ;
      m.left=right_left;
      m.top=right_top;
      m.document.write(table_start + messages[id] + table_end);
      m.document.close();
      m.visibility=what;
    }
  }
}*/

function s_img(i,k) {
  /* how to use it:
  <a onMouseOver="s_img('i0','o')" onMouseOut="s_img('i0','n')"
  href="...."><img src="/images/xyz1.gif" name=i0 ....></a>
  xyz1.gif --> normal,  xyz2.gif --> hover */
  var m,x;
  if (OK) {
    m = i.substring(1);
    x = eval(k+"["+m+"]").src;
    document.images[i].src=x;
  }
}

function preload(img) {
  var a=new Image(); a.src=img; return a;
}

function myfocus(win) {
  if  (OK) {
    mainw = window.open("",win);
    mainw.focus();
  }
}

function new_win(url,w,wi,he) {
  if (wi == null) wi = 700;
  if (he == null) he = 450;
  if (w == null) w = "help";
  window.open(url,w,"location,status,scrollbars,resizable,width="+wi+",height="+he+"");
  myfocus(w);
}

function change_win(url,w) {
  window.open(url,w);
  myfocus(w);
}

/*  how to use 'form_check'
<script language="JavaScript">
must_fields = new Array("Name","Adresse");
</script>
<FORM onSubmit="return form_check(this)" .....>
*/
function form_check(form) {
  var nam = "";
  var j = 0;
  // --- these fields must all be completed ---
  if (typeof must_fields != "undefined") {
    for(var i=0; i<must_fields.length;i++) {
      if (form[must_fields[i]].value == "") {
        nam = must_fields[i];
        alert("Bitte folgendes Feld nicht leer lassen: \n\n     " + nam + "\n");
        form[must_fields[i]].focus();
        return false;
      }
    }
  }
  return true;
}

function mysubmit(url,what) {  // used to call a form via <a href=...
  // In the calling document you need a form with the name 'myform'
  document.myform.action = url;
  document.myform.elements[0].value = what;
  document.myform.submit();
}

function go_url(frm,what) {   // name of form, name of select
  // go to url in select list without submit button
  s = document[frm][what];
  n = s.selectedIndex;
  location.href=s[n].value;
}

function go_sel(frm,what,url) {    // name of form, name of select, url
  // select list without submit button, add selected value to url
  s = document[frm][what];
  n = s.selectedIndex;
  location.href= url + s[n].value;
}

function cookieArray() {
  var cook = new Array();
  if (document.cookie == null) {
    cook[unescape("dummy")] = unescape("dummy");
  } else {
    var cookieList = document.cookie.split("; ");
    for (var i=0; i < cookieList.length; i++) {
      var name = cookieList[i].split("=");
      cook[unescape(name[0])] = unescape(name[1]);
    }
  }
  return cook;
}

function setCookie(name, value, days) {
  var expire = new Date();
  expire.setTime(expire.getTime() + (60*60*24*days*1000));
  document.cookie = name + "=" + escape(value)
  + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}

function getCookie(Name) {
  var search = Name + "="
  if (document.cookie.length > 0) { // if there are any cookies
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset)
      // set index of end of cookie value
      if (end == -1)
        end = document.cookie.length
      return unescape(document.cookie.substring(offset, end))
    }
  }
}
