var currentlyr = "";
var currentli = "";
var currentnr = "";
var defaultwhich = "introduction";

function showTab(nr,which) {

	if(!currentlyr) { 
		currentlyr = nr + "_" + defaultwhich;
	}
	if(!currentli) {
		currentli = "li_" + nr + "_" + defaultwhich;	
	}	
	if(!currentnr) {
		currentnr = nr;	
	}

	lyr = nr + "_" + which;
	li = "li_" + lyr;

	if(nr==currentnr) {
		document.getElementById(currentlyr).style.display = "none";
		//document.getElementById(currentli).style.borderBottomColor = "#006600";
		document.getElementById(currentli).className = "tabnotselected";
	}
	else if(nr!=currentnr) {
		// Indien een tabblad van een ander huis wordt aangeklikt
		
		
		document.getElementById(currentlyr).style.display = "none";
		document.getElementById(currentnr + "_" + defaultwhich).style.display = "";
		document.getElementById(currentli).className = "tabnotselected";
		if(which!=defaultwhich) {	
			document.getElementById("li_" + nr + "_" + defaultwhich).className = "tabnotselected";
			document.getElementById(nr + "_" + defaultwhich).style.display = "none";		
		}
		document.getElementById("li_" + currentnr + "_" + defaultwhich).className = "tabselected";
	}
	document.getElementById(lyr).style.display = "";
	document.getElementById(li).className = "tabselected";
	//document.getElementById(li).style.borderBottomColor = "#FFFFFF";
	//document.getElementById(li).style.backgroundColor = "#FFFFFF";	

	currentlyr = lyr;
	currentli = li;	
	currentnr = nr;
}

function showRegionText(which,rtxt) {
	
	var dat=new Array();
	dat["welke"]=which;
	document.getElementById(which).innerHTML="...";
	xmlophalen( "/gm.php?id="+rtxt, 'test',callbackDetails,dat );
}

function callbackDetails(response,data) {
	which=data["welke"];
	if(document.getElementById(which)) {
		//document.getElementById(which).innerHTML = rtxt;
		aantal=response.getElementsByTagName("data").length;
		if(aantal>0) {
			rtxt=response.getElementsByTagName("data")[0].childNodes.item(0).nodeValue;
			document.getElementById(which).innerHTML = rtxt;
		}
	}
}

function check_Form(formulier, fields, description) {
	d = document.forms [formulier];
	var errors = "";
	
	for (i=0;i<fields.length;i++){ 
		data_field = fields[i];
		if(d [data_field].length && d [data_field].type!="select-one") { // radio or checkbox and no select?
			array_errors = true;
			for (y=0;y<d [data_field].length;y++) { // get options
				if(d [data_field][y].checked == true) {
					array_errors = false;
				}
			}
			if(array_errors != false){
				errors += "- "+description[i]+"\n";
			}
		}		
		else if(d [data_field].type=="checkbox"){
			if(d [data_field].checked == false){
				errors += "- "+description[i]+"\n";
			}
		}
		else {
			if(d [data_field].value == "") {
				errors += "- "+description[i]+"\n";
			}
		}
	}
	if(errors) {
		alert("De volgende veld(en) zijn nog niet ingevuld:\n"+errors);
		return false;
	}
	else {
		return true;
	}

}
function doAndersNamelijk(val) {

	if(val=="Advertentie in het blad" || val=="Anders") {
		document.getElementById('andersNamelijk').style.display = "block";
	}
	else {
		document.getElementById('andersNamelijk').style.display = "none";
	}
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		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;
	if (self.innerHeight) {	// all except Explorer
		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;
	}

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


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

function getPageScroll(){
	
	var yScroll;

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

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
function showAvail(url, huisid, typeid, title, regio) {
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var lightboxTop = arrayPageScroll[1]+((arrayPageSize[3]-500)/2);
	document.getElementById('availpopuptekst2').style.marginTop = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
	if(arrayPageSize[1]>arrayPageSize[3]) {
		document.getElementById('availpopup').style.height = (arrayPageSize[1] + 'px');
	} else {
		document.getElementById('availpopup').style.height = (arrayPageSize[3] + 'px');
	}	
	
	document.getElementById('Titel').innerHTML = title;

	//document.getElementById('popupLink').innerHTML = "<a href=\"javascript:void(0);\" class=\"green\" onclick=\"document.getElementById('popuplegenda').style.visibility = 'hidden';document.getElementById('AvailPopupIframe').src = 'avail.php?action=showForm&title=" + title + "&huisid=" + huisid + "&regio=" + regio + "';\">Reserveer online</a>";	
	//document.getElementById('popupLink2').innerHTML = "<a href=\"javascript:void(0);\" class=\"white\" onclick=\"document.getElementById('popuplegenda').style.visibility = 'hidden';document.getElementById('AvailPopupIframe').src = 'beschikbaarheid.php?title=" + title + "&huisid=" + huisid + "&regio=" + regio + "';\">Aanvraag beschikbaarheid</a>";	
	//document.getElementById('popupLink3').innerHTML = "<a href=\"javascript:void(0);\" class=\"red\" onclick=\"document.getElementById('popuplegenda').style.visibility = 'hidden';document.getElementById('AvailPopupIframe').src = 'zoekopdracht.php?title=" + title + "&huisid=" + huisid + "&regio=" + regio + "';\">Vraag alternatief op</a>";	
	document.getElementById('AvailPopupIframe').src = url;	
	document.getElementById('availpopup').style.display = "block";
}
function hideAvail() {
	window.top.document.getElementById('AvailPopupIframe').src = 'laden.php';
	window.top.document.getElementById('availpopup').style.display='none';
	//document.getElementById('popupLink').innerHTML = '';
}
function changePopupLink(url,title) {
	window.top.document.getElementById('popupLink').innerHTML = "<a href=\"javascript:void(0);\" onclick=\"document.getElementById('AvailPopupIframe').src = '" + url + "';\">" + title + "</a>";		
}
