var dbPath='/medweb/vacature.nsf'
var isIE = (window.ActiveXObject) ? true:false;
var isFF = (window.XMLHttpRequest) ? true:false;
//var IE = document.all ? true:false											// global flag
var req;														// global request and XML document objects
var ventriesdoc;
var printstring=''
var vacastring=''
var numberarray=''
var vacateller=0
var historycounter=1
function gebi(idtxt){
	if(document.getElementById(idtxt)){
		return document.getElementById(idtxt)
	}else{
		//alert('element met ID '+idtxt+' niet gevonden in DOM')
		return false
	}
}
function removeByIndex(arrayName,arrayIndex){ 
	arrayName.splice(arrayIndex,1); 
}
function framekiller(){
	if (top != self) {
		top.location.replace(self.location.href);
	}
}
function installSearchEngine() {
	if (window.external && ("AddSearchProvider" in window.external)) {
	// Firefox 2 and IE 7, OpenSearch
	window.external.AddSearchProvider("http://www.medweb.nl/medweb/vacature.nsf/asb?OpenPage&country=nl");
	}
}
function inloggen(){
	var f=gebi('loginform');
	if(f.username.value=='' | f.password.value==''){
		alert('Geef eerst uw gebruikersnaam EN wachtwoord op.')
	}else{
		document.location.replace('/medweb/vacature.nsf/login?openform&username='+f.username.value+'&password='+f.password.value)
	}
}
function openOverlay(url){
	historycounter+=1
	//alert(historycounter)
	var overlay = document.getElementById('overlay');
	var overlayPos = (isIE) ? document.body.scrollTop : window.scrollY;
	overlay.style.top=overlayPos;
	overlay.style.display = 'block';
	var xiFrame = gebi('entryContentIframe');	
	xiFrame.style.display = 'block';
	xiFrame.style.top = overlayPos + 30;
	xiFrame.style.left = (document.body.clientWidth - xiFrame.scrollWidth) /2 ;
	xiFrame.style.height = document.body.clientHeight - 60;
	xiFrame.src = url;
}
function closeOverlay(){
	var iFrame = window.top.document.getElementById('entryContentIframe');	
	if (iFrame){
		iFrame.src ='/medweb/vacature.nsf/blank.htm?openpage';
		iFrame.style.display = 'none';
		window.top.document.getElementById('overlay').style.display = 'none';
	}else{
		window.close()
	}
}
function openInfoOverlay(infopage, land){
	var loc='/medweb/vacature.nsf/infodisp'+land+'/'+infopage+'?openDocument&ispopup=ja'
	openOverlay(loc)
}
function verstuurCollegaMailClick(){
	var xIframe= gebi('entryContentIframe')
	var xDoc = (xIframe.contentWindow || xIframe.contentDocument);
	if (xDoc.document){
		xDoc = xDoc.document
	}
	var FromEmailObj=xDoc.getElementById('FromEmail')
	var FromNaamObj=xDoc.getElementById('FromNaam')
	var ToEmailObj=xDoc.getElementById('ToEmail')
	if(checkEmailField(FromEmailObj, true)&checkEmailField(ToEmailObj, true)&checkEmpty(FromNaamObj)){
		xDoc.forms[0].mailCollegaBut.click()
		if (xIFrame){
			alert('iframe wordt ook gesloten')
			xIFrame.src ='/medweb/vacature.nsf/blank.htm?openpage';
			xIFrame.style.display = 'none';
			window.top.document.getElementById('overlay').style.display = 'none';
		}else{
			alert('iframe is er niet.')
		}
	}else{
		alert('U hebt nog niet alles goed ingevuld')
	}
}
function mwc(cname,cvalue){
	var d=new Date();
	d.setTime(d.getTime()+3600000);
	document.cookie=cname+'='+cvalue+'; path=/; expires='+d.toGMTString()+';'
};
function mwcd(cname,cvalue,duration){
	var d=new Date();
	if (duration=='undefined'){duration=3600000}
	d.setTime(d.getTime()+duration);
	document.cookie=cname+'='+cvalue+'; path=/; expires='+d.toGMTString()+';'
};
function mss(text,van,tot){
	return text.substring(van,tot)
};
function mio(val,text){
	return val.indexOf(text)
};
function mcv(cid){
	var pos1,ispos,cend,val=''
	var c=document.cookie;
	pos1=mio(c,cid);
	if(pos1>-1){
		ispos=c.indexOf('=',pos1)+1;
		if (ispos>-1){ //komt er een = in voor
			cend=c.indexOf(';',pos1);
			if(cend<0)cend=c.length;
			preval=mss(c,ispos,cend)
			if(ispos<cend&preval.indexOf(';')<0){
				val=mss(c,ispos,cend);
			}else{
				val=false
			}
		}else{
			val=false
		}
	}
	return val
}
function saveVacature(id){
	if(id=='notactive'){
		alert('bewaren kan alleen met actieve vacatures!')
	}else{
		if (mcv('bewaardevacatures')==false){
			//6 weken durend cookie
			mwcd('bewaardevacatures',id, 3628800000)
				alert('vacature is bewaard in een nieuw gemaakt lijstje op uw computer.\nU vindt dit lijstje rechts in uw scherm.')
		}else{
			if(mio(mcv('bewaardevacatures'),id)>-1){
				alert('vacature staat al op het lijstje op uw computer')
			}else{
				mwcd('bewaardevacatures',mcv('bewaardevacatures') + "+"+id, 3628800000)
				alert('vacature is toegevoegd aan het lijstje op uw computer')
			}
			
		}
		displaySavedVacas()
	}
}
function unSaveVacature(id){
	var vacaturelijst=mcv('bewaardevacatures')
	if (vacaturelijst==false){
		alert('U hebt geen vacatures op uw lijstje staan.')
	}else{
		if(mio(vacaturelijst,id)>-1){
			//vacature staat inderdaad in het lijstje
			if (confirm('Vacature '+id+ ' uit uw lijstje verwijderen?')==true){
				var theindex=''
				vacaturelijstarr=vacaturelijst.split('+')
				for(i=0;i<vacaturelijstarr.length;i++){
					if(vacaturelijstarr[i]==id){theindex=i}
				}
				removeByIndex(vacaturelijstarr,theindex)
				mwcd('bewaardevacatures',vacaturelijstarr.join('+'), 3628800000)
			}
		}
		
	}
	displaySavedVacas()
}
function getVacaTitle(vacnr){
	//~ zit in url (en key in view) omdat readviewentries geen exact match terug kan geven (bv scheen geeft ook scheening terug)
	var randomU = Math.random(999999); //bereken random getal om url te wijzigen anders blijft xml gechached (in IE)
	loadVacaXMLDoc('/medweb/vacature.nsf/allevaca?readviewentries&startkey=' + vacnr+'&untilkey='+ vacnr +'~&anyPar='+randomU)
}
function loadVacaXMLDoc(url) {
	if (window.XMLHttpRequest) { 						// branch for native XMLHttpRequest object
		req = new window.XMLHttpRequest();
		req.onreadystatechange = vacaProcessReqChange;
		req.open("GET", url, true);
		req.send(null);
	} else if (isIE) {					// branch for IE/Windows ActiveX version
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = vacaProcessReqChange;   	
			req.open("GET", url, true);
			req.send();
		}
	}
}
function vacaProcessReqChange() {
	if (req.readyState == 4){ 	
		// only if req shows "loaded"
		if (req.status == 200) {  					
			// only if "OK"
	 		ventriesDoc = req.responseXML;
			var viewentrys=ventriesDoc.getElementsByTagName('viewentry')
			//if(viewentrys==undefined){alert ('hiero !')}
			//var viewentrys = ventriesDoc.getElementsByTagName('viewentries').item(0)
			//if (viewentrys.childNodes.length==0){
			if(viewentrys==undefined){
				// vacature bestaat niet meer..
				vacastring='<li>(Vacature verlopen)</li>'
				printstring+=vacastring
				vacastring=''
				vacateller+=1
				getVacaLink()
			}else{
				// get those details				
				// de eerste viewentry, second node (entrydata), de eerste node (text)
				vacastring=ventriesDoc.getElementsByTagName('text').item(1).childNodes[0].wholeText
				//alert('vacastring: ' + vacastring)
				if(vacastring==undefined){
					//vacastring='IE? Weg er mee!'
					//vacastring=ventriesDoc.getElementsByTagName('viewentry').item(0).childNodes[1].childNodes[0].nodeValue geeft null
					vacastring=ventriesDoc.getElementsByTagName('text').item(1).firstChild.nodeValue
				}
				printstring+=vacastring
				vacastring=''
				vacateller+=1
				getVacaLink()
				
			}
		}
	}
}
function displaySavedVacas(){
	printstring=''
	var numbers=mcv('bewaardevacatures')
	if(numbers==false){
		printstring='U hebt nog geen vacatures bewaard'
		gebi('bewaardevacatureslijst').className=''
	}else{
		numberarray=numbers.split('+')
		vacateller=0
		getVacaTitle(numberarray[vacateller])
		//schrijf weg
		//if nog een vaca dan weer verder
	}
	// wordt overschreven als onreadystatechange vuurt.
	gebi('bewaardevacatureslijst').innerHTML=printstring
}
function getVacaLink(){
//globals numberarray en n staan in de kop
	if(vacateller<numberarray.length){
		getVacaTitle(numberarray[vacateller])
	}else{
		// we hebben alle vacatures gehad, nu schrijven!
		gebi('bewaardevacatureslijst').className=''
		gebi('bewaardevacatureslijst').innerHTML='<ul>'+printstring+'</ul>'
		printstring=''
	}
}
function checkEmailField(emailFieldObj, force){
	if(!checkEmailAddress(emailFieldObj.value)|emailFieldObj.value==''&force){
		emailFieldObj.className='error'
		emailFieldObj.focus()
		return false
	}else{
		emailFieldObj.className=''
		return true
	}
}
function checkEmailAddress(email){
	if(email=='') return true
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (!filter.test(email)) {
		return false
	}else{
		return true
	}
}
function checkEmpty(fieldObj){
	if(fieldObj.value==''){
		fieldObj.className='error'
		fieldObj.focus()
		return false
	}else{
		fieldObj.className=''
		return true
	}
}
function checkUserNameSyntax(username){
	var filter=/^[0-9a-zA-Z]+$/i
	if(!filter.test(username)){
		return false
	}else{
		return true
	}
}
function checkPassword(password){
	var filter=/^[0-9a-zA-Z!@&*()?]+$/i
	if(!filter.test(password)){
		alert('password ongeldig')
		addError('',gebi('vac_cp_password'))
		return false
	}else{
		unError(gebi('vac_cp_password'))
		return true
	}
}
function checkPassword2(password){
	if(password!=gebi('vac_cp_password').value){
		alert('passwords niet gelijk')
		addError('',gebi('vac_cp_password2'))
		return false
	}else{
		unError(gebi('vac_cp_password2'))
		return true
	}
}
function checkTelNr(telnrvalue){
	cleantelnrvalue=replaceSubstring(replaceSubstring(replaceSubstring(replaceSubstring(telnrvalue,'-',''),' ',''),"(",""),")","")
	if (cleantelnrvalue/1==cleantelnrvalue){
		return true
	}else{
		return false
	}
} 
function mkUpperCase(value){
	return value.toUpperCase();
}
function resetErrField(fieldObj){
	if(fieldObj.className=='error'&fieldObj.value!=''){
		fieldObj.className=''
	}
	
}
function WriteFlash(swfpath,width,height){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 	codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6, 0, 0, 0"')
	document.write('  width="'+width+'" height="'+height+'" id="top" align="left">')
	document.write('<param name=movie value="'+swfpath+'">')
	document.write('<param name=quality VALUE=high>')
	document.write('<param name=bgcolor VALUE=#FFFFFF>')
	document.write('<embed src="'+swfpath+'" quality=high ')
	document.write('bgcolor=#ffffff width="'+width+'" height="'+height+'" name="kopmw" ')
	document.write(' type="application/x-shockwave-flash" ')
	document.write('pluginspage="http://www.macromedia.com/go/getflashplayer">')
document.write('</embed>')
document.write('</object>')
}
function showVaca(id, specme){
	var dbPath='medweb/vacature.nsf'
	window.location = '/medweb/vacature.nsf/dispvaca/'+id+'?opendocument&specme='+specme
}
function openEntry(id,modus){
	var divName ='uwvacatures'
	var url=''
	if (id ==''){
		url = '/medweb/vacature.nsf/entry?openform&div='+divName
	} else {
		switch (modus){
		case 'edit':
			url = '/medweb/vacature.nsf/vacaedit/'+id+'?editdocument&div='+ divName
			break;
		case 'read':
			url = '/medweb/vacature.nsf/vacaedit/'+id+'?opendocument&div='+ divName
			break;
		case 'preview':
			url = '/medweb/vacature.nsf/dispvaca/'+id+'?opendocument&div='+ divName
			break;
		}
	}
	document.location = url
}
function toonVacature(id){
	document.location.href='/medweb/vacature.nsf/dispvaca/'+id
}
function ShowDiv(divName){
	//alert(document.gebruikersnaam)
	if (divName =='') divName = 'uwgegevens'
	window.location = '/medweb/vacature.nsf/profiles/'+document.gebruikersnaam+'?opendocument&div='+divName
}
function goClientDiv(clnaam, div){
	if (div ==''){div = 'uwgegevens'}
	document.location='/medweb/vacature.nsf/profiles/'+clnaam+'?opendocument&div='+div
}
function toonSollicInfo(vacanr, type, ispopup){
	if (ispopup==undefined){ispopup='nee'}
	document.location.href='/medweb/vacature.nsf/dispvacami/vacature-'+vacanr+'htm?opendocument&type='+type+'&ispopup='+ispopup
}
function Solliciteer(unid)
	{
	window.location = '/medweb/vacature.nsf/sollicitatie?Openform&ParentUNID='+unid+'&Mode=2';
	}
function StuurMeerInfo(unid)
	{
	window.location = '/medweb/vacature.nsf/stuurmeerinformatie?Openform&ParentUNID='+unid+'';
	}
function httpErvoor(value){
	if(value.indexOf('http://')<0 & value!=''){value='http://'+value}
	return(value)
}
function stripfunct(value){
	var newval=''
	for(var n=0;n<value.length;n++){
		var sjar=value.substring(n,n+1)
		if (sjar=='/'){sjar='-'};
		if(sjar=='?'){sjar=''};
		if(sjar=='\\'){sjar='--'};
		if(sjar=='!'){sjar=' '};
		if(sjar=='&'){sjar=' '};
		newval+=sjar
	}
	return newval
}
function replaceSubstring(inputString, fromString, toString) {
	var temp = inputString;
	if (fromString == "") {
		return inputString;
	}
	if (toString.indexOf(fromString) == -1) { 
		while (temp.indexOf(fromString) != -1) {
			var toTheLeft = temp.substring(0, temp.indexOf(fromString));
			var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
			temp = toTheLeft + toString + toTheRight;
		}
	} else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
		var midStrings = new Array("~", "`", "_", "^", "#");
		var midStringLen = 1;
		var midString = "";
		// Find a string that doesn't exist in the inputString to be used
		// as an "inbetween" string
		while (midString == "") {
			for (var i=0; i < midStrings.length; i++) {
				var tempMidString = "";
				for (var j=0; j < midStringLen; j++) { 
					tempMidString += midStrings[i]; 
				}
				if (fromString.indexOf(tempMidString) == -1) {
					midString = tempMidString;
					i = midStrings.length + 1;
				}
			}
		} // Keep on going until we build an "inbetween" string that doesn't exist
	      	// Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
		while (temp.indexOf(fromString) != -1) {
			var toTheLeft = temp.substring(0, temp.indexOf(fromString));
			var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
			temp = toTheLeft + midString + toTheRight;
		}
		// Next, replace the "inbetween" string with the "toString"
		while (temp.indexOf(midString) != -1) {
			var toTheLeft = temp.substring(0, temp.indexOf(midString));
			var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
			temp = toTheLeft + toString + toTheRight;
		}
	} // Ends the check to see if the string being replaced is part of the replacement string or not
	return temp; 
	// Send the updated string back to the user
} 
function getCheckValue(checkbox) {
	var values='';
	for (i = 0; i < checkbox.length; i++) {
		if (checkbox[i].checked) {
			if(values!=''){values+=','+checkbox[i].value};
			if(values==''){values=checkbox[i].value};
		}
	}
	if (values!='') {
		//alert('values is niet leeg')
		return values.split(',')
	} else {
		//alert('values is leeg')
		return null
	}
}
function getRadioValue(radiobutton) {
	for (i = 0; i < radiobutton.length; i++) {
		if (radiobutton[i].checked) {
		return radiobutton[i].value;
		}
	}
	return null;
}
function getMousePosition(){
	document.tempY=document.tempY?document.tempY:275
	if (!isIE){document.captureEvents(Event.MOUSEMOVE)}
	document.onmousemove = getMouseXY;
	return(document.tempY)
}
function getMouseXY(e) {
	var IE = document.all?true:false
	if (IE) { // grab the x-y pos.s if browser is IE
		//document.tempX = event.clientX + document.body.scrollLeft
		document.tempY = event.clientY + document.body.scrollTop
	} else {  // grab the x-y pos.s if browser is NS
		//document.tempX = e.pageX
		document.tempY = e.pageY
  	}	  
	  // catch possible negative values in NS4
	//if (document.tempX < 0){
	//	document.tempX = 0
	//}
 	if (document.tempY < 0){
		document.tempY = 0
	}  
	// show the position values in the form named Show
	// in the text fields named MouseX and MouseY
	//document.Show.MouseX.value = document.tempX
	//document.Show.MouseY.value = document.tempY
	var retval=document.tempY
	return retval
}
function clearNoDocs(doctype){
	var contentdiv=gebi("viewbody")
	if(contentdiv.innerHTML.indexOf('No documents found')>0){
		contentdiv.innerHTML='<span class="warning"><br />Geen '+doctype+' gevonden die aan de selectie voldoen<\/span>'}
}
function wijzigVacature(unid){
	document.location.href='/medweb/vacature.nsf/editvaca/'+unid+'?editdocument'
}
function showTarievenInPopUp(siteCountry){
	openInfoOverlay('informatie', siteCountry)
}
function plaatsVacature(unid,country){
	document.location.href='/medweb/vacature.nsf/PlaatsVacature?openagent&id='+unid+'&land='+country
}
//*ajax functions
function loadXMLDoc(url) {
	if (window.XMLHttpRequest) { 						// branch for native XMLHttpRequest object
		req = new window.XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send(null);
	} else if (window.ActiveXObject) {					// branch for IE/Windows ActiveX version
		isIE = true;
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processReqChange;   	// deze zit weer in de eigen (client, entry etc) js
			req.open("GET", url, true);
			req.send();
		}
	}
}
function addError(err, obj){
	if(errFields == ''){
		obj.focus()
	}
	errFields = errFields + err + '\n'
	obj.className='error'
	doSubmit = false
}
function unError(obj){
	obj.className=''
}
function check(field) {
	for (i = 0; i < field.length; i++) {
		field[i].selected = true;
	}
}
function uncheck(field) {
	for (i = 0; i < field.length; i++) {
		field[i].selected = false;
	}
}
function move(fbox,tbox){
	for(var i=0; i<fbox.options.length; i++){
		if(fbox.options[i].selected != ""){
			var no = new Option();
			no.text = fbox.options[i].text;
			fbox.options[i].text ="";
			tbox.options[tbox.options.length] = no;
			document.forms[0].Edited.value = 'ja';
		}
	}
	this.value=uncheck(fbox)
	BumpUp(fbox);
	BumpUp(tbox);
}
function movenew(fbox,tbox){
	for(var i=0; i<fbox.options.length; i++){
		if(fbox.options[i].selected != ""){
			var no = new Option();
			no.text = fbox.options[i].text;
			no.value = fbox.options[i].value;
			fbox.options[i].text ="";
			fbox.options[i].value ="";
			tbox.options[tbox.options.length] = no;
			document.forms[0].Edited.value = 'ja';
		}
	}
	this.value=uncheck(fbox)
	BumpUp(fbox);
	BumpUp(tbox);
}
function remove(fbox,tbox){
	for(var i=0; i<fbox.options.length; i++){
		if(fbox.options[i].selected != ""){
			var no = new Option();
			no.text = fbox.options[i].text;
			fbox.options[i].text ="";
			tbox.options[tbox.options.length] = no;
			document.forms[0].Edited.value = 'ja';
		}
	}
	this.value=uncheck(fbox)
	BumpUp(fbox);
	BumpUp(tbox);
}
function removenew(fbox,tbox){
	for(var i=0; i<fbox.options.length; i++){
		if(fbox.options[i].selected != ""){
			var no = new Option();
			no.text = fbox.options[i].text;
			no.value = fbox.options[i].value;
			fbox.options[i].text ="";
			fbox.options[i].value ="";
			tbox.options[tbox.options.length] = no;
			document.forms[0].Edited.value = 'ja';
		}
	}
	this.value=uncheck(fbox)
	BumpUp(fbox);
	BumpUp(tbox);
}
function BumpUp(box)  {
	for(var i=0; i<box.options.length; i++) {
		if(box.options[i].text == "")  {
			for(var j=i; j<box.options.length-1; j++)  {
				box.options[j].text = box.options[j+1].text;
			}
			var ln = i;
			break;
		}
	}
	if(ln < box.options.length)  {
		box.options.length -= 1;
		BumpUp(box);
	}
}
function fixLinkTarget(){
	var msg=''
	var urllist=document.getElementsByTagName('a')
	//alert(urllist.length+' links gevonden op deze pagina')
	for(n=0;n<urllist.length;n++){
		var uhref=urllist[n].href;
		var target=urllist[n].target
		if (uhref.indexOf('/medweb')<0 & uhref.indexOf('artsen-')<0 & uhref.indexOf('javascript:')<0& uhref.indexOf('medweb.nl/')<0& uhref.indexOf('medweb.be/')<0 ){
			msg+=n+'.'+uhref +' moet naar target="_blank"; is nu '+target+'\n'
			urllist[n].setAttribute('target','_blank')
		}else{
			urllist[n].setAttribute('target','_top')
		}
	
	}
	//alert(msg)
}
function mailCollega(unid){
	//hier aanroep agent die mailcollegadoc maakt en verzending afhandelt.
	gebi('mailCollegaBut').click()
}
function CheckAdBlocks(adkey, side){
	// het script dat in de div "advertentie-links"staat:  GA_googleFillSlot("MedWebVacaNLRecentKopLinks") 
	// google insert een div met id google_ads_div_MedWebVacaNLRecentKopLinks erin. als die er niet in staat staat er geen 
	// advertentie en kan de div eruit.
	// 30-06 google doet het nu met iframes!
	if (gebi('google_ads_div_'+adkey+side)||gebi('google_ads_iframe_'+adkey+side)){
		//adblok is gevuld, lekker laten staan
	}else{
		lowerside=side.toLowerCase()
		gebi('advertentie-'+lowerside).className='hidden'
	}
	if(gebi('advertentie-rechts').className=='hidden'&gebi('advertentie-links').className=='hidden'){
		// geen advertenties dus advertentiebalk mag ook minder hoog
		gebi('advertenties').style.height='11px';
	}
}

