	
$().ready(function(){
	// Clickhandlers for Gebieden
	$("#gebieden").click(function() {
		var oSel = document.getElementById("gebieden");
		var selectedIndex = oSel.selectedIndex;
		if(selectedIndex == -1) {
			return; // Er zijn geen options meer
		}
		
		var selectedValue = $(this).val();
		var alreadyAdded = false;
		$("#selectedGebieden option").each(function(i, elem) {
			if (selectedValue == $(this).val()) {
				alreadyAdded = true;
				return;
			}
		});
		if (!alreadyAdded) {
			var html = $("<option value=\""+$(this).val()+"\">"+$(this).val()+"</option>");
			$("#selectedGebieden").append(html);
		}
		oSel.options[selectedIndex] = null;
	});
	$("#selectedGebieden").click(function() {
		var oSel = document.getElementById("selectedGebieden");
		var selectedIndex = oSel.selectedIndex;
		if(selectedIndex == -1) {
			return; // Er zijn geen options meer
		}
		var html = $("<option value=\""+$(this).val()+"\">"+$(this).val()+"</option>");
			$("#gebieden").append(html);
		oSel.options[selectedIndex] = null;
	});
	
	$("#constructionYearFrom").change(function(){
		var val = $(this).val();
        if (val == "") {
            return;
        }
        val = parseInt(val, 10);
		if (val == 2000) {
			$("#constructionYearTo").val("");
		} else {
			if (val >= $("#constructionYearTo").val()) {
				$("#constructionYearTo").val(val + 10);
			}
		}
	})
	
	$("#constructionYearTo").change(function(){
		var val = $(this).val();
        if (val == "") {
            return;
        }
        val = parseInt(val, 10);
		if (val == 1910) {
			$("#constructionYearFrom").val("");
		} else {
			if (val <= $("#constructionYearFrom").val()) {
				$("#constructionYearFrom").val(val - 10);
			}
		}
	})
	
	
	
	
});

function checkValue(field, regexp) {
	var $field = $(field);
	var message = regexp.test(field.value) ? "" : $field.attr("message");
	if (message != "" ) {
		alert(message);
		// Doe dit in een aparte thread, een focus event op een blur event 
		// werkt haalt namelijk niets uit in FF.
		setTimeout(function(){$field.focus(), 0});
	}
}

function validateForm(oForm) {
	// Alle options selecteren bij gebieden, zodat die meegepost worden. 
	// Bij Plaatsen gebeurt dit via de CitySelection javascript klass.
	$("#selectedGebieden option").each(function(i, elem){
		this.selected = true;
	});
	
	if ($("#typeOfObject").val() == 5) {
		alert("Maak een keuze bij 'Soort object'");
		return false;	
	}
	// Plaatsnamen verplicht stellen (afh. settings)
	if (plaatsnamenVerplicht) {
		if ($("#selectedCities").children().size() == 0) {
			if ($("#province").is(":visible")) {
				alert("Kies een of meerdere plaatsen. Kies hiervoor eerst een provincie en klik daarna op de gewenste plaatsen.");
			} else {
				alert("Kies een of meerdere plaatsen");
			}
			return false;
		}
	}
	return processForm(oForm);
	
};

// $Id: xString.js 79497 2008-08-29 14:09:41Z fibbe03 $

String.prototype.leftTrim = function() {
	return this.replace( /^\s+/,"");
}

String.prototype.rightTrim = function() {
	return this.replace( /\s+$/g,"");
}

String.prototype.allTrim = function() {
	return this.replace(/^\s*(\S[\d\D]*\S)\s*$/,"$1");
}

String.prototype.trim	=	String.prototype.allTrim;

String.prototype.capitalize = function() {
	return this.substr(0,1).toUpperCase()+this.substr(1).toLowerCase();
}

String.prototype.capitalizeAll = function() {
	var pattern = /(\b.)(\w*\b)(.*)/;
	var oldValue = this;
	var returnString = '';
	var tmp;
	while(pattern.exec(oldValue)) {
		tmp = pattern.exec(oldValue);
		returnString += tmp[1].toUpperCase()+tmp[2].toLowerCase() + ' ';
		oldValue = tmp[3];
	}
	return returnString.rightTrim();
}

String.prototype.removeWhiteSpace = function(){
	var returnString = '';
	for(i=0;i<this.length;i++) {   
  	if(this.charAt(i)!=' ') {
   		returnString += this.charAt(i);
   	}
  }
  return returnString;
}

String.prototype.removeDots = function() {
	var returnString = '';
	for( var i = 0; i < this.length; i++ ) {
		returnString += this.charAt( i ) != "." ? this.charAt( i ) : "";
	}
	
	return returnString;
}

String.prototype.isNumeric = function() {
	var ValidChars = "0123456789.";
   	var IsNumber=true;
 	var Char;
 	if(!this.length) {
 		return false;
 	}
	for (var i = 0; i < this.length && IsNumber == true; i++) 
   	{ 
      Char = this.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsNumber = false;
      }
   	}
   	return IsNumber;
}

;

function CitySelection( formName , cityBoxName, selectedCityBoxName, provinceSelector) {

	this.form = document.forms[formName]; //naam formulier
	this.cityBox = this.form[cityBoxName]; //naam van de plaatsen box
	this.selectedCityBox = this.form[selectedCityBoxName]; //naam geselecteerde plaatsen box
	this.provinceSelector = this.form[provinceSelector]; //naam provincie dropdown

	this.exists = function() {
		alert("cities");
	};

	
	this.searchCities = function() {
		var province = this.provinceSelector.options[ this.provinceSelector.selectedIndex ].value; 
		//disable city box
		this.cityBox.disabled = true;
		//clear option
		this.cityBox.options.length = 0;
		//search array for selected province...

		var obj;
		
		for (var i in citiesAndProvincesJS){
			if(i.toLowerCase() == province.toLowerCase()){	
				obj = citiesAndProvincesJS[i].slice(0); //first element == province, elements 1 thru length == cities
			}
		}

		this.cityBox.options.length = 0;
		if(obj != null) {
			for(i=0;i < obj.length; i++) {
				this.cityBox.options[i] = new Option(obj[i],obj[i]);
			}
		}
		this.cityBox.disabled = false;
	};
	this.addCity = function(text) {
		if(this.cityBox.selectedIndex == -1) {
			return;
		}
		var selectedOption = this.cityBox.options[this.cityBox.selectedIndex];
		var isSelected = false;
		for(y=0;y < this.selectedCityBox.options.length; y++) {
			if(this.selectedCityBox.options[y].value == selectedOption.value){
				isSelected = true;
			}	
		}
		if( !isSelected ) {
			if(!text){
				this.selectedCityBox.options[this.selectedCityBox.options.length] = new Option(selectedOption.text,selectedOption.value);
			}
			else{
				this.selectedCityBox.options[this.selectedCityBox.options.length] = new Option(selectedOption.text,selectedOption.text);
			}
			isSelected = false;
		}
	};
	this.removeCity = function() {
		for(i=0;i < f.selected_cities.options.length; i++) {
			if( this.selectedCityBox.options[i].selected ) {
				this.selectedCityBox.options[i] = null;
			}
		}
	};
	this.selectAll = function( name ) {
		if(name == "selected") {


			for(i=0;i < this.selectedCityBox.options.length ; i++) {
				this.selectedCityBox.options[i].selected = true;
			}
		} else {
			for(i=0;i < this.cityBox.options.length ; i++) {
				this.cityBox.options[i].selected = true;
			}
		}
	};
	
	this.selectedCitiesClicked = function(elem) {
		var index = elem.selectedIndex;
		if (index == -1) {
			return;
		}
		elem.options[index] = null;
	}
	
	
	return this;
};

//$Id: formLib.js 114462 2010-08-17 14:25:35Z Gokhan $
//Copyright 2002-2003 BaseNet Internet Projects B.V., the Netherlands. All Rights Reserved.

if(!String.prototype.leftTrim) {
	alert('xString.js needed from jsLib');
}


function checkForm(fObject,scrollToWhenInvalid,disableHighLighting, invalidClassName){
	var tldList = "eu|ac|ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|info|int|io|iq|ir|is|it|je|jm|jo|jobs|jp|ke|kg|kh|ki|km|kn|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mobi|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|travel|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw";

	var validation 	= new RegExp();
	/* http://data.iana.org/TLD/tlds-alpha-by-domain.txt */
	var fElement;
	var input;
	var message;
	
	if(invalidClassName == null) {
		invalidClassName = 'Invalid';
	}
	
	for(i=0;i<fObject.elements.length;i++) {

		fElement 	= fObject.elements[i];
		fElement.highlight = function() {
			if(scrollToWhenInvalid) {
				window.scrollTo(0,this.offsetTop);
			}
			this.onfocus 	= null;
			fElement.highlightoff();
			this.className 	= this.className + invalidClassName;
		}
		fElement.highlightoff = function() {
			this.className 	= this.className.replace(invalidClassName,'');
		}
		input 		= fElement.value;
		message		= fElement.getAttribute('message');

		fElement.highlightoff();
		if((fElement.getAttribute('required') && input=='')) {
			window.alert(fElement.getAttribute('required'));
			fElement.focus();
			if(!disableHighLighting) {
				fElement.highlight();
			}
			return false;

		} else if(input!='') {
			if(fElement.getAttribute('validate') && fElement.getAttribute('validate') !== 'bankaccount') {
				switch (fElement.getAttribute('validate')) {
					case 'email':
						/* 	email must begin with a letter
						   	email may not contain more that one '@'
							name may contain - , _ or .
							domain may contain - or _
							doomain can contain more than one .
							space is not alowed */
						validation =  /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
						break;
					case 'alpha':
						validation = new RegExp('^[a-zA-Z\.]+$');
						break;
					case 'numeric':
						validation = new RegExp('^[0-9\\-\\s]+$');
						break;
					case 'decimal':
						validation = new RegExp('^[0-9](\.[0-9]+)?$');
						break;
					case 'greater_than_zero':
						validation = new RegExp('^[1-9]([0-9]+)?$');
						break;
					case 'alphanumeric':
						validation = new RegExp('^[a-zA-Z0-9]+$');
						break;
					case 'zipcode':
						validation = new RegExp('^[0-9]{4}[ ]?[A-Za-z]{2}$');
						/*
						 * Als een postcode valideerd op willekeurig postcode format.
						 * Zorg dan dat postcode ook nog mooi
						 * tiara 1.2 geformateerd wordt. bijv. 0000 AA
						 */
						if(validation.test(fElement.value )) 
						{
							fElement.value = fElement.value.toUpperCase();
							if(fElement.value.length === 6)
							{
								var tmp = fElement.value.substring(0,4) + " " + fElement.value.substring(4)
								fElement.value = tmp;
							}
						}
						break;
					case 'telephone':
						var t  = fElement.value.replace(/\s|\-|\+/g , "", "all");
						
						if(!t.isNumeric() || t.length < 10) {
							window.alert(message);
							fElement.focus();
							if(!disableHighLighting) {
								fElement.highlight();
							}
							return false;
						}
						break;
						
				}
				if( !validation.test(input) && fElement.getAttribute('validate') !== 'telephone' ){
					window.alert(message);
					fElement.focus();
					if(!disableHighLighting) {
						fElement.highlight();
					}
					return false;
				} else {
					if ( input.indexOf(">") != -1 || input.indexOf("/") !=-1){
						window.alert(message);
						fElement.focus();
						if(!disableHighLighting) {
							fElement.highlight();
						}
						return false;
					}
				}

			} else if(fElement.getAttribute('validate') && fElement.getAttribute('validate') == 'bankaccount'){
				
				var total = 0;
				var b = input.removeDots();
				var j = b.length;
				var succes = false;
				// Als string zonder dots niet geheel numeriek is.
				// Dan error
				if(!b.isNumeric())
				{
					window.alert(message);
					fElement.focus();
					if(!disableHighLighting) {
						fElement.highlight();
					}
					return false;
				}
				// Doe de elf proef berekening
				for (var y = 0; y < b.length; y++){
					total += (9 - y) * parseInt(b.substr(y, 1))
				}
				// als total 0 is altijd fout ...
				if(total ===  0 || j > 9) {
					window.alert(message);
					fElement.focus();
					if(!disableHighLighting) {
						fElement.highlight();
					}
					return false;
					
				}

				// elf proef als lengte 9 is
				if( j == 9 && ( total % 11 ) == 0) {
					succes = true;
				}
			
				// Als geen elfproef en de lengte groter dan 7 of kleiner dan 3
				// geen rekeningnummer
				if( !succes && (j > 7 || j < 3 )) {
					
					window.alert(message);
					fElement.focus();
					if(!disableHighLighting) {
						fElement.highlight();
					}
					return false;
				} 
			}
		}
	}
	return true;
}

function mask(fElement,type) {
	if(fElement && fElement.value!='' && type) {
		var value = fElement.value.trim();
		var transform = new RegExp();
		switch (type) {
			case 'capitalize':
				value = value.capitalize();
				break;
			case 'capitalizeAll':
				value = value.capitalizeAll();
				break;
			case 'lowercase':
				value = value.toLowerCase();
				break;
			case 'uppercase':
				value = value.toUpperCase();
				break;
			case 'telephone':
				if(fElement.value.length < 10) {
					autoFill('telephone',document.getElementsByName('city')[0].value,fElement.name);
				} else {
					value = fElement.value.removeWhiteSpace();
				}
				break;
			case 'zipcode':
				value = value.toUpperCase().removeWhiteSpace().substr(0,6);
				break;
			case 'zip2':
				value = value.toUpperCase().removeWhiteSpace().substr(0,6);
				break;
		}
		fElement.value = value;
	}
}




function autoFill(type,value,fElement) {
	var done = 0;
	document.body.style.cursor = 'wait';
	//document.body.disabled = true;
	if(!document.getElementById('autoFillFrame')) {
		autoFiller 							= document.createElement('iframe');
		autoFiller.id 					= 'autoFillFrame';
		autoFiller.frameBorder	= 0;
		document.body.appendChild(autoFiller);
		document.body.setAttribute('autoFillFrameLoaded','true');
	}
	 autoFiller = document.getElementById('autoFillFrame');
	switch(type) {
		case 'city':
			autoFiller.src='/public/js/autoFill.cfm?type='+type+'&value='+value.substr(0,4);
			break;
		case 'telephone':
			value = value;
			autoFiller.src='/public/js/autoFill.cfm?type='+type+'&value='+value+'&element='+fElement;
			break;
		case 'title':
			if(document.getElementsByName('title')) {
				titleValue = document.getElementsByName('title')[0].value;
				if(titleValue== '' || titleValue == 'Mevr.' || titleValue == 'Dhr.') {
					document.getElementsByName('title')[0].value = value=='M'?'Dhr.':'Mevr.';
				}
			}
			done = 1;
			break;
		default:
			done = 1;
	}
	if(done) {
		document.body.style.cursor = 'default';
		document.body.disabled = false;
	}
}

function enhanceFormElements(sForm,sEvents) {
	if(sForm && sEvents && document.getElementById(sForm)) {
		fObject = document.getElementById(sForm);
		aEvents = sEvents.split(',');

		for(i=0;i<fObject.elements.length;i++) {
			fElement 	= fObject.elements[i];
			if(fElement.className == 'formElement') {
				for(j=0;j<aEvents.length;j++) {
					switch (aEvents[j]) {
						case 'click':
							fElement.setAttribute('oldOnclick',fElement.onclick);
							fElement.onclick = function() {
								if(this.oldOnclick) {
									this.oldOnclick();
								}
								this.className = 'formElementClick'
							}
							break;
						case 'blur':
							fElement.oldOnblur = fElement.onblur;
							fElement.onblur = function() {
								if(this.oldOnblur) {
									this.oldOnblur();
								}
								this.className = 'formElementBlur';
							}
							break;
						case 'focus':
							fElement.oldOnfocus = fElement.onfocus;
							fElement.onfocus = function() {
								if(this.oldOnfocus) {
									this.oldOnfocus();
								}
								this.className = 'formElementFocus'
							}
							break;
						case 'over':
							fElement.oldOnmouseover = fElement.onmouseover;
							fElement.onmouseover = function() {
								if(this.oldOnmouseover) {
									this.oldOnmouseover();
								}
								this.className = 'formElementOver'
							}
							break;
						case 'out':
							fElement.oldOnmouseout = fElement.onmouseout;
							fElement.onmouseout = function() {
								if(this.oldOnmouseout) {
									this.oldOnmouseout();
								}
								this.className = 'formElementOut'
							}
							break;
						case 'down':
							fElement.oldOnmousedown = fElement.onmousedown;
							fElement.onmousedown = function() {
								if(this.oldOnmousedown) {
									this.oldOnmousedown();
								}
								this.className = 'formElementDown'
							}
							break;
						case 'up':
							fElement.oldOnmouseup = fElement.onmouseup;
							fElement.onmouseup = function() {
								if(this.oldOnmouseup) {
									this.oldOnmouseup();
								}
								this.className = 'formElementUp'
							}
							break;
						case 'dblclick':
							fElement.oldOndblclick = fElement.ondblclick;
							fElement.ondblclick = function() {
								if(this.oldOndblclick) {
									this.oldOndblclick();
								}
								this.className = 'formElementDblClick'
							}
							break;
					}
				}
			}
		}
	}
}
;

 /*
	searchForm_div.js
	Javascript for subscriber form
	Alpha Release: $Id: searchForm_class.js 115026 2010-08-31 11:07:12Z fibbe03 $
	Copyright 2007 Realworks B.V., AMSTERDAM, NL
	All Rights Reserved
*/

// ------------------------------------------------------------------------------------------------------------------------------

// select the option with text <selectedOptionText> of a select input element
// selectInputElement: Id of select element
// selectedOptionText: text of option that has to be selected

function setMenuSelectedValue(selectInputelement,selectedOptionText){
	if(!selectInputelement || !selectedOptionText){return false;}
	var selEl=document.getElementById(selectInputelement);
	for(var i=0; i<selEl.options.length; i++){
		if(selEl.options[i].value == selectedOptionText){
			selEl.selectedIndex=i;
			break;
		}
	}
}

// ------------------------------------------------------------------------------------------------------------------------------

//let the value of form select element 'master' determine the value of text input element 'slave'
//INPUT
// master: reference to select element that determines slave 
// aSlaveValues: possible values for slave

function setInputElementValue(oMaster,sSlaveName,aSlaveValues){
	if(!oMaster){return false;}
	var slaveVal=aSlaveValues[oMaster.selectedIndex];
	document.getElementsByName(sSlaveName)[0].value = slaveVal;
}

// ------------------------------------------------------------------------------------------------------------------------------

function hiliteInputElementBorder(textInput){
	if(!textInput){return;}
	textInput.className="alert";
}

// ------------------------------------------------------------------------------------------------------------------------------

function unHiliteInputElementBorder(textInput){
	if(!textInput){return;}
	textInput.className="";
}

// ------------------------------------------------------------------------------------------------------------------------------

function showElement(elementId) {
	var el = document.getElementById(elementId);
	if(el){
		el.style.display = '';
	}
}

// ------------------------------------------------------------------------------------------------------------------------------

function hideElement(elementId) {
	var el = document.getElementById(elementId);
	if(el){
		el.style.display = 'none';
	}
}
// ------------------------------------------------------------------------------------------------------------------------------

	function SaleRentPrice(value){
		if (value == 1)
			{
			hideRentPrice();
			showSalePrice();
			}
		if (value == 2)
			{
			showRentPrice();
			hideSalePrice();
			}
		if (value== 0)
			{
			showRentPrice();
			showSalePrice();
			}

	}
// ------------------------------------------------------------------------------------------------------------------------------

	function hideRentPrice(){

		document.getElementById("inputrentPriceFrom").style.display="none";
		document.getElementById("inputrentPriceTo").style.display="none";

		
		var selRentFrom = document.getElementById('rentPriceFrom');
		var selRentTo = document.getElementById('rentPriceTo');
		selRentFrom.selectedIndex = 0;
		selRentTo.selectedIndex = 18;
		 
		
	}

// ------------------------------------------------------------------------------------------------------------------------------

	function showRentPrice(){
		document.getElementById("inputrentPriceFrom").style.display="block";
		document.getElementById("inputrentPriceTo").style.display="block";
		

	}

// ------------------------------------------------------------------------------------------------------------------------------

	function hideSalePrice(){
 
		document.getElementById('inputsalePriceFrom').style.display='none';
		document.getElementById('inputsalePriceTo').style.display='none';
	 
		var selSaleFrom = document.getElementById('salePriceFrom');
		var selSaleTo = document.getElementById('salePriceTo');
		selSaleFrom.selectedIndex = 0;
		selSaleTo.selectedIndex = 28;

	}

// ------------------------------------------------------------------------------------------------------------------------------

	function showSalePrice(){
		document.getElementById('inputsalePriceFrom').style.display='block';
		document.getElementById('inputsalePriceTo').style.display='block';
		
	
		
	}

// ------------------------------------------------------------------------------------------------------------------------------

// reset the value of an inputelement

function resetInputelementsValue(aDivIds){
	//loop over array with divs
	for(i=0;i<aDivIds.length;i++){
		try{
			//create reference to table row
			var oDiv = document.getElementById(aDivIds[i])
	
			//create array with references to selects in row 
			aSelects = oDiv.getElementsByTagName('select');
	
			//create array with references to other inputelements in row 
			aInputs= oDiv.getElementsByTagName('input');
	
			//reset selects
			for(j=0;j<aSelects.length;j++){
				aSelects[j].selectedIndex=0;
			}
			//reset other inputelements
			for(j=0;j<aInputs.length;j++){
				if(aInputs[j].type.indexOf('text')!=-1){
					aInputs[j].value="";
				}
				else{
					if(aInputs[j].type.indexOf('checkbox')!=-1){
						aInputs[j].checked=false;
					}
				}
			}
		}
		catch(e){}
	}
}

// ------------------------------------------------------------------------------------------------------------------------------

// toon een table row afhankelijk van selectedOption en
// deselecteer de checkboxes die verborgen worden

function hideElements(selectedValue){ 
	 if(!window.currentSelected){
	 	currentSelected = 5;
	 }

	// show all table rows
	for(var i=0; i<aDivIds.length;i++){
		showElement(aDivIds[i]);
	}

	// hide selected table rows
	for(var i=0; i<aDivIdsToHide[selectedValue].length;i++){
		hideElement(aDivIdsToHide[selectedValue][i]);
	}
	resetInputelementsValue(aDivIdsToHide[selectedValue]);
	checkAllBySoortOg(selectedValue);
}

// Alle checkbox aanvinken van Soort woning, Type woning Kenmerken en Appartement
// afhankelijk van wat er gekozen is.
function checkAllBySoortOg(selectedValue) {
	var WOONHUIS_APPARTEMENT = 0;
	var WOONHUIS = 1;
	var APPARTEMENT = 2;
	var BOUWGROND = 3;
	var GARAGEBOX = 4;
	var NONE = 5;
	
	var divsToCheck = new Array();
	
	divsToCheck[WOONHUIS_APPARTEMENT]	= ['typeOfProperty', 'typeOfResidence', 'kenmerkenOfResidence', 'typeOfApartment'];
	divsToCheck[WOONHUIS]				= ['typeOfProperty', 'typeOfResidence', 'kenmerkenOfResidence'];
	divsToCheck[APPARTEMENT]			= ['typeOfApartment'];
	divsToCheck[BOUWGROND]				= ['kenmerkenOfResidence'];
	divsToCheck[GARAGEBOX]				= ['kenmerkenOfResidence'];
	divsToCheck[NONE]					= [];
	
	var checkIds = divsToCheck[selectedValue];
	
	for(var i=0; i < checkIds.length; i++ ) {
		checkAllInDiv(checkIds[i])
	}
}

// Als het vinkboxje "Allen" aangeinkt wordt
function checkAllInDiv(divId) {
	var oDiv = document.getElementById(divId);
	
	if(oDiv == null) {
		return; // div bestaat niet, door een instelling van de makelaar
	}
	aInputs= oDiv.getElementsByTagName('input');
	
	//Check alle divs
	for(j=0;j<aInputs.length;j++){
		// Triviant, maar je weet maar nooit
		if(aInputs[j].type.indexOf('checkbox')!=-1){
			aInputs[j].checked=true;
		}
	}
}

// Als het vinkboxje "Allen" uitgevinkt wordt
function uncheckAllCheckbox(divId) {
	var oDiv = document.getElementById(divId);
	aInputs= oDiv.getElementsByTagName('input');
		
	//Check alle divs
	for(j=0;j<aInputs.length;j++){
		// Triviant, maar je weet maar nooit
		if(aInputs[j].type.indexOf('checkbox')!=-1){
			aInputs[j].checked=false;
		}
	}
}

// Voor checkboxes voor Soort Woning, Soort Appartement, etc.
function checkboxClicked(checkbox, divId) {
	
	// De bijbehorende 'Allen' checkbox
	var allenId = divId + "_All";
	var oAllen = document.getElementById(allenId);
	
	var endsWith = checkbox.name.substring(checkbox.name.length - 3);
	
	if (endsWith == 'All') {
		if (checkbox.checked) {
			checkAllInDiv(divId);
			return;
		} else {
			uncheckAllCheckbox(divId);
			return;
		}
	}
	
	if (!checkbox.checked) {
		oAllen.checked = false; 
	}
	
	// Als alle checkboxes in de div zijn aangelikt, dan ook de 'Allen' checkbox 
	// aanvinken
	var oDiv = document.getElementById(divId);
	var aInputs= oDiv.getElementsByTagName('input');
	var checkAll = true;
	for(j=0;j<aInputs.length;j++){
		var endsWithTemp = aInputs[j].name.substring(aInputs[j].name.length - 3);
		if (endsWithTemp == 'All') {
			continue;
		}
		if (!aInputs[j].checked) {
			checkAll = false;
		}
	}
	if (checkAll) {
		oAllen.checked = true;		
	}
}

// ------------------------------------------------------------------------------------------------------------------------------

function processForm(oThisForm){
	result = false;
	formValid = checkForm(oThisForm);

	if(formValid){
		if(mySelectAreas.selectAll){
			mySelectAreas.selectAll('selected');
		}
		if(mySelectCities.selectAll){
			mySelectCities.selectAll('selected');
		}
		result = true;
	}

	return result;
}

// ------------------------------------------------------------------------------------------------------------------------------

//show all cities belonging to a province in the selectElementID multi select box

function showCities(selectedProvince,selectElementID){
	if(!selectedProvince)return;
	var sel=document.getElementById(selectElementID);
	for(i=0;i<citiesAndProvincesJS.length;i++){
		if(citiesAndProvincesJS[i][0]==selectedProvince){
			var cityCount=citiesAndProvincesJS[i].length-1;
			for(i=0;i<cityCount;i++){
			}
		}
	}
}

// ------------------------------------------------------------------------------------------------------------------------------

//initialiseer pagina...

window.onload = function(){
	var f = document.getElementById('inschrijfformulier');
	if (!f) {
		return;
	}
	if(typeof CitySelection == "function"){
		mySelectCities = CitySelection('inschrijfformulier','cities','selectedCities','province');	
	}
	 else{
		mySelectCities = new Object();
		mySelectCities.exists = function(){return false;}
	 }

	if(typeof AreaSelection == "function"){
		// don't remove the new keyword - it will overwrite 'mySelectCities'
		mySelectAreas = new AreaSelection('inschrijfformulier','areas','selectedAreas','#owner#','#department#');
	}
	 else{
		mySelectAreas = new Object();
		mySelectAreas.exists = function(){return false;}
	 }

	// ids of all rows
	aDivIds = new Array();
	aDivIds.push('inputnewConstruction','inputpropertySurfaceFrom','inputlivingspaceFrom','inputnumberOfRooms','inputconstructionYearFrom','inputconstructionYearTo');
	aDivIds.push('inputtypeOfProperty','inputtypeOfResidence','inputresidenceFeature','typeOfProperty','typeOfApartment','typeOfResidence', 'kenmerkenOfResidence');

	// ids of rows to hide depending on value of select 'Soort OG' by value of the select
	aDivIdsToHide = new Array();
	// checkboxes in deze rows verbergen bij keuze voor woonhuis/appartement
	aDivIdsToHide[0] = [];
	// Maak keuze
	
	// checkboxes in deze rows verbergen bij keuze voor woonhuis
	aDivIdsToHide[1] = new Array();
	aDivIdsToHide[1] = ['typeOfApartment'];

	// checkboxes in deze rows verbergen bij keuze voor appartement
	aDivIdsToHide[2] = new Array();
	aDivIdsToHide[2].push('typeOfResidence','typeOfProperty', 'kenmerkenOfResidence', 'inputresidenceFeature','inputpropertySurfaceFrom');

	// checkboxes in deze rows verbergen bij keuze voor bouwgrond
	aDivIdsToHide[3] = new Array();
	aDivIdsToHide[3].push('typeOfProperty','typeOfApartment','typeOfResidence','inputtypeOfApartment', 'kenmerkenOfResidence');
	aDivIdsToHide[3].push('inputnewConstruction','inputlivingspaceFrom','inputnumberOfRooms','inputconstructionYearFrom','inputconstructionYearTo');

	// checkboxes in deze rows verbergen bij keuze voor garage
	aDivIdsToHide[4] = new Array();
	aDivIdsToHide[4].push('typeOfProperty','typeOfApartment','typeOfResidence','inputtypeOfApartment');
	aDivIdsToHide[4].push('inputnewConstruction','inputpropertySurfaceFrom','inputlivingspaceFrom','inputnumberOfRooms');
	aDivIdsToHide[4].push('inputconstructionYearFrom','inputconstructionYearTo', 'kenmerkenOfResidence');
	
	// checkboxes in deze rows verbergen bij keuze voor Maak keuze
	aDivIdsToHide[5] = new Array();
	var soort = soortOG;

	var SOORT_OG_APPARTEMENT = 0;
	var SOORT_OG_BOUWGROUND = 1;
	var SOORT_OG_GARAGEBOX = 2;
	var SOORT_OG_WOONHUIS = 3;
	var SOORT_OG_WOONHUIS_APPARTEMENT = 4;

	if(soort.charAt(SOORT_OG_APPARTEMENT) == "0" && soort.charAt(SOORT_OG_WOONHUIS) == "0" && soort.charAt(SOORT_OG_WOONHUIS_APPARTEMENT) == "0") {
		aDivIdsToHide[5].push('inputnewConstruction','inputlivingspaceFrom','inputnumberOfRooms');
		if (soort.charAt(SOORT_OG_WOONHUIS) == "0" && soort.charAt(SOORT_OG_WOONHUIS_APPARTEMENT) == "0") {
			aDivIdsToHide[5].push('inputpropertySurfaceFrom');
		}
	}

	aDivIdsToHide[5].push('inputconstructionYearFrom', 'inputconstructionYearTo');	
	aDivIdsToHide[5].push('typeOfProperty','typeOfApartment','typeOfResidence', 'kenmerkenOfResidence', 'inputtypeOfApartment');

	setInputElementValue(document.getElementsByName('subscriberGender')[0],'subscriberTitle',['De Heer','Mevr','']);
	hideElements(5);
	
	// Wanneer slechts een enkele province in de selectbox, deze automatisch selecteren
	if (keys(citiesAndProvincesJS).length == 1) {
		var oSel = document.getElementById("province");
		oSel.selectedIndex = 1;
		mySelectCities.searchCities();
		$("#inputprovince").hide();				// Selectbox hiden
		$("#inputuitleg ol>li:first").hide();	// De "Kies een province" label hiden
	}
}


/**
 * De indexes op een "associative" array zijn stiekem attributen op het array 
 * object, waardoor assocArray.length altijd 0 terug geeft. Daarom deze methode.
 */
function keys(obj) {
	var ret = [];
	for (key in obj) {
		ret.push(key);
	} 
	return ret;
}

;

function Mask() {
	
	this.tuples = new Array();
	
	this.parseMask = function(sMask) {
		var m = new Mask();
		var vars = sMask.split('|');
        for (var i = 0; i < vars.length; i++) {
            var tmp = vars[i].split(';');
            var key = null;
            var value = null;
            if (tmp.length == 1) {
                key = tmp[0];
                value = tmp[0];
            } else if (tmp.length == 2) {
                key = tmp[0];
                value = tmp[1];
            } else {
                alert("Cannot parse mask part: '" + vars[i] + "'");
            }
			m.add(key, value);
		}
		return m;
	}

	this.add = function(key, value) {
		this.tuples[this.tuples.length] = new Array(key, value);
	}
	
	this.get = function(key) {
		for(var i = 0; i< this.tuples.length; i++) {
			var tuple = this.tuples[i];		
			if(tuple[0] == key) {
				return tuple[1];
			}
		}
		return null;
	}
	
	this.remove = function(key) {
		for(var i = 0; i< this.tuples.length; i++) {
			var tuple = this.tuples[i];		
			if(tuple[0] == key) {
				this.tuples.splice(i, 1); // Verwijder uit array
			}
		}
	}

	this.removeAll = function(aKeys) {
		var removeAll = true;
		if(arguments.length == 2) {
			removeAll = arguments[1];
		}
		if(!isArray(aKeys)) {
			return error("removeAll()", "aKeys mag geen '" + typeof(aKeys) + "' zijn");
		}
		for(var j = 0; j < aKeys.length; j++) {
			this.remove(aKeys[j]);
		}
	}

	this.maskAsString = function() {
		var sMask = "";
		var first = true;
		for(i = 0; i < this.tuples.length; i++) {
			if(!first) {
				sMask += "|";
			}
			first = false;
			var tuple = this.tuples[i];
			var key = tuple[0];
			var value = tuple[1];
			sMask += key + ";" + value;
		}
		return sMask;
	}

	this.keySet = function() {
		var keys = new Array();
		for(var i=0; i < this.tuples.length; i++) {
			var tuple = this.tuples[i];
			keys[keys.length] = tuple[0];
		}
		return keys;
	}
};


