window.onload = doen;

// -----------------------------------------------
document.write('<scr' + 'ipt type="text/javascript" src="/uitklapmenu.aspx"></scr' + 'ipt><style>.cmssp{color:white}</style>');
window.highlighter = new SearchTermHighlighter();
var isIE = (navigator.appName.indexOf("Microsoft") != -1)+1-1;
iniFS(); 
var vorigbl = 'xxx';
var hasFlash = hf();

if (hasFlash) {document.write('<style>#video{width:400px;height:320px;margin-bottom:15px;background:#DDD7CC;color:#DDD7CC}</style>');}
if (isIE) {document.write('<style>#zoom{float:left;} #beeldtable{margin-top:-20px}</style>');}

function hf(){
	var nRequiredVersion = 8;
	if(navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Windows") > -1){
		document.write('<script language="VBScript"\> \non error resume next \nhasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & ' + nRequiredVersion + '))) \n</script\> \n');
		if(window.hasFlash != null){
			return window.hasFlash;};
	};
	if(navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
		var flashDescription = (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description;
		var vr = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1)); if (vr < 4) vr += 10;	
		return vr >= nRequiredVersion;
	};
	return false;
}

function doen(){
	
	objBody = document.getElementsByTagName("body").item(0);

	if (eId("video") && hasFlash) {zetVideo(eId('video').title)}
	if (eId("zoom") && hasFlash) {zetZoom(eId('zoom').title)}
	
	if (eId("flash")) {
			srfv = (eId('flash').title + '?').split('?');
			eId('flash').innerHTML = flash(srfv[0], '100%', '100%', '', '', srfv[1]);
	}
	
	if (eId("groeikaart")) {eId('groeikaart').innerHTML = flash('/kaart/groeikaart.swf', 700, 553, '', '', '')}
	
	if (eId("tekst") && !eId("deree")){
		//document.domain="ab-c.nl";
		
		var anchors = eId("tekst").getElementsByTagName('a');
		for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];
			if (anchor.name.indexOf('ref') > 1){
				ref = anchor.name.replace('ref','');
				if (anchor.innerText) {aobj = document.getElementById(ref); anchor.title = aobj.parentNode.innerText;}
				if (anchor.textContent) {aobj = document.anchors[ref];anchor.title = aobj.parentNode.textContent;}
				anchor.onclick = function () {notenaan();}
			}
		}
		var imgs = eId("tekst").getElementsByTagName('img');
			for (var i=0; i<imgs.length; i++){
				var img = imgs[i];
				if(img.title =='') img.title = img.alt;
				if (img.src.indexOf('_zoom') >1){ //zoomify
					zpad = img.src; img.src='/grafiek/info.gif';
					img.parentNode.id = 'zoom2';
					zpad = zpad.replace('/grafiek/info.gif?','');
					zpad = zpad.replace('http://hua.ab-c.nl','');
					zpad = zpad.replace('http://www.hetutrechtsarchief.nl','');
					zpad = zpad.replace('.jpg','');  zpad = zpad.replace('.JPG',''); zpad = zpad.replace('_500/','_zoom/');
					zetZoom2(zpad, img.width, img.height)}
			}
		//itjes in formulierlabels zetten
		var labels = eId("tekst").getElementsByTagName('label');
		for (var i=0; i<labels.length; i++){
				var label = labels[i];
				if (label.title && label.getElementsByTagName('span')){
					label.innerHTML += ' <a class="itje" href="javascript:dialoog(\'' + label.getElementsByTagName('span')[0].innerHTML + '\')" onclick="zetInfo(this.parentNode.title)">&nbsp;</a>'
				}
		}

		if (!eId('reeres')){
			socdiv = document.createElement("div"); socdiv.id='alg';
			socdiv.innerHTML = sociaal();
			eId('tekst').appendChild(socdiv);
		}

	} //einde if eID(tekst)
	
	if (window.uitklapsDiv){
		uitklapsWaas = document.createElement("div"); uitklapsWaas.id='uitklapsWaas'; uitklapsWaas.onmouseover = klapin;
		objBody.appendChild(uitklapsWaas); objBody.appendChild(uitklapsDiv);
		for (var i=1; i<8; i++){eId('m'+i).onmouseover = new Function("klapuit(" + i + ")");}
	}
	// handschriften
	if (eId("weergavekeuze")) {verberg(readCookie('verberg'))}
	

	
	//iframe voor formulier
	if (eId('postform')){
		objIframe = document.createElement("div");
		objIframe.innerHTML='<iframe name="posttarget" style="visibility:hidden" width="0" height="0"></iframe>';
		objBody.appendChild(objIframe);
	}


	//eindekolom();
	if (eId('gezochtop')) {highlighter.highlight()}
}

function bb(){if (hasFlash) document.write('<script>//')}
function eb(){if (hasFlash) document.write('</script'  + '>')}

function zetInfo(str){window.infotekst = str + ' '; }

function hl(id){
	if (eId(vorigbl)){
		eId(vorigbl).firstChild.style.backgroundColor='#eae4da';
		eId(vorigbl).firstChild.style.color='#7E6666';
	}
	if (eId(id)){
		eId(id).firstChild.style.backgroundColor='#e4e2ee';
		eId(id).firstChild.style.color='#494370';
		vorigbl = id;
	}
}

function eindekolom(){
	//archiefbank
	if (location.toString().indexOf('/archiefbank/') > 0){
		eId('kolomkop').innerHTML  = 'Archiefbank &nbsp;<a href="/collectie/archiefbank/over-de-archiefbank/snel-op-weg"><img src="/grafiek/vraagteken.gif" border="0" alt="?" /></a>';
	}

	if (eId('bovenin')){
		terugul = document.createElement("ul");
		terugul.innerHTML = '<li><a href="javascript:history.back()">terug naar vorige pagina</a></li>';
		eId('terugplek').appendChild(terugul);
	}

	//reactielink
	if (document.body.className != 'home'){
		reactiediv = document.createElement("div"); reactiediv.id='reageren';
		pad = window.location.pathname.substr(1);
		adreslijst = 'genealogie;communicatie;bibliotheek;beeldmateriaal;webmaster;fotodienst;vacature;vrienden;educatie;webwinkel';
		adr = adreslijst.split(';'); aan = '';
		for (var i=0; i<adr.length; i++){if ((pad + '/').indexOf(adr[i] + '/') > -1){aan=adr[i]}}
		if (aan=='genealogie') {aan='genlias'};if (aan=='akten') {aan='notaris'};

		reactiediv.innerHTML = 'Reageren<ul><li><a href="/contact/reactieformulier?onderwerp=' + escape(pad) + '&aan=' + aan + '">contact over deze pagina</a></li></ul>';
		eId('kolom').appendChild(reactiediv);
	}

}


function dialoog(tit) {
   var objLink = document.createElement('a'); objLink.title=tit;
   objLink.setAttribute('href','/scripts/info.htm'); objLink.setAttribute('rel','lyteframe');
   objLink.setAttribute('rev','width:300px;height:200px;')
   myLytebox.start(objLink, false, true);
}

function reageer(par, subj){
	if (eId('postform')){
		eId('postform').onderwerp.value = subj;
		eId('postform').cf_Parent.value = par;}
}

function klapuit(nr){
	for (var i=1; i<8; i++){eId('uitklap' + i).style.display='none';}
	eId('uitklapsWaas').style.display='block';
	eId('uitklap' + nr).style.left = eId("m" + nr).offsetLeft + 'px';
	eId('uitklap' + nr).style.display='block';
}

function klapin(){
	eId('uitklapsWaas').style.display='none';
	for (var i=1; i<8; i++){eId('uitklap' + i).style.display='none';}
}


function gazoek(){
	eId('zoekform').target='_top';
	eId('zoekform').action = '/zoeken/';
	if (eId('m')) {eId('m').checked=false;}
	if (eId('s').value=='kaart') {
			eId('zoekform').action = '/kaart/';
			if (eId('isKaart')) {eId('m').checked=true;eId('zoekform').target='kaart_rechts'}
	}
}

function minmax2(){window.parent.minmax();}


function zetZoom2(welke, w, h){
		zoomHtml = flash("/grafiek/swf/zoom.swf", w+28, h, "#DDD7CC", '', "pad=" + welke + "&opsl=" + welke.replace('_zoom','_500') + ".jpg&Klaar=1");
		//bladeren???
		matches = welke.match(/(.*?)(\d+)van(\d+)/);
		if (matches){;
			zoomHtml += '<span id="nummertjes" class="zoomnrs">Pagina\'s: ';
			for (var z=1; z <= parseFloat(matches[3]); z++){
				if (z == parseFloat(matches[2])) {cl = 'class="navsel"'} else {cl = ''}
				zoomHtml += '<a ' + cl + ' href="javascript:zetZoom2(\'' + matches[1] + z + 'van' + matches[3] + '\',' + w + ',' + h + ')">' + z + '</a> ';}
			zoomHtml += '</span>';
		}
		
		eId('zoom2').innerHTML = zoomHtml;
}

function zetZoom(welke){
	eId('zoom').innerHTML= flash("/grafiek/swf/zoom.swf", '100%', '100%', "#DDD7CC", '', "pad=" + welke + "&opsl=" + welke.replace('_zoom','_500') + ".jpg&Klaar=1")
}

function checkmail(w){
	if (w=='' || w.indexOf('.') < 1 || w.indexOf('@') < 2) {alert('Vul a.u.b. een geldig e-mailadres in.'); return false}
	else {return true}
}

function ww_plusmin(welke, hoeveel){
	eval('w = document.winkelwagen.' + welke);
	n = 1;
	n = parseInt(w.value) + hoeveel;
	if (n < 0) n=0;
	w.value = n;
	ww_update(w);
}

function ww_update(welke){
	var subm = true;
	if (welke.value=="0") {subm = confirm("Wilt u dit item verwijderen?");}
	if (subm) document.winkelwagen.submit();
}

function zetVideo(welke){
	
	if (isNaN(parseInt(welke))){
		img = '/beeld/video/' + welke + '.flv.jpg';}
	else {
		img = '/beeld/atlantis/' + welke.substring(welke.length-3) + '/_400/' + welke + '.jpg';}
	
	if (hasFlash){
		var ht;
		
		var xtra = '';

		flashv = 'width=400&screencolor=#DDD7CC';
		
		if (welke.indexOf('.xml') > 1) {
				ht = 650;
				xtra = '<div id="klikwmv"></div>';
				flashv += '&file=/beeld/video/' + welke + '&height=650&thumbsinplaylist=true&showdownload=true&linktarget=_self&shuffle=false&repeat=list&displayheight=240';
		} else {
			ht = 320;
			flashv += '&type=flv&file=/beeld/video/' + welke + '.flv&height=320&image=' + img;
		}
		
		document.getElementById('video').innerHTML= xtra + flash('/grafiek/swf/mediaplayer.swf', 400, ht, '', '', flashv);
		document.getElementById('video').style.height = ht + 'px';
		document.getElementById('video').title = '';
		
	} else {
		document.getElementById('video').innerHTML='Flash 8 of hoger benodigd om video te bekijken.'}
}
	
function notenaan(){document.getElementById('tekst').className='notenaan'}

function verberg(welke){
	var divs = eId("tekst").getElementsByTagName('div');
	for (var i=0; i<divs.length; i++){divs[i].style.display='block';}
	
	if (eId("weergavekeuze")) {var lnks = eId("weergavekeuze").getElementsByTagName('a');
	for (var i=0; i<lnks.length; i++){lnks[i].className='';}}
	
	if (welke != '') document.getElementById(welke).style.display="none";
	document.getElementById("verberglink_" + welke).className="sellink";
	createCookie("verberg", welke)
}

function zet(str){document.write(str);}

function doeMizigtabs(){
    if (eId('mizigtabs')){
	var tbl = eId("deree_zoekingang").getElementsByTagName('table')[0];
	eId("mizigtabs").style.top = (getY(tbl) + 1) +'px';
	eId("mizigtabs").style.marginTop = '-' + eId('mizigtabs').offsetHeight + 'px';
	var as = eId("mizigtabs").getElementsByTagName('a');
	for (var i=1; i<as.length; i++){
		if (as[i].href.indexOf(location.search.replace('?','')) > 1) {as[i].className='sel'; as[0].className=''}
	}
    }
}

function getY( oElement ){
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}


function minmax(){
	if (document.body.className=='bodymax'){
		document.body.className = "";
	} else {
		document.body.className = "bodymax";
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return '';
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function zet(str){document.write(str);}

function flash(movie, w, h, bg, wm, flashvars){
	id = '';
	if (movie.indexOf('mediaplayer') > 1) id = 'devideo';
	if (movie.indexOf('plattegrond') > 1) id = 'plattegrond'; 
	if (isIE){
		return '<object id="' + id + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+ w + '" height="' + h + '"><param name="movie" value="' + movie + '" /><param name="FlashVars" value="ie=1&' + flashvars + '" /><param name="quality" value="high" /><param name="menu" value="true" /><param name="wmode" value="' + wm + '" /><param name="bgcolor" value="' + bg + '" /><param name="allowScriptAccess" value="sameDomain" /><param name="allowfullscreen" value="true" /></object>';
	} else {
		return '<embed id="' + id + '" src="' + movie + '" quality="high" wmode="' + wm + '" bgcolor="' + bg + '" menu="true" width="'+ w + '" height="'+ h + '" FlashVars="' + flashvars + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer allowfullscreen="true"" />';}
}


function iniFS(){
	if (isIE) {document.write('<scr' + 'ipt FOR="plattegrond" EVENT="FSCommand" LANGUAGE="Jscript">hl(arguments[1]);</scr' + 'ipt>');}
}




var url = window.document.location.toString();
var title = window.document.title;

function fav(){
	if (isIE) {window.external.AddFavorite(url,title)} else {alert('Sleep het aangeklikte icoontje naar de bookmark-balk van uw browser!')}
}

function sociaal(){
	title = window.document.title;
	var r = '';
	var favtit = "voeg toe aan favorieten"; if (!isIE) favtit = "sleep naar bookmarks";
	r += '<a href="mailto:?subject=' + escape(title) + '&amp;body=' + escape(url) + '" id="mail" title="doorsturen per e-mail"></a>';
	r += '<a href="' + url + '" onclick="fav(); return false;" id="fav" title="' + favtit + '"><span>' + title + '</span>&nbsp;&nbsp;&nbsp;&nbsp;</a>';
	r += '<a target="_blank" href="http://www.delicious.com/post?url=' + escape(url) + '&title=' + escape(title) + '" title="Delicious"></a>';
	r += '<a target="_blank" href="http://twitter.com/home?status=' + escape(title + ' ' + url.replace('www.','')) + '" title="Twitter"></a>';				
	r += '<a target="_blank" href="http://www.hyves.nl/profilemanage/add/tips/?name=' + escape(title) + '&text=' + escape(url) + '&type=12" title="Hyves"></a>';		
	r += '<a target="_blank" href="http://www.google.com/buzz/post?url=' + escape(url) + '" title="Google Buzz"></a>';
	r += '<a target="_blank" href="http://favorites.live.com/quickAdd.aspx?url=' + escape(url) + '&title=' + escape(title) + '" title="Msn/Live Favorite"></a>';				
	return r;
}





function eId(w){return document.getElementById(w);}

function SearchTermHighlighter(){

	var ok = ((document.createElement) ? true : false);
	var searchTerms = new Array();
	var foundCount = 0;
	this.init = init;
	this.highlight = highlight;
	this.highlightTerm = highlightTerm;
	
	if (!ok) return;

	function init(){
		var termenlijst = document.getElementById('gezochtop').innerHTML.split(' ');
		var index = 0;
		for (j = 0; j < termenlijst.length; j++){
				if (termenlijst[j] != '' && termenlijst[j].length > 2){searchTerms.push(new SearchTerm(index++, termenlijst[j].toLowerCase()));}
		}
	}

	function highlight(){
		highlighter.init();
		searchTerms.sort(function(term1, term2){return(term2.term.length-term1.term.length)});
		var welkeparent;
		if (eId('zoekres')) {welkeparent = eId('zoekres')} else {welkeparent = eId('tekst')}
		for (var i = 0; i < searchTerms.length; i++){
			this.highlightTerm(welkeparent, searchTerms[i]);
		}
	}
	
	function highlightTerm(node, term){
		if (node.nodeType == 1){
			if (node.getAttribute("sth_x") == term.term) return;
			else node.setAttribute("sth_x", term.term);
		}
		if (node.hasChildNodes()){
			for (var i = 0; i < node.childNodes.length; i++) {
				this.highlightTerm(node.childNodes[i], term);
			}
		}

		if (node.nodeType == 3){
			var p = node.parentNode;
			if (p.nodeName != 'TEXTAREA' && p.nodeName != 'SCRIPT' && p.className.substr(0, term.CSS_CLASS_PREFIX.length) != term.CSS_CLASS_PREFIX){
				var result = term.pattern.exec(node.nodeValue);
				if (result != null){
					term.found = true;
					foundCount++;
					var v = node.nodeValue;
					var lt = document.createTextNode(v.substr(0, result.index));
					var rt = document.createTextNode(v.substr(result.index + result[0].length));
					var span = document.createElement('SPAN');
					span.className = term.cssClass;
					span.appendChild(document.createTextNode(result[0]));
					p.insertBefore(lt, node);
					p.insertBefore(span, node);
					p.replaceChild(rt, node);
				}
			}
		}
	}
	
	function SearchTerm(index, term){
		this.CSS_CLASS_PREFIX = 'sth_';
		this.index = index;
		this.term = term.toLowerCase();
		this.cssClass = this.CSS_CLASS_PREFIX + 'markeer';
		this.pattern = new RegExp('\\b' + this.term + '\\b', 'i');
		this.found = false;
		this.toString = function(){return this.term};
	}

}