var clrTM;
var ___cmCurrentItem;

function xajax_processContactFormulier() {
	xajax.call("processContactFormulier",arguments,1);
}

function controlScrollbars() {
	var h = document.getElementById('htmlelem');
	if (window.showModalDialog) {
		var t = document.getElementById('mainTable');
		if ((h.offsetWidth > t.offsetWidth) && (h.offsetHeight > t.offsetHeight)) {
			h.style.overflow = 'hidden';
		} else {
			h.style.overflowX = (h.offsetWidth > t.offsetWidth) ? 'hidden' : 'auto';
			h.style.overflowY = (h.offsetHeight > t.offsetHeight) ? 'hidden' : 'auto';
		}
	} else {
		h.style.height=document.body.clientHeight+"px";
	}
}


function setcombovalues(frm) {
	var cb = frm.getElementsByTagName('SELECT');
	var i;
	var x;
	var v;
	var o;
	var mu;
	var y;
	for (i=0;i<cb.length;i++) {
		v = cb[i].getAttribute('v');
		//mu = cb[i].getAttibute('multiple');
		mu = cb[i].multiple;
		va = v.split('|');
		o = cb[i].options;
		for (y=0;y<va.length;y++) {
			v = va[y];
			for (x=0;x<o.length;x++) {
				if (v == o[x].value) {
					if (mu) {
						o[x].selected = true;
					} else {
						cb[i].selectedIndex = x;
					}
				}
			}
		}
	}
}
function setcheckboxvalues(frm) {
	var cb = frm.getElementsByTagName('INPUT');
	var i;
	var x;
	var v;
	var o;

	for (i=0;i<cb.length;i++) {
		if ((cb[i].type == 'radio') || (cb[i].type == 'RADIO')) {
			v = cb[i].getAttribute('v');
			if (v == cb[i].value) {
				cb[i].checked = true;
			}
		}
		if ((cb[i].type == 'checkbox') || (cb[i].type == 'CHECKBOX')) {
			v = cb[i].getAttribute('v');
			if (v == cb[i].value) cb[i].checked = true;
		}
	}
}
function submitContactForm(frm) {
	var e = frm.elements;

	if (!checkWebForm(e)) return;

	//location.href="#top";
	var chksum = location.hostname;
	e['checksum'].setAttribute("value",chksum);
	if (xajax.$('submitButton')) {
		xajax.$('submitButton').disabled=true;
		xajax.$('submitButton').value="Momentje aub...";
	}
	var fd = xajax.getFormValues("ContactForm");
	xajax_processContactForm(fd);
	return false;
}

function contact_status(status,errormsg) {
	if (status) {
		document.getElementById('ContactForm_form').style.display = 'none';
		document.getElementById('ContactForm_submitted').style.display = 'block';
	} else {
		alert(errormsg);
		xajax.$('submitButton').disabled=false;
		xajax.$('submitButton').value="Versturen";
	}
}
function checkWebForm(e)
{

	var msg = '';
	var chk = '';
	var focusfld = '';
	var i,ii,x;
	var rclist = [];
	var val = '';
	for(i=0;i<e.length;i++) {
		if (chk = e[i].getAttribute('inpchk')) {
			e[i].className = e[i].className.replace('mandatory','');
			if ((chk == 'notempty')) {
				if (e[i].type == 'checkbox') {
					val = (e[i].checked) ? '1' : '';
				} else {
					val = e[i].value;
				}
				if (val == '') {
					if (focusfld == '') focusfld = e[i].name;
					msg += e[i].getAttribute('chkmsg')+"\n";
					e[i].className += ' mandatory';
				}
			}
			if ((chk == 'minmaxlen')) {
				var min = e[i].getAttribute('minlen');
				var max = e[i].getAttribute('maxlen');
				if (e[i].value.length < min) {
					msg += e[i].getAttribute('chkmsg')+"\n";
					if (focusfld == '') focusfld = e[i].name;
					e[i].className += ' mandatory';
				}
				if (e[i].value.length > max) {
					msg += e[i].getAttribute('maxmsg')+"\n";
					if (focusfld == '') focusfld = e[i].name;
					e[i].className += ' mandatory';
				}
			}
			if ((chk == 'radiovalue')) {
				if (rclist[e[i].name] == 1) continue;
				rclist[e[i].name] = 1;
				x = e[e[i].name];
				//				alert(x.name + ":" + x.value + ":" + x.checked + ":" + x.length);
				if (!!x[0]) {
					for(ii=0;ii<x.length;ii++) {
						x[ii].className = x[ii].className.replace('mandatory','');
					}
					val = false;
					for(ii=0;ii<x.length;ii++) {
						if (x[ii].checked) val = true;
					}
					if (!val) {
						for(ii=0;ii<x.length;ii++) {
							x[ii].className += ' mandatory';
						}
						if (focusfld == '') focusfld = i;
						msg += e[i].getAttribute('chkmsg')+"\n";
					}
				}
			}
		}
	}
	if (msg) {
		alert(msg);
		//location.href="#top";
		e[focusfld].scrollIntoView(false);
		e[focusfld].focus();
		return false;
	}
	return true;
}

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
		if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
var map = null;
var geocoder = null;

geoloc = new Array();
geoll = new Array();
loc = -1;

function createMarker(point,name,html,icon) {
	var marker = new GMarker(point, { title: name, icon: icon});
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
	});
	return marker;
}

function createNoClickMarker(point,name,icon) {
	var marker = new GMarker(point, { title: name, icon: icon});
	return marker;
}

function createBlowup(point,html) {
	var marker = new GMarker(point, {title: html});
	GEvent.addListener(marker, "click", function() {
		marker.showMapBlowup();
	});
	return marker;
}

function loadmap() {
	if (GBrowserIsCompatible()) {
		geocoder = new GClientGeocoder();
		/* set loc op het einde van geoloc zodat we geen addressen zoeken maar de lat/lng uit de db gebruiken */
		loc = geoloc.length;
		getlatlng(0);
	}
}

function getlatlng(point) {
	var add = '';
	if (loc > -1) {
		if (point) {
			geoloc[loc].lat= point.lat();
			geoloc[loc].lng = point.lng();
		}
	}
	if (++loc < geoloc.length) {
		if (geoloc[loc].lat == 0 && geoloc[loc].lng == 0) {
			add = geoloc[loc].address;
			geocoder.getLatLng(add,function(point) {getlatlng(point);});
		} else {
			setTimeout("getlatlng(0)",20);
		}
	} else {
		var baseIcon = new GIcon();
		baseIcon.iconSize=new GSize(32,32);
		baseIcon.shadowSize=new GSize(56,32);
		baseIcon.iconAnchor=new GPoint(16,32);
		baseIcon.infoWindowAnchor=new GPoint(16,0);

		var icon_default = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal3/icon48.png", null, "http://maps.google.com/mapfiles/kml/pal3/icon48s.png");
		var icon_special = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal3/icon56.png", null, "http://maps.google.com/mapfiles/kml/pal3/icon56s.png");
		var map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		var lft = 52.24600;
		var rgt = 5.38600;
		map.setCenter(new GLatLng(lft,rgt), 7);
		map.setMapType(G_SATELLITE_MAP)
		var id, add, pt,title,lat,lng;
		var f = document.getElementById('locs');
		var nf = document.getElementById('noloc');
		for(var i=0;i<geoloc.length;i++) {
			add = geoloc[i].address;
			html = geoloc[i].popup_text;
			title = geoloc[i].title;
			id = geoloc[i].id;
			lat = geoloc[i].lat;
			lng = geoloc[i].lng;
			icon = (geoloc[i].icon) ? icon_special : icon_default;
			if (lat == 0 && lng == 0) {
				nf.innerHTML += id + "|" + lat + "|" + lng + '|' + add + "<br>\n";
			} else {
				var point = new GLatLng(geoloc[i].lat,geoloc[i].lng);
				// create the marker
				var marker = createMarker(point,title,html,icon);
				map.addOverlay(marker);
				//				f.innerHTML += "update article set lat = " + lat + ", lng = " + lng + " where id = " + id + ";<br>\n";
			}
		}

	}
}

function showprojectgml(lat,lng,title,html,icon) {
	if (lat == 0 && lng == 0) return;
	var baseIcon = new GIcon();
	baseIcon.iconSize=new GSize(32,32);
	baseIcon.shadowSize=new GSize(56,32);
	baseIcon.iconAnchor=new GPoint(16,32);
	baseIcon.infoWindowAnchor=new GPoint(16,0);

	var icon_default = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal3/icon48.png", null, "http://maps.google.com/mapfiles/kml/pal3/icon48s.png");
	var icon_special = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal3/icon56.png", null, "http://maps.google.com/mapfiles/kml/pal3/icon56s.png");
	document.getElementById('pimage').style.display="none";
	document.getElementById('gmpmap').style.display="block";
	var map = new GMap2(document.getElementById("gmpmap"));
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	map.setCenter(new GLatLng(lat,lng), 14);
	map.setMapType(G_SATELLITE_MAP)
	icon = (icon) ? icon_special : icon_default;
	var point = new GLatLng(lat,lng);
	var marker = createNoClickMarker(point,title,icon);
	map.addOverlay(marker);
}

function eventElm(e) {
	if (e.srcElement)
	tmp = e.srcElement;
	else
	tmp = e.target;
	return tmp;
}

function stopbubble(e) {
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}


function enlargeNav(e) {
	var tmp = eventElm(e);
	if (tmp.parentNode.rowIndex == 0) return;
	var enav = document.getElementById("enav");
	_cmNoHide = true;
	dbg("EnlargeNav");
	//xalert(tmp.className);
	if (enav.innerHTML == tmp.innerHTML && enav.style.display != 'none') {
		if (document.getElementById('enavTarget')) {
			document.getElementById('enavTarget').onmouseover();
		}
	}
	if (tmp.className == "ThemePanelMainFolderText" || tmp.className == "ThemePanelMainItemText") {
		if (clrTM) clearTimeout(clrTM);
		enav.innerHTML = tmp.innerHTML;
		enav.style.left= cmGetX(tmp.parentNode)-5+"px";
		enav.style.top= cmGetY(tmp.parentNode)-10+"px";
		enav.style.display = 'block';
		if (document.getElementById('enavTarget')) {
			if (document.getElementById('enavTarget') != tmp.parentNode) {
				document.getElementById('enavTarget').id = '';
			}
		}
		tmp.parentNode.setAttribute('id',"enavTarget");
	}
}

function propagateNavClick(e) {
	stopbubble(e);
	var ent = document.getElementById('enavTarget');
	ent.onmouseup();
}

function clearEnlargeNav(e) {
	//_cmCurrentItem = _ urrentItem;
	if (document.getElementById('enav').style.display == 'none') {
		dbg("no_CEN");
		return;
	}
	_cmNoHide = false;
	dbg("clearEnlargeNav");
	if (document.getElementById('enavTarget')) {
		document.getElementById('enavTarget').onmouseout();
	}
	clrTM = setTimeout('tmEnlargeNav()',200);
}

function tmEnlargeNav() {
	dbg("tmEnlargeNav");
	if (document.getElementById('enavTarget')) {
		var ent = document.getElementById('enavTarget');
		if (ent.className == 'ThemePanelMainItemHover' || ent.className == 'ThemePanelMainFolderHover') {
			clrTM = setTimeout('tmEnlargeNav()',200);
		} else {
			var ent = document.getElementById('enavTarget');
			//ent.onmouseout();
			
			ent.id = '';
			var enav = document.getElementById("enav");
			dbg("DN:" + ent.className);
			enav.style.display = 'none';
			
		}
	}
}

function enav_mo(e) {
	dbg('enav_MO');
	if (clrTM) {
		clearTimeout(clrTM);
		var ent = document.getElementById('enavTarget');
		ent.onmouseover();
	}
}
function dbg(msg) {
	//document.getElementById('dbg').innerHTML += msg + "\n";
}


//SWF stuff
var ie=(navigator.appName.indexOf('Explorer')>-1);
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1);
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1);
var isOpera = (navigator.userAgent.indexOf("Opera") != -1);
var flash_plugin;
function GetSwfVer(){
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flashObj;
		if ((flashObj=navigator.plugins["Shockwave Flash 2.0"]) || (flashObj=navigator.plugins["Shockwave Flash"])) return parseInt(flashObj.description.split(" ")[2]);
	} else if ( isIE && isWin && !isOpera ) {
		var axo,e;
		try {
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
			return parseInt(axo.GetVariable("$version").split(" ")[1]);
		} catch (e) {}
	}
	return 0;
}
function checkFlash(swf_version,no_flash_url) {
	if (flash_plugin) return true;
	if (no_flash_url && location.href.indexOf(no_flash_url)>-1) return false;
	flash_plugin = GetSwfVer() >= swf_version;
	if ( !flash_plugin && no_flash_url) location.href=no_flash_url;
	return flash_plugin;
}
function gettag(name) {
	var attr=''; var j=0; var ref,i;
	while(ref=arguments[++j]) for (var i in ref) attr+=' '+i+'="'+ref[i]+'"';
	return '<'+name+attr+'>\n';
}
function getflash(url,paramsref,dim,swf_version,noflash) {
	var attr={data:url,TYPE:"application/x-shockwave-flash"};
	var str=gettag('object',attr,dim);
	
	str+=gettag('param',{name: 'movie',value:url});
	for (var i in paramsref) str+=gettag('param',{name: i,value:paramsref[i]});
	//attr={src:url,TYPE:"application/x-shockwave-flash",PLUGINSPAGE:"http://www.macromedia.com/go/getflashplayer"};
//	attr={data:url,TYPE:"application/x-shockwave-flash",width: paramref['width'],height: paramref['height']};
	
	//str+=gettag('object',attr,dim);
	//str+=gettag('param',{name: 'movie',value:url});
	//for (var i in paramsref) str+=gettag('param',{name: i,value:paramsref[i]});
	
	if (typeof(noflash) == "object") {
		str += noflash.innerHTML;
	} else {
		if (typeof(noflash) == "string") str += noflash;
	}
	str+=gettag('/object');
	return str;
}
function writeflash(url,paramsref,dim,swf_version,noflash) {
	document.write(getflash(url,paramsref,dim,swf_version,noflash));
}

function fixmouseovercultuurerfgoed() {
	if (document.getElementById('mb_cultuurerfgoed')) {
		var ce = document.getElementById('mb_cultuurerfgoed')
		ce.parentNode.className += " td_cultuurerfgoed";
	}
}





// Add-on for the new gallery class


var base64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split("");
var base64inv = {};
for (var i = 0; i < base64chars.length; i++) base64inv[base64chars[i]] = i;

function base64_decode(s) {
	s = s.replace(new RegExp('[^'+base64chars.join("")+'=]', 'g'), "");
	var p = (s.charAt(s.length-1) == '=' ? (s.charAt(s.length-2) == '=' ? 'AA' : 'A') : "");
	var r = "";
	s = s.substr(0, s.length - p.length) + p;
	for (var c = 0; c < s.length; c += 4) {
		var n = (base64inv[s.charAt(c)] << 18) + (base64inv[s.charAt(c+1)] << 12) + (base64inv[s.charAt(c+2)] << 6) + base64inv[s.charAt(c+3)];
		r += String.fromCharCode((n >>> 16) & 255, (n >>> 8) & 255, n & 255);
	}
	return r.substring(0, r.length - p.length);
}




/* FdB - Content Slider */

function ContentSlider(name, container_id, back_id, front_id) {

	//Private vars and functions
	this.this_name = name;
	this.container = container_id;
	this.divs = new Array();
	this.is_rotating = 0;
	
	this.backdiv_id = back_id;
	this.backdiv = null;

	this.frontdiv_id = front_id;
	this.frontdiv = null;

	// Public vars
	this.slide_speed = 1000; //Slide the content in (default) 1000ms
	this.div_count = 0;
	this.div_current = 0;

	this.slide_auto = 0;
	this.slide_auto_speed = 5000;
}


ContentSlider.prototype.Current = function () {
	return this.div_current;
}

ContentSlider.prototype.Add = function (id) {
	this.divs[this.div_count] = document.getElementById(id);
	this.div_count++;
}

ContentSlider.prototype.Render = function () {
	var e = document.getElementById(this.container);
	if(e) this.Set(0);
}

ContentSlider.prototype.Set = function (div_index) {
	if( (div_index < 0) || (div_index > this.div_count)) return false;
	if(this.is_rotating) return false;
	this.is_rotating = 1;
	var bckpid = this.div_current;
	this.div_current = div_index;

	if (this.backdiv == null) {
		this.backdiv = document.getElementById(this.backdiv_id);
		this.frontdiv = document.getElementById(this.frontdiv_id);
		this.backdiv.style.display = 'none';
		this.frontdiv.innerHTML = this.divs[div_index].innerHTML;
		this.is_rotating = 0;
	} else {
		if (this.backdiv.style.display == 'none') {
			this._changeOpac(0, this.backdiv.id);
			this.backdiv.innerHTML = this.divs[div_index].innerHTML;
			setTimeout(this.this_name+"._set_opacity('"+this.backdiv.id+"',0,100,"+this.slide_speed+")",100);
			setTimeout(this.this_name+"._set_opacity('"+this.frontdiv.id+"',100,0,"+this.slide_speed+")",100);
		} else if (this.frontdiv.style.display == 'none') {
			this._changeOpac(0, this.frontdiv.id);
			this.frontdiv.innerHTML = this.divs[div_index].innerHTML;
			setTimeout(this.this_name+"._set_opacity('"+this.frontdiv.id+"',0,100,"+this.slide_speed+")",100);
			setTimeout(this.this_name+"._set_opacity('"+this.backdiv.id+"',100,0,"+this.slide_speed+")",100);
		}
		setTimeout(this.this_name + ".is_rotating=0", this.slide_speed);
	}
	updateLightbox();
}

ContentSlider.prototype.Prev = function () {
	var bckpid = this.div_current;
	this.div_current--;
	if(this.div_current < 0) this.div_current = this.div_count-1;
	this.Set(this.div_current);
}

ContentSlider.prototype.Next = function () {
	var bckpid = this.div_current;
	this.div_current++;
	if(this.div_current > this.div_count-1) this.div_current = 0;
	this.Set(this.div_current);
}

ContentSlider.prototype.Click = function () {
	return true;
}

ContentSlider.prototype.SlideAuto = function(state) {
	if(state) {
		this.slide_auto = true;
		this._autoslide();
	} else {
		this.slide_auto = false;
	}
}

ContentSlider.prototype._autoslide = function () {
	if(this.slide_auto) {
		setTimeout(this.this_name+"._autoslide()", this.slide_auto_speed);
		this.Next();
	}
}

ContentSlider.prototype._set_opacity = function (id, opacStart, opacEnd, millisec) {

	//speed for each frame
	var speed = Math.round(millisec * 0.01);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout(this.this_name+"._changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++) {
			setTimeout(this.this_name+"._changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
ContentSlider.prototype._changeOpac = function (opacity, id) {
	var object = document.getElementById(id).style;
	if(opacity < 5) {
		object.display = "none";
	} else {
		object.display = "block";
	}
	object.opacity = (opacity * 0.01);
	object.MozOpacity = (opacity * 0.01);
	object.KhtmlOpacity = (opacity * 0.01);
	object.filter = "alpha(opacity=" + opacity + ")";
}

