function windowW() {
  if (window.innerWidth) {
    return window.innerWidth;
  } else if (document.body && document.body.offsetWidth) {
    return document.body.offsetWidth;
  } else {
    return 0;
  }
}

function windowH() {
  if (window.innerHeight) {
    return window.innerHeight;
  } else if (document.body && document.body.offsetHeight) {
    return document.body.offsetHeight;
  } else {
    return 0;
  }
}


var pop = null;

function tx_xp_ctype_popdown() {
  if (pop && !pop.closed) pop.close();
}

function tx_xp_ctype_openW(obj,w,h) {
  var url = (obj.getAttribute) ? obj.getAttribute('href') : obj.href;
  if (!url) return true;
  w = (w) ? w += 0 : 150;  // 150px*150px is the default size
  h = (h) ? h += 0 : 150;
  
  var ww = windowW();
  var wh = windowH();
  
  if (ww/2 >= w/2){
	  var l = Math.round(ww/2 - w/2);
  } else {
	  var l = 350;
  }
  
  if (wh/2 >= h/2){
	  var t = Math.round(wh/2 - h/2);
  } else {
	  var t = 300;
  }
  
  var args = 'width='+w+',height='+h+',resizable=yes,top='+t+',left='+l+'';
  tx_xp_ctype_popdown();
  pop = window.open(url,'',args);
  return (pop) ? false : true;
}

function tx_xp_ctype_openWScroll(obj,w,h) {
  var url = (obj.getAttribute) ? obj.getAttribute('href') : obj.href;
  if (!url) return true;
  w = (w) ? w += 0 : 150;  // 150px*150px is the default size
  h = (h) ? h += 0 : 150;
  
  var ww = windowW();
  var wh = windowH();
  
  if (ww/2 >= w/2){
	  var l = Math.round(ww/2 - w/2);
  } else {
	  var l = 350;
  }
  
  if (wh/2 >= h/2){
	  var t = Math.round(wh/2 - h/2);
  } else {
	  var t = 300;
  }
  
  var args = 'width='+w+',height='+h+',resizable=yes,top='+t+',left='+l+',scrollbars=yes';
  tx_xp_ctype_popdown();
  pop = window.open(url,'',args);
  return (pop) ? false : true;
}

window.onunload = tx_xp_ctype_popdown;
window.onfocus = tx_xp_ctype_popdown;



function tx_xp_ctype_show(id){
	if (element = document.getElementById(id)){
		element.style.display = "block";
	}
}

function tx_xp_ctype_hide(id){
	if (element = document.getElementById(id)){
		element.style.display = "none";
	}
}


function tx_xp_ctype_pi4_showHide(id, ahref){
	if (element = document.getElementById(id)){
		if (element.style.display == "none"){
			element.style.display = "block";
			if (ahref){
				ahref.className = "act";
			}
		} else {
			element.style.display = "none";
			if (ahref){
				ahref.className = "";
			}
		}
	}
}

function tx_xp_ctype_pi4_showHideCloseOthers(id, ahref){
	if (element = document.getElementById(id)){
		if (element.style.display == "none"){
			// Alle Header finden
			my_classes = tx_xp_ctype_pi4_getElementsByClassName(document, "div", 'xp_ctype_pi4_header');
			// Schleife fuer jeden Header
			for (i=0;i<my_classes.length;i++){
				// Klassenname der darinliegenden Anker loeschen. = Standardstyle
				my_classes[i].childNodes[0].className = "";
				
				// Das naechste Element ist der DIV mit dem Content. Diesen ausblenden.
				my_classes[i].nextSibling.style.display = "none";
			}
			// den eigenen Content einblenden
			element.style.display = "block";
			// den eigenen Style auf aktiv setzen
			if (ahref){
				ahref.className = "act";
			}
		}
	}
}

/*
	Die getElementsByClassName-Funktion gibt es nicht ueberall - also gibt es hier die Pseudo-Funktion
*/
function tx_xp_ctype_pi4_getElementsByClassName(oElm, strTagName, oClassNames){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if(typeof oClassNames == "object"){
		for(var i=0; i<oClassNames.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
	}
	else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k=0; k<arrRegExpClassNames.length; k++){
			if(!arrRegExpClassNames[k].test(oElement.className)){
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}



