function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function openCv(link) {
	window.open(link, "cv", "toolbar=no, location=no, directories=no, status=yes, menubar=no," 
		+ "scrollbars=yes, resizable=yes, width=510, height=700");
}

function viewAssignment(link) {
	window.open(link, "cv", "toolbar=no, location=no, directories=no, status=yes, menubar=no," 
		+ "scrollbars=yes, resizable=yes, width=510, height=400");
}

function openAssign(link) {
	window.open(link, "cv", "toolbar=no, location=no, directories=no, status=yes, menubar=no," 
		+ "scrollbars=yes, resizable=yes, width=510, height=700");
}

function openMail(link) {
	window.open(link, "cv", "toolbar=no, location=no, directories=no, status=no, menubar=no," 
		+ "scrollbars=yes, resizable=yes, width=375, height=400");
}

function setDisplay(id) {
	if (getCookie(id) == 'block') {
		document.getElementById(id).style.display = "block";
	}
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function hide(id) {
	setCookie(id, 'none');
	document.getElementById(id).style.display = "none";
}
function show(id) {
	setCookie(id, 'block');
	document.getElementById(id).style.display = "block";
}

function submitForm(formname)
{
	 eval('document.' + formname + '.submit();');
}

function checkForm(frm) {
	var el = eval('document.' + frm + '.elements');
	
	var phoneRegExp = new RegExp('^[0-9]{10}$'); 
	var zipRegExp 	= new RegExp('^[0-9]{4}$'); 
	var cRegExp 	= new RegExp('^[A-Z]{2}$'); 
	for (var i=0; i<el.length; ++i) {
			
			if ((el[i].id == "required") && (el[i].value.length == 0)) {
				alert('Niet alle verplichte velden zijn ingevuld!');
				return;
			}			
			
			if (el[i].name == "cvPostcode") {
				if (zipRegExp.test(el[i].value) == false) {
					alert('Formaat postcode cijfer is onjuist\nMoet vier cijfers bevatten: 1234');
					return;
				}
			}
			
			if (el[i].name == "cvPostcodeC") {
				if (cRegExp.test(el[i].value) == false) {
					alert('Formaat postcode is onjuist\nMoet zoals: \'AB\' in hoofdletters');
					return;
				}
			}
			
			if (el[i].name == "cvTelefoon") {
				if (phoneRegExp.test(el[i].value) == false) {
					alert('Formaat telefoonnummer is onjuist\nMoet 10 cijfers bevatten');
					return;
				}
			}
			if (el[i].name == "cvMobiel") {
				if(phoneRegExp.test(el[i].value) != '') {
					if (phoneRegExp.test(el[i].value) == false) {
						alert('Formaat telefoonnummer is onjuist\nMoet 10 cijfers bevatten');
						return;
					}
				}
			}
	}
	eval('document.' + frm + '.submit();');
}

function confirmDelete(url, object) {
	if (confirm('Weet u zeker dat u ' + object + ' wilt verwijderen?')) {
		document.location = url;
	}
}

function confirmChange(url, object) {
	if (confirm('Als u de ' + object + ' wilt wijzigen, moet u alle zoekgegevens opnieuw invullen. Klik op ok om door te gaan.')) {
		document.location = url;
	}
}
function parentUrl(url) {
	opener.document.location = url;
	window.close();
}