function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function setCounter(limitField, limitCount, limitNum) {
	if(limitCount == null) return;
	if((limitNum - limitField.value.length) >= 0) {
		limitCount.value = limitNum - limitField.value.length;
	}else limitCount.value = 0;
}

var PZNDEBUG = 0;

function alterString(src, str, place){
	if(src == '') return src;
	
	if(place == 'voor') return str + src;
	if(place == 'na' || place == 'achter') return src + str;
	else return src;
}


function relocate(where) {
	window.location = where;	
}

function sureRelocateBlank(where){
	if(confirm("Weet je het zeker?")) {
		relocateBlank(where);
	}
}

function sureRelocate(where){
	if(confirm("Weet je het zeker?")){
		relocate(where);
	}
}

function relocateBlank(where) {
	window.open(where, 'PZN');
}

function conditionalRelocateBlank(condition, where1, where2) {
	if(condition) 
		window.open(where1, 'PZN');
	else
		window.open(where2, 'PZN');
}

function sure(msg, url) {
	if(confirm(msg)) {
		relocate(url);
	} 	
}

function reallysure(msg, msgreally, url) {
	if(confirm(msg)) {
		if(confirm(msgreally)) {
			relocate(url);	
		}
	} 	
}

function openHelp(theURL) {
	window.open(theDomain + theURL, 'pznhelp', 'toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=1,width=790,height=625');
}

function videoLink(theVideo) {
	var theURL = "index.php?module=faq&action=category&video=" + theVideo;
	window.open(theDomain + theURL, 'pznvideo', 'toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=1,width=790,height=625');
}

/* 5 minutes before refresh */
var keepAliveTime = 5*60*1000;

function pznInit() {
	
	//resizeImage('foto_', 75);
	
	
	setTimeout('keepAlive();', keepAliveTime);
}

function keepAlive() {
	
	dummy = new Image();
	
	theUrl = theDomain + 'index.php?module=login&action=keepalive&rand=' + Math.round( Math.random()* 1000000, 0);
	
	dummy.src = theUrl;
	
	setTimeout('keepAlive();', keepAliveTime);
}

function addPostfix( postfix ) {
	
	var loc = '' + window.location;
	
	loc = stripAnchor( loc );
	
	if(loc.indexOf('?') != -1) {
		
		//Add using &
		loc += '&' + postfix;
		
	} else {
		//Add using ?
		loc += '?' + postfix;
	}

	return loc;
}

function stripAnchor( URL ) {
	
	var pos = URL.indexOf('#');
	
	if(pos != -1) {
		URL = URL.substring(0, pos);
	}
	
	return URL;
	
}

function flashMovie( url, width, height ) {
	
	theObj = '' +
	'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' +
	'	codebase="https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ' +
	'	width="_WIDTH_" ' +
	'	height="_HEIGHT_" ' +
	'	id="2389802349" ' +
	'	align="middle">' +
	'	' +
	'	<param name="allowScriptAccess" value="sameDomain" />' +
	'	<param name="movie" value="_URL_" />' +
	'	<param name="quality" value="high" />' +
	'	<param name="bgcolor" value="#ffffff" />' +
	'	' +
	'	<embed src="_URL_" ' +
	'		quality="high" ' +
	'		bgcolor="#ffffff" ' +
	'		width="_WIDTH_" ' +
	'		height="_HEIGHT_" ' +
	'		name="PZN Video" ' +
	'		align="middle" ' +
	'		allowScriptAccess="sameDomain" ' +
	'		type="application/x-shockwave-flash" ' +
	'		pluginspage="https://www.macromedia.com/go/getflashplayer" />' +
	'</object>';
	
	
	theObj = theObj.replace( /_URL_/g, 	url );
	theObj = theObj.replace( /_WIDTH_/g, 	width );
	theObj = theObj.replace( /_HEIGHT_/g, 	height );
	
	write( theObj );
}

function resetScroll() {

	/* Do not scroll if current URL contains an anchor! */
	
	var URL = "" + window.location;
	
	if( URL.indexOf( '#') != -1) {
		//Anchor found, do not reset scroll;
		return;
	}
	
	var scrollX = 0;
	var scrollY = 0;
	
	if( (scrollY = Get_Cookie( 'scrollY' )) ) { 
		scrollTo(0, scrollY);
		
		//Now reset cookie otherwise scroll will remain
		Delete_Cookie( 'scrollY' );
	} 
	
}

function leavePage() {
	
	//Save scroll position of last page.
	var x = 0;
	var y = 0;
	
	if(document.all) {
		//x = document.body.scrollLeft;
		y = document.body.scrollTop;
		var y2 = document.documentElement.scrollTop;
		if(y2>y) y = y2;
	} else {
		//x = window.pageXOffset;
		y = window.pageYOffset;
	}
	
	Set_Cookie( 'scrollY', y, 1 );
}

function resizeImage(tag, max) {
	for(var i=0; i<document.images.length; i++) {

		img = document.images[i];

		if(img.id.indexOf(tag) > -1) {
			
			var factor;
			if(img.height < max && img.width < max) {
				factor = 1;
			} else {
				(img.height > img.width) ? factor = img.height / max : factor = img.width / max;
			}

			img.width = (img.width / factor);
			//img.height = (img.height / factor);
		}
	}
}

function checkBrowser() {
	nav = navigator.userAgent;
	nav = nav.toUpperCase();
	
	if( (nav.indexOf("MSIE") > -1) && (nav.indexOf("MAC") > -1) ) {
		//The bad browser has been found.
		alert("U gebruikt Internet Explorer op de Mac.\nDeze browser werkt slecht op deze site.\nWij raden Firefox aan als alternatief");
	}
}

function makeLink(str) {
	window.opener.document.getElementById("attachment").value = str;
	self.close();	
}

function switchByID(id, firstClass, secondClass) {
	i = 1;
	while( (element = document.getElementById(id + i++)) != null ) {
		if(element.className == firstClass) {
			element.className = secondClass;
		} else  element.className = firstClass;
	}
}

function switchBySpecificID(tag, id, firstClass, secondClass, classForZero) {
	i = 1;
	while( (element = document.getElementById(tag + i)) != null ) {
		if(id == i) {
			element.className = firstClass;
		} else  element.className = secondClass;
		
		i++;
	}
	
	element = document.getElementById(tag + '0');
	element.className = classForZero;
}


function switchBySingleID(id, firstClass, secondClass) {
	element = document.getElementById(id);
	
	if(element.className == firstClass) {
		element.className = secondClass;
	} else  element.className = firstClass;
}

function switchImage(obj, first, second) {
	str = obj.src; 
	begin = str.substring(0,str.indexOf('images'));
 	first  = begin + first;
	second = begin + second;
	if(obj.src == first) obj.src = second;
	else obj.src = first;
}

function debugDOM(element) {
	
	str = '';
	counter = 0;
	for(aap in element) {
		if(++counter > 10) {
			alert(str);
			counter = 0;
			str = '';
		}
		str += aap + ':\t' + element[aap] + "\n";
	}
}

function switchClass(id, cname, caltname) {
	obj = getObjReference(id);
	
	if(obj.className == cname) {
		obj.className = caltname;
	} else {
		obj.className = cname;
	}
}

function getObjReference(name) {
	element = document.getElementById(name);
	
	if(element == null) {
		if(PZNDEBUG == 1) {
			alert("getObjReference(" + name + "): no such object found!");
		}
	}
	return element; 
}

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

function submitenter(myfield,e) {
	var keycode;

	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13) {
   		myfield.form.submit();
   		return false;
   	} else {
   		return true;
	}
}

function padTime(string) {
	string = new String(string);
	if(string.length == 1) return "0" + string;
	
	return string;
}

function hasValue(theArray, theValue) {
	for(val in theArray) {
		if(theArray[val] == theValue) return val;
	}
	
	return -1;
}

function addEvent(obj, evType, fn){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, true);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}

function getRadioValue(el) {
	for (var i=0; i < el.length; i++) {
		if (el[i].checked) {
			return el[i].value;
		}
	}
}


function dayOfWeek(day, month, year)  {
	if (month > 2) {
	    month -= 2;
	} else {
	    month += 10;
	    year--;
	}

	day = ( Math.floor((13 * month - 1) / 5) +
	    day + (year % 100) +
	    Math.floor((year % 100) / 4) +
	    Math.floor((year / 100) / 4) - 2 *
	    Math.floor(year / 100) + 77);
	    
	var weekday_number = ((day - 7 * Math.floor(day / 7)));
	
	/* Correct sunday to the 7th day instead of zeroth day */
	if(weekday_number == 0) weekday_number=7;
//	alert(" day of week: " +weekday_number);
	return weekday_number;	
	
}

// flag == true disabled alles, flag == false enabled alle elementen
function disableFormElements(flag) {
	for(var i = 0; i < document.forms.length; i++) {
		for(var j = 0; j < document.forms[i].elements.length; j++) {
			document.forms[i].elements[j].disabled = flag;
		}
	}
}

function shortLastName(lastName) {
	
	var skipNames = new Array( 
		'van',
		'der',
		'v/d',
		'vd',
		'den',
		'het',
		'in',
		'des',
		'de',
		'\'s',
		'\'',
		'en'	
	);
	
	var pieces = lastName.split(' ');
	var goodPieces = new Array();
	
	for(i=0; i<pieces.length; i++) {
	
		var ok = 1;
		
		for(j=0; j<skipNames.length; j++) {
			
			if( pieces[i] == skipNames[j] ) {
				ok = 0;
			}
		}
		
		
		
		if(ok == 1) goodPieces.push(pieces[i]);
	}
	
	var shortName = '';

	for(i=0; i<goodPieces.length; i++) {
		shortName += goodPieces[i].substring(0,1);
	}
	
	return shortName.toUpperCase();
}

function initials(voornaam, achternaam) {
	
	return '' + voornaam.substring(0,1) + shortLastName(achternaam);
	
}

function write(str) {
	document.write(str);
}


function getItemInURL(theArgName) {
	var sArgs = location.search.slice(1).split('&');
	var r = '';

	for (var i = 0; i < sArgs.length; i++) {
        if (sArgs[i].slice(0,sArgs[i].indexOf('=')) == theArgName) {
        	r = sArgs[i].slice(sArgs[i].indexOf('=')+1);
            break;
        }
    }
    
    
	return (r.length > 0 ? unescape(r).split(',') : '')
}

function Get_Cookie( name ) {
	
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
	var today = new Date();

	today.setTime( today.getTime() );
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

/**
 * Laat een messagebox zien met alle attributen van het gegeven object
 * 
 * @param object het object waarvan de attributen getoond worden
 * @param functions boolean, laat al dan niet functies zien
 */
function printObject(object,functions){
	var text = '';
	for(val in object){
		if(typeof(object[val]) != 'function' || functions){
			if(object[val] != null){
				text += val + ' = ' + object[val] + '\n';
			}
		}
	}
	
	alert(text);
}

var straat_done = false;
var postcode_woonplaats_done = false;
var woonplaats_done = false;
/**
 * Gets the user location according to the specified zipcode
 * Initialize the *_done variables to false, as well as VOnaam!
 *
 * Zoekt naar 1) straatnaam, woonplaats
 * 			  2) postcode, woonplaats
 * 			  3) woonplaats
 */
 
var VOnaam = false;
var straat_done = postcode_woonplaats_done = woonplaats_done = false;
 
function getLocation(vo){
	if(!VOnaam) VOnaam = vo;

	var postcode = document.getElementById(VOnaam + '_postcode').value;
		postcode = postcode.toUpperCase();
	var woonplaats = document.getElementById(VOnaam + "_woonplaats").value;

	if(VOnaam== "VacatureVO"){
		var adres = 'not important';
		straat_done = true;
	}else 	var adres = document.getElementById(VOnaam + "_adres").value;
		
   if(postcode!='' && woonplaats!='' && adres!='') {
	   
   		var client = new GClientGeocoder();
	    if(!straat_done){
	    	straat_done = true;
	     	client.getLocations(adres + ", " + woonplaats + ", Netherlands", submitLocationStrict);
			return false;
	     }else if(!postcode_woonplaats_done && postcode.match(/[0-9]{4}[A-Z]{2}/)){
	    	postcode_woonplaats_done = true;
	    	client.getLocations(woonplaats + ", " + postcode + ", Netherlands", submitLocationStrict);
			return false;
	 	}else if(!woonplaats_done) {
	 		woonplaats_done = true;
	    	client.getLocations(woonplaats + ", Netherlands", submitLocation);
			return false;
	 	} else {
	 		woonplaats_done = straat_done = postcode_woonplaats_done = false;
			alert('Vul een geldig adres in');
	 	 	return false;
	 	}
	 	return false;
	}
	return true;
}

function submitLocationStrict(response){
	submitLocation(response, true);	
	
}
/**
 * Sets the latitude and longitude in the hidden input and submits the form.
 */
function submitLocation(response, be_strict){
	if(response.Status.code == 200 && response.Placemark[0].AddressDetails.Country.CountryNameCode == "NL" && (response.Placemark[0].AddressDetails.Accuracy<9 || !be_strict)) {

		country = response.Placemark[0].AddressDetails.Country;

		document.getElementById("LocationVO_land").value = country.CountryNameCode;

		if(adminArea = country.AdministrativeArea) {
			document.getElementById("LocationVO_provincie_id").value = adminArea.AdministrativeAreaName;
			if(locality = adminArea.SubAdministrativeArea){
				document.getElementById("LocationVO_gemeente_id").value = locality.SubAdministrativeAreaName;
			
				if(dependentlocality = adminArea.SubAdministrativeArea.Locality.DependentLocality) {
					document.getElementById("LocationVO_woonplaats_id").value = dependentlocality.DependentLocalityName;	
				} 			
			}
		}

		document.getElementById("LocationVO_precisie").value = response.Placemark[0].AddressDetails.Accuracy;	
		document.getElementById("LocationVO_latitude").value = response.Placemark[0].Point.coordinates[1];
		document.getElementById("LocationVO_longitude").value = response.Placemark[0].Point.coordinates[0];

		/* Sla de gegevens op grond waarvan we een hit hebben gehad */
		if(straat_done && !postcode_woonplaats_done) {
			document.getElementById("LocationVO_adres").value = document.getElementById(VOnaam + "_adres").value;
		} else if (postcode_woonplaats_done && !woonplaats_done) {
			document.getElementById("LocationVO_postcode").value = 
								document.getElementById(VOnaam + "_postcode").value;
		} else { // woonplaats_done
		
		}

		document.getElementById('registerform').submit();
	}else{
		getLocation();
	}
	//stopLoading();
}

/**
 * Bookmarks the given url under the given title. Works for
 * ff, ie and opera.
 */
function bookmarkthis(title,url) 
{
	if (window.sidebar) { // firefox
		window.sidebar.addPanel(title, url, "");
	} 
	else if (document.all) { // IE
		window.external.AddFavorite(url, title);
	} 
	else if (window.opera && window.print) { // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
}


function getBrowserWidth(){
	if (self.innerHeight){ //all except Explorer
		return self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientHeight){ //IE6 strict
		return document.documentElement.clientWidth;
	}
	else if (document.body){ // other Explorers
		return document.body.clientWidth;
	}
	return 0;
}

function getBrowserHeight(){
	if (self.innerHeight){ //all except Explorer
		return self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight){ //IE6 strict
		return document.documentElement.clientHeight;
	}
	else if (document.body){ //other Explorers
		return document.body.clientHeight;
	}
	return 0;
}

function formatFilesize(size){
	if(size / (1024*1024) > 1000){
		return Math.round(size / (1024*1024*1024) * 100) / 100 + 'GB';
	}else if(size / 1024 > 100000){
		return Math.round(size / (1024*1024)) + 'MB';
	}else if(size / 1024 > 10000){
		return Math.round(size / (1024*1024) * 10) / 10 + 'MB';
	}else if(size / 1024 > 1000){
		return Math.round(size / (1024*1024) * 100) / 100 + 'MB';
	}else if(size > 100000){
		return Math.round(size / 1024) + 'KB';
	}else if(size > 10000){
		return Math.round(size / 1024 * 10) / 10 + 'KB';
	}else if(size > 1000){
		return Math.round(size / 1024 * 100) / 100 + 'KB';
	}else{
		return Math.round(size) + 'B';
	}
}

function toggleHulp(el){
	if(el.checked){
		document.getElementById('HulpVO'+el.value+'_tarief').style.visibility = 'visible';
	}else document.getElementById('HulpVO'+el.value+'_tarief').style.visibility = 'hidden';
	refreshLeeftijdsgroepen();
}
			
function initHulp(){
	var els = document.getElementsByName('hulp[]');
	for(var i =0; i<els.length; i++) toggleHulp(els[i])
}
function loadInfoPopup(url, caption) {
	$('.popup_content').html('<iframe frameborder="0" src="'+theDomain + url+'" id="info_popup"></iframe>');
	popup_show(caption,'info_popup',800);
}

/* For CheckboxTextFormfield */
function toggleTextboxDisabled(key) {
	if($('#' + key + '_checkbox').attr('checked')) {
		$('#' + key).attr("disabled", "disabled");
		$('#' + key).val('');
	} else {
		$('#' + key).removeAttr("disabled");
		$('#' + key + '_checkbox').removeAttr('checked');
	}
}

function refreshLeeftijdsgroepen(){
	if(
		$("#kinderopvang_table").find("input:checked").length != 0 &&
		$("#thuiszorg_table").find("input:checked").length == 0 &&
		$("#huishoudelijk_table").find("input:checked").length == 0 &&
		$("#dagopvang_table").find("input:checked").length == 0
	){
		//hide oudere categorien.
		$("#LeeftijdscategorieVOList3").parent().parent().hide();
		$("#LeeftijdscategorieVOList4").parent().parent().hide();
		$("#LeeftijdscategorieVOList5").parent().parent().hide();
	}else{
		$("#LeeftijdscategorieVOList3").parent().parent().show();
		$("#LeeftijdscategorieVOList4").parent().parent().show();
		$("#LeeftijdscategorieVOList5").parent().parent().show();
	}

	
}

function toggleHulptype(hulptype){

	if($("#"+hulptype+"_table").find("input:checked").length || hulptype == chosen_type){
		$("#"+hulptype+"_table").show();
		$("#"+hulptype+"_arrow").attr('src', theDomain+'images/new/dropdown_out.png');
	}else{
	 	$("#"+hulptype+"_table").toggle();
	 	if($("#"+hulptype+"_arrow").attr('src')==theDomain+'images/new/dropdown_in.png'){
	 			var arrow_image =theDomain+'images/new/dropdown_out.png'
	 	}else 	var arrow_image = theDomain+'images/new/dropdown_in.png' ;
	 	$("#"+hulptype+"_arrow").attr('src',  arrow_image);
	}
}

var kind_hulpids = [0, 1, 2, 3, 4]; //no, these are not the actual db ids..
var hh_hulpids = [10, 11, 12, 13, 14]; //no, these are not the actual db ids..

function checkQualityHulp() {
	 var found_hh = false;
	 var found_non_hh = false;
    $('input[name="hulp[]"]:checked').each(
		function(){
			if(in_array($(this).val(),  hh_hulpids))
				found_hh = true;
			else found_non_hh = true;
		}
   	)
	
    if(found_hh && !found_non_hh) {
    	$('tr[id=quality_za_hh]').hide();
    	$('tr[id=quality_zb_hh]').hide();
    	$('#specialty_fieldset').hide();
    	$('.leeftijdscategorielist').hide();
    } else{
    	$('tr[id=quality_za_hh]').show();
    	$('tr[id=quality_zb_hh]').show();
    	$('#specialty_fieldset').show();
    	$('.leeftijdscategorielist').show();
    }
    
    var found_kind = false;
    $('input[name="hulp[]"]:checked').each(
		function(){
			if(in_array($(this).val(),  kind_hulpids))
				found_kind = true;
		}
   	)

   	if(found_kind){
   		 $('tr[id=quality_za_kinder]').show();
   		 $('tr[id=quality_zb_kinder]').show();
	}else{
		 $('tr[id=quality_za_kinder]').hide();
		 $('tr[id=quality_zb_kinder]').hide();
	}	
}

function zorgtypeString(string){ 
	if($("#kinderopvang_table").find("input:checked").length > 0)
		string += "||1";	
	if($("#thuiszorg_table").find("input:checked").length > 0)
		string += "||2";	
	if($("#huishoudelijk_table").find("input:checked").length > 0)
		string += "||3";	
	if($("#dagopvang_table").find("input:checked").length > 0)
		string += "||4";	

	return string;

}

function in_array( what, where ){
    var a=false;
    for(var i=0;i<where.length;i++){
	    if(what == where[i]){
	    	return true;
	    }
    }
    return false;
}

/**
 * Gets the user location according to the specified zipcode
 */
 
function getStartLocation()
{
	zipcodeInput = document.getElementById("zipcode");
	
	if(zipcodeInput && zipcodeInput.value!='') {
	    var	zipcode_city = zipcodeInput.value;
	    if(zipcode_city.match(/[0-9]{4}[A-Z]{2}/)){
	    	zipcode_city = zipcode_city.toUpperCase();
	    }
	   	var client = new GClientGeocoder();
	  	client.getLocations(zipcode_city + ", Netherlands", submitStartLocation);	
		return false;
	}else{
	   	alert("Vul woonplaats of postcode in.");

	   	return false;
	} 
}

/**
 * Sets the latitude and longitude in the hidden input and submits the form.
 */
function submitStartLocation(response) 
{	
	if(response.Status.code == 200) {
	
		document.getElementById("LocationVO_latitude").value = response.Placemark[0].Point.coordinates[1];
		document.getElementById("LocationVO_longitude").value = response.Placemark[0].Point.coordinates[0];
		var adminArea, locality;
		
		try {
			if(! response.Placemark[0].AddressDetails.Country || response.Placemark[0].AddressDetails.Country.CountryNameCode != 'NL') {
				alert("Voer een juiste postcode en woonplaats in.");
				return false;
			}
		} catch(e) {}
		
		if(adminArea = response.Placemark[0].AddressDetails.Country.AdministrativeArea) {

			if(locality = adminArea.SubAdministrativeArea) {
				document.getElementById("LocationVO_gemeente_id").value = locality.SubAdministrativeAreaName;
			}
		} 
		document.getElementById('searchform').submit();
		
	}else {
		alert("Voer een juiste postcode en woonplaats in.");
	}

	return false;
}

