// meerdere onloads handelen
function addOnload(newFunction) {
	var oldOnload = window.onload;
	if (typeof oldOnload == "function") {window.onload = function() {if (oldOnload) {oldOnload();} newFunction();};}
	else {window.onload = newFunction;} 
}

function emailtruc() {
	var spans = document.getElementsByTagName('span');
	for (var i=0, spansL = spans.length; i < spansL; i++) {
		if (spans[i].className == 'emailtruc') {
			spans[i].innerHTML = spans[i].innerHTML.replace(/ p[u#]nt /g, '.');
			spans[i].innerHTML = spans[i].innerHTML.replace(/^(.*?) b[i#]j(.*?)\.([a-z]{2,6})$/i, "$1@$2.$3");
			spans[i].innerHTML = spans[i].innerHTML.replace(/ /g, '');
			spans[i].innerHTML = spans[i].innerHTML.replace(/^(.*)$/, "<a href=\"mailto:$1\">$1</a>");
		}
	}
}
addOnload(emailtruc);

function bevestigLogout() {
	var l = document.getElementById('uitloglink');
	if (l) {l.onclick = function () {return confirm('Wilt u inderdaad uitloggen?')};}
}
addOnload(bevestigLogout);

// validatie-object
function myValid() {
	this.errMsg = [];
	this.markeerTR = false;
}
myValid.prototype.voegToe = function(tekst) {
	this.errMsg.push(tekst);
	if (arguments.length > 1) {
		if (this.markeerTR && arguments[1].parentNode.parentNode.tagName.toLowerCase() == 'tr') {
			arguments[1].parentNode.parentNode.className += ' nietgoed';
		} else {
			arguments[1].className += ' nietgoed';
		}
	}
};
myValid.prototype.rondAf = function() {
	if (this.errMsg.length > 0) {
		alert(this.errMsg.join('\n'));
		this.errMsg = [];
		return false;
	} else {
		return true;
	}
};

// xml-http-request-object
var req = false;
function initXmlHttpRequest() {
    if(window.XMLHttpRequest) {try {req = new XMLHttpRequest();} catch(e) {req = false;}
    } else if(window.ActiveXObject) {try {req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {try {req = new ActiveXObject("Microsoft.XMLHTTP");} catch(e) {req = false;}}
    }
}

// boxje voor (ajax)feedback
var berichtbox, tmo;
function toonAjaxbericht(bericht, duur) {
	berichtbox = document.getElementById('ajaxbericht');
	if (!berichtbox) {
		var nwEl = document.createElement('div');
		nwEl.id = 'ajaxbericht';
		berichtbox = document.body.appendChild(nwEl);
	}
	clearTimeout(tmo);
	berichtbox.innerHTML = bericht;
	var y = document.documentElement ? document.documentElement.scrollTop : document.body.scrollTop;
	berichtbox.style.top = y + 'px';
	berichtbox.style.display = 'block';
	if (duur > 0) {
		tmo = setTimeout('berichtbox.style.display="none"', duur*1000);
	}
}

// standaard hulp-popup
function hulppop(topic) {
	window.open('\/hulp.php?topic='+topic,'hulppopje','width=400,height=500,scrollbars=yes');
}


// tbv account werkgevers
function copyData(f, van, naar) {
	f[naar + 'adres'].value = f[van + 'adres'].value;
	f[naar + 'adres2'].value = f[van + 'adres2'].value;
	f[naar + 'postcode'].value = f[van + 'postcode'].value;
	f[naar + 'plaats'].value = f[van + 'plaats'].value;
}

// in loginbox
function doeCookietest() {
	if (!navigator.cookieEnabled) {
		document.write('<p class="message">Deze site maakt gebruik van cookies. Schakel de cookie-ondersteuning van uw browser s.v.p. in voor een correcte werking van de site.<\/p>');
	}
}

// flash-kopjes maken
function maakFlashkoppen() {
	var box = document.getElementById('mainContent');
	if (box) {
		var h2s = box.getElementsByTagName('h2');
		for (var i = 0, h2L = h2s.length; i < h2L; i++) {
			if (h2s[i].className.indexOf('noflash') > -1) {continue;}
			if (!h2s[i].id) {h2s[i].id = '_foH2' + i;}
			var fo = new FlashObject("/js/header.swf", "header2_" + i, "540", "40", "5");
			fo.addVariable("titel", h2s[i].innerHTML);
			fo.addParam("wmode", "transparent");
			fo.addParam("menu", "false");
			fo.write(h2s[i].id);
			h2s[i].style.marginBottom = 0;
		}
	}
}
addOnload(maakFlashkoppen);

function togglereactieform() {
	var f = document.getElementById('reactieform');
	if (f) {f.style.display = (f.style.display == 'none' || f.style.display == '') ? 'block' : 'none';}
}

function setTonen(val, vacID) {
	if(!req) {initXmlHttpRequest();}
	req.open("POST", location.protocol + "//" + location.hostname + location.pathname, true);
	req.onreadystatechange = processVacPubStatus;
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send('setTonen=' + val + '&vacID=' + vacID);
}
function processVacPubStatus() {
    if (req.readyState == 4) {
		// alert(req.responseText);
		toonAjaxbericht(req.responseText,3);
	}
}

// tabbladfunctionaliteit
function Tabjes() {
	// constructor, krijgt id's van divs als argumenten
	this.arrTabs = [];
	this.arrLinks = [];
	for (var i = 0, arg; (arg = arguments[i]); i++ ) {
		this.arrTabs.push(arg);
	}
	this.smachtendeTabID = '';
	this.menuID = '';
}
Tabjes.prototype.setMenuID = function(ID) {this.menuID = ID;};
Tabjes.prototype.setLinks = function(lijstID) {
	this.arrLinks = document.getElementById(lijstID).getElementsByTagName('a');
};
Tabjes.prototype.toonTab = function (pLink, teTonenDivID) {
	for (var i = 0, L = this.arrTabs.length; i < L; i++) { 
		document.getElementById(this.arrTabs[i]).style.display = 'none';
	}
	document.getElementById(teTonenDivID).style.display = 'block';
	// eenmalig de arr met links vullen
	if (this.arrLinks.length === 0) {
		this.setLinks(this.menuID);
	}
	for (i = 0, L = this.arrLinks.length; i < L; i++) {
		this.arrLinks[i].className = 'uit';
	}
	pLink.className = 'aan';
	return false;
};

// geeft de key terug indien in-array
Array.prototype.in_array = function (s) {
	for(var i=0;i<this.length;i++)
		if(this[i] == s) return i; 
	return false;
};

// cv verwijderen
function verwijderCV() {
	if (confirm('U staat op het punt uw cv te verwijderen van onze site. Wilt u doorgaan?')) {
		if(!req) {initXmlHttpRequest();}
		req.open("POST", location.protocol + "//" + location.hostname + location.pathname, true);
		req.onreadystatechange = processVerwijderingCV;
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send('verwijderCV=1');
	}
	return false;
}
function processVerwijderingCV() {
    if (req.readyState == 4) {
		// alert(req.responseText);
		toonAjaxbericht(req.responseText,3);
		document.getElementById('cvUpload').innerHTML = '<input type="file" name="cv">';
	}
}

