var _W=window,_D=document,popupEl,nrSteps=20,dragObj,dragX,dragY,dragZ=1,close_n=new Image(13,13),close_h=new Image(13,13);;
_D.onmouseup=function(){dragObj=_D.onselectstart=_D.onmousemove=null};

var en = new Image();
var en_over = new Image();
var nl = new Image();
var nl_over = new Image();

en.src = '/pics/flags/nl.jpg';
en_over.src = '/pics/flags/nl_over.jpg';
nl.src = '/pics/flags/en.jpg';
nl_over.src = '/pics/flags/en_over.jpg';

close_h.src = '/pics/close_hi.gif';
close_n.src = '/pics/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=_W.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&&_D.createComment?T:F;
	t.opera9=ua.indexOf('opera 9')!=-1||ua.indexOf('opera/9')!=-1;
	t.ie5=t.ie55=t.ie6=F;
	t.ie=_D.all&&!t.opera&&ua.indexOf('msie')!=-1?T:F;
	if(t.ie){
		t.ieBox=_D.compatMode!='CSS1Compat';
		t.ie5=!_D.fireEvent?T:F;
		t.ie55=_D.fireEvent&&!_D.createComment?T:F;
		t.ie6=_D.fireEvent&&_D.createComment?T:F
	}
	t.gecko=!t.khtml&&!_D.all&&!t.opera&&_D.getElementById?T:F;
	t.ns4=n.appName=='Netscape'&&t.ver==4
}
var is=new sniff(),op=is.opera;
function gE(e){if(_D.getElementById)return _D.getElementById(e);if(_D.all)return _D.all[e]}
function sE(e){e.style.visibility='visible'}
function hE(e){e.style.visibility='hidden'}
function SE(e){e.style.display=''}
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 sC(e,t,r,b,l){e.style.clip='rect('+t+'px '+r+'px '+b+'px '+l+'px)';}


function showNote(el,content) {
	stopFade = true;
	fadingOut = false;
	var x=y=0;

	x = PixelsFrom('x', el);
	y = PixelsFrom('y', el);


	i = gE('info');

	i.innerHTML = content;
	x = parseInt(x) - 415
	y = parseInt(y) + 15;

	i.style.top = y + 'px';
	i.style.left = x + 'px'; 
	i.style.display = 'block';

	if (is.ie || is.gecko || is.opera9) {
		if (is.ie) i.filters.item(0).enabled = 1
		fadeIn();
	}
}

function hideNote() {
	i = gE('info');
	stopFade = false;
	setTimeout('fadeOut()',200);
}

function PixelsFrom (from, elem) {
	var x = 0
	while (elem) {
		x += from == 'x' ? elem.offsetLeft : elem.offsetTop
		elem = elem.offsetParent
	}
	return x
}

var fadingOut = hoveringText = stopFade = false;

function fadeIn() {
	i = gE('info');
	var opacity = is.ie ? i.filters.alpha.opacity : i.style.opacity * 100;

	// Set new opacity
	opacity = parseInt(opacity) + 10;

	if (is.ie) {
		i.filters.alpha.opacity = opacity;
	} else {
		op = opacity / 100;
		i.style.opacity = op;
	}

	if (opacity >= 100 || fadingOut) {
		return false;
	}

	setTimeout('fadeIn()',30);
}

function fadeOut() {
	if (hoveringText || stopFade) return false;
	fadingOut = true;

	i = gE('info');

	var opacity = is.ie ? i.filters.alpha.opacity : i.style.opacity * 100;
	opacity = parseInt(opacity) - 10;

	if (is.ie) {
		i.filters.alpha.opacity = opacity;
	} else {
		op = opacity / 100;
		i.style.opacity = op;
	}

	if (opacity <= 0 || (!is.ie && !is.gecko && !is.opera9)) {
		i.style.display = 'none';
		fadingOut = false;
		return false;
	}

	setTimeout('fadeOut()',30);
}

function overTxt(tf) {
	i = gE('info');

	if(is.ie) {
		i.filters.alpha.opacity = 100;
	} else if (is.gecko || is.opera9) {
		i.style.opacity = 1;
	}

	hoveringText = tf;
}

function checkEnter(kc, val) {
	if (kc == 13 && val.replace(/[\W]/, '') != '') {
		document.forms['zoeken'].submit();
	}
}

function navHover(id, tf)
{
	var el = gE('over_'+id);

	if (!el) return false;

	if (is.ie)
	{
		el.filters.alpha.opacity = tf ? 50 : 0;
	} else
	{
		el.style.opacity = tf ? 0.5 : 0;
	}
}

function printPage() 
{
	var html = gE('page_content').innerHTML;
	var printFrame = gE('printFrame');

	printFrame.contentWindow.document.body.innerHTML = html
	printFrame.contentWindow.focus();
	printFrame.contentWindow.print();
}

function makePopup(e, width, height, title, i, is_img) {
	killPopup(1);
	height += 24;
	curImg = i;
	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) ? _D.body.scrollLeft : _D.documentElement.scrollLeft;
		st = (is.ieBox) ? _D.body.scrollTop  : _D.documentElement.scrollTop;
	}
	else {
		sl = _W.pageXOffset;
		st = _W.pageYOffset;
	}
	if (e.clientX + width > ww)
		left = ww-width-5;
	if (e.clientY + height > wh)
		top = wh-height-5;

	popupEl = _D.createElement('div');
	popupEl.onmousedown=function(event){dragStart(event,this)};
	popupEl.className = 'popup';
	popupEl.setAttribute('id','captionWindow');
	_D.body.appendChild(popupEl);
	sizePopup(title,i,left+sl,top+st,width,height,is_img,nrSteps);
}

function makePopupForum(e, width, height, title, i, is_img) {
	curImg = i;
	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;

	var specs = 'left='+(Math.ceil(left))+', top='+(Math.ceil(top))+', width='+width+', height='+height;
	
	//alert(i+', '+title+', '+specs);
	window.open(i, '_blank', specs);
}

function killPopup(now) {
   if (popupEl) {
      var code = '_D.body.removeChild(popupEl);popupEl=null;';
      if (now)
         eval(code);
      else
         setTimeout(code,10);
   }
}

function getWinSize(what) {
   if (what == 'height')
      return (is.ie) ? (is.ieBox) ? _D.body.clientHeight : _D.documentElement.clientHeight : _W.innerHeight;
   if (what == 'width')
      return (is.ie) ? (is.ieBox) ? _D.body.clientWidth : _D.documentElement.clientWidth : _W.innerWidth;
}

function sizePopup(title,url,left,top,width,height,is_img,step) {
   // New and improved: with slomogrow effect!
   var html, mouse;
   if (step < 0) {
		if (is.ie) {
         SW(popupEl, width+2);
         SH(popupEl, height+1);
      }

      mouse = (is.ie) ? 'onmouseover="this.src=close_h.src" onmouseout="this.src=close_n.src"' : '';
      html  = '<table class="popupCaption" cellpadding="0" cellspacing="3" width="'+(width+2)+'"><tr>';
      html += '<td width="99%" align="center" id="captionTitle">'+title+'</td>';
      html += '<td width="1%" align="right"><img src="/pics/close.gif" class="ptr" width="13" height="13" vspace="2" alt="Close" onclick="killPopup(0)" '+mouse+' /></td>';

		/*if (is_img) {
			html += '</tr><tr><td style="background-color:#FFFFFF;padding:0 10px;" colspan="2">';
			html += '<span style="float:right;color:#000;" id="captionNext">';
			html += '<a href="#" onclick="nextImage();return false;"><?=word(85)?></a> &raquo;';
			html += '</span>';
			html += '<span style="float:left;color:#000;" id="captionPrev">';
			html+= '&laquo; <a href="#" onclick="prevImage();return false;"><?=word(86)?></a>';
			html += '</span>';
			html += '</td>';
		}*/
		html += '</tr></table>';
		if (is_img) {
			url = '/img.php?url='+captionFiles[curImg][1];
		}
      wH(popupEl, html+'<iframe frameborder="0" src="'+url+'" style="width:'+width+'px;height:'+(height-24)+'px;margin:0;padding:0" id="captionFrame"></iframe>');
		if (is_img) {
			gE('captionNext').style.visibility = curImg < captionFiles.length - 1 ? 'visible' : 'hidden';
			gE('captionPrev').style.visibility = curImg > 0 ? 'visible' : 'hidden';
		}
      return;
   }
   sX(popupEl, left + step*width/nrSteps/2);
   sY(popupEl, top + step*height/nrSteps/2);
   SW(popupEl, width - step*width/nrSteps);
   SH(popupEl, height - step*height/nrSteps + (is.safari?2:0));
   setTimeout("sizePopup('"+title+"','"+url+"',"+left+","+top+","+width+","+height+","+is_img+","+(step-1)+")",0);
}

function dragStart(e,el) {
   if (!e)e=_W.event;
   dragObj = el;
   dragObj.style.zIndex = dragZ++;
   dragX = e.clientX - dragObj.offsetLeft;
   dragY = e.clientY - dragObj.offsetTop;
   _D.onmousemove=dragMove;
   _D.onselectstart=function(){return false};
}

function dragMove(e) {
   if (!e)e=_W.event;
   if(dragObj) {
      sX(dragObj,e.clientX - dragX);
      sY(dragObj,e.clientY - dragY);
   }
}

function _checkPoll(F) {
	if(!valRadioButton(F['vote'])) {
		alert('Je hebt nog geen keuze gemaakt!');
		return false;
	}	
	return true;
}

function valRadioButton(btn) {
	var cnt = -1;
	for(var i = 0; i < btn.length; i++){
		if(btn[i].checked){
			cnt = i; 
			i = btn.length;
		}
	}
	if (cnt > -1){
		return btn[cnt].value;
	}
	else{
		return false;
	}
}