
	function setBedroomsState (strParentControlName, strChildControlName, strTextToMatch)
	{
		if (document.getElementById (strParentControlName) && 
			document.getElementById (strChildControlName)) { 

			var ctlParent = document.getElementById(strParentControlName);

			if (ctlParent.options[ctlParent.selectedIndex].value == strTextToMatch) {
				toggleControl2 (ctlParent.form, strChildControlName, true);
			}
			else {
				toggleControl2 (ctlParent.form, strChildControlName, false);
			}
		}
	}

	function disableControlConditional (objParentControl, strControlToDisable, strTextToMatch)
	{
		var ctlParent = objParentControl;
		var objForm = ctlParent.form;

		// Get the text selected in this control.
		varSelectedText = objParentControl.options[objParentControl.selectedIndex].value;

		// Set a flag that identifies whether we're enabling or disabling this control.		
		var blnDisabling = false;
		if (varSelectedText == strTextToMatch) {
			blnDisabling = true;
		}

		// Iterate through the elements on the form.
		for (var i = 0; i < objForm.elements.length; i++) {
			// If the selected item in the parent control matches the text parameter then disable the named 
			// control.
			if (objForm.elements[i].name == strControlToDisable) {
				if (blnDisabling && !objForm.elements[i].disabled) {
					if (objForm.elements[i].type == 'select-one') {
						objForm.elements[i].selectedIndex = 0;
					}
					objForm.elements[i].disabled = true;
				}
				else if (objForm.elements[i].disabled) {
					objForm.elements[i].disabled = false;
				}
			}
		}
	}

	function cascadeDdls (arrLinkArray, arrParentOptions, arrChildOptions, lngParentControlId, lngChildControlId)
	{
		var ctlParent = document.getElementById (lngParentControlId);
		var ctlChild = document.getElementById (lngChildControlId);
		
		var strDefaultChildText = ctlChild.options[0].text;

		// if no options are selected in the parent control then display a message in the child control
		if (ctlParent.value == '') {

			// enable the child control if it's disabled
			if (!ctlChild.disabled) {
				ctlChild.disabled = true;
			}
			// clear the child option list
			ctlChild.options.length = 1;
		}
		else {
		
			// grab the key of the selected option from the source list
			var varSelectedKey = ctlParent.options[ctlParent.selectedIndex].value;

			// look the key for this parent option up in the parent options array, get the numeric index
			for (var i = 1; i <= arrParentOptions.length; i++) {
				if (arrParentOptions[i][1] == varSelectedKey) {
					iCurrSource = i;
					break;
				}
			}
			
			// if an entry doesn't exist in the link array for this parent option then children don't exist
			// disable the child control and display a message in the list
			if (arrLinkArray[iCurrSource] == null) {
			
				// truncate the list of child options to display only the first (default) message
				ctlChild.options.length = 1;

				// disable the child control if it's enabled
				if (!ctlChild.disabled) {
					ctlChild.disabled = true;
				}
			}
			else {
			
				// enable the child control if it's disabled
				if (ctlChild.disabled) {
					ctlChild.disabled = false;
				}

				// copy the elements from the link array for this parent option to aOptions
				var aNewOptions;
				aNewOptions = new Array();

				for (destArrLoop in arrLinkArray[iCurrSource]) {
					aNewOptions[destArrLoop] = destArrLoop;
				}

				// we now have a list of all the combined children options
				// put them into a new array and sort them, use this
				// to populate the option list
				sortedOptions = new Array();			// the sorted output array
				sortIndex=0;							// an index
				for (iLoop in aNewOptions) {
					if (aNewOptions[iLoop] != null) {
						sortedOptions[sortIndex] = aNewOptions[iLoop];
						sortIndex = sortIndex + 1;
					}
				}

				// array to hold the child options
				var arrChildOptionsOutput = new Array(sortIndex);	
				for (i = 0; i < sortIndex; i++) {
					arrChildOptionsOutput[i] = new Array(1);
					arrChildOptionsOutput[i][0] = arrChildOptions[sortedOptions[i]][0];
					arrChildOptionsOutput[i][1] = arrChildOptions[sortedOptions[i]][1];
				}

				// remove the current options (leave the default option)
				ctlChild.options.length = 1;

				var strSelectedControlId = "selected_" + lngChildControlId;
				var ctlSelectedControl = document.getElementById (strSelectedControlId);

				// load the child list with the sorted list (starting from the second element)
				var intItemToSelect = 0;
				for (i = 0; i < arrChildOptionsOutput.length; i++) {
					if (ctlSelectedControl) {
						if (ctlSelectedControl.value != '' && arrChildOptionsOutput[i][1] == ctlSelectedControl.value) {
							intItemToSelect = i + 1		// add 1 to account for the default text option
						}
					}
					if (arrChildOptionsOutput[i][0]) {
						ctlChild.options[i + 1] = new Option (arrChildOptionsOutput[i][0], arrChildOptionsOutput[i][1], false, false);
					}
				}
				
				// all options rendered - select the correct option
				ctlChild.options[intItemToSelect].selected = true;
			}
		}
	}
	
	function getBitArray (arrIn)
	{
		var arrOut = new Array();
		
		for (iLoop = 0; iLoop < arrIn.length; iLoop++) {
			arrOut[arrIn[iLoop]] = 1;
		}
		
		return (arrOut);
	}

