  /**
  * JavaScript for the jaron.de main navigation.
  *
  * @author Steffen Friedrich (steffen@myhopa.de, wWw.MyHoPa.de)
  ***/

function get( id )
{ return document.getElementById( id ); }

function startUp( root, setH )
{
	var node = root.firstChild;
	
	do{
		while( node && (!node.nodeName || node.nodeType != 1 ) ) node = node.nextSibling;

		if(node)
		{
			if( node.className && node.className.length ) node.openClass = ' hover';
			else node.openClass ='hover';

			node.onmouseover = function(){
				this.className += this.openClass;
			      }
			
			node.onmouseout = function(){
			      	this.className = this.className.replace(new RegExp(this.openClass,'g'),'');
			      }
		
		startUp(node);
		node = node.nextSibling;
	}
		
	}while(node);
}

function setBookmark() {
	var t="Tagesgeld.de", u = "http://www.tagesgeld.de";
    if (window.sidebar) window.sidebar.addPanel(t,u,"");
	else if( window.external ) window.external.AddFavorite(u,t);
	else if(window.opera && window.print) return true;
}

 /**
  * JavaScript for changing images
  *
  * @author Yan Dehner, yan.dehner@pingping.ag
  * @copy pingping.ag
  ***/

function imageChanger(_id, _path, _name, _images)
{
	this.name = _name;
	this.path = _path;
	this.element = get(_id);
	this.images = new Object();
	this.queue = null;
	this.act_image_nr = 0;
	this.isCool = !document.all;

	this.complete = function(_image)
	{
		var image;
		image = document.createElement("IMG");
		image.src = _image.src;
		this.element.appendChild(image);

		image.style.top = Math.round(45 - image.height/2) + "px";
		image.style.left = Math.round(99-image.width/2) + "px";

		if(this.isCool) image.style.opacity = 0.0;
			else image.style.filter='alpha(opacity=0)';
		if ( this.queue )
		{
			this.queue.push(image);
		} else {
			this.queue = new Array(image);
			this.animate(0);
			this.blend(0, 0, 10);
		}
	}

	this.animate = function( image_nr )
	{
		if ( this.act_image_nr != image_nr )
		{
			this.blend(this.act_image_nr, 10, 0);

		}

		if ( this.act_image_nr != image_nr )
		{
			this.blend(image_nr, 0, 10);
			this.act_image_nr = image_nr;
		}

		this.queue[image_nr].style.visibility = "visible";
		window.setTimeout(this.name + ".animate("+ ((image_nr+1)%this.queue.length) +")", 3000);
	}

	this.blend = function( image_nr, from_value, to_value )
	{
		var step = (to_value - from_value) / 10;

		if(!to_value)
			window.setTimeout(this.name+'.queue['+image_nr+'].style.visibility="hidden"',from_value*100);
		else this.queue[image_nr].style.visibility="visible";

		for(var sklave=from_value;sklave<=to_value&&step>0||sklave>=to_value&&step<0;sklave+=step)
		{
			if(this.isCool) window.setTimeout(this.name+'.queue['+image_nr+'].style.opacity='+sklave*.1,step>0?sklave*100:1000-sklave*100);
			else window.setTimeout(this.name+'.queue['+image_nr+'].style.filter="alpha(opacity='+sklave*10+')"',step>0?sklave*100:1000-sklave*100);

			// filter:alpha(opacity=50);
		}
	}

	for(var i=0; i<_images.length; i++)
	{
		this.images[_images[i]] = new Image();
		this.images[_images[i]].src = this.path + _images[i];
		this.images[_images[i]].changer = this;
		this.images[_images[i]].onload = function () {this.changer.complete(this);}
	}


}

 /**
  * JavaScript for paginating through google results.
  *
  * @author Steffen Friedrich, steffen.friedrich@pingping.ag
  * @copy pingping.ag
  ***/
function GoogleSearchResultBrowser(elementPrefix,resultsNumber,resultsPerPage,startAtResult)
{
	this.prefix = elementPrefix;
	this.current = startAtResult ? startAtResult : 0;
	this.count = resultsNumber;
	this.rpp = resultsPerPage;
	this.boxes = new Array();

	var sklave=0;

	var resF = get(this.prefix+'_resultsFrom'),
		resT = get(this.prefix+'_resultsTo');

	while(get(this.prefix+sklave) && get(this.prefix+sklave+'_button'))
	{	this.boxes[sklave] = new Object();

		this.boxes[sklave] = get(this.prefix+sklave);
		this.boxes[sklave].button = get(this.prefix+sklave+'_button');
		this.boxes[sklave].num = sklave;
		this.boxes[sklave].ePrefix = elementPrefix;

		this.boxes[sklave].fromElement = resF;
		this.boxes[sklave].from = sklave*this.rpp+1;

		this.boxes[sklave].toElement = resT;
		this.boxes[sklave].to = Math.min((sklave+1)*this.rpp,this.count);

			this.boxes[sklave].hide = function() {
				this.style.display = 'none';
				this.button.className = 'tx-jppageteaser-pi1-browsebox-inactive-link';
				if(!this.num)
					{	get(this.ePrefix+'_toStart_button').className = 'tx-jppageteaser-pi1-browsebox-inactive-link';
						get(this.ePrefix+'_retreat_button').className = 'tx-jppageteaser-pi1-browsebox-inactive-link';
					}else
				if(this.num==this.max)
					{	get(this.ePrefix+'_toEnd_button').className = 'tx-jppageteaser-pi1-browsebox-inactive-link';
						get(this.ePrefix+'_advance_button').className = 'tx-jppageteaser-pi1-browsebox-inactive-link';
					}

			}

			this.boxes[sklave].show = function() {
				this.style.display = 'block';
				this.button.className = 'tx-jppageteaser-pi1-browsebox-active-link';
				this.fromElement.innerHTML = this.from;
				this.toElement.innerHTML = this.to;

				if(!this.num)
					{	get(this.ePrefix+'_toStart_button').className = 'tx-jppageteaser-pi1-browsebox-active-link';
						get(this.ePrefix+'_retreat_button').className = 'tx-jppageteaser-pi1-browsebox-active-link';
					}else
				if(this.num==this.max)
					{	get(this.ePrefix+'_toEnd_button').className = 'tx-jppageteaser-pi1-browsebox-active-link';
						get(this.ePrefix+'_advance_button').className = 'tx-jppageteaser-pi1-browsebox-active-link';
					}

			}

		sklave++;
	}

	this.max = sklave-1;

	for(box in this.boxes)
		this.boxes[box].max = this.max;

	this.open = function(nr)
	{
		if(this.boxes[nr])
		{	this.boxes[this.current].hide();
			this.boxes[nr].show();
			this.current=nr;
		}

    return false;
	}

	this.toStart = function()
	{	this.open(0); }

	this.advance = function()
	{	if(this.current<this.max) this.open(this.current+1); }

	this.retreat = function()
	{	if(this.current>0) this.open(this.current-1); }

	this.toEnd = function()
	{	this.open(this.max); }
}

/**
 * Klasse um Tabellen dynamisch sortierbar zu machen.
 * Die Tabelle braucht ein thead und ein tbody Element. Jede Spalte braucht ein einzelnes th-element im thead.
 * Alle trs im tbody müssen die gleiche Anzahl tds haben. Das erste tr mit einer unterschiedlichen Anzahl tds und alle folgenden werden ignoriert (potentieller footer Bereich).
 *
 * @author Steffen Friedrich (steffen.friedrich@pingping.ag)
 */
function TableSorter( table )
{	this.init = _TableSorter_init;
	
	this.extractHeader = _TableSorter_extractHeader;
	this.extractData = _TableSorter_extractData;
	this.getComparableData = _TableSorter_getComparableData;
	this.cleanData = _TableSorter_cleanData;
	this.sortData = _TableSorter_sortData;
	this.createInputs = _TableSorter_createInputs;
	this.createInput = _TableSorter_createInput;
	this.sort = _TableSorter_sort;
	this.seemsAnumber = _TableSorter_seemsAnumber;
	
	
	this.tab = table;
	this.tabBody = 0;
	this.tabHead = 0;
	this.bodyData = 0;
	this.headData = 0;
	this.headerRows = 0;
	this.footerRows = 0;
	this.cellco = 0;
	this.activeButton;
	
	if(!this.init()) return;
}

function _TableSorter_getElementsByTagName(name)
{	if(name=='tr') return this;

	var tA = new Array();
	for(var sklave=0;sklave<this.length;sklave++)
		tA = tA.concat(this[sklave].getElementsByTagName(name));

	return tA;
}

function  _TableSorter_init()
{
	var el = this.tab.getElementsByTagName('thead');
	if(!el || !el.length) 
	{	el = this.tab.getElementsByTagName('tr');
		var arr=new Array();
		for(var tr in el)
			if(el[tr].className && el[tr].className.indexOf('thead')>-1)
				arr.push(el[tr]);
		if(!arr.length) return;
		else 
		{	arr.getElementsByTagName = _TableSorter_getElementsByTagName;
			this.tabHead = arr;
		}
	} else this.tabHead = el[0];
		
	el = this.tab.getElementsByTagName('tbody');
	if(!el || !el.length) return false;
	
	this.tabBody = el[0];
	
	this.extractData();
	
	if(this.bodyData && this.bodyData.length && this.bodyData[1].length>1) this.extractHeader();
		else return false;

	if(this.headData && this.headData.length) this.cleanData();
		else return false;
	
	this.sortData();
	this.createInputs();
	
	return true;
}

function _TableSorter_extractData()
{	this.bodyData = new Array();
	
	var trs = this.tabBody.getElementsByTagName('tr'), tds, sklave, knecht, dataO, cnt=0;
	for(sklave=0; sklave<trs.length; sklave++)
	{	if(trs[sklave].className && trs[sklave].className.indexOf('thead')>-1)
		{	if(!this.headerRows)this.headerRows=new Array();
			this.headerRows.push(trs[sklave]);
			continue;
		} 

		tds = trs[sklave].getElementsByTagName('td');

		if(cnt && tds.length!=cnt) break;
			else if(!cnt) 
			{	cnt = tds.length;
				for(knecht = 0; knecht<cnt; knecht++)
					this.bodyData[knecht] = new Array();
			}
		
		for(knecht = 0; knecht<tds.length; knecht++)
		{	dataO = new Object();
			dataO.value = this.getComparableData(tds[knecht]);
			dataO.tr = trs[sklave];
			this.bodyData[knecht].push(dataO);
		}
	}
	
	if(sklave<trs.length)
	{	this.footerRows = new Array();
		for(sklave; sklave<trs.length; sklave++)
			this.footerRows.push(trs[sklave]);
	}
	
	this.cellco = this.bodyData.length;
	
	return true;
}

function _TableSorter_getComparableData(node)
{
	if(node.nodeType==3)
		return node.data.toLowerCase().replace(/\s+$/,"").replace(/^\s+/,"");
	else if(node.nodeType==1 && node.nodeName.toUpperCase()=='IMG' && node.getAttribute('alt'))
		return node.getAttribute('alt').toLowerCase().replace(/\s+$/,"").replace(/^\s+/,"");

	var val = '', child = node.firstChild;
	
	while(child)
	{	val += this.getComparableData(child);
		child = child.nextSibling;
	}
	
	return val;
}

function _TableSorter_extractHeader()
{ 	var trs = this.tabHead.getElementsByTagName('tr'), tds, sklave, knecht, meister, garcon;
 	
 	this.headData = new Array();
 	for(sklave=0; sklave<this.cellco; sklave++)
 		this.headData[sklave]=0;
	
	for(sklave=0;sklave<trs.length;sklave++)
 	{	knecht=0;
 		meister=0;
 		
 		ths = trs[sklave].getElementsByTagName('th');
 		if(!ths||!ths.length)
 			ths = trs[sklave].getElementsByTagName('td');

	 	while(knecht<this.cellco)
	 		if(ths[knecht-meister].getAttribute('colspan')&&parseInt(ths[knecht-meister].getAttribute('colspan'))>1)
	 		{	garcon = parseInt(ths[knecht-meister].getAttribute('colspan'));
	 			meister+=garcon-1;
	 			knecht +=garcon;
	 		}
	 		else if(this.headData[knecht])
	 			knecht++;
	 		else
		 	 {	this.headData[knecht] = new Object();
		 	 	this.headData[knecht].th = ths[knecht-meister];
		 	 	this.headData[knecht].compare = _TableSorter_compare;
	 	 		knecht++;
		 	 }
 	}
}

function _TableSorter_cleanData()
{	var sklave, knecht, val;
	for(sklave=0;sklave<this.cellco;sklave++)
	{	val = this.bodyData[sklave][0].value;
		
		if(this.headData[sklave].th.className && this.headData[sklave].th.className.indexOf('sortable')>-1)
			for(knecht=1;knecht<this.bodyData[sklave].length;knecht++)
				if(val!=this.bodyData[sklave][knecht].value) 
					break;
		
		if( !this.headData[sklave].th.className 
			|| this.headData[sklave].th.className.indexOf('sortable')==-1 
			||  knecht==this.bodyData[sklave].length)
		{	for(knecht=sklave;knecht<this.cellco-1;knecht++)
			{	this.bodyData[knecht] = this.bodyData[knecht+1];
				this.headData[knecht] = this.headData[knecht+1];
			}
			this.cellco--;
			this.bodyData[this.cellco] = null;
			this.headData[this.cellco] = null;
			sklave--;
		}
	}
	
	for(sklave=0;sklave<this.cellco;sklave++)
		for(knecht=0;knecht<this.bodyData[sklave].length;knecht++)
			if(this.bodyData[sklave][knecht].value && this.bodyData[sklave][knecht].value.length)
				if(val=this.seemsAnumber(this.bodyData[sklave][knecht].value))
				{	while(knecht<this.bodyData[sklave].length)
					{	if(this.bodyData[sklave][knecht].value && this.bodyData[sklave][knecht].value.length)
							if(this.seemsAnumber(this.bodyData[sklave][knecht].value)!=val)
								knecht = this.bodyData[sklave].length+1;
						knecht++;
					}
					
					if(knecht==this.bodyData[sklave].length)
						this.headData[sklave].compare = _TableSorter_compareAsFloat;
						
				}else knecht = this.bodyData[sklave].length;
	
}

function _TableSorter_seemsAnumber( value )
{
	if(!value || !value.length) return 0;
	if(value.indexOf('%')==value.length-1) return 1;
		else {
			value = value.replace(new RegExp('&euro;','g'),'€');
			if(value.indexOf('€')==0)
				return 2;
		}
}

function _TableSorter_compare(a,b)
{	return a.value < b.value;
}

function _TableSorter_extractFloat(value)
{	if(!value||!value.length) return 0;
	return  parseFloat((value.replace(/\./g,'').match(/\d+,\d+/)+'').replace(/,/,'.'));
}

function _TableSorter_compareAsFloat(a,b)
{	return _TableSorter_extractFloat(b.value) - _TableSorter_extractFloat(a.value);
}

function _TableSorter_sortData()
{	for(var sklave=0;sklave<this.cellco;sklave++)
		this.bodyData[sklave].sort(this.headData[sklave].compare);
}

function _TableSorter_createInput(th, row, dir)
{	button = document.createElement('div');
			
	button.tabSorter = this;
	button.tabRow = row;
	button.tabDirection = dir;
	button.onclick = function(){ this.tabSorter.sort(this, this.tabRow, this.tabDirection); }
			
	button.className = 'sort-button';

	img = document.createElement('img');

	if( !dir )
	 {
		button.style.marginLeft = 0;
		button.title = 'Aufsteigend sortieren';
		img.src = 'fileadmin/tpls/img/sorting-button-up.gif';
	 }
	 else 
	 {
	 	button.style.marginRight = 0;
	 	button.title = 'Absteigend sortieren';
		img.src = 'fileadmin/tpls/img/sorting-button-down.gif';
	 }
	
	button.appendChild(img);
		
	return button;
}

function _TableSorter_createInputs()
{
	var sklave, th, sdiv, button, img, bW;
	for(sklave=0;sklave<this.cellco;sklave++)
		{	th = this.headData[sklave].th;
			
			th.style.paddingLeft = 0;
			th.style.paddingRight = 0;
			th.style.paddingBottom = 0;
			
			sdiv = document.createElement('div');

			sdiv.appendChild( this.createInput(th, sklave, 1) );
			sdiv.appendChild( this.createInput(th, sklave, 0) );
			
			startUp(sdiv);
			th.appendChild(sdiv);			
		}
}

function _TableSorter_sort(button, row, asc)
{
	if(this.activeButton)
		this.activeButton.className = this.activeButton.className.replace(new RegExp(' active','g'),'').replace(new RegExp('active','g'),'');
	
	this.activeButton = button;
	
	if(this.activeButton.className)
		this.activeButton.className += ' active';
	else this.activeButton.className = 'active';

	var paNo = this.bodyData[row][0].tr.parentNode;		
	
	while(paNo.firstChild)
		paNo.removeChild(paNo.firstChild);
		
	//for(var sklave=0; sklave<this.bodyData[row].length; sklave++)
	//		paNo.removeChild( this.bodyData[row][sklave].tr );

	paNoFiChi = paNo.firstChild;

	if(this.headerRows)
		for(var sklave=0;sklave<this.headerRows.length;sklave++)
			paNo.appendChild( this.headerRows[sklave] );

	if(asc)
		for(var sklave=0; sklave<this.bodyData[row].length; sklave++)
			paNo.appendChild( this.bodyData[row][sklave].tr );
		else for(var sklave=this.bodyData[row].length-1; sklave>=0; sklave--)
			paNo.appendChild( this.bodyData[row][sklave].tr );
	
	if(this.footerRows)
		for(var sklave=0;sklave<this.footerRows.length;sklave++)
			paNo.appendChild( this.footerRows[sklave] );
}


function showInfo( img )
{	img.nextSibling.style.display='block';
}

function hideInfo( img )
{	img.nextSibling.style.display='none';
}


/** Finanzscout Rechner **/


function send(where)
		{	if(!where) where = 'geldanlage-banking/tagesgeld/tagesgeld-vergleich.aspx';
			document.form.action = 'http://www.financescout24.de/'+where+'?' + 'betr=' + document.form.betr + '&lz=' + document.form.lz + '&sich' + document.form.sich;
		}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}