// Based on DHTML Window Widget- By Dynamic Drive, available at: http://www.dynamicdrive.com
var dhtmlwindow={
	ajaxbustcache: true,
	minimizeorder: 0,
	tobjects: [],
	init:function(t){
		var domwindow=document.createElement("div");
		domwindow.id=t;
		domwindow.className="dhtmlwindow";
		var domwindowdata='';
		domwindowdata='<div class="drag-handle">';
		domwindowdata+='DHTML Window <div class="drag-controls" title="Close">Sluit venster</div>';
		domwindowdata+='</div>';
		domwindowdata+='<div class="drag-contentarea"></div>';
		domwindowdata+='</div>';
		domwindow.innerHTML=domwindowdata;
		document.getElementById("dhtmlwindowholder").appendChild(domwindow);
		this.zIndexvalue=(this.zIndexvalue)? this.zIndexvalue+1 : 100;
		var t=document.getElementById(t);
		var divs=t.getElementsByTagName("div");
		for (var i=0; i<divs.length; i++){
			if (/drag-/.test(divs[i].className))
				t[divs[i].className.replace(/drag-/, "")]=divs[i];
		}
		t.style.zIndex=this.zIndexvalue;
		t.controls._parent=t;
		t.onclose=function(){return true};
		t.onmousedown=function(){dhtmlwindow.zIndexvalue++; this.style.zIndex=dhtmlwindow.zIndexvalue};
		dhtmlwindow.addEvent(t.controls, dhtmlwindow.enablecontrols, "click");
		t.show=function(){dhtmlwindow.show(this)};
		t.hide=function(){dhtmlwindow.close(this)};
		t.setSize=function(w, h){dhtmlwindow.setSize(this, w, h)};
		t.moveTo=function(x, y){dhtmlwindow.moveTo(this, x, y)};
		t.isScrolling=function(bol){dhtmlwindow.isScrolling(this, bol)};
		t.load=function(contenttype, contentsource, title){dhtmlwindow.load(this, contenttype, contentsource, title)};
		this.tobjects[this.tobjects.length]=t;
		return t;
	},
	open:function(contentsource, title, attr){
		
		/*  begin Omniture tracking */
		aName = title;
		if ( !aName ) {
			aName = contentsource;
		}
		aPrevPagename = s.pageName;
		if ( !s.pageName ) {
			s.pageName = 'unknown';	
		}
		s.pageName = s.pageName + '#dl:' + aName;
		s.t();
		s.pageName = aPrevPagename;
		/*  eind Omniture tracking */
				
		var d=dhtmlwindow;
		var contenttype="ajax";
		var t="dlayer";
		d.addEvent(window, d.setDimmedLayerSize, "resize");
		d.addEvent(window, d.setDimmedLayerSize, "scroll");
		d.addEvent(document.getElementById('dimmedlayer'), d.close, "click");
		selects = document.getElementsByTagName("select");
		for (i = 0; i != selects.length; i++) {
			selects[i].style.visibility = "hidden";
		}
		selects = document.getElementsByTagName("OBJECT");
		for (i = 0; i != selects.length; i++) {
			selects[i].style.visibility = "hidden";
		}
		if (document.getElementById('dimmedlayer').style.display == "none"){
			document.getElementById('dimmedlayer').style.display = "block";
		}
		dhtmlwindow.setDimmedLayerSize();
		function getValue(Name){
			var config=new RegExp(Name+"=([^,]+)", "i");
			return (config.test(attr))? parseInt(RegExp.$1) : 0;
		}
		if (document.getElementById(t)==null){
			t=this.init(t);
		}
		else{
			t=document.getElementById(t);
		}
		t.setSize(getValue(("width")), (getValue("height")));
		var xpos=getValue("center")? "middle" : getValue("left");
		var ypos=getValue("center")? "middle" : getValue("top");
		t.isScrolling(getValue("scrolling"));
		t.style.visibility="visible";
		t.style.display="block";
		t.contentarea.style.display="block";
		t.moveTo(xpos, ypos); //Position window
		t.load(contenttype, contentsource, title);
		return t
	},
	setDimmedLayerSize:function(){
		if (document.getElementById('dimmedlayer').style.display != 'none'){
			dhtmlwindow.getviewpoint();
			var dimmedLayer = document.getElementById('dimmedlayer');
			dimmedLayer.style.display = "block";
			var arrayPageSize = dhtmlwindow.getPageSize();
			dimmedLayer.style.height = arrayPageSize[1] + "px";
			dimmedLayer.style.width = arrayPageSize[0] + "px";
			dhtmlwindow.moveTo(document.getElementById('dimmedlayer'), "middle", "middle");
		}
	},
	getPageSize:function(){
		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){
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else {
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		var windowWidth, windowHeight;
		if (self.innerHeight) {
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) {
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}
		if(xScroll < windowWidth){
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
		return arrayPageSize;
	},
	setSize:function(t, w, h){
		t.style.width=Math.max(parseInt(w), 150)+"px";
		t.contentarea.style.height=Math.max(parseInt(h), 100)+"px";
	},
	moveTo:function(t, x, y){
		this.getviewpoint();
		t.style.left=(x=="middle")? Math.max(this.scroll_left+(this.docwidth-t.offsetWidth)/2, 0)+"px" : this.scroll_left+parseInt(x)+"px";
		t.style.top=(y=="middle")? Math.max(this.scroll_top+(this.docheight-t.offsetHeight)/2, 0)+"px" : this.scroll_top+parseInt(y)+"px";
	},
	isScrolling:function(t, bol){
		t.contentarea.style.overflow=(bol)? "auto" : "hidden";
	},
	load:function(t, contenttype, contentsource, title){
		var contenttype=contenttype.toLowerCase();
		if (typeof title!="undefined")
			t.handle.firstChild.nodeValue=(title=="")?"":title;
		this.ajax_connect(contentsource, t);
		t.contentarea.datatype=contenttype;
	},
	getviewpoint:function(){
		var ie=document.all && !window.opera;
		var domclientWidth=document.documentElement && parseInt(document.documentElement.clientWidth) || 100000;
		this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body;
		this.scroll_top=(ie)? this.standardbody.scrollTop : window.pageYOffset;
		this.scroll_left=(ie)? this.standardbody.scrollLeft : window.pageXOffset;
		this.docwidth=(ie)? this.standardbody.clientWidth : (/Safari/i.test(navigator.userAgent))? window.innerWidth : Math.min(domclientWidth, window.innerWidth-16);
		this.docheight=(ie)? this.standardbody.clientHeight: window.innerHeight;
	},
	enablecontrols:function(e){
		var d=dhtmlwindow;
		d.close(this._parent);
		return false;
	},
	close:function(){
		
		/*  begin Omniture tracking */
		s.t();
		/*  eind Omniture tracking */
		
		var t = document.getElementById("dlayer");
		t.style.display="none";
		document.getElementById('dimmedlayer').style.display = "none";
		selects = document.getElementsByTagName("select");
		for (i = 0; i != selects.length; i++) {
			selects[i].style.visibility = "visible";
		}
		selects = document.getElementsByTagName("OBJECT");
		for (i = 0; i != selects.length; i++) {
			selects[i].style.visibility = "visible";
		}
		t.parentNode.removeChild(t);
		return true;
	},
	show:function(t){
			t.style.display="block";
	},
	ajax_connect:function(url, t){
		var page_request = false;
		var bustcacheparameter="";
		if (window.XMLHttpRequest)
			page_request = new XMLHttpRequest();
		else if (window.ActiveXObject){
			try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e){
				try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e){}
			}
		}
		else
			return false;
		page_request.onreadystatechange=function(){dhtmlwindow.ajax_loadpage(page_request, t)}
		if (this.ajaxbustcache)
			bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime();
		page_request.open('GET', url+bustcacheparameter, true);
		page_request.send(null);
	},
	ajax_loadpage:function(page_request, t){
		if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){

			t.contentarea.innerHTML=page_request.responseText;

			// import flash movies seperately
			var scripts = t.contentarea.getElementsByTagName('script');

			for(var s = 0; s < scripts.length; s++) {
				if (scripts[s].innerHTML.toString().indexOf("writeFlash") != -1){
					var script = scripts[s].innerHTML.toString();
					var fl_s = "/" + script.substring(script.indexOf("writeFlash")+13,script.indexOf(",")-1);
					script = script.slice(script.indexOf(",")+1);
					var fl_w = script.substring(0,script.indexOf(","));
					script = script.slice(script.indexOf(",")+1);
					var fl_h = script.substring(0,script.indexOf(","));
					script = script.slice(script.indexOf(",")+2);
					var fl_a = script.substr(0,script.indexOf("'")-1);

    alternateContent = 'Voor deze site heeft u <a target="_blank" href="http://www.microsoft.com/download/">Microsoft Internet Explorer</a> versie 5.5 (of hoger) en de <a target="_blank" href="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&P5_Language=English">Macromedia Flash plugin</a> versie ' + requiredVersion + ' (of hoger) nodig.'
					var el_flash=document.createElement("div");
					el_flash.innerHTML='<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+fl_w+'" height="'+fl_h+'" CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
  + '<PARAM name="MOVIE" value="'+fl_s+'">'
  + '<PARAM name="PLAY" value="true">'
  + '<PARAM name="LOOP" value="false">'
  + '<PARAM name="QUALITY" value="high">'
  + '<PARAM name="MENU" value="false">'
  + '<EMBED src="'+fl_s+'" width="'+fl_w+'" height="'+fl_h+'" play="true" loop="false" quality="high" menu="false" type="application/x-shockwave-flash" pluginspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>'
  + '<NOEMBED>' + alternateContent + '</NOEMBED></OBJECT>';

					var newdiv = document.createElement("div");
					newdiv.setAttribute('id','flashid');
					//newdiv.style.width='400px';
					//newdiv.style.height='300px';
					scripts[s].parentNode.insertBefore(newdiv,scripts[s]);
					document.getElementById('flashid').appendChild(el_flash);
					//alert(document.getElementById('flashid').innerHTML);

				}
			}
		}
	},
	stop:function(){
		dhtmlwindow.etarget=null;
	},
	addEvent:function(target, functionref, tasktype){
		var tasktype=(window.addEventListener)? tasktype : "on"+tasktype;
		if (target.addEventListener){
			target.addEventListener(tasktype, functionref, false);
		}
		else if (target.attachEvent){
			target.attachEvent(tasktype, functionref);
		}
	},
	createBasicElements:function(){
		var el_dhtmlwindowholder=document.createElement("div");
		el_dhtmlwindowholder.id="dhtmlwindowholder";
		el_dhtmlwindowholder.innerHtml='<span style="display:none">.</span>';
		document.body.appendChild(el_dhtmlwindowholder);
		var el_dimmedlayer=document.createElement("div");
		el_dimmedlayer.id="dimmedlayer";
		document.body.appendChild(el_dimmedlayer);
	},
	cleanup:function(){
		for (var i=0; i<dhtmlwindow.tobjects.length; i++){
			dhtmlwindow.tobjects[i].handle._parent=dhtmlwindow.tobjects[i].resizearea._parent=dhtmlwindow.tobjects[i].controls._parent=null
		}
	}
}
dhtmlwindow.addEvent(window, dhtmlwindow.createBasicElements, "load");


function openDimmedLayer(page, w, h){
    dhtmlwindow.open(page, '', 'width='+w+'px,height='+h+ 'px,resize=0,scrolling=0,center=1,dragging=0');
//return true;
}
