var periodeVan;
var periodeTot;

var wistudat     = new Array;
var currWistudat = 0;
var statWistudat = false;

function pageLoaded(page) {
	if (top.location.href != self.location.href) {
		top.location.href = self.location.href;
		return false;
	}
	
//	resizeScreen();
	
	document.getElementById('infoFrame').src = page;
}

function resizeScreen() {
	window.moveTo 	(0,0);
	window.resizeTo (screen.availWidth, screen.availHeight);

/*
//	for testing:
	if (screen.availWidth > 1024) {
		window.moveTo  ((screen.availWidth - 1024)/2 ,(screen.availHeight - 735)/2);
		window.resizeTo(1024, 735);
	}
*/
}

function selectPeriode(van, tot) {
	periodeVan = van;
	periodeTot = tot;

	markPeriode(periodeTot);
	pageLoaded("php/maps.php?periodeVan=" + periodeVan + "&periodeTot=" + periodeTot);	
}

function showLegenda() {
	markPeriode("legenda");
	document.getElementById('legenda').style.visibility = "visible";
}

function hideLegenda() {
	markPeriode(periodeTot);
	document.getElementById('legenda').style.visibility = "hidden";
}

function markPeriode(periode) {
	for (var i=1800; i<=2000; i+=50) {
		if (parseInt(periode) == i) {
			document.getElementById('periode-' + i).style.color = "#FF8010";
		} else {
			document.getElementById('periode-' + i).style.color = "white";
		}
	}
	
	if (periode == "legenda") {
		document.getElementById('legendaLink').style.color = "#FF8010";
	} else {
		document.getElementById('legendaLink').style.color = "white";
	}	
}

function validateSearch() {
	validChar  = /[a-z]|[0-9]|[-]/i;
	searchText = document.getElementById('searchText').value;

	if (searchText.search(validChar) != -1) {
		document.getElementById('searchForm').target = "infoFrame";
		document.getElementById('searchForm').method = "get";
		document.getElementById('searchForm').action = "php/search.php";
		document.getElementById('searchForm').submit();
	} else {
		alert("U kunt alleen zoeken op (alfa)numerieke tekens...");
		return false;
	}
}

function showSearch() {
	document.getElementById('searchDiv').style.visibility = "visible";
	selectSearch();
}

function hideSearch() {
	document.getElementById('searchDiv').style.visibility = "hidden";
}

function selectSearch() {
	document.getElementById('searchText').select();
}

function startWistudat() {
	if (!statWistudat) {
		showWistudat();
		wistudatInterval = window.setInterval('showWistudat()', 7500);
		statWistudat = true;
	}
}

function showWistudat() {
	top.document.getElementById("wistudat").innerHTML = wistudat[currWistudat];
	
	if (currWistudat < wistudat.length-1) {
		currWistudat += 1
	} else {
		currWistudat = 0
	}
}

function toggleDisplay(id, imgId) {
	if (document.getElementById(id).style.display != 'block') {
		document.getElementById(id).style.display = 'block'
		if (imgId != "") {
			document.getElementById(imgId).src = "../images/min.gif";
		}
	} else {
		document.getElementById(id).style.display = 'none'
		if (imgId != "") {
			document.getElementById(imgId).src = "../images/plus.gif";
		}
	}
}

function addFields(fieldType, col_1, col_2) {
	var tableCode = "";
	var fieldNr   = "";
	var aantal    = parseInt(document.getElementById(fieldType + "Nr").value) + 1;
	
	document.getElementById(fieldType + "Nr").value = aantal;
	
	if (fieldType == "adressen") {
		tableCode = '<table border="0" cellpadding="0" cellspacing="0">';
		tableCode += '<tr><td class="fieldTitle"></td><td class="relatieHeader">&nbsp;</td><td width="25"></td><td class="relatieHeader"></td></tr>';
		tableCode += '<tr><td>Gewoond van - tot</td><td><input type="text" name="vanTotdat_5a_' + aantal + '" id="vanTotdat_5a_' + aantal + '" value=""></td></tr>';
		tableCode += '<tr><td>Adres</td><td><input type="text" name="adres_5a_' + aantal + '" id="adres_5a_' + aantal + '" value=""></td></tr>';
		tableCode += '<tr><td>Postcode</td><td><input type="text" name="postcode_5a_' + aantal + '" id="postcode_5a_' + aantal + '" value=""></td></tr>';
		tableCode += '<tr><td>Kadastrale gegevens</td><td><input type="text" name="kadastraal_5a_' + aantal + '" id="kadastraal_5a_' + aantal + '" value=""></td></tr>';
		tableCode += '<tr><td>Functie van het pand</td><td><input type="text" name="functie_5a_' + aantal + '" id="functie_5a_' + aantal + '" value=""></td></tr>';
		tableCode += '<tr><td>Beschrijving</td><td><input type="text" name="beschrijving_5a_' + aantal + '" id="beschrijving_5a_' + aantal + '" value=""></td></tr>';
		tableCode += '<tr><td>Nieuwbouwdatum</td><td><input type="text" name="nieuwdat_5a_' + aantal + '" id="nieuwdat_5a_' + aantal + '" value=""></td></tr>';
		tableCode += '<tr><td>Herbouwdatum</td><td><input type="text" name="herbouwdat_5a_' + aantal + '" id="herbouwdat_5a_' + aantal + '" value=""></td></tr>';
		tableCode += '<tr><td>Sloopdatum</td><td><input type="text" name="sloopdat_5a_' + aantal + '" id="sloopdat_5a_' + aantal + '" value=""></td></tr>';
		tableCode += '</table>';
	} else {
		if (fieldType == "kinderen") {
			fieldNr = "4";
		} else {
			fieldNr = "3";
		}
		
		tableCode =  '<table border="0" cellpadding="0" cellspacing="0">';
		tableCode += '<tr><td class="fieldTitle"></td><td class="relatieHeader">' + col_1 + '</td><td width="25"></td><td class="relatieHeader">' + col_2 + '</td></tr>';
		tableCode += '<tr><td>Familienaam</td><td><input type="text" name="familienaam_' + fieldNr + 'a_' + aantal + '" id="familienaam_' + fieldNr + 'a_' + aantal + '" value=""></td><td></td><td><input type="text" name="familienaam_' + fieldNr + 'b_' + aantal + '" id="familienaam_' + fieldNr + 'b_' + aantal + '" value=""></td></tr>';
		tableCode += '<tr><td>Voorletters</td><td><input type="text" name="voorletters_' + fieldNr + 'a_' + aantal + '" id="voorletters_' + fieldNr + 'a_' + aantal + '" value=""></td><td></td><td><input type="text" name="voorletters_' + fieldNr + 'b_' + aantal + '" id="voorletters_' + fieldNr + 'b_' + aantal + '" value=""></td></tr>';
		tableCode += '<tr><td>Doopnamen</td><td><input type="text" name="doopnamen_' + fieldNr + 'a_' + aantal + '" id="doopnamen_' + fieldNr + 'a_' + aantal + '" value=""></td><td></td><td><input type="text" name="doopnamen_' + fieldNr + 'b_' + aantal + '" id="doopnamen_' + fieldNr + 'b_' + aantal + '" value=""></td></tr>';
		tableCode += '<tr><td>Roepnaam</td><td><input type="text" name="roepnaam_' + fieldNr + 'a_' + aantal + '" id="roepnaam_' + fieldNr + 'a_' + aantal + '" value=""></td><td></td><td><input type="text" name="roepnaam_' + fieldNr + 'b_' + aantal + '" id="roepnaam_' + fieldNr + 'b_' + aantal + '" value=""></td></tr>';
		tableCode += '<tr><td>Bijnaam</td><td><input type="text" name="bijnaam_' + fieldNr + 'a_' + aantal + '" id="bijnaam_' + fieldNr + 'a_' + aantal + '" value=""></td><td></td><td><input type="text" name="bijnaam_' + fieldNr + 'b_' + aantal + '" id="bijnaam_' + fieldNr + 'b_' + aantal + '" value=""></td></tr>';
		tableCode += '<tr><td>Beroep</td><td><input type="text" name="beroep_' + fieldNr + 'a_' + aantal + '" id="beroep_' + fieldNr + 'a_' + aantal + '" value=""></td><td></td><td><input type="text" name="beroep_' + fieldNr + 'b_' + aantal + '" id="beroep_' + fieldNr + 'b_' + aantal + '" value=""></td></tr>';
		tableCode += '<tr><td>Geboortedatum</td><td><input type="text" name="gebdat_' + fieldNr + 'a_' + aantal + '" id="gebdat_' + fieldNr + 'a_' + aantal + '" value=""></td><td></td><td><input type="text" name="gebdat_' + fieldNr + 'b_' + aantal + '" id="gebdat_' + fieldNr + 'b_' + aantal + '" value=""></td></tr>';
		tableCode += '<tr><td>Overlijdensdatum<br><span style="font-size:10px;">(indien van toepassing)</span></td><td valign="top"><input type="text" name="overdat_' + fieldNr + 'a_' + aantal + '" id="overdat_' + fieldNr + 'a_' + aantal + '" value=""></td><td></td><td valign="top"><input type="text" name="overdat_' + fieldNr + 'b_' + aantal + '" id="overdat_' + fieldNr + 'b_' + aantal + '" value=""></td></tr>';
		tableCode += '</table>';
	}

	document.getElementById(fieldType).innerHTML += tableCode;
}


