// JavaScript Document
window.onerror = stopError
function stopError() {
	return true;
}

// We need the path bacause of the base-tag
var baseHref = "";
function getBase(){
     var baseTag = document.getElementsByTagName("base");
     for(var i = 0; i < baseTag.length; i++){
          baseId = baseTag[i].id;
          baseHref = baseTag[i].href;
     }
}
getBase();

// We need to modify the anchors bacause of the base-tag
function replaceAnchors(){
     var linkTags = document.getElementsByTagName("a");
     for(var i = 0; i < linkTags.length; i++){
          linkHref = linkTags[i].href;
		  anchorPos = linkHref.indexOf("#");
		  if(anchorPos!=-1){
			anchorName = linkHref.substr(anchorPos);
			linkTags[i].href = "javascript:void(document.location.hash='"+anchorName+"')";
		 }
     }
}

addHoverEffect = function() {
	var sfEls = document.getElementById("menu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
/*		var sfUls = sfEls[i].getElementsByTagName("UL");
		for (var j=0; j<sfUls.length; j++) {
			alert(sfUls[i].innerHTML);
			sfUls[i].onmouseout=function() {
				sfEls[i].className=sfEls[i].className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
*/	}
}

if (window.addEventListener) window.addEventListener('load', replaceAnchors, false);
else if (window.attachEvent) {
	window.attachEvent("onload", replaceAnchors);
	window.attachEvent("onload", addHoverEffect);
}

function doMail(which) {
	//Init
	var valid = "yes";

	if(which=="contact"){
		//Check
		if (document.getElementById('naam').value=='') var valid = 'no';
		if (document.getElementById('email').value.indexOf('@')==-1 || document.getElementById('email').value.indexOf('.')==-1) var valid = 'no';
		if (document.getElementById('opmerkingen').value=='') var valid = 'no';
	} else if(which=="vacatures"){	
		//Check  
		var aantal_uploads = document.getElementById('aantal_uploads').value;
		for(i=1;i<=aantal_uploads;i++) {
			if (document.getElementById('userfilename_'+i).value=="") valid = 'no';
		}
		if (document.getElementById('naam').value=='') var valid = 'no';
		if (document.getElementById('roepnaam').value=='') var valid = 'no';
		if (document.getElementById('adres').value=='') var valid = 'no';
		if (document.getElementById('postcode').value=='') var valid = 'no';
		if (document.getElementById('woonplaats').value=='') var valid = 'no';
		if (document.getElementById('telefoon').value=='') var valid = 'no';
		if (document.getElementById('email').value.indexOf('@')==-1 || document.getElementById('email').value.indexOf('.')==-1) var valid = 'no';
		if (document.getElementById('nationaliteit').value=='') var valid = 'no';
		if (document.getElementById('geboortedatum').value=='') var valid = 'no';
		if (document.getElementById('geboorteplaats').value=='') var valid = 'no';
	} else if(which=="open_vacatures"){	
		if (document.getElementById('naam').value=='') var valid = 'no';
		if (document.getElementById('adres').value=='') var valid = 'no';
		if (document.getElementById('postcode').value=='') var valid = 'no';
		if (document.getElementById('woonplaats').value=='') var valid = 'no';
		if (document.getElementById('telefoon').value=='') var valid = 'no';
		if (document.getElementById('email').value.indexOf('@')==-1 || document.getElementById('email').value.indexOf('.')==-1) var valid = 'no';
		if (document.getElementById('bericht').value=='') var valid = 'no';
	}	
	
	//If ok, then submit
	if (valid == "yes") {
		document.home_form.submit(document.home_form);
	} else {
		alert("U dient alle vereiste velden in te voeren.");
	}
}

function doPrint(_base, _text, _logo, _adres) {
	if (document.getElementById(_text)) {
		tekst = document.getElementById(_text).innerHTML;
	} else {
		alert("Container niet gevonden");
	}
	tekst = "<html><head><title>Printvriendelijke versie</title><base href='"+_base+"'><link href='css/print.css' rel='stylesheet' /></head><body>"+_logo+"<br /><br />"+tekst+"<br /><br /><hr /> "+_adres+"<br /><br /><br /><br /><center><a href='javascript: window.print()'>Pagina printen</a> &nbsp;&nbsp; <a href='javascript: window.close()'>Venster sluiten</a></center></body></html>";
	printWin = window.open('','','width=700,height=600,scrollbars=yes,resizable=yes,titlebar=0');
	printWin.document.write(tekst);
	printWin.document.close();
	printWin.print();
}

function replaceQueryString(a,k,v) {
   var re = new RegExp("([?|&])" + k + "=.*?(&|$)","i");
   if (a.match(re))
       return a.replace(re,'$1' + k + "=" + v + '$2');
   else
       return a + '&' + k + "=" + v;
}

function fontSize(size) {
	var url = window.location+'';
	
	if (url.indexOf('#')!=-1) url = url.replace('#','');
	window.location = replaceQueryString(url,'fontsize',size);
}