var backSlash = '\\';
var callTo = 'callto:';
var delim = " - ";
var greenFlag = false;
var hash = '#';
//  var homeContentFile = 'horst_walther';  // to be customized
var homeId = 'home';
//  var homePage = 'www.horst-walther.de';  // to be customized
var htm = '.htm';
var http = 'http:';
var https = 'https:';
var idNo = 0;
var javaScript = 'javascript:';
var linkText = "&#x2219;";
var loadNodeName = 'naviMap';
var mail = '@';
var navigatorName = '/HTML/navigate.xhtml';
var naviMap = null;
var oldText = new Array ();
var point = '.';
//  var rootFile = '/index.htm';  // to be customized
var shortenTry = false;
var siteMapCount = 0;
var siteMapDone = false;
var slash = '/';
var targetNodeName = 'siteMapBox';
var underscore = '_';
var missingLanguagePattern = underscore+point;
var traceId = "trace";

//  ---------------------------------------------------------------------------
function traceln (s) {
  return trace (s+'<br />');
}

//  ---------------------------------------------------------------------------
function trace (s) {
  var traceTag = document.getElementById(traceId);
  if (!traceTag)
    traceTag = createTraceTag (traceId);
  traceTag.innerHTML += s;
  return s;
}

//  ---------------------------------------------------------------------------
function createTraceTag (id){
  var traceTag = document.createElement("div");
  traceTag.setAttribute("id", id);
  traceTag.innerHTML = id+": <br />";
  document.body.appendChild(traceTag);
  traceTag.style.color= "yellow";
  traceTag.style.zIndex= "25";
//  traceTag.style.backgroundColor= "white";
//  traceTag.style.border= "1px solid red";
//  traceTag.style.visibility = "hidden";
  return traceTag;
}

//  ------------------------------------------------------------
function addLoadEvent(func) {  // adding several functions to 'window.onload'
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) oldonload();
      func();
    }
  }
}

//  ---------------------------------------------------------------------------
function doFire(action, id) {
  traceln ('doFire ('+action+', '+id+')');
  var tmpTag =  document.getElementById (id);
  if (document.createEvent) {
    var myEvent = document.createEvent("HTMLEvents");
    myEvent.initEvent(action, false, true);
    myEvent.cancelBubble = true; 
//    myEvent.button = 1;
    tmpTag.dispatchEvent(myEvent);
  } else 
    if( document.createEventObject ) 
      tmpTag.fireEvent(action, myEvent);
  traceln ('fired to '+tmpTag.id);
}

//  ---------------------------------------------------------------------------
function containsSlash (scope) {
  return (scope.URL.indexOf (backSlash) < 0);
}  

//  ---------------------------------------------------------------------------
function getSelfDomain () {
//  traceln ('getSelfDomain ():'+document.URL);
  if (document.URL.indexOf (http) < 0)
    return localHomePath;
  else
    return getDomain(document);
}

//  ---------------------------------------------------------------------------
function getDomain (scope) {
//  traceln ('getDomain: '+ scope.URL.slice(0, scope.URL.indexOf(containsSlash (scope) ? slash : backSlash, 7)));
  return scope.URL.slice(0, scope.URL.indexOf(containsSlash (scope) ? slash : backSlash, 7));
}

//  ---------------------------------------------------------------------------
function getSelfPath () { // returns path until last slash (backslash)
  return getPath (document);
}

//  ---------------------------------------------------------------------------
function getPath (scope) { // returns path until last slash (backslash)
  var lastSlashPos = scope.URL.lastIndexOf(containsSlash (scope) ? slash : backSlash)+1;
  //traceln (document.URL.substring(0, lastSlashPos)); 
  return document.URL.substring(0, lastSlashPos); 
}

//  ------------------------------------------------------------
function getSelfURL () { // returns the filename
  return getFilename (document);
}
  
//  ------------------------------------------------------------
function getFilename (scope) { // returns the filename
  var fileName = scope.URL.substr(scope.URL.lastIndexOf(containsSlash (scope) ? slash : backSlash)+1);
  return fileName.indexOf ('?') < 0 ? fileName : fileName.substring(0, fileName.indexOf('?'));
}
  
//  ---------------------------------------------------------------------------
function withoutExtension (url) {
  return url.substring(0, url.lastIndexOf(point)); 
}

//  ---------------------------------------------------------------------------
function handleInternalReference (loadNode) {
  if (loadNode.href.indexOf (hash) > -1) {
    loadNode.style.color = '#c6c6c6';
    return true;
  }
}
//  ---------------------------------------------------------------------------
function handleMailReference (loadNode) {
  if (loadNode.href.indexOf (mail) > -1) {
    loadNode.style.color = '#c6c6c6';
    return true;
  }
}
//  ---------------------------------------------------------------------------
function handleJavascript (loadNode) {
  if (loadNode.href.indexOf (javaScript) > -1) {
    loadNode.style.color = '#c6c6c6';
    return true;
  }
}
//  ---------------------------------------------------------------------------
function checkPagelinks (loadNode) { 
  loadNode.style.backgroundColor = '#efefef';
  if (handleInternalReference (loadNode)) return false;
  if (handleMailReference (loadNode)) return false;
  if (handleJavascript (loadNode)) return false;
  var existFunction = function () {loadNode.style.color = 'green'; loadNode.innerHTML = '&#x2714;'};
  var notExistFunction = function () {loadNode.style.color = 'red'; loadNode.innerHTML = '&#x2718;'};
  var forbiddenFunction = function () {loadNode.style.color = 'red'; loadNode.innerHTML = '&#xe403;'};
  var elseFunction = function () {loadNode.style.color = '#c6c6c6'; loadNode.innerHTML = '&#x2023;'};
  checkOnExistance (loadNode.href, existFunction, notExistFunction, elseFunction, forbiddenFunction);
  return true;
}

//  ---------------------------------------------------------------------------
function check (loadNode) { 
  if (siteMapCount) {
    alert ('###  please wait for loadingthe sitemap!');
    return;
  }
  while (loadNode) {
    if (loadNode.nodeName.toLowerCase() == "div") {
      check (loadNode.firstChild);
    }
    if (loadNode.nodeName.toLowerCase() == "a") {
      if (loadNode.id.indexOf ('a_div') > -1) {
        loadNode.style.color = '#c6c6c6';
        checkPagelinks (loadNode)
      }
    } 
    loadNode = loadNode.nextSibling;
  }  
  return;
}

//  ---------------------------------------------------------------------------
function lastDelimiterPos (actULR) {
//  if (actULR.lastIndexOf (hash)      > -1) return actULR.lastIndexOf (hash);
  if (actULR.lastIndexOf (slash)     > -1) return actULR.lastIndexOf (slash);
  if (actULR.lastIndexOf (backSlash) > -1) return actULR.lastIndexOf (backSlash);
  return -1;
}

//  ---------------------------------------------------------------------------
function delOldText (actText, oldText) {
  alert ("delOldText ("+actText+", "+oldText+")");
  if (oldText.length > 0)
    if (actText.length > 0)
      if (actText.indexOf(oldText) > -1)
        return actText.slice (actText.indexOf(oldText)+oldText.length);
  return actText;
}

//  ---------------------------------------------------------------------------
function showGreen () { 
  document.getElementById('workListCounter').innerHTML = siteMapCount ? siteMapCount : ' ';
  if (shortenTry) {
    return;
  }
  if (greenFlag) {
    clearTimeout(greenFlag);
    greenFlag = false;
    document.getElementById(targetNodeName).firstChild.style.color = "#00ff00";
//    alert ("now green: all done!");
  }
}  

//  ---------------------------------------------------------------------------
function shorten (loadNode, level) { 
  if (siteMapCount)
    return;
  if (shortenTry) {
    clearTimeout(shortenTry);
    shortenTry = false;
//    document.getElementById(targetNodeName).firstChild.src = "../images/yellow-on.gif";
    document.getElementById(targetNodeName).firstChild.style.color = "#ffff00";
  }
  while (loadNode) {
    if (loadNode.nodeName.toLowerCase() == "div") {
      if (loadNode.id.indexOf ('level') == 0) {
        level = loadNode.id.replace ('level', '');
//        alert ("level: "+level);
      }
      shorten (loadNode.firstChild);
      if (loadNode.id.indexOf ('level') == 0) 
        level--;
    }
    else {
      if (loadNode.nodeName.toLowerCase() == "a") {
        if (loadNode.id.indexOf ('a_div') < 0) {
//          alert ('shorten ('+level+': '+loadNode.innerHTML+', '+ oldText [level-1]+')'); 
          oldText [level] = loadNode.innerHTML+delim;
          loadNode.innerHTML = loadNode.innerHTML.replace (oldText [level-1], "");
        }
      } /* else
         alert ('no shorten( '+level+' ('+loadNode.nodeName.toLowerCase()+')');  */
    }
    loadNode = loadNode.nextSibling;
  }  
  return;
}

//  ---------------------------------------------------------------------------
function addRefs (doc, iD, newPath) {
  var aList =  makeaList (doc);
  if (aList.length > 0) 
	for (i = 0; i < aList.length; i++) 
	  if (checkableLink (aList[i])) 
	    addRef(aList[i].href.toString(), iD, i, newPath);
}

//  ---------------------------------------------------------------------------
 function makeaList (doc) {
   var tmpDiv = document.createElement("div");
   tmpDiv.innerHTML = doc; 
   return tmpDiv.getElementsByTagName("a");
 }
 
//  ---------------------------------------------------------------------------
function checkableLink (linkNode) {
  if (!linkNode) return false;
  if (!linkNode.href) return false;
  var link = linkNode.href.toString();
  if (link.length == 0) return false;
  if (link.indexOf (hash) > -1) return false;
  if (link.indexOf (mail) > -1) return false;
  if (link.indexOf (javaScript) > -1) return false;
  if (link.indexOf (callTo) > -1) return false;
  return true;
}

//  ---------------------------------------------------------------------------
function addRef(href, iD, i, newPath) {
//  traceln ('addRef('+href+', '+iD+', '+i+')');
  var aTag = document.createElement("a");
//  traceln (href+': '+getSelfPath ()+'-->'+newPath+'='+href.replace (getSelfPath (), newPath));
  href = href.replace (getSelfPath (), newPath);
  aTag.href = href.indexOf ('?') < 0 ? href : href.substring(0, '?');
  aTag.innerHTML = linkText;
  aTag.setAttribute("class", 'unchecked');
  aTag.setAttribute("id", "a_"+(iD+"_"+i));
  document.getElementById(iD).appendChild(aTag); 
}

//  ---------------------------------------------------------------------------
function newDiv (loadNode, targetNode, level) { 
  var div = document.createElement("div");
  div.setAttribute("id", "level"+level);
  div.style.textIndent = ""+20+"px";
  targetNode.appendChild(div); 
  return div;
}

//  ---------------------------------------------------------------------------
function doSiteMap () { 
//  traceln ('doSiteMap()'); 
  var loadNode = document.getElementById(loadNodeName);
  if (!loadNode) {traceln ('###  No such loadNode: '+loadNodeName); return};
  var targetNode = document.getElementById(targetNodeName);
  if (!targetNode) {traceln ('###  No such targetNode: '+targetNodeName); return};
  targetNode.firstChild.style.color = "red";
  siteMap (loadNode, targetNode, 0);
  clearTimeout(siteMapDone);
  shortenTry = setInterval("shorten (document.getElementById(targetNodeName))",1000, 0);
  greenFlag = setInterval("showGreen ()",1000);
  return;
}

//  ---------------------------------------------------------------------------
function siteMap (loadNode, targetNode, level) { 
//  traceln ('siteMap('+loadNode.id+') to '+targetNode.id);
//  targetNode.firstCild.src = "../images/red-blink-1.gif";
  if (loadNode) {
    if (loadNode.hasChildNodes()) {
      loadNode = loadNode.firstChild;
      while (loadNode) {
        if (loadNode.nodeName.toLowerCase() == "div") 
          siteMap (loadNode, newDiv (loadNode, targetNode, level+1), level+1);
        else {
          if (loadNode.nodeName.toLowerCase() == "span") {
            processEntry (loadNode, targetNode, level)
          } else {
//            traceln ("error: "+loadNode.nodeName.toLowerCase());
          }
        }
        loadNode = loadNode.nextSibling;
      }
    }
  }
  return;
}

//  ---------------------------------------------------------------------------
function processEntry (loadNode, targetNode, level) { 
//  traceln ('processEntry ('+loadNode.id+', '+targetNode.id+')'); 
  siteMapCount++;
  targetNode.appendChild(makeNaviMapDiv(loadNode, ++idNo, level)); 
  var newPath = getSelfDomain()+localizeLink (loadNode.innerHTML);
//  traceln ("newPath: "+newPath);
  var newDir = newPath.slice (0, lastDelimiterPos (newPath)+1);
  var divId = 'div'+(idNo); // just to force evaluation now - not lazy!
  var aIdNo = 'a'+idNo; // just to force evaluation now - not lazy!
  var func = function (request) {if (newPath.indexOf(htm)>0) if (request.indexOf('<title>') > -1) document.getElementById(aIdNo).innerHTML = (request.slice (request.indexOf('<title>')+7,request.indexOf('</title>'))); addRefs (request, divId, newDir); siteMapCount--};
  loadAndDo (newPath, func);
  return;
}

//  ---------------------------------------------------------------------------
 function makeNaviMapDiv(loadNode, idNo, level) {
//  traceln('makeNaviMapDiv('+loadNode.id+', '+idNo+', '+level+')');
  var divNoFix = 'div'+(idNo);
  var aNoFix = 'a'+idNo;
  var naviMapDiv = document.createElement("div");
  naviMapDiv.setAttribute("id", divNoFix);
  naviMapDiv.style.textIndent = ""+(level*20)+"px";
  var navigatorTag = document.createElement("a");
  navigatorTag.href = loadNode.innerHTML;
  navigatorTag.innerHTML = loadNode.innerHTML;
  navigatorTag.setAttribute("class", 'plainlink');
  navigatorTag.setAttribute("id", "a"+(idNo));
  naviMapDiv.appendChild(navigatorTag); 
//  traceln (naviMapDiv.innerHTML);
  return naviMapDiv;
}

//  -------------------------------------------------------------------------
function getNaviMap() { 
//  alert ('getNaviMap()');
  var id = "naviMapBox" ;
  if (arguments[0]) { id = arguments[0]; }
  if (!naviMap) {
    naviMap = document.createElement("div");
    naviMap.style.visibility = "hidden" ;
    naviMap.setAttribute("id", id);
    naviMap.onclick =  function () {document.getElementById("ToolTipBox").style.visibility = "hidden"};
    document.body.appendChild(naviMap);
  }
  return naviMap;
}

//  ---------------------------------------------------------------------------
function showAll (naviMap) {  
//  traceln ('start at '+document.body.getAttribute("id"));
  traverse (document.body, naviMap, 0);
}

//  ---------------------------------------------------------------------------
function traverse (oldTag, tag, level) {  
  traceln ('traverse ('+oldTag+', '+tag+', '+level+')');  
  traceln (tag.getAttribute("id"));
  var firstNode= null; var prevNode = null; var nextNode = null; var lastNode= null;
  traceln (' & '+'traverse '+indent (level, '_')+tag.getAttribute("id")+':');
  if (tag.hasChildNodes()) {
    var iNode = tag.firstChild;
    while (iNode) {
      if (iNode.nodeName.toLowerCase() == "div") 
        traverse (tag, iNode, level+1);
      else
        if (iNode.nodeName.toLowerCase() == "span") {
          if (!firstNode)
            firstNode = iNode;
          if (!prevNode)
            prevNode = iNode;
          traceln (indent(level, '_')+iNode.innerHTML
                 + ', <<:'+firstNode.innerHTML
                 + ', < :'+prevNode.innerHTML
                 + ', ^:'+getParentNode(iNode, "span").innerHTML
                 + ', >>:'+getNextNode (iNode, "span").innerHTML
                 + ', > :'+getLastNode (iNode, "span").innerHTML);
          prevNode = iNode;
        }
      iNode = iNode.nextSibling;
    }
  }
  traceln (indent (level, '_')+'back from '+tag.getAttribute("id")+' to '+oldTag.getAttribute("id"));
}

//  ---------------------------------------------------------------------------
function getNaviMapOld() {  /*  construction of naviMap box  */
    var id = "naviMapBox" ;
    if (arguments[0]) { id = arguments[0]; }
    if (!naviMap) {
      naviMap = document.createElement("div");
      naviMap.style.visibility = "hidden" ;
      naviMap.style.display = "none" ;
      naviMap.setAttribute("id", id);
      naviMap.onclick =  function () {document.getElementById("naviMapBox").style.visibility = "hidden"};
      document.body.appendChild(naviMap);
    }  
    return naviMap;
}

  //  -------------------------------------------------------------------------
  function resolveEvent (evt) {
    var e = evt || window.event ;
    if (evtGetTarget(e).className == 'navigator') {
      if (e.stopPropagation) 
        e.stopPropagation();    // at the right place we can stop event propagation
      e.cancelBubble = true;
    }
    return e;
  }

  //  -------------------------------------------------------------------------
function positionNaviMap (e) {  /* tip positioning */
  alert ('positionNaviMap ('+e+')');
    var div = getNaviMap() ;
    div.innerHTML = "Loading data ..." ;
    if (window.pageXOffset || window.pageYOffset) {
      x = window.pageXOffset+(e?e.clientX:window.pageXOffset/2);
      y = window.pageYOffset+(e?e.clientY:window.pageYOffset/2);
    } else if (document.documentElement.scrollTop || document.documentElement.scrollLeft) {
      x = document.documentElement.scrollLeft+(e?e.clientX:document.documentElement.scrollLeft/2) ;
      y = document.documentElement.scrollTop +(e?e.clientY:document.documentElement.scrollTop/2) ;
    } else {      // ie < 6
      x = document.body.scrollLeft+(e?e.clientX:document.body.scrollLeft/2);
      y = document.body.scrollTop +(e?e.clientY:document.body.scrollTop/2) ;
    }
    if (x > 500) {  // we put it on the left side of the event otherwise it might went leave the window
      x -= 250 ;
    }
    if (y > 300) {  // like with x
      y -= 30;
    }
    div.style.left = x+"px";
    div.style.top  = y+"px";
    div.style.visibility = "visible" ;
//    window.setTimeout('document.getElementById("naviMapBox").style.visibility = "visible"', 2000);
  }

  //  -------------------------------------------------------------------------
function processLinks (iNode) {  
  alert ('processLinks ('+iNode+')');
//  var e = resolveEvent (evt); 
  positionNaviMap (window.event); // (e);
  return getContent (iNode); // evtGetTarget(e));
}

//  -----------------------------------------------------------------------
function displayLinks (response) {
//  alert ('displayLinks ('+response+')');
  var div = getNaviMap() ;
  div.innerHTML = response;
  div.style.top = Math.min(1.0*div.style.top.slice (0,div.style.top.length-2), (window.innerHeight ? window.innerHeight : document.documentElement.clientHeight)-div.offsetHeight-32)+"px";
  }

//  ---------------------------------------------------------------------------
function showLinks (iNode) {  
  var event = window.event ; // does not work for ff. But I don't know what to do here
  alert ('event='+window.event);
  if (!event)
    event = window.event;
//  alert ('event='+event);
  displayLinks (processLinks (iNode));
}

//  ---------------------------------------------------------------------------
//  the following parts are essential for operational navigation settings
//  ---------------------------------------------------------------------------
function getHomeNode () {
  return document.getElementById(homeId);
}

//  ---------------------------------------------------------------------------
function getFirstNode (iNode, tag) {
  if (!iNode) return iNode; //  alert ('###err: getFirstNode ('+iNode+', '+tag+')');
  var firstNode = iNode; 
  var i = 0;
//  iNode = iNode.previousSibling;
  while (iNode) {
//    trace ((++i)+': '+iNode.nodeName.toLowerCase());
    if (iNode.nodeName.toLowerCase() == tag) {
      firstNode = iNode;
//      traceln (iNode.innerHTML);
    }
    iNode = iNode.previousSibling;
  }
  return firstNode;
}

//  ---------------------------------------------------------------------------
function getLastNode (iNode, tag) {
//  alert ('getLastNode ('+iNode+', '+tag+')');
  if (!iNode) return iNode;
  var lastNode = iNode;
//  iNode = iNode.nextSibling;
  while (iNode) {
    if (iNode.nodeName.toLowerCase() == tag)
      lastNode = iNode;
    iNode = iNode.nextSibling;
  }
  return lastNode;
}

//  ---------------------------------------------------------------------------
function getNextNode (iNode, tag) {
//  alert ('getNextNode ('+iNode.nodeName.toLowerCase()+', '+tag+')');
  if (!iNode) return iNode;
  var nextNode = iNode;
  iNode = iNode.nextSibling;
  while (iNode) {
    if (iNode.nodeName.toLowerCase() == tag)
      return iNode;
    iNode = iNode.nextSibling;
  }
  return nextNode;
}

//  ---------------------------------------------------------------------------
function getNextNodeAt (iNode, tag, no) {
//  alert ('getNextNodeAt ('+iNode.nodeName.toLowerCase()+', '+tag+', '+no+')');
  for (var i=0; i < no; i++) 
    iNode = getNextNode (iNode, tag);
  return iNode;
}

//  ---------------------------------------------------------------------------
function getPrevNode (iNode, tag) {
//  alert ('getPrevNode ('+iNode.nodeName.toLowerCase()+', '+tag+')');
  if (!iNode) return iNode;
  var prevNode = iNode;
  iNode = iNode.previousSibling;
  while (iNode) {
    if (iNode.nodeName.toLowerCase() == tag)
      return iNode;
    iNode = iNode.previousSibling;
  }
  return prevNode;
}

//  ---------------------------------------------------------------------------
function getParentNode (iNode, tag) {
//  alert ('getParentNode ('+iNode.id+', '+tag+'), title='+iNode.title);
  if (!iNode) return iNode;
  if (!iNode.title) return iNode;
  if (iNode.id == homeId) return iNode;
  return document.getElementById(iNode.title); 
}

//  ---------------------------------------------------------------------------
function findNode (iNode, docURL, level) { 
  if (!iNode) return iNode;
  docURL = deLocalizeLink (docURL.toLowerCase()); // if no language tag coded file names in the navigator file 
//  traceln (indent(level, '  ')+'findNode('+iNode.nodeName+' id='+iNode.id+', '+docURL+', '+level+')');
  var oldNode = iNode;
  var resultNode = null;
  if (iNode.hasChildNodes()) {
    var iNode = iNode.firstChild;
    while (iNode) {
      if (iNode.nodeName.toLowerCase() == "div") {
        resultNode = findNode (iNode, docURL, level+1);
        if (resultNode)
          return resultNode;
      } else
        if (iNode.nodeName.toLowerCase() == "span") {
          if (iNode.innerHTML.toLowerCase().search(docURL) >= 0) {
//            traceln (indent(level, '  ')+docURL+' found in '+iNode.innerHTML);
            return iNode;
          }
//          traceln (indent(level, '  ')+docURL+' != '+iNode.innerHTML.toLowerCase());
        }
      iNode = iNode.nextSibling;
    }
  }
  if (!level) traceln (docURL+' not found in '+(oldNode == null ? oldNode : oldNode.nodeName.toLowerCase()+' id='+oldNode.id));
  return null;
}

//  ---------------------------------------------------------------------------
function indent(level, filler) {
  var indentLevel = '';
  for (var i=0; i < level; i++) 
    indentLevel += filler;
  return indentLevel;
} 

//  ---------------------------------------------------------------------------
function insertNavigatorInfo (docURL) {
//  traceln ('insertNavigatorInfo ('+docURL+')');
  setLang ();
  setLangSwitch ();
  setFooter (docURL);
  setPrev (docURL);
  setHead (docURL);
  setNext (docURL);
  setTitle (docURL);
  setMenu (docURL);
}

//  ---------------------------------------------------------------------------
function setFooter (docURL) {
//  traceln ('setFooter ('+docURL+')');
  var footer = document.getElementById ('footer');
  if (!footer) return; // {traceln ('###  sorry, there is no footer!')};
  footer.innerHTML = getContent (findNode (naviMap, docURL, 0))+(footer.innerHTML ? '|'+document.getElementById ('footer').innerHTML : ""); // append, what is there already
}

//  ---------------------------------------------------------------------------
function setPrev (docURL) {
  var prev = document.getElementById ('prev');  if (!prev) return;
  var iNode = findNode (naviMap, docURL, 0);   if (!iNode) return;
//  var footer = document.getElementById ('footer');  if (!footer) return;
//  prev.firstChild.href = getNextNodeAt (footer.firstChild, 'a', 2).href;
  if (ajaxMode) {
    traceln (getMenuItemId ());
    traceln (nodeOf(getMenuItemId ()));
    traceln ('setPrev('+getMenuIndex()+') --> '+makeAjaxLink (nodeOf(getMenuItemId ()), '', getMenuIndex()));}
  else
    prev.firstChild.href = localizeLink(getPrevNode  (iNode, "span").innerHTML);
}

//  ---------------------------------------------------------------------------
function setHead (docURL) {
  var head = document.getElementById ('head');
  if (!head) return;
  if (head.firstChild.innerHTML.length > 0) return;
  head.firstChild.innerHTML = findNode (naviMap, docURL, 0).id + '&nbsp;&hellip;'; 
}

//  ---------------------------------------------------------------------------
function setNext (docURL) {
  var next = document.getElementById ('next');  if (!next) return;
  var iNode = findNode (naviMap, docURL, 0);    if (!iNode) return;
//  var footer = document.getElementById ('footer');  if (!footer) return;
//  next.firstChild.href = getNextNodeAt (footer.firstChild, 'a', 4).href;
  if (ajaxMode) {
    traceln (getMenuItemId ());
    traceln (nodeOf(getMenuItemId ()));
    traceln ('setNext('+getMenuIndex() +') --> '+makeAjaxLink (nodeOf(getMenuItemId ()), '', getMenuIndex())); }
  else
    next.firstChild.href = localizeLink(getNextNode  (iNode, "span").innerHTML);
}

//  ---------------------------------------------------------------------------
function getMenuItemId () {
  return location.href.substr (location.href.indexOf('#')+1)
};

//  ---------------------------------------------------------------------------
function getMenuIndex () {
  if (location.href.indexOf('#') < 0)
    return 1;
  else 
    return location.href.substr (location.href.length-3);
};

//  ---------------------------------------------------------------------------
function setTitle (docURL) {
  if (document.title) return;
  document.title = homeContentFile + ' - ' + findNode (naviMap, docURL, 0).id + ' ...'; 
}

//  ---------------------------------------------------------------------------
function setLang () {
  document.body.lang = decodeLanguage (getSelfURL ());
}

//  ---------------------------------------------------------------------------
function decodeLanguage (url) {
  if (url.indexOf('_') != (url.length-3)) return document.body.lang;
  return url.substring(0,url.lastIndexOf('.')).substr(url.indexOf('_')+1);
}

//  ---------------------------------------------------------------------------
function setLangSwitch () {
  var langSwitch = document.getElementById ('langSwitch');  if (!langSwitch) return;
  var selfURL = getSelfURL ();
  langSwitch.firstChild.href = selfURL.substring (0,selfURL.indexOf('_')+1) + toggleLanguage() + htm; 
  langSwitch.className = toggleLangSwitchClassName ();
//  traceln ('setLangSwitch (): '+langSwitch.className+'-->'+langSwitch.firstChild.href);
}

//  ---------------------------------------------------------------------------
function setLangSwitchToLoad (targetURL, targetLang) {
  var langSwitch = document.getElementById ('langSwitch');  if (!langSwitch) return;
  while (langSwitch.hasChildNodes()) langSwitch.removeChild(langSwitch.lastChild)
  var input = document.createElement('input');
  input.type='button';
  langSwitch.className = setLangSwitchClassName(targetLang);
  input.onclick = function () {toggleLanguageClass (); loadFileToId (localizeLinkBy(targetURL, document.body.lang), 'content'); dhtmlHistory.add(document.body.lang+document.body.actMenuItem, document.body.lang); if (ajaxMode) changeLanguageHTML(document.body.lang, 'menuItem', window.document)}; 
  langSwitch.appendChild(input);
}

//  ---------------------------------------------------------------------------
function setMenu (docURL) {
//  traceln ('setMenu ('+docURL+')');
  var thisNode = findNode (naviMap, docURL, 0);  
  if (!thisNode) {
    traceln (docURL+' not found in '+naviMap); 
    return
  }
  var menu = document.getElementById ('menu');  
  setSubMenu (menu,thisNode, 1);
  if (ajaxMode)
    try {
      if (dhtmlHistory.isFirstLoad()) 
        if (document.getElementById('menuItem001')) {
//          traclen ('1. load');
          document.getElementById('menuItem001').onclick(); 
          dhtmlHistory.add(document.body.lang+'menuItem001', document.body.lang);
          document.body.actMenuItem = 'menuItem001';
        }
    } 
    catch (evt) {
      if (document.getElementById('menuItem001')) 
        document.getElementById('menuItem001').onclick(); 
    }
}

//  ---------------------------------------------------------------------------
function setSubMenu (menu, thisNode, i) {
  if (!menu) return;
//  traceln ('setSubMenu ('+menu.id+', '+thisNode.id+')');
//  traceln ('anchor='+thisNode.nodeName.toLowerCase()+' : '+thisNode.id);
  thisNode = getNextSiblingIgnore (thisNode, '#text'); if (!thisNode) {traceln (docURL+' has no sibling in '+naviMap); return};
//  traceln ('1. sibling='+thisNode.nodeName.toLowerCase()+' : '+thisNode.id);
  if (!thisNode.hasChildNodes()) return;
  thisNode = getFirstChildIgnore (thisNode, '#text');
  while (menu.hasChildNodes()) menu.removeChild(menu.lastChild);
  while (thisNode) {
    menu.appendChild(getMenuItem(thisNode, 'content', i++)); 
    if (nextIsDiv (thisNode)) {
      var tmpNode = getNextSiblingIgnore (thisNode, '#text');
      var ul = document.createElement('ul');   
      ul.style.visibility = "hidden" ;
      ul.style.display = "none" ;
      menu.lastChild.appendChild (ul);
      var id = menu.lastChild.firstChild.id;
//      if (menuTypeIs (bottomMenu)) menu.lastChild.onmouseover = function () {document.getElementById(id).nextSibling.style.display = 'block'};  // works now, but how to take it back
      i = setSubMenu (ul, thisNode, i)
   }/* */
//    traceln (getMenuItem(thisNode).firstChild.innerHTML+': '+getMenuItem(thisNode).firstChild.href)
    thisNode = getNextSiblingMatch (thisNode, 'span');
  }
//  traceln ('setSubMenu end: '+thisNode);
  return i;
}

//  ---------------------------------------------------------------------------
function menuTypeIs (menuType) {
  return document.getElementById('menu').className.toLowerCase() == menuType;
}

//  ---------------------------------------------------------------------------
function runScripts (iNode) {
//  traceln ('runScripts ('+iNode.id+')');
  var scriptList = iNode.getElementsByTagName("script");
  if (scriptList.length == 0) return;
//  traceln ('scriptList.length: '+scriptList.length);
  for (var i=0; i< scriptList.length; i++) 
    if (scriptList[i].src) {
      alert ('append'+i+': '+scriptList[i].src);
      document.body.appendChild(document.createElement('iframe').appendChild (loadJsFile (scriptList[i].src)))
      scriptList[i].src = '';
    } else {
//      alert ('eval '+scriptList[i].innerHTML);
      eval (scriptList[i].innerHTML);
    }
}

//  ---------------------------------------------------------------------------
function loadJsFile (fileName){
  var fileRef=document.createElement('script');
  fileRef.setAttribute("type","text/javascript");
  fileRef.setAttribute("src", fileName);
  return fileRef;
}

//  ---------------------------------------------------------------------------
function nextIsDiv (iNode) {
  if (!iNode) return false;
  var nextSibling = getNextSiblingIgnore (iNode, '#text');
  if (!nextSibling) return false;
  return (nextSibling.nodeName.toLowerCase() == 'div');
}

//  ---------------------------------------------------------------------------
function getFirstChildIgnore (iNode, ignoreType) {
  if (!iNode) return iNode;
  if (!iNode.firstChild) return iNode;
  return iNode.firstChild.nodeName == ignoreType ? iNode.firstChild.nextSibling : iNode.firstChild;
}

//  ---------------------------------------------------------------------------
function getNextSiblingIgnore (iNode, ignoreType) {
  if (!iNode) return iNode;
  if (!iNode.nextSibling) return iNode;
  return (iNode.nextSibling.nodeName == ignoreType ? iNode.nextSibling.nextSibling : iNode.nextSibling);
}

//  ---------------------------------------------------------------------------
function getNextSiblingMatch (iNode, matchType) {
  if (!iNode) return null;
  if (!iNode.nextSibling) return null;
//  traceln ('iNode: '+iNode.nodeName.toLowerCase());
//  traceln ('iNode.nextSibling: '+iNode.nextSibling.nodeName.toLowerCase());
  while (iNode.nextSibling) {
    if (iNode.nextSibling.nodeName.toLowerCase() == matchType) return iNode.nextSibling; 
    iNode = iNode.nextSibling;
  }
  return iNode.nextSibling;
}

//  ---------------------------------------------------------------------------
function getMenuItem (iNode, target, i) {
  var li = document.createElement('li');
  if (ajaxMode) 
    li.appendChild (makeAjaxLink (iNode, target, i));
  else
    li.appendChild (makeLink (iNode, target, i));
//  traceln (ajaxMode+': '+li.firstChild.href+', '+li.firstChild.target+', '+li.firstChild.innerHTML+', '+li.firstChild.onclick+', '+li.firstChild.id+', '+li.firstChild.toString());
  return li;
}

//  ---------------------------------------------------------------------------
function makeAjaxLink (iNode, target, i) {
  var span = document.createElement('span');
  span.innerHTML = iNode.id;
  var actURL = ''+iNode.innerHTML;
  span.id = 'menuItem'+threeDigit (i);
  var func = function (historyLang) {resetMenuItems (document.getElementById('menu'), ''); span.style.color="#cecece"; var targetLang = isString (historyLang) ? historyLang : document.body.lang; /*traceln ('loadToID (localizeLinkBy('+actURL+', '+targetLang+'), content)');*/ loadToID (localizeLinkBy(actURL, targetLang), 'content', function () {runScripts (document.getElementById ('content'))}); setLangSwitchToLoad (actURL, toggleLanguage(targetLang)); if (toolTipTimer) toolTipTimer = new ToolTip('toolTipTimer', withoutExtension (deLocalizeLink (actURL))+'tips',6000); if (!isString(historyLang)) dhtmlHistory.add(targetLang+span.id, targetLang); document.body.actMenuItem = span.id}; 
  span.onclick = func;
  if (ajaxMode)
    if (i==1) 
      if (nodeOf('logo'))
        nodeOf('logo').onclick=func;
  return span;
};

//  ---------------------------------------------------------------------------
function makeLink (iNode, target, i) {
  var a = document.createElement('a');
  a.href = localizeLink(iNode.innerHTML)
  a.innerHTML = iNode.id;
  a.target = target;
  a.id = 'menuItem'+threeDigit (i);
  return a;
};

//  ---------------------------------------------------------------------------
function resetMenuItems (loadNode, style) { 
//  traceln ('resetMenuItems ('+loadNode.nodeName+', '+style+')');
  if (!loadNode) return;
  loadNode = loadNode.firstChild;
  if (!loadNode) return;
  while (loadNode) {
    loadNode.firstChild.style.color = style;
    if (getNextSiblingMatch (loadNode.firstChild, 'ul'))
      resetMenuItems (getNextSiblingMatch (loadNode.firstChild, 'ul'), style)
    loadNode = getNextSiblingMatch (loadNode, 'li')
  }
  return;
}

//  ---------------------------------------------------------------------------
function getContent (iNode) {
  if (!iNode) return "";
  return '<a href="'+localizeLink(getHomeNode  (             ).innerHTML)+'"'+setTarget(getHomeNode  (             ),'')+'>home</a>&nbsp;'
       + '<a href="'+localizeLink(getFirstNode (iNode, "span").innerHTML)+'"'+setTarget(getFirstNode (iNode, "span"),'')+'>&lt;&lt;</a>'
       + '<a href="'+localizeLink(getPrevNode  (iNode, "span").innerHTML)+'"'+setTarget(getPrevNode  (iNode, "span"),'')+'>&lt;</a>'
       + '<a href="'+localizeLink(getParentNode(iNode, "span").innerHTML)+'"'+setTarget(getParentNode(iNode, "span"),'')+'>^</a>'
       + '<a href="'+localizeLink(getNextNode  (iNode, "span").innerHTML)+'"'+setTarget(getNextNode  (iNode, "span"),'')+'>&gt</a>'
       + '<a href="'+localizeLink(getLastNode  (iNode, "span").innerHTML)+'"'+setTarget(getLastNode  (iNode, "span"),'')+'>&gt;&gt;</a>';
}

//  ---------------------------------------------------------------------------
function setTarget (iNode, target) {
//  traceln (iNode.id+': '+(isHomeNode (iNode) ? ' target="_top"' : target));
  return isHomeNode (iNode) ? ' target="_top"' : target;
}

//  ---------------------------------------------------------------------------
function isHomeNode (iNode) {
//  traceln (iNode.id+' == '+getHomeNode().id+'?'+(iNode.id == getHomeNode().id));
  return iNode.id == getHomeNode().id;
}

//  ------------------------------------------------------------
function localizeLink (link) {
  return localizeLinkBy (link, document.body.lang);
}

//  ------------------------------------------------------------
function localizeLinkBy (link, lang) {
  return link.indexOf (missingLanguagePattern) < 0 ? link : link.replace (missingLanguagePattern, underscore+lang+point);
}

//  ------------------------------------------------------------
function deLocalizeLink (link) {
  var pointPos = link.indexOf (htm); 
  if (pointPos < 0) return link;
  if (link.charAt(pointPos-3) != underscore) return link;
  return link.substring (0, pointPos-2)+link.substring (pointPos);
}

//  ---------------------------------------------------------------------------
function setNavigators (docURL, id, postAction) {
//  traceln ('setNavigators ('+docURL+', '+id+') ');
  if (!naviMap) {
    createNaviMap (id)
    if (!postAction) postAction = function () {};
    var func = function () {insertNavigatorInfo(docURL); postAction ()};
    var sourceURL = getSelfDomain ()+navigatorName;
//    traceln ('sourceURL:'+sourceURL);
    loadToID(sourceURL, id, func);
  } else 
    insertNavigatorInfo(docURL);
}

//  ---------------------------------------------------------------------------
function createNaviMap (id) {  /*  construction of the navigator container tag  */
//  traceln ('createNaviMap ('+id+')');
  naviMap = document.createElement("div");
  naviMap.innerHTML = id;
  naviMap.setAttribute("id", id);
  naviMap.style.backgroundColor= "white";
  naviMap.style.border= "1px solid red";
  naviMap.style.borderBottom= "1px solid aqua";
  naviMap.style.visibility = "hidden" ;
  naviMap.style.display = "none" ;
  document.body.appendChild(naviMap);
  return naviMap;
}

//  ---------------------------------------------------------------------------

function historyInitialize() {
  try {
    dhtmlHistory.initialize();  // initialize the DHTML History framework
  } catch (evt) {return}
  dhtmlHistory.addListener(historyChange); // subscribe to DHTML history change events         
  if (dhtmlHistory.isFirstLoad()) {  // if this is the first time we have loaded the page...
//    traceln("Adding values to browser "+ "history");
/* start adding history
    dhtmlHistory.add("helloworld", "Hello World Data");
    dhtmlHistory.add("foobar", 33);
    dhtmlHistory.add("boobah", true);
    var complexObject = new Object();
    complexObject.value1 = "This is the first value";
    complexObject.value2 = "This is the second data";
    complexObject.value3 = new Array();
    complexObject.value3[0] = "array 1";
    complexObject.value3[1] = "array 2";
    dhtmlHistory.add("complexObject", complexObject); */
/* cache some values in the history storage
    debug("Storing key 'fakeXML' into " + "history storage", false);
    var fakeXML = '<?xml version="1.0" '+      'encoding="ISO-8859-1"?>'
            +      '<foobar>'
            +         '<foo-entry/>'
            +      '</foobar>';
    historyStorage.put("fakeXML", fakeXML); */
  } 
/* retrieve our values from the history storage
  var savedXML = historyStorage.get("fakeXML");
  savedXML = prettyPrintXml(savedXML);
  var hasKey = historyStorage.hasKey("fakeXML");
  var message = "historyStorage.hasKey('fakeXML')=" + hasKey + "<br>" + "historyStorage.get('fakeXML')=<br>" + savedXML;
  debug(message, false); */
}
         
//  ---------------------------------------------------------------------------
function historyChange (newLocation, historyData) {
//  traceln('historyChange ('+newLocation+', '+historyData+')');
  if (!(newLocation.length > 1)) return;
  newLocation = newLocation.substring(2, newLocation.length)
//  traceln ('now searching: '+newLocation+': '+document.getElementById(newLocation));
  if (!document.getElementById(newLocation)) return;
//  traceln ('now call document.getElementById('+newLocation+').onclick('+historyData+')');
  document.getElementById(newLocation).onclick(historyData); 
}
      
//  ---------------------------------------------------------------------------
function debug(msg, clear) {
  var output = document.getElementById("output");
  if (clear == true)
    output.innerHTML  = "<p>" + msg + "</p>";
  else 
    output.innerHTML += "<p>" + msg + "</p>";
}
      
//  ---------------------------------------------------------------------------
function prettyPrintXml(content) {
  if (content == null)
    return null;
  content = content.replace(/</g, "&lt;");
  content = content.replace(/>/g, "&gt;<br>");
  return content;
}
//  ---------------------------------------------------------------------------//  ---------------------------------------------------------------------------
addLoadEvent(function () {setLang(); setNavigators(window.location.pathname, loadNodeName, function () {historyInitialize()})})
//  ---------------------------------------------------------------------------//  ---------------------------------------------------------------------------