/*
 * Ersetzt eine CSS-Klasse durch eine andere
 *
 * @author Alexander Fuchs
 */
function replaceClassNames (oldClass, newClass)
{
	elements = document.getElementsByClassName(oldClass);
	for(itemx in elements)
		if(elements[itemx].className)
		{
			elements[itemx].addClassName(newClass);
			elements[itemx].removeClassName(oldClass);
		}

	// Alte Version, ging aber nicht in FF3
	/*document.getElementsByClassName(old_class).each(
		function(item){
			item.className = new_class;
		});*/

}

/*
 * Blendet ein Element anhang der CSS-Klasse aus
 *
 * @author Alexander Fuchs
 */
function displayNoneByClassName (class_name)
{
	elements = document.getElementsByClassName(class_name);
	for(itemx in elements)
		if(elements[itemx].style) elements[itemx].style.display = 'none';

}



function overallDiv ()
{
	// Erstelle die OverlayDiv
	var objBody = document.getElementsByTagName("body").item(0);

	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	//objOverlay.style.display = 'none';
	objOverlay.onclick = function() { alert('test'); }
	objBody.appendChild(objOverlay);
}


function changeTab (selectedElement, displayIn, displayOut, tabActive, tabDeactive)
{
	// Haue alle erstmal raus
	displayNoneByClassName(displayOut);

	// Markiere die Navigation
	replaceClassNames(tabActive, tabDeactive);

	$(selectedElement).addClassName(tabActive);

	// Zeige die DIV
	$(displayIn).style.display = '';
}

var running = false;
function changeTabSpeedy (selectedElement, displayIn, displayOut, tabActive, tabDeactive)
{

	displayNoneByClassName(displayOut);

	// Markiere die Navigation
	replaceClassNames(tabActive, tabDeactive);

	$(selectedElement).addClassName(tabActive);

	// Zeige die DIV
	$(displayIn).style.display = '';


}




//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}

	arrayPageScroll = new Array(xScroll,yScroll)
	return arrayPageScroll;
}

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

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------
function getPosition(obj)
{
	var pos = { x:0, y:0 };

	do {
		pos.x += obj.offsetLeft;
		pos.y += obj.offsetTop;
	} while (obj = obj.offsetParent);

	return pos;
}

// http://javascript.jstruebig.de/javascript/37/
function money_render(zahl, k, fix)
{
	if(!k) k = 2;
	fix = true;
	var neu = '';

	// Runden
	var f = Math.pow(10, k);
	zahl = '' + parseInt( zahl * f + (.5 * (zahl > 0 ? 1 : -1)) ) / f ;

	// Komma ermittlen
	var idx = zahl.indexOf('.');

	// fehlende Nullen einf?gen
	if(fix)
	{
		zahl += (idx == -1 ? '.' : '' ) + f.toString().substring(1);
	}

	// Nachkommastellen ermittlen
	idx = zahl.indexOf('.');
	if( idx == -1) idx = zahl.length;
	else neu = ',' + zahl.substr(idx + 1, k);


	// Tausendertrennzeichen
	while(idx > 0)
	{
		if(idx - 3 > 0) neu = '.' + zahl.substring( idx - 3, idx) + neu;
		else neu = zahl.substring(0, idx) + neu;
		idx -= 3;
	}
	return neu;
}