// Set up Event Listener - the script that allows us to use the addEvent call below

function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
	elm.addEventListener(evType, fn, useCapture);
	return true;
	} else if (elm.attachEvent) {
	var r = elm.attachEvent('on' + evType, fn);
	return r;
	} else {
	elm['on' + evType] = fn;
	}
}

// tabs function
function showDbmTabs(id){
	var tabCont = document.getElementById("tCongTabsContainer");
	var tabs = document.getElementById("tCongTabs");
	for(var i=0;i<tabCont.childNodes.length;i++){
		if(tabCont.childNodes[i]&&tabCont.childNodes[i].style)
			tabCont.childNodes[i].style.display = "none";
	}
	for(var i=0;i<(tabs.childNodes.length);i++){
		var childNode = tabs.childNodes[i];
		if(childNode&&childNode.style&&childNode.tagName=="DIV") {
			childNode.className = "";				
			for(var j=0;j< childNode.childNodes.length;j++){	
				var tabChildNode = tabs.childNodes[i].childNodes[j];
				if(tabChildNode&&tabChildNode.style&&tabChildNode.tagName=="SPAN") {
					tabChildNode.className = "leftImg";
				}
			}
		}
	}

	document.getElementById("tabCont"+id).style.display = "block";
	document.getElementById("tab"+id).className = "active";
	document.getElementById("_tImg"+id).className = "leftImgActive";		
}

function showSearchTabs(id){
	var tabCont = document.getElementById("tSearchTabsContainer");
	var tabs = document.getElementById("tSearchTabs");
	for(var i=0;i<tabCont.childNodes.length;i++)
		if(tabCont.childNodes[i]&&tabCont.childNodes[i].style)
			tabCont.childNodes[i].style.display = "none";
	for(var i=0;i<(tabs.childNodes.length);i++)
		if(tabs.childNodes[i]&&tabs.childNodes[i].style&&tabs.childNodes[i].tagName=="LI") {
			tabs.childNodes[i].className = "";
			document.getElementById("tabCont"+id).style.display = "block";
			document.getElementById("tab"+id).className = "active";
		}
}

function showComment(id){
	var react = document.getElementById(id);
	if (react.style.display=="none") {react.style.display="block"}
	else {react.style.display ="none"}
}

function makeFloatRight(){
	var divs = document.body.getElementsByTagName("DIV");
	for(var i=0;i<divs.length;i++){
		if(divs[i].className=="aThemeDouble" || divs[i].className=="aThemeNDouble"){
			//if(divs[i].parentNode.className=="leftContent"){
				var childDivs = divs[i].childNodes;
				var counter1 = 0;
				for(var j=0;j<childDivs.length;j++){
					if(childDivs[j].tagName && childDivs[j].tagName=="DIV" && (childDivs[j].className=="aThemeBig" || childDivs[j].className=="aThemeSimple")){
						counter1++;
						if(counter1%2==0){
							childDivs[j].style.styleFloat="right";
							childDivs[j].style.cssFloat="right";
							//childDivs[j].style.clear="both";
							//childDivs[j].style.clear="left";
							//childDivs[j].style.cssText="float:right; clear:left; border:1px solid red";
							//childDivs[j].style.marginLeft="5px";
							//childDivs[j].style.clear="none";
							//alert(childDivs[j].style.cssText);
						}
						// Let's determine the maximum height out of all columns specified
						//if(counter1%2!=0) {
						var maxHeight = 0;
						for (var y=0; y<childDivs.length; y++) {
								if (childDivs[y].offsetHeight > maxHeight) maxHeight = childDivs[y].offsetHeight;
							}
	
						// Let's set all columns to that maximum height
						for (var y = 0; y < childDivs.length; y++) {
							//alert(maxHeight);
							childDivs[j].style.height = maxHeight + 'px';
		
							// Now, if the browser's in standards-compliant mode, the height property
							// sets the height excluding padding, so we figure the padding out by subtracting the
							// old maxHeight from the new offsetHeight, and compensate!  So it works in Safari AND in IE 5.x
							if (childDivs[j].offsetHeight > maxHeight) {
								childDivs[j].style.height = (maxHeight - (childDivs[j].offsetHeight - maxHeight)) + 'px';
							}
						}
						//}
						//childDivs[j].style.width=divs[i].parentNode.offsetWidth/2-5+"px";

						/*if((counter1%2-1)==0){
							childDivs[j].style.clear="both";
						}*/
					}
				}
		//}
		}
	}
}
function JSTextAnimation(){

  this.textString = "";
  this.container = null;
  this.timeout = 0;
  this.timer = null;
  this.charNum = 0;  

  this.startAnimation = function(txt,container,timeout){
  this.textString = txt;
    this.container = (typeof container=="string")?document.getElementById(container):container;
    this.timeout = timeout;
		this.animateText();
  }
  
  this.stopAnimation = function(){
  	if(this.timer) window.clearTimeout(this.timer);
  }
  
  function animateText(){
  	if(TextAnimation.charNum>TextAnimation.textString.length){
        TextAnimation.container.innerHTML = TextAnimation.container.innerHTML.replace(/_$/g,"");
    	TextAnimation.stopAnimation();
      return false;
    }
    TextAnimation.container.innerHTML = TextAnimation.textString.substr(0,TextAnimation.charNum)+"_";
    TextAnimation.charNum++;
    window.setTimeout(TextAnimation.animateText,TextAnimation.timeout);
  }
  this.animateText = animateText;
} 
var TextAnimation = new JSTextAnimation();

function typeText() {
	var analyseTitle = document.getElementById('analyseTitle');
	if(analyseTitle){
		var analyseLink = document.getElementById('analyseLink');      
		if(analyseLink){
				TextAnimation.startAnimation(analyseTitle.innerHTML,'analyseLink',100);
		}
	}
}

function reageren() {
	rPopup = window;
	rPopup.open("reageren.html","","toolbar=false,status=false,width=423,height=353");
}
function reagerenH() {
	rPopup = window;
	rPopup.open("hdb-reageren.html","","toolbar=false,status=false,width=423,height=475");
}
function printen() {
	rPopup = window;
	rPopup.open("printen.html","");
}

var __hideList = true;

function cloneList(id,className){
 var list = document.getElementById(id);
 if(!list){
  id = id.split("_")[0];
  list = document.getElementById(id);
 }
 if(!list) return;
 var clonedList = list.cloneNode(true);
 clonedList.style.display="block";
 clonedList.className=className;
 clonedList.id = id;
 var divContainer = document.getElementById("_listContainer");
 if(!divContainer){
  divContainer = createDivContainer(id);
 }
 divContainer.appendChild(clonedList);
 if(list.id.indexOf("_main")==-1) list.id+="_main";
 list.className="";
 list.style.display="none";
}

//cloneList("test","twoColums");

function divideUls(){
  var c = 0;
  var uls = document.body.getElementsByTagName("UL");
  for(var i=0;i<uls.length;i++){
   if(uls[i].className=="twoColums" && uls[i].id.indexOf(String("__dividedUL_"+c))!=0){
    c++;
    divideList(uls[i],2,String("__dividedUL_"+c));
   }
  }
}

function divideList(parentId,n,prefix){
 var counter=1;
 var tag=(typeof parentId=="object")?parentId:document.getElementById(parentId);
 var ch = getChildren(tag);
 if(tag.tagName=="DL") assignSubChildren(ch);
 for(var x=n;x>1;x--){
  var arrA = getChildren(tag);
  var newTag = document.createElement(tag.tagName);
  newTag.className = tag.className+"1";
  var dividedListnum = Math.ceil(arrA.length/x);
  newTag.id = prefix+counter;
  if(tag.nextSibling) tag.parentNode.insertBefore(newTag,tag.nextSibling);
  else tag.parentNode.appendChild(newTag);
  for(i=dividedListnum;i<arrA.length;i++){
   var newChild = arrA[i].cloneNode(true);
   appendNewChild(newTag.id,newChild);
  }
  for(var j=arrA.length-1;j>=dividedListnum;j--){
   if(arrA[j].removeNode) arrA[j].removeNode(true);
   else if(arrA[j].parentNode.removeChild) arrA[j].parentNode.removeChild(arrA[j]);
  }
  tag = document.getElementById(newTag.id);
  counter++;
 }
 if(tag.tagName=="DL") appendSubChildren(n,prefix);
}

function getChildren(o){
 if(o.tagName=="UL") return o.getElementsByTagName("LI");
 else if(o.tagName=="DL") return o.getElementsByTagName("DT");
}

function assignSubChildren(dtArr){
  var resArr = [];
  for(var i=0;i<dtArr.length;i++){
   var ddArr = [];
   dtArr[i].setAttribute("__index__",String(i))
   var dd = dtArr[i].nextSibling;
   while(dd){
    if(dd.tagName){
     ddArr[ddArr.length] = dd;
    }
    dd = dd.nextSibling;
    if(dd && dd.tagName && dd.tagName=="DT") break;
   }
   resArr[resArr.length] = [String(i),ddArr];
  }
  window.tempNodesArray = resArr;
}

function appendNewChild(newTagId,o){
 if(o.tagName=="LI") document.getElementById(newTagId).appendChild(o);
 else if(o.tagName=="DT"){
  document.getElementById(newTagId).appendChild(o);
 }
}

function appendSubChildren(n,prefix){
 for(var z=1;z<n;z++){
  var dl = document.getElementById(prefix+z);
  var dtChildren = dl.getElementsByTagName("DT");
  for(var v=0;v<dtChildren.length;v++){
   for(var i=0;i<window.tempNodesArray.length;i++){
    if(window.tempNodesArray[i][0]==dtChildren[v].getAttribute("__index__")){
     for(var j=0;j<window.tempNodesArray[i][1].length;j++){
      var cloneDD = window.tempNodesArray[i][1][j].cloneNode(true);
      if(window.tempNodesArray[i][1][j].removeNode) window.tempNodesArray[i][1][j].removeNode(true);
      else if(window.tempNodesArray[i][1][j].parentNode.removeChild) window.tempNodesArray[i][1][j].parentNode.removeChild(window.tempNodesArray[i][1][j]);
      if(dtChildren[v+1]){
       dl.insertBefore(cloneDD,dtChildren[v+1]);
      }else{
       dl.appendChild(cloneDD);
      }
     }
     break;
    }
   }
  }
 }
}

addEvent(window, 'load', makeFloatRight, false);


