var winn=window,docc=document,navv = navigator, winReference = null,poppEll,nrSteps=15,dragObj,dragX,dragY,dragZ=1,closenavv=new Image(13,13),close_h=new Image(13,13);
docc.onmouseup=function(){try{dragObj=docc.onselectstart=docc.onmousemove=null}catch(e){}};

close_h.src = '/pdf/close_hi.gif';
closenavv.src = '/pdf/close.gif';

function sniff(){
	var t=this,T=true,F=false,n=navigator,ua=n.userAgent.toLowerCase();
	t.ver=parseInt(n.appVersion);
	t.mac=ua.indexOf('mac')!=-1;
	t.win=!t.mac&&ua.indexOf('wind')!=-1||ua.indexOf('16bit')!=-1;
	t.safari=ua.indexOf('safari')!=-1&&t.mac;
	t.konq=ua.indexOf('konqueror')!=-1;
	t.khtml=t.safari||t.konq;
	t.opera=winn.opera?T:F;
	t.opera5=ua.indexOf('opera 5')!=-1||ua.indexOf('opera/5')!=-1;
	t.opera6=ua.indexOf('opera 6')!=-1||ua.indexOf('opera/6')!=-1;
	t.opera7=t.opera&&docc.createComment?T:F;
	t.ie5=t.ie55=t.ie6=F;
	t.ie=docc.all&&!t.opera&&ua.indexOf('msie')!=-1?T:F;
	if(t.ie){
		t.ieBox=docc.compatMode!='CSS1Compat';
		t.ie5=!docc.fireEvent?T:F;
		t.ie55=docc.fireEvent&&!docc.createComment?T:F;
		t.ie6=docc.fireEvent&&docc.createComment?T:F
	}
	t.gecko=!t.khtml&&!docc.all&&!t.opera&&docc.getElementById?T:F;
	t.ns4=n.appName=='Netscape'&&t.ver==4
}
is=new sniff();
op=is.opera;
function gE(e){if(docc.getElementById)return docc.getElementById(e);if(docc.all)return docc.all[e]}
function sE(e){e.style.visibility='visible'}
function hE(e){e.style.visibility='hidden'}
function SE(e){e.style.display='block'}
function HE(e){e.style.display='none'}
function sX(e,x){op?e.style.pixelLeft=x:e.style.left=x+'px'}
function sY(e,y){op?e.style.pixelTop=y:e.style.top=y+'px'}
function sW(e,w){op?e.style.pixelWidth=w:e.style.width=w+'px'}
function sH(e,h){op?e.style.pixelHeight=h:e.style.height=h+'px'}
function wH(e,h){e.innerHTML=h}

function getWinSize(what) {
	if (what == 'height')
		return (is.ie) ? (is.ieBox) ? docc.body.clientHeight : docc.documentElement.clientHeight : winn.innerHeight;
	if (what == 'width')
		return (is.ie) ? (is.ieBox) ? docc.body.clientWidth : docc.documentElement.clientWidth : winn.innerWidth-16;
}

// Core utility function that actually creates the window and gives focus to it
function openWindow(url, name, properties, openerName) {
	var agent = navv.userAgent.toLowerCase();
	if (agent.indexOf("msie") != -1 && parseInt(navv.appVersion) == 4 && agent.indexOf("msie 5") == -1 && agent.indexOf("msie5") == -1 && agent.indexOf("win") != -1 && url.indexOf('http://') == 0) {
		winReference = winn.open('about:blank', name, properties);

		setTimeout('if (winReference && !winReference.closed) winReference.location.replace("' + url + '")', 300);
	}
	else
		winReference = winn.open(url, name, properties);
	setTimeout('if (winReference && !winReference.closed) winReference.focus()', 200);
	if (openerName) self.name = openerName;
	return winReference;
}

// Open a window at a given position on the screen
function openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName) {
	var agent = navv.userAgent.toLowerCase();
	if (agent.indexOf("mac") != -1 && agent.indexOf("msie") != -1 && (agent.indexOf("msie 4") != -1 || agent.indexOf("msie 5.0") != -1) ) {
		height += (status) ? 17 : 2;
	}
	width += (scrollbars != '' && scrollbars != null && agent.indexOf("mac") == -1) ? 16 : 0;
	var properties = 'width=' + width + ',height=' + height + ',screenX=' + x + ',screenY=' + y + ',left=' + x + ',top=' + y + ((status) ? ',status' : '') + ',scrollbars' + ((scrollbars) ? '' : '=no') + ((moreProperties) ? ',' + moreProperties : '');
	return openWindow(url, name, properties, openerName);
}

// Open a window at the center of the screen
function openCenteredWindow(url, name, width, height, status, scrollbars, moreProperties, openerName) {
	var x, y = 0;
	if (screen) {
      x = (screen.availWidth - width) / 2;
	   y = (screen.availHeight - height) / 2;
   }
	if (!status) status = '';
	if (!openerName) openerName = '';
	var reference = openPositionedWindow(url, name, width, height, x, y, status, scrollbars, moreProperties, openerName);
	return reference;
}

function makePopup(e, width, height, title, url) {
	killPopup(1);
	height += 24;
	if (is.gecko) width+=1;
	var wh = getWinSize('height'), ww = getWinSize('width'), st, sl;
	if (!e) {
		e = new Object();
		e.clientX = ww/2-width/2;
		e.clientY = wh/2-height/2;
	}
	var top = e.clientY, left = e.clientX;
	if (is.ie) {
		sl = (is.ieBox) ? docc.body.scrollLeft : docc.documentElement.scrollLeft;
		st = (is.ieBox) ? docc.body.scrollTop  : docc.documentElement.scrollTop;
	}
	else {
		sl = winn.pageXOffset;
		st = winn.pageYOffset;
	}
	if (e.clientX + width > ww)
		left = ww-width-5;
	if (e.clientY + height > wh)
		top = wh-height-5;

	poppEll = docc.createElement('div');
	poppEll.onmousedown=function(event){dragStart(event,this)};
	poppEll.className = 'pup';
	docc.body.appendChild(poppEll);
	sizePopup(title,url,left+sl,top+st,width,height,0); // nrSteps i.p.v. de 0 voor zoom effect.
}

function sizePopup(title,url,left,top,width,height,step) {
	var html, mouse;
	if (step < 0) {
		if (is.ie) {
			sW(poppEll, width+2);
			sH(poppEll, height+1);
		}
		mouse = (is.ie) ? 'onmouseover="this.src=close_h.src" onmouseout="this.src=closenavv.src"' : '';
		html  = '<table class="pupCaption" cellpadding="0" cellspacing="3"><tr>';
		html += '<td width="99%" align="center">'+title+'</td>';
		html += '<td width="1%" align="right"><img src="/pdf/close.gif" class="ptr" width="13" height="13" alt="Close" style="cursor: pointer;" onclick="killPopup(0)" '+mouse+' /></td>';
		html += '</tr></table>';
		wH(poppEll, html+'<iframe frameborder="0" src="'+url+'" style="width:'+width+'px;height:'+(height-20)+'px"></iframe>');
		return;
	}
	sX(poppEll, left + step*width/nrSteps/2);
	sY(poppEll, top + step*height/nrSteps/2);
	sW(poppEll, width - step*width/nrSteps);
	sH(poppEll, height - step*height/nrSteps + (is.safari?2:0));
	setTimeout("sizePopup('"+title+"','"+url+"',"+left+","+top+","+width+","+height+","+(step-1)+")",0);
}

function killPopup(now) {
	if (poppEll) {
		var code = 'docc.body.removeChild(poppEll);poppEll=null;';
		if (now)
			eval(code);
		else
			setTimeout(code,10);
	}
}

function dragStart(e,el) {
	if (!e)e=winn.event;
	dragObj = el;
	dragObj.style.zIndex = dragZ++;
	dragX = e.clientX - dragObj.offsetLeft;
	dragY = e.clientY - dragObj.offsetTop;
	docc.onmousemove=dragMove;
	docc.onselectstart=function(){return false};
}

function dragMove(e) {
	if (!e)e=winn.event;
	if(dragObj) {
		sX(dragObj,e.clientX - dragX);
		sY(dragObj,e.clientY - dragY);
	}
}

function fontSize(adj) {
	var loc = docc.location.href;
	loc = loc.replace(/[\?&]fa=[\+\-]?[0-9]+/, '');
	var sep = (loc.indexOf('?') == -1) ? '?' : '&';
	loc += sep + 'fa=' + adj;
	docc.location.replace(loc);
}

function emailPage(evt,url) {
	url = 'pemail.php?'+url;
	makePopup(evt,340,is.ie?346:380,'E-mail pagina',url);
}

function pdfPage(evt) {
	var h = getWinSize('height')-30, w = Math.floor(h*.7);
	makePopup(evt,w,h,'PDF-versie','ppdf.php');
}

function printPage(evt) {
	var h = getWinSize('height')-125;
	makePopup(evt,550,h,'Print-versie','pprint.php');
}
