/*
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
lib.js
Script library for SPOE-OOE

Version:             1.33
Last Changed:        2008-07-18
manfred.schneiderbauer@world-direct.at
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/

// temp redir for a news detail article
if(location.href.indexOf('detailansicht+M5bbac05dae1.html')!=-1){location.replace('http://www.das-ist-faymann.at');};


// firefox/AllOS and Gecko/Mac have a smaller default font size, so increase it there

function resizeFonts(){
if(document.body&&document.body.innerHTML)
	{
	var resizeFirefox=true;
	// measure if currently used Firefox displays small or large default fonts; no resizing if already large
	if(isGecko&&navigator.userAgent.indexOf('Firefox')!=-1)
		{
		var measureEl=document.createElement('span');
		measureEl.id='measureEl';
		measureEl.innerHTML='X';
		document.body.appendChild(measureEl);
		if(measureEl.offsetHeight>14){resizeFirefox=false;}
		measureEl.style.display='none';
		}
	// dyn resize the font sizes depending on the browser used
	if((!isMac&&(resizeFirefox&&navigator.userAgent.indexOf('Firefox')!=-1))||(isGecko&&isMac)||(isSafari))
		{
		var r=document.styleSheets[2].cssRules; // ref to clib's CSS #2 (browser specific CSS)
		var rr='';var thisFs='';var fsMode='';
		for(var i=0;i<r.length;i++)
			{
			if(r[i].style.fontSize)
				{
				thisFs=r[i].style.fontSize;
				if(thisFs.indexOf('em')!=-1){fsMode='em';}
				if(thisFs.indexOf('pt')!=-1){fsMode='pt';}
				if(thisFs.indexOf('px')!=-1){fsMode='px';}
				thisFs=Number(r[i].style.fontSize.replace('em','').replace('pt','').replace('px',''));
				if(!isSafari){thisFs+=.2;}else{thisFs=thisFs-.1;}
				r[i].style.fontSize=thisFs+fsMode;
				}
			}
		}
	} else { window.setTimeout("resizeFonts();",250);
	}
}
resizeFonts();

// create image ALT attributes if there are none set yet
function createALTs(){
if(document.body&&document.body.innerHTML)
	{
	var iA=document.getElementsByTagName('img');
	for(var i=0;i<iA.length;i++)
		{
		if(!iA[i].alt||iA[i].alt=='')
			{
			iA[i].alt=iA[i].toLowerCase().src.replace('.jpg','').replace('.jpeg','').replace('gif','').replace('png','');
			iA[i].alt=iA[i].alt.substring(iA[i].alt.lastIndexOf('/')+1,iA[i].length).replace('.','');
			iA[i].alt=iA[i].alt.toUpperCase().substring(0,1)+iA[i].alt.substring(1,iA[i].alt.length);
			while(iA[i].alt.indexOf('_')!=-1){iA[i].alt=iA[i].alt.replace('_',' ');}
			iA[i].alt+='\n© SPÖ';
			iA[i].title=iA[i].alt;
			} else {
			iA[i].title=iA[i].alt;
			}
		}
	} else {
	window.setTimeout("createALTs();",250);
	}
}
//createALTs();

// center the main element and perform some layout quirks @ non-ie
function centerContent(){
if(d('dvMain')){
if(isIE5up&&!isIE55up){window.setTimeout("d('spNvTopHeadline').style.position='relative';d('spNvTopHeadline').style.left='7px';",500);} // IE5.0 quirk
if(!isIE5up)
	{
	// x center
	var dM=d('dvMain');
	dM.style.position='absolute';
	dM.style.left=Number(window.innerWidth/2-390)+'px';
	if(isSafari) // Safari quirk to trigger reflow
		{
		if(!window.safRes||window.safRes==undefined)
			{
			window.safRes=1;
			window.resizeBy(1,0);
			} else if (window.safRes==1) {
			window.safRes=2;
			window.resizeBy(-1,0);
			}
		}
	// y content height fix
	try{if(d('tbContent')){d('tbContent').style.height=Number(window.innerHeight)-(d('tdFooter').offsetHeight*2)-90+'px';}}catch(error){}

	window.setTimeout("centerContent();",100);
	}
}else{window.setTimeout("centerContent();",100);}
}
centerContent();

// left navigation onmouseover
function ln_Mark(el,mode){
if(mode)
	{
	if(el.className=='lnv_tx_tx_line_1')
		{
		el.wasMarked=true;
		} else {
		el.className='lnv_tx_tx_line_1';
		}
	} else {
	if(!el.wasMarked)
		{
		el.className='lnv_tx_tx_line_0';
		}
	}
}
// permanently center the top menu
function centerMenu(){
if(d('cMenu')){
var yp=d('cMenu');
var ww=0;
if(isIE5up){ww=document.body.clientWidth;}else{ww=window.innerWidth;}
yp.style.position='absolute';
yp.style.zIndex=5;
var xCorr=0;
if(!isIE5up){xCorr=0;}
yp.style.left=(ww/2+390) - ((yp.offsetWidth)+xCorr) + 'px';
if(isIE5up){yp.style.top='54px';}else if(isSafari){yp.style.top='50px';}else{yp.style.top='50px';}
window.menuCentering=true;
} window.setTimeout("centerMenu();",200);
}
centerMenu();

// recalculate menu heights
function correctMenuHeights(){
if(document.body&&document.body.innerHTML){
var mc=document.getElementsByTagName('div');
var tic='';
var liArr=new Array;
for (var i=0;i<mc.length;i++) // collect containers
	{
	if(mc[i].className=='mmContainer')
		{
		try{mc[i].style.height=mc[i].getElementsByTagName('ul')[0].offsetHeight-1;}catch(error){} // tear it down by 1
		}
	}
}else{window.setTimeout("correctMenuHeights();",2500);}
}
window.setTimeout("correctMenuHeights();",250);

// recalculate menu left positions, but not on opera, since it misses document.styleSheets access
function correctMenuLeftPos(){
if(window.menuCentering&&!isOpr) // if menu is rendered and positioned
	{
	var mW=d('cMenu').offsetWidth;
	var ss=document.styleSheets[document.styleSheets.length-1]; // get ref to last CSS in document
	var ru='';if(isIE5up){ru=ss.rules;}else{ru=ss.cssRules;} // ref to rules, different @ ie / non-ie
	var tl='';
	for(var i=0;i<ru.length;i++) // search lefts (lechz for the lefts!)
		{
		tl=ru[i].style.left; // get lefts
		if(tl!='')
			{
			tl=Number(tl.replace('px',''));
			if((tl+200)>mW) // ... and finally correct it
				{
				tl=mW-200;
				tl=tl+'px';
				ru[i].style.left=tl;
				}
			}
		}
	} else {window.setTimeout("correctMenuLeftPos()",500);}
if(d('cMenu')&&!isIE5up&&!isOpr){window.setTimeout("correctMenuLeftPos()",500);} // some browsers render later -> quirk
}
correctMenuLeftPos();

// overwhelm input elemtns
function cleanElements(){
if(document.body&&document.body.innerHTML)
	{
	var isForumProfileSearch=false;
	if(location.href.indexOf('forum')!=-1&&(location.href.indexOf('profile')!=-1||location.href.indexOf('search')!=-1)){isForumProfileSearch=true;}
	var el=document.getElementsByTagName('input');
	for(var i=0;i<el.length;i++)
		{
		if(isForumProfileSearch)
			{
			// standard class to inputs without class declaration
			if(el[i].type!='submit'&&el[i].type!='reset'&&el[i].type!='button')
				{
				el[i].className='input_std_n';
				el[i].style.fontSize='11px';
				}
			}
		// reformat 'helpbox' element in forum
		if(location.href.indexOf('forum')!=-1&&el[i].name=='helpbox')
			{
			el[i].style.border='0px solid transparent';
			el[i].style.width='700px';
			}
		// extra classes to checkbox and radio elements
		if(el[i].type=='checkbox'){el[i].className='input_cb';}
		if(el[i].type=='radio'){el[i].className='input_rd';}
		// button class to buttons
if((el[i].type=='submit'||el[i].type=='button'||el[i].type=='reset'||(isGecko&&el[i].type==''))&&el[i].className!='ip_sbt')
			{
			el[i].className='ip_sbt';
			el[i].value=el[i].value.toUpperCase();
			el[i].onmouseover='';el[i].onmouseout=null;
			}
		}
	el=document.getElementsByTagName('select');
	if(isForumProfileSearch)
		{
		for(i=0;i<el.length;i++)
			{
 			el[i].className='select_std_n';
  		el[i].style.fontSize='11px';
			}
		}
	} else {
	window.setTimeout("cleanElements();",250);
	}
window.setTimeout("cleanElements();",2500);
}
cleanElements();

// Ideenforum
function showBlock(idFrag,nr)
{
d('sp_'+idFrag+'_'+nr).style.display='none';
for(var i=1;i<5;i++)
  {
    if(d(idFrag+'_'+nr+'_'+i))
      {
      d(idFrag+'_'+nr+'_'+i).style.display='';
      try{d(idFrag+'_'+nr+'_del').style.display='';}catch(error){}
      }
  }
}

// Ideenforum: show/hide results table header
function showResults(){
try{
var tables=document.getElementsByTagName('table');
for(var i=0;i<tables.length;i++)
  {
  if(tables[i].name=='tb_result')
    {
     d('tbResultHead').style.display='';
    }
  }
window.setTimeout("showResults();",500);
}catch(error){window.setTimeout("showResults();",500);}
}

// In order to prevent a FF menu layout error, do a cache-cleaning reload on initial loading
if(isGecko&&navigator.userAgent.indexOf('Firefox')!=-1)
  {
   if(navigator.cookieEnabled)
    {
     var hasReloaded=getCookie('ffHasReloaded');
     if(!hasReloaded||hasReloaded==null)
      {
       setCookie('ffHasReloaded',true);
       hookFFReload(); // set cookie and perform reload
      }
    }
  }
function hookFFReload(){
if(document.body)
  {
    if(d('measureEl')) // perform only if html has completely loaded
      {
      location.reload(true);
      } else {
      window.setTimeout("hookFFReload();",1000);
      }
  } else {
  window.setTimeout("hookFFReload();",1000);
  }
}

// block search button as long as query fields are not filled in
// used in plugin sp_directory, directory.tmpl
function blockSearch(id,idF1,idF2,idF3)
{
  var bt=d(id);
  if(d(idF1).value==''&&d(idF2).value==''&&d(idF3).value=='')
    {
     bt.disabled=true;
     if(isIE5up){if(bt.style.filter==''){bt.style.filter='Alpha(opacity=50)';}}
     if(isGecko){bt.style.MozOpacity='.5';bt.style.opacity='.5';}
     if(isSafari){bt.style.opacity='.5';bt.style.KhtmlOpacity='.5';}
    } else {
     bt.disabled=false;
     if(isIE5up){if(bt.style.filter!=''){bt.style.filter='';}}
     if(isGecko){bt.style.MozOpacity='';bt.style.opacity='';}
     if(isSafari){bt.style.opacity='';bt.style.KhtmlOpacity='';}
    }
window.setTimeout("blockSearch('"+id+"','"+idF1+"','"+idF2+"','"+idF3+"');",15);
}

// show only fields being not empty at the vcard page
// used in plugin sp_directory, directory.tmpl
function showFilledFields(){
var trs=d('tbAdditionalData').getElementsByTagName('tr');
for(var i=0;i<trs.length;i++)
  {
  if(trs[i].getElementsByTagName('td')[1].innerHTML!=''&&trs[i].getElementsByTagName('td')[1].innerHTML!='  ')
    {
    trs[i].style.display='';
    }
  }
trs=d('tbData').getElementsByTagName('tr');
for(i=0;i<trs.length;i++)
  {
  if(trs[i].getElementsByTagName('td')[1].innerHTML!='')
    {
    trs[i].style.display='';
    }
  }

}

// update the field titles in the entry form
// used in plugin sp_directory, directory.tmpl
function liveUpdateFieldTitles(){
var fields=d('tbData').getElementsByTagName('input');
for (var i=0; i<fields.length; i++)
  {
  if(fields[i].title!='')
    {
      //try
        //{
        if(fields[i].parentNode.parentNode.getElementsByTagName('td')[0].getElementsByTagName('input')[0].value=='')
          {
          fields[i].parentNode.getElementsByTagName('div')[0].innerHTML='Inhalt<br>'+fields[i].title+':<br>';
          } else  {
          fields[i].parentNode.getElementsByTagName('div')[0].innerHTML='Inhalt<br>'+fields[i].title+',  "'+fields[i].parentNode.parentNode.getElementsByTagName('td')[0].getElementsByTagName('input')[0].value+'":<br>';
          }
        //} catch(error) {}
      }
  }
window.setTimeout("liveUpdateFieldTitles();",100);
}

// if no user image is given, show a placeholder
// used in plugin sp_directory, directory.tmpl
function replaceEmptyImage(){
  if(d('dvImage').innerHTML=='')
    {
     d('dvImage').innerHTML='<div style="height:160px;width:120px;border:1px solid #E4DECF;text-align:center;"><br><br><br><br>Leider<br>kein<br>Bild<br>vorhanden</div>';
    }
}

// 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';",265);
}
if(isIE7up){clib_onload("fixStickyTopMenuOnIE7()");}

// fix top menu z-index
function fixMenuZIndex(){
var menu=d('clib_MenuWrapper'); var i=0; var zi=10; var allEl='';
allEl=menu.getElementsByTagName('div'); for(i=0;i<allEl.length;i++){allEl[i].style.zIndex=zi;}
allEl=menu.getElementsByTagName('ul'); for(i=0;i<allEl.length;i++){allEl[i].style.zIndex=zi;}
allEl=menu.getElementsByTagName('li'); for(i=0;i<allEl.length;i++){allEl[i].style.zIndex=zi;}
allEl=menu.getElementsByTagName('span'); for(i=0;i<allEl.length;i++){allEl[i].style.zIndex=zi;}
allEl=menu.getElementsByTagName('a'); for(i=0;i<allEl.length;i++){allEl[i].style.zIndex=zi;}
}
clib_onload("fixMenuZIndex()");

// fix scrambled top menu on FF
function fixScrambledTopMenuOnFF(){
try{
  var tm=d('spNvTopHeadline').parentNode;
  // if the td containing the navtopheadline exceeds a height of 100 px (normally 78), ...
  if(Number(document.defaultView.getComputedStyle(tm,null).getPropertyValue('height').replace('px',''))>100)
    {
     // ... the document is reloaded from the server.
     location.reload(true);
    }
}catch(error){}
}
if(isGecko){clib_onload("fixScrambledTopMenuOnFF()");}

// Again about the font sizes: after some updates, 'em' unit font settings produced trouble on FF/Mac.
function scaleEmFontSizesOnFFMac(){try{
if(window.scaleEmFontSizesOnFFMac.runCount==undefined||!window.scaleEmFontSizesOnFFMac.runCount){window.scaleEmFontSizesOnFFMac.runCount=0;}
var ss=''; var r=''; var c=''; var fPos=0; var fs='';

// loop thru external CSS files
for(var i=0;i<document.styleSheets.length;i++)
  {
    ss=document.styleSheets[i];
    // loop thru rules
    for(var ii=0;ii<ss.cssRules.length;ii++)
      {
       r=ss.cssRules[ii];
       if(r.cssText.indexOf('font-size')!=-1) // if a font-size is set...
        {
        // ...get its value
        c=r.cssText;
        fPos=c.indexOf('font-size')+10;
        fs=c.substring(fPos,c.length);
        fs=fs.substring(0,fs.indexOf(';'));

        if(fs.indexOf('em')!=-1) // only if it's a em value...
          {
            // get its numeric value
            fs=fs.replace('em','');
            fs=Number(fs);
            if(fs<.6&&fs>0) // if we're smaller than .6, set to .6
              {
              ss.insertRule(r.cssText.substring(0,r.cssText.indexOf('{'))+'{ font-size: 0.6em; }',ss.cssRules.length);
              }
            if(fs==1.3) // if we're at 1.3, set to 1
              {
              ss.insertRule(r.cssText.substring(0,r.cssText.indexOf('{'))+'{ font-size: 1em; }',ss.cssRules.length);
              }
          }
        }
      }
  }
if(window.scaleEmFontSizesOnFFMac.runCount==0){window.scaleEmFontSizesOnFFMac.runCount=1;window.setTimeout("scaleEmFontSizesOnFFMac();",1000);}
}catch(error){}}
if(isMac&&isGecko){clib_onload("scaleEmFontSizesOnFFMac()");}

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){}}}