var areq=''
function checkInstellingsType(iType) {
	var isMV
	if(iType=='maatschap'||iType=='vakgroep'){isMV=true}else{isMV=false}
	gebi('intermediairTr').className=(iType == 'intermediair'? 'shown':'hidden')
	gebi('noIntermediairTr').className=(iType=='intermediair'?'hidden':'shown')
	gebi('vac_cp_specialisme').className=(isMV?'shown':'hidden')
	gebi('vac_cp_medspace').className=(isMV?'shown':'hidden')
}
var frm=document.forms[0]
var errFields
var doSubmit
function checkUserName(UserName){
	var userNameField=gebi('vac_cp_username')
	if(checkUserNameSyntax(userNameField.value)){
		//sterretje 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)
		loadXMLDoc('/medweb/vacature.nsf/(gebruikers)?readviewentries&startkey=' + UserName+'&untilkey='+ UserName +'0~&anyPar='+randomU)
	}else{
		alert('Gebruikersnaam mag alleen letters en cijfers bevatten')
		addError('Gebruikersnaam mag alleen letters of cijfers bevatten',userNameField)
		userNameField.focus()
	}
}
function processReqChange() {
	if (req.readyState == 4){ 	
		// only if req shows "loaded"
		if (req.status == 200) {  					
			// only if "OK"
	 		var entriesDoc = req.responseXML;
			var entries = entriesDoc.getElementsByTagName("viewentry")
			if (entries.length!=0){
				var str='De door u gekozen gebruikersnaam\n'
				str+=gebi('vac_cp_username').value
				str+= '\nbestaat al!\n\nKies een andere gebruikersnaam.'
				alert(str);
				gebi('vac_cp_username').className='error'
				gebi('vac_cp_username').value=''
				gebi('vac_cp_username').focus()
			}else{
				unError(gebi('vac_cp_username'))
			}
		}
	}
}
function checkSubmit(isnew){
	var frm=document.forms[0]
	var err= 'De volgende velden zijn niet of niet correct ingevuld:\n\n'
	errFields = ''
	doSubmit= true
	if (frm.vac_cp_voorletters.value==''){
		addError('Voorletters', frm.vac_cp_voorletters)
	}else{
		unError(frm.vac_cp_voorletters)
	}
	if (frm.vac_cp_naam.value==''){
		addError('Achternaam', frm.vac_cp_naam)
	}else{
		unError(frm.vac_cp_naam)
	}
	if (frm.vac_cp_telefoonnr.value==''){
		addError('Telefoonnummer', frm.vac_cp_telefoonnr)
	}else{
		unError(frm.vac_cp_telefoonnr)
	}
	if (frm.vac_cp_email.value=='') {
		addError('E-mailadres', frm.vac_cp_email)
	} else {
		if(checkEmailAddress(frm.vac_cp_email.value) == false){
			addError('E-mailadres', frm.vac_cp_email)
		}else{
			unError(frm.vac_cp_email)
		}
	}
	if(isnew=="new"){			
		if (frm.vac_cp_instellingstype[frm.vac_cp_instellingstype.selectedIndex].value!='intermediair'){
			if(frm.vac_cp_instelling.value==''){
				addError('Naam zorginstelling', frm.vac_cp_instelling)
			}else{
				unError(frm.vac_cp_instelling)
			}
		}
		if(frm.vac_cp_instellingstype[frm.vac_cp_instellingstype.selectedIndex].value=='intermediair' && frm.vac_cp_firma.value ==''){	
			addError('Naam plaatsingsbureau', frm.vac_cp_firma)
		}else{
			unError(frm.vac_cp_firma)
		}
	}
		
	if (frm.vac_cp_adres.value==''){
		addError('Adres', frm.vac_cp_adres)
	}else{
		unError(frm.vac_cp_adres)
	}
	if (frm.vac_cp_postcode.value==''){
		addError('Postcode', frm.vac_cp_postcode)
	}else{
		unError( frm.vac_cp_postcode)
	}
	if (frm.vac_cp_plaats.value==''){
		addError('Plaats', frm.vac_cp_plaats)
	}else{
		unError(frm.vac_cp_plaats)
	}
	if (frm.vac_cp_username){
		if (frm.vac_cp_username.value == '' || frm.vac_cp_username.value =='Kies gebruikersnaam' ){
			addError('Gebruikersnaam', frm.vac_cp_username)
		}else{
			unError(frm.vac_cp_username)
		}
	}	
	if (frm.vac_cp_password.value == ''){
		addError('Wachtwoord', frm.vac_cp_password)
	}else{
		unError(frm.vac_cp_password)
	}
	if (frm.vac_cp_password.value!=frm.vac_cp_password2.value){
		addError( 'Wachtwoorden niet gelijk', frm.vac_cp_password2)
	}else{
		unError(frm.vac_cp_password2)
	}
	
	if (doSubmit == false) {
		alert(err + errFields)
	} else {
		if (frm.vac_cp_username){
			setLoginCookie(frm.vac_cp_username.value, frm.vac_cp_password.value)
		}
	}	
	return doSubmit
}
var currentDiv;
function ShowDiv(divToShow) {
	divToShow=(divToShow=='')?'uwgegevens':divToShow
	if (currentDiv && currentDiv!=divToShow) {
		currentDiv.className = 'hidden'
	}
	gebi(divToShow).className = 'shown'
	if(divToShow=='uwgegevens'){
		gebi('hbterugbut').className='hidden'
		gebi('hbannuleerbut').className='button'
		gebi('hbbewerkbut').className='button';
	}else{
		gebi('hbterugbut').className='button'
		gebi('hbannuleerbut').className='hidden'
		gebi('hbbewerkbut').className='hidden';
		
	}	
	currentDiv = gebi(divToShow)
}		
function showContextMenu(newMenuName, oldMenuName){
	var li = document.getElementById(newMenuName + 'Li')
	if (li) li.innerHTML = getContextMenuName(newMenuName)
	if (oldMenuName!= '') {
		li = document.getElementById(oldMenuName + 'Li')
		if (li) li.innerHTML = '<a href="javascript:ShowDiv(\''+oldMenuName+'\')">'+getContextMenuName(oldMenuName)+'</a>'
	}	
	setContextMenuLi(newMenuName, 'uwgegevens', 'uwgegevenschangeLi');
	setContextMenuLi(newMenuName,'uwinstellingspagina', 'instellingnewLi');
}
function setContextMenuLi(newMenuName,liid, setli){
	var li = document.getElementById(setli)
	if (li) li.className = (newMenuName == liid) ? 'shown': 'hidden'	
}
function getContextMenuName(liid){
	switch (liid){
		case 'uwgegevens' : return 'Uw gegevens';
		case 'uwvacatures' :  return 'Actuele vacatures';
		case 'uwvacaturearchief' : return 'Vacature archief';
		case 'uwinstellingspagina' : return 'Uw instellingspagina';
		case 'uwreacties' : return 'Reacties';
		case 'uwstatistieken' :  return 'Statistieken'
	}
	return ''
}
function openEntry(id){
	if (id ==''){
		var url = dbPath + '/entry?openform&div='+currentDiv.id
	} else {
		var url = dbPath +'/vacaedit/'+id+'?opendocument&div='+ currentDiv.id
	}
	window.location = url
}
function wisConcept(id){
	if(confirm('Weet u zeker dat u dit concept wilt verwijderen?')){
		var username=mcv('MWVaca2010-Naam')
		var url='/medweb/vacature.nsf/conceptwisser?openagent&id='+id+'&user='+username+'&div=uwvacatures'
		document.location.href=url
	}
}
function stopVacature(id){
	var username=mcv('MWVaca2010-Naam')
	var url='/medweb/vacature.nsf/stopper?openagent&id='+id+'&user='+username+'&div=uwvacaturearchief'
	document.location.href=url
}
function herstartVacature(id){
	var username=mcv('MWVaca2010-Naam')
	var url='/medweb/vacature.nsf/starter?openagent&id='+id+'&user='+username+'&div=uwvacatures'
	document.location.href=url
}
function herplaatsVacature(id,land){
	var username=mcv('MWVaca2010-Naam')
	var url='/medweb/vacature.nsf/herplaatser?openagent&id='+id+'&user='+username+'&div=uwvacaturearchief'
	loadAgentXMLDoc(url)
}
function loadAgentXMLDoc(url) {
	if (isFF) { 						// branch for native XMLHttpRequest object
		areq = new window.XMLHttpRequest();
		areq.onreadystatechange = agentProcessReqChange;
		areq.open("GET", url, true);
		areq.send(null);
	} else if (isIE) {						// branch for IE/Windows ActiveX version
		areq = new ActiveXObject("Microsoft.XMLHTTP");
		if (areq) {
			areq.onreadystatechange = agentProcessReqChange;   	
			areq.open("GET", url, true);
			areq.send();
		}
	}
}
function agentProcessReqChange() {
	if (areq.readyState == 4){ 	
		// only if req shows "loaded"
		if (areq.status == 200) {  					
			// only if "OK"
			//agent is klaar
			openInfoOverlay('resp_vacatureherplaatst','nl')
	 	}
	}
}	
function showClientHulpText(nm, value){}
function setClientHulp(txt, px){
	if (txt =='') return ''
	hulpSpacerGif.style.height = px +'px'
	return txt + '<\/p>'
}
function addOption(txt, value){
	var inst = frm.vac_cp_instelling_id;
	var s = inst.length
	inst.options[s] = new Option(txt,value);
	inst.selectedIndex = s
}
function setLoginCookie(nm, pw){
	var CookiePrefix='MWVaca2010'
	var name = CookiePrefix + '-Naam';
	var wachtwoord = CookiePrefix + '-Wachtwoord';
	
    	var today = new Date();
  	var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000);
  
   	 if (nm != null && nm != "")
   	 	{
      	document.cookie= name + "=" + escape(nm) + "; path=/ ; expires=" + expiry.toGMTString();
      	document.cookie= wachtwoord + "=" + escape(pw) + "; path=/ ; expires=" + expiry.toGMTString();
  		}
}
function showTarievenInPopUp(siteCountry){
	var url = dbPath + '/infodisp'+siteCountry+'/informatie?opendocument&form=popupinfopage'
	window.open(url,'prices','height=400,width=620, top=150, left=150, location=0, menubar=0, resizable=0, status=0, toolbar=0, titlebar=0, scrollbars=1')
}
function createInstelling(){
	var url= dbPath + '/instnew?openform'
	window.open(url,'instelling','height=600,width=620, top=150, left=150, location=0, menubar=0, resizable=0, status=0, toolbar=0, titlebar=0, scrollbars=1')
}
function getTavInfo(tav) {
	var frm = document.forms[0];
	if (tav != '' ) return tav
	tav = tav + getTavValue(frm.vac_cp_gesl.value);
	tav = tav + getTavValue(frm.vac_cp_voorletters.value);
	tav = tav + getTavValue(frm.vac_cp_tussenvoegsel.value);
	tav = tav + frm.vac_cp_naam.value;
	return tav;
}
function getTavValue(txt){
	if (txt == '') return ''
	return txt+ ' '
}

