function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function district () {
	var lstClubMap = document.getElementById("districtClubmap");
	if(lstClubMap) {
		var ClubMapAs = lstClubMap.getElementsByTagName("a");
		for(var i=0; i<ClubMapAs.length; i++) {
			if(ClubMapAs[i].className=="pin") {
				ClubMapAs[i].onclick = function () { 
					//alle clubs sluiten
					for(var j=0; j<ClubMapAs.length; j++){
						if(ClubMapAs[j].className=="pin") {
							changeClubDisplay("",ClubMapAs[j].id.replace("pin",""));
						}
					}
					//club openen
					changeClubDisplay("visible",this.id.replace("pin","")); 
					return false; 
				}
				ClubMapAs[i].onmouseover = ClubMapAs[i].onclick;
			}
			if(ClubMapAs[i].className=="close") {
				ClubMapAs[i].onclick = function () { 
					//1 club sluiten
					changeClubDisplay("",this.id.replace("close","")); 
					return false; 
				}
			}
		}
		var lstDistrictList = document.getElementById("districtList");
		if(lstDistrictList) {
			var Clubs = lstDistrictList.getElementsByTagName("a");
			for(var i=0; i<Clubs.length; i++) {
				Clubs[i].onmouseover = function () { 
					//alle clubs sluiten
					for(var j=0; j<ClubMapAs.length; j++){
						if(ClubMapAs[j].className=="pin") {
							changeClubDisplay("",ClubMapAs[j].id.replace("pin",""));
						}
					}
					//club openen
					changeClubDisplay("visible",this.id.replace("link","")); 
				}
				/*
				Clubs[i].onmouseout = function () { 
					//club sluiten
					changeClubDisplay("",this.id.replace("link","")); 
				}
				*/
			}
		}
	}
}
function changeClubDisplay(className,id) {
	var club = document.getElementById("club"+id);
	if(club) { club.className = className; }
}


function removeActiveThums() {
	var ul = document.getElementById("fotos");
	if (ul) {
		var list = ul.getElementsByTagName("li");
		for (var i=0;i<list.length;i++) {
			list[i].className=list[i].className.replace(new RegExp(" active\\b"), "");
		}
	}
}

function doThumbs() {
	var thumbs =  document.getElementById("thumbs");
	var fotos =  document.getElementById("fotos");
	if (thumbs && fotos) {
		var list = thumbs.getElementsByTagName("a");
		var type = fotos.className;
		for (var i=0;i<list.length;i++) {
			if(list[i].parentNode.tagName == "LI") {
				list[i].onclick = function() {
					removeActiveThums();
					this.parentNode.className+=" active";
					var img = this.getElementsByTagName("img");
					if (img) {
						var bigpic = document.getElementById("bigPicture");
						var divCaption = document.getElementById("caption");
						if(bigpic) {
							if(type=="multi") {
								bigpic.src = img[0].src.replace("thumbs/","");
							}else{
								bigpic.src = img[0].src.replace("th_","");
							}
							bigpic.alt = this.title;
							divCaption.innerHTML = this.title;
						}
					}
					return false;
				}
			}	
		}
	}
}

function search() {
	var btn = document.getElementById("ZoekButton");
	if (btn) {
		btn.onclick = function() {
			document.formZoek.submit();
		}
	}
	var btn2 = document.getElementById("ZoekClubButton");
	if (btn2) {
		btn2.onclick = function() {
			if (document.formZoekClub.this_action.value != "") {
				document.formZoekClub.action = document.formZoekClub.this_action.value;
				document.formZoekClub.submit();
			}	
			else {
				alert("Geef een club in om verder te gaan.");
			}
		}
	}
	var txt1 = document.getElementById("clubnaam");
	if (txt1) {
		txt1.onclick = function() {
			this.value = "";
		}
		txt1.onblur = function() {
			if (this.value == "") {
				this.value = this.title;
			}
		}
	}
	var txt2 = document.getElementById("trefwoord");
	if (txt2) {
		txt2.onclick = function() {
			this.value = "";
		}
		txt2.onblur = function() {
			if (this.value == "") {
				this.value = this.title;
			}
		}
	}
}


function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
	  // Internet Explorer
	  try {
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	  catch (e) {
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	}
	return xmlHttp;
}

function addClub(id, naam) {
	var theForm = document.agendaform;
	var newIndex = theForm.clubSelection.options.length;
	theForm.clubSelection.options[newIndex]= new Option(naam, id,false,false);
}

function ClubAgendaSearched() {
	var theForm = document.agendaform;
	while (theForm.clubSelection.options.length > 1) {
		theForm.clubSelection.options[(theForm.clubSelection.options.length - 1)] = null;
	}
	theForm.clubSelection.options[0]= new Option("", "", true, true);
 	var splitter;
	if (xmlHttp4.readyState == 4) {
		var lines = xmlHttp4.responseText.split("\n");
		for(i=0; i < lines.length - 1; i++) {
			splitter = lines[i].split("|");
			addClub(splitter[0], splitter[1]);
		}
   }
}

var xmlHttp4;
function searchClubAgenda(startingAt,str,lang) {
	xmlHttp4=GetXmlHttpObject();
	if (xmlHttp4==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	if (xmlHttp4.readyState == 4 || xmlHttp4.readyState == 0) {
		if(str.length >= startingAt) {
			xmlHttp4.onreadystatechange = ClubAgendaSearched; 
			xmlHttp4.open("GET", "/inc/searchClubAgenda.dhtml?str=" + str  + ",content_language=" + lang , true);
			xmlHttp4.send(null);
		}
	}		
}

function Agenda() {
	var selD = document.getElementById("districtSelection");
	if (selD) {
		selD.onchange = function() {
			searchClubAgenda(0,this.value,document.agendaform.this_lang.value);
		}
	}	
	var frm = document.getElementById("agendaform");
	if (frm) {
		frm.onsubmit = function() {
			if (this.districtSelection.value != "") {
				this.action = this.districtSelection.value;
			}
			if (this.clubSelection.value != "") {
				this.action = this.clubSelection.value;
			}
			this.submit();
		}
	}
}

function getDocument(theFrame)	{
	if (theFrame.contentDocument) {
		// For NS6
		return theFrame.contentDocument;
	}
	else if (theFrame.contentWindow) {
		// For IE5.5 and IE6
		return theFrame.contentWindow.document;
	}
	else if (theFrame.document)	{
		// For IE5
		return theFrame.document;
	}
	else {
		return 0;
	}
}


function ikalender(yearfield, monthfield, dayfield, formulier, year, month) {
	aDoc = getDocument(document.getElementById("smallkalender"));
	if (aDoc) {
		aDoc.location.replace("/kalender.dhtml?yearfield="+yearfield+",monthfield="+monthfield+",dayfield="+dayfield+",year="+year+",month="+month+",formulier="+formulier);
	}
}	

function doSupervisor() {
	var txt1 = document.getElementById("supervisorname");
	if (txt1) {
		txt1.onkeyup = function() {
			var str = this.value;
			if(str.length >= 3) {
			 	searchSupervisor(1,this.value);
			 }	
		}
	}
}

function ticker() {
	shufobj = document.getElementById("banner"+banner1);
	shufobj2 = document.getElementById("banner"+banner2);
	shufobj.style.top = (parseInt(shufobj.style.top) + 2) + "px";
	if (parseInt(shufobj.style.top) > document.getElementById("banner1").offsetHeight) {
		shufobj.style.zIndex = 0;
		shufobj.style.top = "0";
		for (i=1;i<=banner_tot;i++) {
			document.getElementById("banner"+i).style.zIndex = document.getElementById("banner"+i).style.zIndex + 1;
		}
		banner1 = banner1 + 1
		banner2 = banner2 + 1
		if (banner2 > banner_tot) banner2=1;
		if (banner1 > banner_tot) banner1=1;
		setTimeout("ticker()",3600);
	}
	else {
		setTimeout("ticker()",6);
	}	
}
	
function banners() {
	for (i=1;i<=banner_tot;i++) {
		document.getElementById("banner"+i).style.top = "0";
	}
	var ban1 = document.getElementById("banner1");
	var ban2 = document.getElementById("banner2");
	if (ban1 && ban2) {
		setTimeout("ticker()",3600);
	}
}

addLoadEvent(banners);
addLoadEvent(Agenda);
addLoadEvent(search);
addLoadEvent(doThumbs);
addLoadEvent(district);