
/*
lib.js for SPOE LINZ

Author:			  manfred.schneiderbauer@world-direct.at
Version:      1.32 (last: 1.311)
Last Changed:	2008-11-10 (last: 2008-02-20)
*/

// CSS menu (top navigation)
var leftNO=new Image(); leftNO.src='fileadmin/bo-linz-stadt/img/menuNO_left.gif';
var leftRO=new Image(); leftRO.src='fileadmin/bo-linz-stadt/img/menuRO_left.gif';
var rightNO=new Image(); rightNO.src='fileadmin/bo-linz-stadt/img/menuNO_right.gif';
var rightRO=new Image(); rightRO.src='fileadmin/bo-linz-stadt/img/menuRO_right.gif';
var middleNO=new Image(); middleNO.src='fileadmin/bo-linz-stadt/img/menuNO_middle.gif';
var middleRO=new Image(); middleRO.src='fileadmin/bo-linz-stadt/img/menuRO_middle.gif';

function menu_toggleMain(obj,mode){ // toggle 1st menu level graphical elements
  try{
    if(mode)
      {
      obj.parentNode.getElementsByTagName('img')[0].src=middleRO.src;obj.parentNode.previousSibling.getElementsByTagName('img')[0].src=leftRO.src;obj.parentNode.nextSibling.getElementsByTagName('img')[0].src=rightRO.src;
      }else{
      obj.parentNode.getElementsByTagName('img')[0].src=middleNO.src;obj.parentNode.previousSibling.getElementsByTagName('img')[0].src=leftNO.src;obj.parentNode.nextSibling.getElementsByTagName('img')[0].src=rightNO.src;}
      }
  catch(error){showError('In function menu_toggleMain():\n'+error.message);}
}
function resizeButtons(){ // scale the bg graphics to the link's dimensions
try{
var offsetNotAvail=false; var oW=0;
var allNavImg=d('clib_MenuWrapper').getElementsByTagName('img');
for(var i=0;i<allNavImg.length;i++)
  {
  if(allNavImg[i].src.toLowerCase().indexOf('middle')!=-1)
    {
    thisA=allNavImg[i].parentNode.getElementsByTagName('a')[0]; // get offset width
    // Older Gecko versions can't correctly measure the A tag's offset width
    // So we need to clone the A into a new SPAN and to measure its width instead:
    if((!isIE55up&&!isGecko)||(isGecko&&GeckoVersion>1.7))
      {
      oW=thisA.offsetWidth;
      } else {
       measureEl=document.createElement('span');
       measureEl.id='measureEl';
       document.body.appendChild(measureEl);
       if(isGecko)
        {
        d('measureEl').innerHTML='<nobr>'+thisA.text+'</nobr>';
        } else {
        d('measureEl').innerHTML='<nobr>'+thisA.innerHTML+'</nobr>';
        }
       if(isGecko)
        { // use getComputedStyle
        d('measureEl').style.fontSize=
       document.defaultView.getComputedStyle(thisA,null).getPropertyValue('font-size');
        d('measureEl').style.fontWeight=
       document.defaultView.getComputedStyle(thisA,null).getPropertyValue('font-weight');
        d('measureEl').style.fontFamily=
       document.defaultView.getComputedStyle(thisA,null).getPropertyValue('font-family');
        d('measureEl').style.margin=
       document.defaultView.getComputedStyle(thisA,null).getPropertyValue('margin');
        d('measureEl').style.padding=
       document.defaultView.getComputedStyle(thisA,null).getPropertyValue('padding');
        oW=d('measureEl').offsetWidth;
        }else{ // use currentStyle
        d('measureEl').style.fontSize=thisA.currentStyle.fontSize;
        d('measureEl').style.fontWeight=thisA.currentStyle.fontWeight;
        d('measureEl').style.fontFamily=thisA.currentStyle.fontFamily;
        d('measureEl').style.margin=thisA.currentStyle.margin;
        d('measureEl').style.padding=thisA.currentStyle.padding;
        oW=d('measureEl').offsetWidth-15;
        }
       if(oW>0){oW+=16;}
       document.body.removeChild(d('measureEl'));
      }
    if(!oW||oW==''||oW==0){offsetNotAvail=true;}
    allNavImg[i].style.width = oW+'px';
    d('clib_MenuWrapper').style.visibility='visible';
    }
  }
  window.setTimeout("resizeButtons();",1000);
}catch(error){showError('In function resizeButtons():\n'+error.message);}
}
clib_onload("resizeButtons();");

// manipulate t3 onmousemove wrapper; remove overlib handlers from document and plug them into jwcalendar elements
// this is to prevent flickering effects in the CSS menu on IE resulting from a rendering engine bug
function changeOnmousemove(mod){
if(window.pageLoaded){
// strip overlib out of wrapper
try{
eval("document.onmousemove="+document.onmousemove.toString().replace('overlib.mouseMove(e);',''));
// ...and put it into all elements related with the content (*cnt*)
var allTds=document.getElementsByTagName('td');
for(var i=0;i<allTds.length;i++)
  {
    // plug the handler into all TDs having a content related CSS class
    if(allTds[i].className.indexOf('cnt')!=-1)
      {
      allTds[i].onmousemove=function(){overlib.mouseMove();}
      }
  }
}catch(error){showError('In function changeOnmousemove():\n'+error.message);}
}else{window.setTimeout("changeOnmousemove();",250);}
}
if(isIE5up){clib_onload("changeOnmousemove();");}

// Insert line breaks after all bindestrichs in the calendar extension`s month view`s table cells
function breakAtBindestrichs(mod){
try{
  var tablesArr=document.getElementsByTagName('table'); var calTab=''; var thisTd=''; var ii=0;
  for(var i=0;i<tablesArr.length;i++)
    {
     if(tablesArr[i].className=='days') // see if the days table exists in this page
      {
       calTab=tablesArr[i];
      }
    }
   if(calTab!='') // if it exists...
    {
      var allTds=calTab.getElementsByTagName('td');
      for(i=0;i<allTds.length;i++)
        {
          if(allTds[i].className=='item') // get an item cell
            {
            thisTd=allTds[i].getElementsByTagName('div')[0];
            for(ii=0;ii<thisTd.childNodes.length;ii++) // go thru all child nodes
              {
              if(thisTd.childNodes[ii].nodeType==3&&thisTd.childNodes[ii].nodeValue.indexOf('-')!=-1)
                { // if this is a text node and contains a bindestrich...
                while(thisTd.childNodes[ii].nodeValue.indexOf('-')!=-1) // ...replace it by placeholder...
                  {thisTd.childNodes[ii].nodeValue=thisTd.childNodes[ii].nodeValue.replace('-','###');}
                while(thisTd.childNodes[ii].nodeValue.indexOf('###')!=-1) // ...and re-replace placeholder.
                  {thisTd.childNodes[ii].nodeValue=thisTd.childNodes[ii].nodeValue.replace('###','- ');}
                }
              if(thisTd.childNodes[ii].tagName&&thisTd.childNodes[ii].tagName.toLowerCase()=='a')
                { // do similar stuff in the link texts
                if(thisTd.childNodes[ii].textContent.indexOf('-')!=-1)
                  {
                    while(thisTd.childNodes[ii].textContent.indexOf('-')!=-1)
                      {
                        thisTd.childNodes[ii].textContent=thisTd.childNodes[ii].textContent.replace('-','###');
                      }
                    while(thisTd.childNodes[ii].textContent.indexOf('###')!=-1)
                      {
                        thisTd.childNodes[ii].textContent=thisTd.childNodes[ii].textContent.replace('###','- ');
                      }
                  }
                }
              }
          }
        }
    }
 mod++;
 if(mod<5){window.setTimeout("breakAtBindestrichs("+mod+");",2500);} // repeat max five times (rendering delay)
}catch(error){showError('In function breakAtBindestrichs():\n'+error.message);}
}
clib_onload("breakAtBindestrichs(0)");

// Simulate border:collapse on IE
function collapseIE(mod){
try{
var tablesArr=document.getElementsByTagName('table'); var calTab=''; var thisTd=''; var ii=0;
for(var i=0;i<tablesArr.length;i++)
  {
   if(tablesArr[i].className=='days') // see if the days table exists in this page
    {
     calTab=tablesArr[i];
    }
  }
 var ii=0; var thisTDs='';
 if(calTab!='') // if it exists...
  {
    var allTRs=calTab.getElementsByTagName('tr');
    for(var i=0;i<allTRs.length;i++)
      {
        thisTDs=allTRs[i].getElementsByTagName('td');
        for(ii=1;ii<thisTDs.length-1;ii++)
          {
           //thisTDs[ii].style.borderRight='none';
           thisTDs[ii].style.borderLeft='none';
          }
      }
  }
mod++;
if(mod<5){window.setTimeout("breakAtBindestrichs("+mod+");",2500);} // repeat max five times (rendering delay)
}catch(error){showError('In function collapseIE():\n'+error.message);}
}
if(isIE5up){clib_onload("collapseIE(0)");}

// show try/catch results
function showError(mess){
// see if edit panel is active; if so, show error alert
var isBackenduser=false; var allForms=document.getElementsByTagName('form');
for(var i=0;i<allForms.length;i++)
  {
    if(allForms[i].name.indexOf('TSFE_EDIT_FORM')!=-1) // if some frontend edit element is present...
      {isBackenduser=true;}
  }
 if(isBackenduser)
  {alert('Error message for backend users:\n\n'+mess);} // ...show the message.
}

// Menu watchdog; if menu CSS rendering fails, force page reload
function menuWatchdog(){
try{
 var allTables=document.getElementsByTagName('table');
 for(var i=0;i<allTables.length;i++)
  {
    if(allTables[i].style.height=='64px') // find menu table
      {
        if(allTables[i].offsetHeight>100) // if it has been rendered too high...
          {
           showError('Gecko CSS rendering failed. Reloading page.'); // ...reload.
           location.reload(true);
           document.body.innerHTML='<center>Bitte warten Sie einen Augenblick, die Seite wird geladen...</center>';
          }
      }
   }
}catch(error){}
}
clib_onload('window.setTimeout("menuWatchdog();",1000);');

// fix sticky top menu on IE7; makes menu flicker a little but prevents it keeping open
function fixStickyTopMenuOnIE7(){
window.bombIsZuended=false;
var allMLis=getElementsByClass('li','menu_button');
for(var i=0;i<allMLis.length;i++)
  {
   allMLis[i].onmouseout=fixStickyTopMenuOnIE7_Handler;
   allMLis[i].onmouseover=function(){window.bombIsZuended=false;}
  }
try
 {
   getElementsByClass('li','menu_button menu_button_active')[0].onmouseout=fixStickyTopMenuOnIE7_Handler;
   getElementsByClass('li','menu_button menu_button_active')[0].onmouseover=function(){window.bombIsZuended=false;}
 }catch(error){}
}
function fixStickyTopMenuOnIE7_Handler(){
  window.bombIsZuended=true;
  //window.setTimeout("if(window.bombIsZuended){d('clib_MenuWrapper').style.visibility='hidden';window.bombIsZuended=false;}",250);
  //window.setTimeout("d('clib_MenuWrapper').style.visibility='visible';",251);
  window.setTimeout("if(window.bombIsZuended){d('clib_MenuWrapper').style.position='relative';window.bombIsZuended=false;}",250);
  window.setTimeout("d('clib_MenuWrapper').style.position='';",251);
}
if(isIE7up){clib_onload("fixStickyTopMenuOnIE7()");}

// style the related news (content, right box)
function styleRelatedNews(done){
var allSp=document.getElementsByTagName('span'); var relSp='';
for(var i=0;i<allSp.length;i++) // look for headline; must contain string "verwandte artikel", case-insensitive
  {
   if(allSp[i].innerHTML.toLowerCase().indexOf('verwandte artikel')!=-1&&allSp[i].className=='lnv_hd_tx_tx')
    {
      relSp=allSp[i]; // found headline node
    }
  }
if(relSp!='') // if headline node found...
  {
   var relCont=relSp.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.getElementsByTagName('div')[0];
   var rHTML=relCont.innerHTML;
   // replace single linebreak by double one; first line all browsers, second line IE
   while(rHTML.indexOf('"><br><a')!=-1){rHTML=rHTML.replace('"><br><a','"><br><br><a');}
   while(rHTML.indexOf('0><BR><A')!=-1){rHTML=rHTML.replace('0><BR><A','0><BR><BR><A');}
   relCont.innerHTML=rHTML;
  }
if(!done){window.setTimeout("styleRelatedNews(true);",5000);} // repeat to ensure execution on very slow connections
}
clib_onload("styleRelatedNews(false)");

if(isIE55up)
	{
	try
		{
 		document.execCommand('BackgroundImageCache', false, true);
		} catch(error) {}
	}

function gecko_triggerMenu(obj,mode) {if(isGecko){try{
var drop=obj.getElementsByTagName('ul')[0].parentNode;
if(mode)
  { // activate sub menus
  drop.style.left=0;
  }else{ // deactivate'em
  drop.style.left='-3000px';
  }
}catch(error){}}}