function pointer(oCursor){
	oCursor.style.cursor='pointer';
}

function ChangeLanguage(oItem){
	var newLang, oldLang;
	oldLang = oItem.id;
	if(oldLang == "DE"){
		newLang = "PL";
	}
	else{
		newLang = "DE";
	}
	oItem.id = newLang;
	//switch language
	SwitchLang(newLang,oldLang);
}

function SwitchLang(newLang,oldLang) {
	divArray=document.getElementsByTagName('div');
	for(var i=0; i<divArray.length; i++){
		var idValue=divArray[i].id;
		if(idValue && idValue.toUpperCase()==oldLang){
			divArray[i].style.display='none';
		}
		if(idValue && idValue.toUpperCase()==newLang){
			divArray[i].style.display='block';
		}
	}
}
function load(){
	SwitchLang('DE','PL');
}

/*
a	defines the action you want the function to perform.
o	the object in question.
c1	the name of the first class
c2	the name of the second class 

swap	replaces class c1 with class c2 in object o.
add	adds class c1 to the object o.
remove	removes class c1 from the object o.
check	test if class c1 is already applied to object o and returns true or false. 
*/
function cssjs(a,o,c1,c2)
{
	switch (a){
		case 'swap':
			o.className=!cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
		break;
		case 'add':
			if(!cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
		break;
		case 'remove':
			var rep=o.className.match(' '+c1)?' '+c1:c1;
			o.className=o.className.replace(rep,'');
		break;
		case 'check':
			return new RegExp('\\b'+c1+'\\b').test(o.className)
		break;
	}
}

function TabPageClick(oBtn){
	var splitArray = oBtn.id.split('_');		//split up tab_item id: tab_1 => [tab][1]
	var clickIndex = parseInt( splitArray[1] );	//index of clicked button = [1]
	var tabBar = oBtn.parentNode.parentNode;	//determine tab_bar div object
	
	if(cssjs('check',oBtn,'navUnselected')){
		//step 1: unselect previous selected tab_item and tab_page
		for(var i=0; i<oBtn.parentNode.childNodes.length; i++){
			if( cssjs('check',oBtn.parentNode.childNodes[i],'navSelected') ){
				//unselect previous selected tab
				cssjs('swap',oBtn.parentNode.childNodes[i],'navSelected','navUnselected');
				//store previous tab index
				var prevSplitArray=oBtn.parentNode.childNodes[i].id.split('_');
				var prevClickIndex = parseInt(prevSplitArray[1]);
				//hide previous selected tabpage content
				document.getElementById("tabpage_"+(prevClickIndex)).style.display="none";
			};
		}
		//step 2: select clicked tab_item and show its tab_page
		cssjs('swap',oBtn,'navUnselected','navSelected');
		document.getElementById("tabpage_"+clickIndex).style.display="block";
		
		//step 3: determine language to change
		lng=oBtn.parentNode.id;
		var toChange;
		if(lng == "DE"){
			toChange='tab_pl';
		}
		else{
			toChange='tab_de';
		}
		
		//step 4: change classes of other language part of tab_bar
		for(var i=0; i<tabBar.childNodes.length; i++){
			if(tabBar.childNodes[i].className){
				//search div 'tab_pl' or 'tab_de'
				if(cssjs('check',tabBar.childNodes[i],toChange)){
					//loop through items
					for(var j=0; j<tabBar.childNodes[i].childNodes.length; j++){
						if (tabBar.childNodes[i].childNodes[j].id){
							var split = tabBar.childNodes[i].childNodes[j].id.split('_');
							var index = parseInt(split[1]);
							if( index == prevClickIndex){
								cssjs('swap',tabBar.childNodes[i].childNodes[j],'navSelected','navUnselected');
							}
							if( index == clickIndex ){
								cssjs('swap',tabBar.childNodes[i].childNodes[j],'navUnselected','navSelected');
							}
						}
					}
				}
			}
		}
	}
}

var notWhitespace = /\S/;
function cleanWhitespace(node) {
	for (var x = 0; x < node.childNodes.length; x++) {
		var childNode = node.childNodes[x];
		if ((childNode.nodeType == 3)&&(!notWhitespace.test(childNode.nodeValue))) {
			// that is, if it's a whitespace text node
			node.removeChild(node.childNodes[x])
			x--
		}
		if (childNode.nodeType == 1) {
			// elements can have text child nodes of their own
			cleanWhitespace(childNode)
		}
	}
}


