// browser check
var agent = window.navigator.userAgent; 
var i = agent.indexOf("MSIE ")+5;
isIE5plus = (parseInt(agent.substr(i)) >= 5 && agent.indexOf("5.0b1") < 0);
isMac = agent.indexOf("Mac") != -1;
//isNN6plus = (agent.toLowerCase().indexOf("gecko") > 0);
//isSafari = agent.toLowerCase().indexOf("safari") != -1;

//This function is supposed to be called from the a-tag with valid href-attribute
//If pWidth and pHeight are given, the popup will assume them as width and height
function ndPopup(aTag, pWidth, pHeight) {	
	if (!pWidth) pWidth=600; if (!pHeight) pHeight=500;
	if (top.ndCMSPopup && !top.ndCMSPopup.closed && top.ndCMSPopup.close) top.ndCMSPopup.close();
	top.ndCMSPopup = top.open(aTag.href, "ndCMSPopup", "width="+pWidth+",height="+pHeight+",resizable=1,menubar=1");
	top.ndCMSPopup.focus();
	return false;
}

// icons
function writeIcons() {
	//preload images;
	topImg = 	new Image(); topImg.src = "../images/button_up_off.gif"; 
	topImgF = 	new Image(); topImgF.src = "../images/button_up_on.gif";
	printImg = 	new Image(); printImg.src = "../images/button_print_off.gif"; 
	printImgF = new Image(); printImgF.src = "../images/button_print_on.gif";
	var strTmp = '' +
		'<div id="icons" style="position: absolute; margin-left: 610px;">' +
		'<a href="#" onclick="goUp(); this.blur(); return false;" onmouseover="document.topIcon.src=topImgF.src; status=\'Naar boven\'" onmouseout="document.topIcon.src=topImg.src; status=\'\'">' +
			'<img src="images/button_up_off.gif" alt="Naar boven" title="Naar boven" name="topIcon">' +
		'</a><br>'  +
		'<a href="#" onclick="printPage(); this.blur(); return false;" onmouseover="document.printIcon.src=printImgF.src; status=\'Print deze pagina\'" onmouseout="document.printIcon.src=printImg.src; status=\'\'">' +
			'<img src="images/button_print_off.gif" alt="Print deze pagina" title="Print deze pagina" name="printIcon" style="margin-top: 16px;">' +
		'</a>' +
		'</div>';
	document.write(strTmp);
	positionIcons();
	window.onresize = positionIcons;
	if (isIE5plus) {
		window.onscroll = positionIcons;
		if (isMac && isIE5plus) {
			window.onload = function() {
				window.scrollTo(0,1);
				window.scrollTo(0,0);
				positionIcons;
			}
			window.onmousemove = positionIcons;	
		} else {
			window.onload = positionIcons;
			window.onmousemove = positionIcons;	
		}
	} else {
		window.onmousemove = positionIcons;	
	}
}

function positionIcons() {
	var iconMinY = 49;
	if (isIE5plus) {
		if (isMac && isIE5plus) document.body.style.visibility = 'hidden';
		document.all.icons.style.top = (Math.max(document.body.scrollTop, iconMinY) + 18) + "px";
		if (isMac && isIE5plus) document.body.style.visibility = 'visible';
	} else {
		document.getElementById("icons").style.top = (Math.max(document.body.scrollTop, iconMinY) + 18) + "px";
	}
}

var scrollstep	   = 40;
var scrollint	   = 30;

function goUp() {
	smoothScroll();	
}

function getPageOffset() {
	return (document.documentElement.scrollTop) ? document.body.scrollTop : document.body.scrollTop;
}

function smoothScroll() {
	docheight = (window.innerHeight) ? window.innerHeight : document.body.clientHeight;
	pageoffset = getPageOffset();
	step = (pageoffset <= scrollstep) ? Math.round(pageoffset / 2) : ( ( pageoffset >  docheight) ?  docheight : scrollstep );	
	new_y = pageoffset - step; 
	if (new_y<0) new_y = 0;
	window.scrollTo(0, new_y);
	if (new_y>0) setTimeout("smoothScroll()", scrollint);
}

// print functions
function printPage() {
	top.ndContentFrame.focus();
	top.ndContentFrame.print();
}

// setMenu func (for content pages)
function setMenu(mainId, subId) {
	if (top == this) {
		var urlParts = this.location.href.split("/");
		var url = urlParts[urlParts.length-1];
		//location.href = "redirect.html?url=" + escape(url);
		location.href="index.php?url=" + escape(url);
	} else {
		if (top && top.ndMenuFrame && top.ndMenuFrame.loaded) {
			top.ndMenuFrame.setMenu(mainId, subId);
		} else {
			setTimeout("setMenu('" + mainId + "','" + subId + "')", 500);
		}
	}
}


function checkSearchForm() {
	if (document.getElementById("qry").value == "" || document.getElementById("qry").value == transYourSearchTerms) {
		alert(transFillInSearchTerm); 
		document.getElementById("qry").focus(); 
		return false;
	};
	
	if (document.getElementById("qry").value.length <= 2) {
		alert(transTerm3chars); 
		document.getElementById("qry").focus(); 
		return false;
	};
	
	if (document.getElementById("qry").value.indexOf("<") > -1 
		|| document.getElementById("qry").value.indexOf("#") > -1
		|| document.getElementById("qry").value.indexOf("$") > -1
		|| document.getElementById("qry").value.indexOf("%") > -1
		|| document.getElementById("qry").value.indexOf("^") > -1
		|| document.getElementById("qry").value.indexOf("*") > -1
		|| document.getElementById("qry").value.indexOf(">") > -1) {
		alert(transSearchInvalidChars); 
		document.getElementById("qry").focus(); 
		return false;
	};
	return true;
}