function addLoadEvent(func) {
	var oldonload = window.onload;
	if( typeof window.onload != 'function' ){
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
			oldonload();
			}
			func();
		}
	}
}
function addUnloadEvent(func) {
     var oldunload = window.onunload;
     if( typeof window.onunload != 'function' ){
     	 window.onunload = func;
     } else {
     	 window.onunload = function() {
			if( oldunload ){
				oldunload();
			}
			func();
		}
     }
}

addLoadEvent(function() {
	initSearchSmall();
})



/**
 * Toggle a panel
 */
function togglePanel(panelID) {
	var panel = document.getElementById(panelID);

	// Toggle the panel
	if(panel.style.display == 'none') {
		panel.style.display = 'block';
	} else {
		panel.style.display = 'none';
	}
}



//init search small
initSearchSmall = function() {
	var frm = document.getElementById('siteSearch');
	var submit = document.getElementById('siteSearchSubmit');
	var query = document.getElementById('siteSearchQuery');
	var h = document.getElementsByTagName('span');

	if( query===null ){
		return false;
	}

	if( query.value==''){
		query.value = submit.title;
	};

	frm.onsubmit=function() {
		if(this.siteSearchQuery.value=='doorzoek website'||this.siteSearchQuery.value=='') {
			alert('Voer een zoekterm in.');
			this.siteSearchQuery.focus();
			return false;
		}
	}
	submit.onmousedown=function() {this.src='images/layout/search/input-button-down.gif';}
	submit.onmouseout=function() {this.src='images/layout/search/input-button.gif';}
	query.onfocus=function() {if(this.value=='doorzoek website'){this.value=''};}
	query.onblur=function() {if(this.value==''){this.value='doorzoek website'};}
	for (var i=0;i<h.length;i++) {
		if (h[i].className=='noscript') {h[i].className = 'siteSearchLabel';}
	}
}

//init search large
initSearchLarge = function( frmID, queryID, submitID ) {
	var frm = document.getElementById(frmID);
	var query = document.getElementById(queryID);
	var submit = document.getElementById(submitID);

	frm.onsubmit=function() {
		if(query.value=='doorzoek website'||query.value=='') {
			alert('Voer een zoekterm in.');
			query.focus();
			return false;
		}
	}
	submit.onmousedown=function() {this.src='images/layout/search/input-button-down.gif';}
	submit.onmouseout=function() {this.src='images/layout/search/input-button.gif';}
	query.onfocus=function() {if(this.value=='doorzoek website'){this.value=''};}
	query.onblur=function() {if(this.value==''){this.value='doorzoek website'};}
}


function printPreview(){

	var currentTime = new Date();
	var month = currentTime.getMonth() + 1;
	var day = currentTime.getDate();
	var year = currentTime.getFullYear();

	var sendto = window.open("Print.php","Print","toolbar=1,location=1,status=1,menubar=1,scrollbars=1,width=800,height=600");
	sendto.document.open();
	sendto.focus();
	sendto.document.write('<html><head><link rel="stylesheet" type="text/css" href="css/printpreview.css" media="all"><link rel="stylesheet" type="text/css" href="css/forms.css" media="all"></head>');
	sendto.document.write('<body onload="document.getElementById(\'note\').focus();">');
	sendto.document.write('<div id="bodyWrapper">');
	sendto.document.write('<div id="printPreviewHeader">');
	sendto.document.write('<form action="print.php" method="post">');
	sendto.document.write('<div id="labelDate">'+day+'-'+month+'-'+year+'</div>');
	sendto.document.write('<div id="labelUrl">'+document.location+'</div>');
	sendto.document.write('<textarea id="note" name="note"></textarea>');
	sendto.document.write('<input type="submit" id="sendToPrinter" name="sendToPrinter" value="Print pagina" />');
	sendto.document.write('<textarea style="display:none;" name="page">'+document.getElementById('mainWrapperSmall').innerHTML+'</textarea>');
	sendto.document.write('<input type="hidden" name="url" value="'+document.location+'" />');
	sendto.document.write('</form>');
	sendto.document.write('</div>');
	var body = document.getElementById('mainWrapperSmall').innerHTML;
	sendto.document.write('<div id="printPreviewBody">' + body + '<img src="images/layout/bg-print-page-footer.jpg" title="" alt="" /></div>');
	sendto.document.write('</div>');
	sendto.document.write('</body>');
	sendto.document.write('</html>');
	sendto.document.close();
}

function mailFriend(){
	var p = location.pathname.lastIndexOf('/');
	var filename = location.pathname.substr(p+1);
	var send = window.open('mail-a-friend.php?page='+filename,"Mail","toolbar=1,location=1,status=1,menubar=1,scrollbars=1,width=800,height=600");
}

function popup(url,name,windowWidth,windowHeight){
	myleft=(screen.width)?(screen.width-windowWidth)/2:100;
	mytop=(screen.height)?(screen.height-windowHeight)/2:100;
	properties = "toolbar=0,location=0,status=1,menubar=0,scrollbars=0,width="+windowWidth+",height="+windowHeight+", top="+mytop+",left="+myleft;
	window.open(url,name,properties)
}
function popupCircle(swf){
	popup('http://www.capwell.nl/ict/flash/cirkel/cirkel.php?swf='+swf,"Capwell",770,770);
}
