﻿// DHTML-Bibliothek Version 1.0  last-update: 15.03.2006
// letzte Änderung: Funktion showHideNav hinzugefügt

  var browserName = navigator.appName,
      browserVersion = parseInt(navigator.appVersion),
      isIE = browserName.indexOf("Microsoft Internet Explorer") ==-1 ? false : true,
      isNN = browserName.indexOf("Netscape")==-1 ? false : true,
      isOp = browserName.indexOf("Opera")==-1 ? false : true,
      isMacIE = /msie .* mac/i.test(navigator.userAgent),
      isDOM = document.getElementById,
      isDomNN = document.layers,
      isDomIE = document.all,
      docStr,
      styleStr= isDomNN ? '' : 'style.';
  if (isDOM)
     docStr="document.getElementById(elem).";
  else if (isDomIE)
     docStr="document.all[elem].";
  else
     docStr="document.layers[elem].";
  function setAttr(elem, attr, val)
  {
    if ( typeof elem != 'object' )
       eval("elem= " + docStr.substr(0, docStr.length-1)+ ";");
    if ( elem )
       eval("elem." + styleStr + attr + "= val");
  }
  function getAttr(elem, attr)
  {
    if ( typeof elem == 'object' )
       eval("var ret= elem." + styleStr + attr + ";");
    else
       eval("var ret= " + docStr + styleStr + attr + ";");
    return (ret ? ret: '');
  }
  function getObject(elem)
  {
    eval("var ret= " + docStr.substr(0, docStr.length-1)+ ";");
    return (ret ? ret: void(0));
  }
  function getContent(elem)
  {
    var content= false;
    if ( typeof elem != 'object' )
       eval("elem= " + docStr.substr(0, docStr.length-1) + ";");
    if ( !elem )
       return false;
    if (isDOM)
    {
       if ( elem.firstChild )
          content= elem.firstChild.nodeValue;
    }
    else
       if (isDomIE )
          content= elem.innerText;
       else
          if ( isDomNN )
          {
             elem.document.open();
             content= elem.document.read();
             elem.document.close();
          }
          else
             return false;
    return content;
  }
  function setContent(elem, content)
  {
    if ( typeof elem != 'object' )
       eval("elem= " + docStr.substr(0, docStr.length-1) + ";");
    if ( !elem )
       return false;
    if (isDOM)
    {
       if ( elem.firstChild )
          elem.firstChild.nodeValue= content;
    }
    else
       if (isDomIE )
          elem.innerText= content;
       else
          if ( isDomNN )
          {
             elem.document.open();
             elem.document.write(content);
             elem.document.close();
          }
          else
             return false;
    return true;
  }
  
  function popup(url, target, param)
  {
     var win;
     param= param || "width=500, height=500, dependent=yes, location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no";
     if ( target )
        target= target.replace(/\W/g, '');
     else
        target= 'info';    
     win= window.open(url, target, param);
     win.focus();
  }
  
if ( isDOM )
{
   document.write("<style>span.jsClosed { background-image:url(/media/haushalt/common/sub_passiv.gif) }\n"
     + "table.jsClosed { display:none }\n"
     + "tbody.jsClosed { display:none }\n"
     + "div.jsClosed { display:none }\n"
     + "</style>")
}
  
  // Für den Mozilla, Firefox und Opera die Höhe anpassen
 function setContentHeight(conDivIds, bodytableId, deltaHeight, minWidth, isResize)
 {
   if ( isDOM )
   {
      if ( !window.contentHeight && setContentWidthHeight() === false )
         return false;
      var conDiv,
          ids= conDivIds.split(','),
          bodytable=document.getElementById(bodytableId),
          conHeight= window.contentHeight,
          conWidth= window.contentWidth;
      if ( isResize !== true )
      {   
         if ( !window.contentHeight_calls )
         {
            window.contentHeight_calls= new Array();
            document.body.onunload= new Function("if ( detailWin && !detailWin.closed) detailWin.close();");
            window.onresize= checkContentHeights;
         }
         window.contentHeight_calls['"' + conDivIds + '","' + (bodytableId || "") + '",' + (deltaHeight || "null") + ',' + (minWidth || "null")]= true;
      }
      minWidth= minWidth || 980;   
      if ( conWidth < minWidth )
      {
         if ( document.body.scroll != 'yes' )
            document.body.scroll= 'yes';
         if ( document.body.scroll == 'yes' )
            conHeight-= 20;
      }
      else
         document.body.scroll= 'no';
      if ( bodytable )
      {
         bodytable.style.height= conHeight + 'px';
         bodytable.style.maxHeight= conHeight + 'px';
         bodytable.className= bodytable.className.replace(/([ ]?jsClosed)/, '');
      }
      conHeight-= deltaHeight;
      for ( var i= 0; i < ids.length; i++)
      {
         conDiv=document.getElementById(ids[i]);
         if ( conDiv )
         {
            conDiv.style.height= conHeight + 'px';
            conDiv.style.maxHeight= conHeight + 'px';
         }
      }
    }
  }
  
  function setContentWidthHeight()
  {
      if (self.innerHeight)
      { 
         window.contentHeight= self.innerHeight;
         window.contentWidth= self.innerWidth;
         if ( isOp ) 
            window.contentHeight-= 5;
      }
      else if (document.documentElement && document.documentElement.clientHeight)
      {
         window.contentHeight= document.documentElement.clientHeight;
         window.contentWidth= document.documentElement.clientWidth;
      }
      else if (document.body) // other Explorers
      {
         window.contentHeight= document.body.clientHeight;
         window.contentWidth= document.body.clientWidth;
      }
      else
         return false;
      return true;
  }
  
  function checkContentHeights()
  {
      var conHeight= window.contentHeight,
          conWidth= window.contentWidth;
      setContentWidthHeight();   
      if ( conHeight == window.contentHeight && conWidth == window.contentWidth )
         return; 
      for ( var paramStr in window.contentHeight_calls )
          eval('setContentHeight(' + paramStr + ',true);');
  }
  
// Almenü elszíneződése
function topnav(elem, over)
{
  if(over)
     setAttr(elem, 'backgroundColor', '#C8C8C8');
  else
     setAttr(elem, 'backgroundColor', '#9B9B9B');
}

function showCon(conID, left, top, height)
{
   hideCon();
   if ( document.onclick != hideCon )
       document.conID_onclick= document.onclick || null;
   if ( isDomNN  )
      setPos(conID, left, top);
   else
      if ( height )
         setAttr(conID, 'height', height);
   window.setTimeout("document.conID= '" + conID + "'; setAttr(document.conID, 'display', 'block');document.onclick= hideCon;", 200);
}
function hideCon()
{
   setAttr(document.conID, 'display', 'none');
   document.conID= null;
   document.onclick= document.conID_onclick || null;
}

function showHideNav(alwaysOpen, id)
{
   if ( document.getElementById )
   {
      var span= document.getElementById('e' + id),
          div= document.getElementById('s' + id),
          show= true;
      if ( span && div )
      {
         if ( alwaysOpen )
            show= (span.className.indexOf(' jsClosed') >= 0);
         else
         {
            var elem= div.parentNode.firstChild;
            while ( elem )
            {
               if ( elem.id && elem.className == "nSub" )
               {
                  if ( elem == div )
                     show= false;
                  else
                  { 
                     elem.className= elem.className + " jsClosed";
                     elem= document.getElementById('e' + elem.id.slice(1));
                     if ( elem )
                        elem.className= elem.className + " jsClosed";
                  }
                  break;
               }
               elem= elem.nextSibling;
            }
         }
         if ( show )
         {
            span.className= span.className.replace(" jsClosed", "");
            div.className= div.className.replace(" jsClosed", "");
         }
         else
         {
            span.className= span.className + " jsClosed";
            div.className= div.className + " jsClosed";
         }
      }
   }
} 

 var detailWin;
/* 
  imgUrl= die Url des Bildes
  [prevWidth]= Die Breite des Vorschaubildes oder false, wenn das Bild als Vollbild angezeigt werden soll
               default= 200
  [prevHeight]= Die Höhe des Vorschaubildes
                default= proportional zu prevWidth  
  [withDownload]= bei true wird ein DownloadButton angezeigt
*/
   function openDetail(imgUrl, prevWidth, prevHeight, withDownload)
   {
      if ( detailWin )
         detailWin.close();
      if ( !imgUrl )
         return;
      var imgUrlType = imgUrl.slice(imgUrl.lastIndexOf(".")+1).toUpperCase();
      if (imgUrlType != "JPG" && imgUrlType != "JPEG" && imgUrlType != "GIF" && imgUrlType != "PNG")
      {
        popup(imgUrl,"detail");
        return;
      }
      var start= imgUrl.indexOf("://" + location.hostname);
      if ( start > 0 )
         imgUrl= imgUrl.slice(start + 3 + location.hostname.length)
      if ( prevWidth === false )
      {
         prevWidth= "&fullImage=1"; 
         prevHeight="";
         withDownload= "";
      }
      else
      {
        if ( !prevWidth && !prevHeight )
            prevHeight= 200;
        prevWidth= prevWidth ? "&prevWidth=" + prevWidth : "";
        prevHeight= prevHeight ? "&prevHeight=" + prevHeight : "";
        withDownload= withDownload ? "&download=yes" : "";
      }
      detailWin= window.open('/de/haushalt/imagedetail.aspx?img=' + imgUrl
        + prevWidth + prevHeight + withDownload
        , "detail", "width=300, height=300, dependent=yes, location=no,menubar=no,resizable=yes,scrollbars=no,status=no,toolbar=no");
      if ( detailWin )
      {
         detailWin.focus();
      }
   }

   function openAsDownload(filename)
   {
      if ( detailWin )
         detailWin.close();
      if ( !filename )
         return;
      var start= filename.indexOf("://" + location.hostname);
      if ( start > 0 )
         filename= filename.slice(start + 3 + location.hostname.length)
      detailWin= window.open('/de/haushalt/getFile.aspx?src=' + filename
        , "download", "width=300, height=300, dependent=yes, location=no,menubar=no,resizable=yes,scrollbars=no,status=no,toolbar=no");
      if ( detailWin )
         detailWin.focus();
   }

function showHide(id, show)
{
    var elem= getObject(id);
    if ( !elem )
       return;
    if ( show !== true && show !== false )
       show= (elem.style.display != 'block');
    elem.style.display= show ? 'block' : 'none'; 
} 

var curInfoArea= new Array(),
    curShowPicture= new Array();
function showInfoArea(id, pageID)
{
  if ( isDOM )
  {
     var info= document.getElementById(id);
     if ( !info || info == curInfoArea[pageID] )
        return;
     info.className= info.className.replace(/([ ]?jsClosed)/, '');
     if ( curInfoArea[pageID] )
        curInfoArea[pageID].className= String(curInfoArea[pageID].className.replace(/([ ]?jsClosed)/, '') + ' jsClosed').replace(/^[ ]*/, '');
     curInfoArea[pageID]= info;
  }
}

function showPictureArea(id, pageID, area)
{
  if ( isDOM )
  {
     if ( curShowPicture[pageID] )    
        curShowPicture[pageID].style.display= 'none';
     var sp= document.getElementById(id);
     if ( sp )
     {
        sp.style.display= 'block';
        if ( !sp.onclick && area.onclick )
           sp.onclick= area.onclick; 
     }
     curShowPicture[pageID]= sp;      
  }
}

function initInfoArea(parentID, showFirst, pageID)
{
  if ( isDOM )
  {
     var area= document.getElementById(parentID);
     if ( !area )
        return false;
     area= area.firstChild;
     while ( area && area.nodeType != 1 )
        area= area.nextSibling;
     if ( !area )
        return false;
     //var cnt= curInfoArea.length;
     if ( showFirst )
     {
        curInfoArea[pageID]= area;
        //area.curIndex= cnt;
        area.className= area.className.replace(/([ ]?jsClosed)/, '');
        //area= area.nextSibling;
     }
  }
}

function checkTargetLink(link)
{
  try
  {
    if (!link || !link.target || link.target == '_self')
       return;
    if ( opener.name == link.target )
       opener.focus()
    else
       self.blur();
  }
  catch (e) {}
}

function changeImage(name, url)
{
    if (document.getElementsByName(name)[0])
       document.getElementsByName(name)[0].src= url;
}
 
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) 
    {
       var val= node.nodeValue,
           valLower= val.toLowerCase(),
           pos= valLower.indexOf(word);
        if ( pos != -1 ) 
        {
            var par= node.parentNode,
            em= document.createElement("em");
            em.style.backgroundColor= "yellow";
            em.style.fontStyle= "normal";
            if ( pos > 0 )
               par.insertBefore(document.createTextNode(val.substr(0,pos)), node);
            else
               pos= 0;   
            em.appendChild(document.createTextNode(val.substr(pos, word.length)));   
            par.insertBefore(em, node);
            pos+= word.length;
            if ( pos < val.length )
               par.insertBefore(document.createTextNode(val.substr(pos)), node);
            par.removeChild(node);
        }
    }
}
function highlight()
{
   var sv= document.location.href.match(/\?highlight=([^&]+)/);
   if ( sv )
   {
       var words= decodeURI(sv[1].toLowerCase()).split(" "),
           word, 
           i=0;
       while ( i < words.length )
       {
           word= words[i];
           while ( ++i < words.length && word.length < 5 )
              word+= ' ' + words[i];
           highlightWord(document.getElementsByTagName("body")[0],word);
       }
   }
}
if ( isDOM )
   window.setTimeout('highlight()', 500);