/*
	searchForm_div.js
	Javascript for subscriber form
	Alpha Release: $Id: $
	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(object){
	
	
		if (object.selectedIndex == 0)
			{
			hideRentPrice();
			showSalePrice();
			}
		if (object.selectedIndex == 1)
			{
			showRentPrice();
			hideSalePrice();
			}
		if (object.selectedIndex == 2)
			{
			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]);
}

// ------------------------------------------------------------------------------------------------------------------------------

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(){
	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');

	// 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','inputresidenceFeature','inputpropertySurfaceFrom');

	// checkboxes in deze rows verbergen bij keuze voor bouwgrond
	aDivIdsToHide[3] = new Array();
	aDivIdsToHide[3].push('typeOfProperty','typeOfApartment','typeOfResidence','inputtypeOfApartment');
	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');
	
	// checkboxes in deze rows verbergen bij keuze voor Maak keuze
	aDivIdsToHide[5] = new Array();
	aDivIdsToHide[5].push('typeOfProperty','typeOfApartment','typeOfResidence','inputtypeOfApartment');
	aDivIdsToHide[5].push('inputnewConstruction','inputpropertySurfaceFrom','inputlivingspaceFrom','inputnumberOfRooms');
	aDivIdsToHide[5].push('inputconstructionYearFrom', 'inputconstructionYearTo');

	setInputElementValue(document.getElementsByName('subscriberGender')[0],'subscriberTitle',['De Heer','Mevr','']);
	hideElements(5);
	}


