
var saleOnLeft = new Image(); saleOnLeft.src = "/images/property/landing/sale_on_left.gif";
var saleOnRight = new Image(); saleOnRight.src = "/images/property/landing/sale_on_right.gif";
var rentOnLeft = new Image(); rentOnLeft.src = "/images/property/landing/rent_on_left.gif";
var rentOnRight = new Image(); rentOnRight.src = "/images/property/landing/rent_on_right.gif";

var sidebarHousesOnLeftImage = new Image(); sidebarHousesOnLeftImage.src =				"/images/property/sidebar/left_houses.gif";
var sidebarHousesOnLeftBackground = new Image(); sidebarHousesOnLeftBackground.src =	"/images/property/sidebar/background_left_houses.gif";
var sidebarHousesOnMiddleImage = new Image(); sidebarHousesOnMiddleImage.src =			"/images/property/sidebar/middle_houses.gif";
var sidebarHousesOnRightBackground = new Image(); sidebarHousesOnRightBackground.src =	"/images/property/sidebar/background_right_houses.gif";
var sidebarHousesOnRightImage = new Image(); sidebarHousesOnRightImage.src =			"/images/property/sidebar/right_houses.gif";

var sidebarRentalsOnLeftImage = new Image(); sidebarRentalsOnLeftImage.src =			"/images/property/sidebar/left_rentals.gif";
var sidebarRentalsOnLeftBackground = new Image(); sidebarRentalsOnLeftBackground.src =	"/images/property/sidebar/background_left_rentals.gif";
var sidebarRentalsOnMiddleImage = new Image(); sidebarRentalsOnMiddleImage.src =		"/images/property/sidebar/middle_rentals.gif";
var sidebarRentalsOnRightBackground = new Image(); sidebarRentalsOnRightBackground.src ="/images/property/sidebar/background_right_rentals.gif";
var sidebarRentalsOnRightImage = new Image(); sidebarRentalsOnRightImage.src =			"/images/property/sidebar/right_rentals.gif";

var tmpDiv;
var px = 'unused_';

function displayPanel (panelName, location)
{
	// Removes the panel with an id of panelName and replaces it with the panel referenced by tmpDiv.
	if (document.getElementById(panelName) == null) return false;

	// Get a reference to the panel we're hiding.
	var parentNode = document.getElementById(panelName).parentNode;

	// Retrieve the hidden object - we need to attach it.
	var objToAppend = tmpDiv;
	
	// If we haven't got an object to attach then return true to follow the hyperlink.
	if (objToAppend == null) return true
	
	// Remove the panel we're hiding - will persist it as tmpDiv.
	removePanel (panelName);
	
	/*
		Browser hack. Moz doesn't like having a collection of nodes within the dom
		that the same id as nodes that actually exist within the dom. 
		IE and Opera don't like to have the nodes renamed and hidden from being rendered
		for some reason and won't cascade the locality dropdowns correctly. 
		This same hack is applied in the method appendPrefix. 
	*/
	if (objToAppend.style && navigator.product == 'Gecko') {
		removePrefix(objToAppend, px);
		objToAppend.style.display = '';
	} else {
		// Add the node referenced by objToAppend.
		//parentNode.appendChild(objToAppend);
		var endEl = document.getElementById("attributeSearchBottom");
		parentNode.insertBefore(objToAppend, endEl);
	}
	
	// Refresh control states - hard-coded attribute ids here.
	setDdlState ('134', '135');
			
	// Only call these functions when processing properties search forms
	switch (panelName) {
		case "housesForSaleSearchForm" :
        case "rentalsSearchForm" :			
	setDdlState ('135', '136');
	setControlState ('136', '133');
			break;				
	}		
	
	var saleLink = document.getElementById("saleLink");	
	var rentalLink = document.getElementById("rentalLink");

	switch (panelName) {
		case "housesForSaleSearchForm" :
		case "commercialForSaleSearchForm" :
			saleLink.className = "";
			rentalLink.className = "selected";
			break;
		case "rentalsSearchForm" :
		case "commercialForLeaseSearchForm" :
			saleLink.className = "selected";
			rentalLink.className = "";
			break;
	}
	
	//    toggle ye olde imag0rs
	var saleImage = document.getElementById("asCom");
	var leaseImage = document.getElementById("asLea");

	if (saleImage && leaseImage) {
		if (saleImage.src.indexOf("/Images/3/Property/comm_sale_blue.gif") > 0) 
			saleImage.src = "/Images/3/Property/comm_sale_white.gif";
		else
			saleImage.src = "/Images/3/Property/comm_sale_blue.gif";
		
		if (leaseImage.src.indexOf("/Images/3/Property/comm_lease_blue.gif") > 0) 
			leaseImage.src = "/Images/3/Property/comm_lease_white.gif";
		else
			leaseImage.src = "/Images/3/Property/comm_lease_blue.gif";
      }	
	
	// Return false to stop the link from being followed.
	return false;
}

function removePanel (panelName)
{
	tmpDiv = document.getElementById(panelName);
	var parent = tmpDiv.parentNode;
	
	if (tmpDiv.style && navigator.product == 'Gecko') {
		appendPrefix(tmpDiv, px);
		tmpDiv.style.display = 'none';
	} else {
		parent.removeChild(tmpDiv);
	}
}

function appendPrefix (pc, prefix) {

	if (pc.childNodes.length > 0) {
		for (var i = 0; i < pc.childNodes.length; i++) {
			appendPrefix(pc.childNodes[i], prefix)
		}
	}
	
	if (pc.id) {
		pc.id = prefix + pc.id;
	}
	
	return;
}

function removePrefix(pc, prefix) {

	if (pc.childNodes.length > 0) {
		for (var i = 0; i < pc.childNodes.length; i++) {
			removePrefix(pc.childNodes[i], prefix)
		}
	}
	
	if (pc.id) {
		if (pc.id.length > prefix.length && pc.id.substr(0, prefix.length) == prefix) {
			pc.id = pc.id.substr(prefix.length, pc.id.length - prefix.length);
		}
	}
	
	return;
}

// Specifically created to enable/disable the a locality ddl based on the 
// state of the ddl that's supposed to be driving it. If the parent ddl is enabled and
// it's value is not '' then enable the child ddl. Disable it otherwise.
function setDdlState (parentDdlId, childDdlId)
{
	// grab a reference to the checkbox whose state we're setting.
	var parentDdl = document.getElementById(parentDdlId);

	// grab a hard-coded reference to the ddl that's driving the checkbox.
	var childDdl = document.getElementById(childDdlId);

	// if the ddl is disabled or the value is zero-length then disable the child.
	if (parentDdl.disabled || parentDdl.value == '') {
		childDdl.value = '';
		childDdl.disabled = true;
	}
	// Enable it otherwise.
	else {
		childDdl.disabled = false;
	} 
}

// Specifically created to enable/disable the 'adjacent suburb' checkbox on the UI based on the 
// state of the suburb select control. If the select control is enabled and the value is not "" then
// enable the adjacent suburb checkbox. Disable it otherwise.
function setControlState (ddlId, checkboxId)
{
	// grab a reference to the checkbox whose state we're setting.
	var cbo = document.getElementById(checkboxId);
	
	// grab a hard-coded reference to the ddl that's driving the checkbox.
	var ddl = document.getElementById(ddlId);

	// if the ddl is disabled or the value is zero-length then clear the checkbox
	// and disable it.
	if (ddl.disabled || ddl.value == '') {
		document.getElementById('span_' + checkboxId).style.color = "#999";
		cbo.checked = false;
		cbo.disabled = true;
	}
	// enable the checkbox.
	else {
		document.getElementById('span_' + checkboxId).style.color = "#333";
		cbo.disabled = false;
	} 
}

function setOptionState ()
{
	// real gash - we don't know which form we're displaying so try them both - they're called 'sidebar'
	// and 'rentals_main'
	if (document.sidebar) {
		var ctrlHidden = document.getElementById('enableBedroomOptions');
		if (ctrlHidden.value == "1") {
			toggleControl (document.sidebar, '27', false);				// ID of the Bedrooms attribute control
		}
		else {
			toggleControl (document.sidebar, '27', true);				// ID of the Bedrooms attribute control
		}
	}
	else if (document.rentals_main) {
		var ctrlHidden = document.getElementById('enableBedroomOptions');
		if (ctrlHidden.value == "1") {
			toggleControl (document.rentals_main, '27', false);			// ID of the Bedrooms attribute control
		}
		else {
			toggleControl (document.rentals_main, '27', true);			// ID of the Bedrooms attribute control
		}
	}
}

function toggleControl (strTheForm, strNameOfControl, blnDisabled)
{
	for (var i = 0; i < strTheForm.elements.length; i++) {
		if (strNameOfControl == strTheForm.elements[i].name) {
			var ctrl = strTheForm.elements[i];
			// select the first option (probably 'any')
			if (ctrl.disabled != blnDisabled) {
				if (ctrl.type == 'select-one') {
					ctrl.selectedIndex = 0;
				}
				ctrl.disabled = blnDisabled;
			}
		}
	}
}

function toggleControl2 (theForm, strNameOfControl, blnDisabled)
{
	for (var i = 0; i < theForm.elements.length; i++) {
		if (strNameOfControl == theForm.elements[i].name) {
			var control = theForm.elements[i];
			if (control.disabled != blnDisabled) {
				if (control.type == 'select-one') {
					control.selectedIndex = 0;
				}
				control.disabled = blnDisabled;
			}
		}
	}
}

function cascadeLocationsByAttributeId (arrParentChildLink, arrParentOptions, arrChildOptions, strParentNoun, strChildNoun, strMode)
{
	var ctlLocation = document.getElementById('71');					//	ID of the Location attribute DDL
	var ctlSuburb = document.getElementById('72');						//	ID of the Suburb attribute DDL
	var ctlSelectedSuburb = document.getElementById('selected72');		//	ID of the selected suburb hidden control
	var strActionText = strMode == "search" ? "Any " + strChildNoun : "Choose..."
	
	// if no options are selected in the parent control then display a message in the child control
	if (ctlLocation.value == '' || ctlLocation.text == '') {

		// enable the child control if it's disabled
		if (ctlSuburb.disabled) {
			ctlSuburb.disabled = false;
		}
		// clear the child option list
		ctlSuburb.options.length = 0
		ctlSuburb.options[0] = new Option(strActionText, '', false, false);
	}
	// if there is no comma in the value string then user has selected a region - show the please choose message
	else if (ctlLocation.options[ctlLocation.selectedIndex].value.indexOf (', ') == -1) {

		// enable the child control if it's disabled
		if (ctlSuburb.disabled) {
			ctlSuburb.disabled = false;
		}
		// clear the child option list
		ctlSuburb.options.length = 0
		ctlSuburb.options[0] = new Option(strActionText, '', false, false);
	}
	// otherwise find the selected option and generate a list of child options
	else {
	
		var iCurrSource; 
		
		// grab the key of the selected option from the source list
		iCurrSourceString = ctlLocation.options[ctlLocation.selectedIndex].value
		
		// look the key for this parent option up in the parent options array, get the numeric index
		for (i = 0; i < arrParentOptions.length; i++) {
			if (arrParentOptions[i] == iCurrSourceString) {
				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 (arrParentChildLink[iCurrSource] == null) {

			var strNoChildrenMsg = 'No ' + strChildNoun + 's';
			if (ctlSuburb.options[0].text != strNoChildrenMsg) {
			
				// clear the child option list
				ctlSuburb.options.length = 0
				ctlSuburb.options[0] = new Option (strNoChildrenMsg, '', false, false);

				// disable the child control if it's enabled
				if (!ctlSuburb.disabled) {
					ctlSuburb.disabled = true;
				}
			}
		}
		else {
		
			// enable the child control if it's disabled
			if (ctlSuburb.disabled) {
				ctlSuburb.disabled = false;
			}

			// copy the elements from the link array for this parent option to aOptions
			var aOptions;
			aOptions = new Array();

			for (var destArrLoop = 0; destArrLoop < arrParentChildLink.length; destArrLoop++) {
				aOptions[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 (var iLoop = 0; iLoop < aOptions.length; iLoop++) {
				if (aOptions[iLoop] != null) {
					sortedOptions[sortIndex] = aOptions[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
			ctlSuburb.options.length = 0

			// load the 'Choose...' option
			ctlSuburb.options[0] = new Option(strActionText, '', false, false);

			// load an empty option to give us a bit of space
			ctlSuburb.options[1] = new Option('', '', false, false);

			// load the child list with the sorted list (starting from the second element)
			var intItemToSelect = 0;
			for (i = 0; i < arrChildOptionsOutput.length; i++) {
				if (ctlSelectedSuburb.value != '' && arrChildOptionsOutput[i][1] == ctlSelectedSuburb.value) {
					intItemToSelect = i + 2		// add 1 to account for the 0-based array and the 'Choose...' option
				}
				ctlSuburb.options[i + 2] = new Option(arrChildOptionsOutput[i][0], arrChildOptionsOutput[i][1], false, false);
			}
			
			// all options rendered - select the correct option
			ctlSuburb.options[intItemToSelect].selected = true;
		}
	}
}

function cascadeExtra(
	area, 
	prefix,	
	isAdjacentSearchCheckedProperty,
	isAdjacentSearchCheckedRentals,
	arrParentChildLink, 
	arrParentOptions, 
	arrChildOptions, 
	strParentNoun, 
	strChildNoun, 
	strMode,
	parentControlId, 
	childControlId,
	countsArrayName) {
		
	if( prefix=='cnt_f' || prefix=='cnt_r' ) {
			
		cascadeLocationsByAttributeId2(
			arrParentChildLink, 
			arrParentOptions, 
			arrChildOptions, 
			strParentNoun, 
			strChildNoun, 
			strMode,
			parentControlId, 
			childControlId,
			countsArrayName) 
		
		displayPanel('rentalsSearchForm',area);

		// ALH: Hack to force the adjacent suburb check box to be correctly set in Firefox.
		if(isAdjacentSearchCheckedProperty=='True') { setAdjacentAsChecked(); }
		
		cascadeLocationsByAttributeId2(
			arrParentChildLink, 
			arrParentOptions, 
			arrChildOptions, 
			strParentNoun, 
			strChildNoun, 
			strMode,
			parentControlId, 
			childControlId,
			countsArrayName) 
			
		displayPanel('housesForSaleSearchForm',area);
		
		// ALH: Hack to force the adjacent suburb check box to be correctly set in Firefox.
		if(isAdjacentSearchCheckedRentals=='True') { setAdjacentAsChecked(); }

	} else if( prefix=='cnt_l' ) {
			
		cascadeLocationsByAttributeId2(
			arrParentChildLink, 
			arrParentOptions, 
			arrChildOptions, 
			strParentNoun, 
			strChildNoun, 
			strMode,
			parentControlId, 
			childControlId,
			countsArrayName) 
		
		displayPanel('commercialForLeaseSearchForm',area);
		
		cascadeLocationsByAttributeId2(
			arrParentChildLink, 
			arrParentOptions, 
			arrChildOptions, 
			strParentNoun, 
			strChildNoun, 
			strMode,
			parentControlId, 
			childControlId,
			countsArrayName) 
			
		displayPanel('commercialForSaleSearchForm',area);			
			
	} else if (prefix=='cnt_c') {
	
		cascadeLocationsByAttributeId2(
			arrParentChildLink, 
			arrParentOptions, 
			arrChildOptions, 
			strParentNoun, 
			strChildNoun, 
			strMode,
			parentControlId, 
			childControlId,
			countsArrayName) 
			
		displayPanel('commercialForSaleSearchForm',area);
		
		cascadeLocationsByAttributeId2(
			arrParentChildLink, 
			arrParentOptions, 
			arrChildOptions, 
			strParentNoun, 
			strChildNoun, 
			strMode,
			parentControlId, 
			childControlId,
			countsArrayName) 
		
		displayPanel('commercialForLeaseSearchForm',area);			
				
	} else {
	
		cascadeLocationsByAttributeId2(
			arrParentChildLink, 
			arrParentOptions, 
			arrChildOptions, 
			strParentNoun, 
			strChildNoun, 
			strMode,
			parentControlId, 
			childControlId,
			countsArrayName) 
		
		displayPanel('housesForSaleSearchForm',area);
		
		// ALH: Hack to force the adjacent suburb check box to be correctly set in Firefox.
		if(isAdjacentSearchCheckedRentals=='True') { setAdjacentAsChecked(); }
		
		cascadeLocationsByAttributeId2(
			arrParentChildLink, 
			arrParentOptions, 
			arrChildOptions, 
			strParentNoun, 
			strChildNoun, 
			strMode,
			parentControlId, 
			childControlId,
			countsArrayName) 
	
		displayPanel('rentalsSearchForm',area);		
				
		// ALH: Hack to force the adjacent suburb check box to be correctly set in Firefox.
		if(isAdjacentSearchCheckedProperty=='True'){ setAdjacentAsChecked(); }
		
	}
	
}

function setAdjacentAsChecked() {

	var cbo = document.getElementById(133);
	var ddl = document.getElementById(136);

	if (!ddl.disabled || !ddl.value == '') {
		cbo.disabled = false;
		cbo.checked = true;
	}
}


//TradeMe.namespace('TradeMe.Flat')
//TradeMe.Flat.getElementByIdViaTag = function(id,tagType){
//    var tags = document.getElementsByTagName(tagType);
//    for (var i = 0; i < tags.length; i++) {
//	    if (tags[i].id == id) {return tags[i];}
//    }
//    return null;
//}

function cascadeLocationsByAttributeId2 (
	arrParentChildLink, 
	arrParentOptions, 
	arrChildOptions, 
	strParentNoun, 
	strChildNoun, 
	strMode,
	parentControlId, 
	childControlId,
	countsArrayName) {

	// alert (strChildNoun);

	var ctlParent = $(parentControlId);						    //	ID of the Location attribute DDL
	var ctlChild = $(childControlId);							//	ID of the Suburb attribute DDL
	var ctlSelectedChild = $('selected' + childControlId);	    //	ID of the selected suburb hidden control
	var strActionText  = '';
	var strActionValue = '';	
	if (strMode == 'search') {
		/* HACK for job sub cats */
		if (strChildNoun == 'sub category') {
			strActionText = 'Any sub category';
		}
		else {
			strActionText = 'All ' + strChildNoun + 's';
		}
	}
	else {
		if (strMode == 'default') {
			strActionText  = strChildNoun;
			strActionValue = strChildNoun;
		}
		else {
		    strActionText = 'Choose a ' + strParentNoun + ' first';
		}
	}
	
	/*
	*	Weird hack:
	*		Safari doesn't want to use the getElementById calls above when
	*		the page hasn't finished loading so we have to get all the tags
	*		and loop through to find the correct tag. Putting in onload event
	*		doesn't fix this but subsequent calls to the page later on once loaded
	*		by the user do not seem to be an issue...
	*/
	if (!ctlParent) {ctlParent = "";}		
	if (!ctlChild) {ctlChild = "";}
	if (!ctlSelectedChild) {ctlSelectedChild = "";}
    
	// if no options are selected in the parent control then display a message in the child control
	if (ctlParent.value == '' || ctlParent.text == '') {

		// disable the child control if it's enabled
		if (!ctlChild.disabled) {
			ctlChild.disabled = true;
		}

		// clear the child option list
		ctlChild.options.length = 0
		ctlChild.options[0] = new Option(strActionText, strActionValue, false, false);
	}
	else {
	
		// grab the key of the selected option from the source list
		iCurrSource = ctlParent.options[ctlParent.selectedIndex].value		
	
		// 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 (arrParentChildLink[iCurrSource] == null || arrParentChildLink[iCurrSource].length == 0) {

			var strNoChildrenMsg = '';
			/* HACK for jobs sub categories */
			if (strChildNoun == 'sub category') {
				strNoChildrenMsg = 'No sub categories';
			}
			else {
				strNoChildrenMsg = 'No ' + strChildNoun + 's';
			}
			
			if (ctlChild.options[0].text != strNoChildrenMsg) {

				// clear the child option list
				ctlChild.options.length = 0
				ctlChild.options[0] = new Option (strNoChildrenMsg, strActionValue, false, false);

				// 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 aOptions = new Array();
			for (i = 0; i < arrParentChildLink[iCurrSource].length; i++) {								
				if (arrParentChildLink[iCurrSource][i] == 1) {
					aOptions[i] = i;
				}
			}	
					
			// 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 (i = 0; i < aOptions.length; i++) {
				if (aOptions[i] != null) {
					sortedOptions[sortIndex] = aOptions[i];		// the value (for display) for this child option
					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] = [sortedOptions[i], arrChildOptions[sortedOptions[i]]];				
			}
			
			// Sort the child options array into alphabetical order
                  arrChildOptionsOutput.sort( function( a, b ) {
                 // Hack for jobs: Sort 'Other' subcat last in the list

                 if ( a[1] == 'Other') {
                     return 1;
                 }

                 else if ( b[1] == 'Other') {
                    return -1;
                }

                 else if ( a[1] == b[1] ) {
                     return 0;
                 }

                 else {
                     return a[1] > b[1] ? 1 : -1;
                }

                } );


			// remove the current options
			ctlChild.options.length = 0

			// load the top option
			var topOptionText = '';
			if (strMode == 'search') {
				if (strChildNoun == 'sub category') {
					topOptionText = 'Any sub category';
				}
				else {
					topOptionText = 'All ' + strChildNoun + 's';
				}
			}
			else {
		          if (strMode == 'default') {
		         	topOptionText  = strChildNoun;
					strActionValue = strChildNoun;
				  }
				  else {
		    		topOptionText = 'Choose...';
		  		  }				
			}
			
			ctlChild.options[0] = new Option(topOptionText, strActionValue, false, false);

			// load an empty option to give us a bit of space
			ctlChild.options[1] = new Option('', '', false, false);
			
			// load the child list with the sorted list (starting from the second element)
			var intItemToSelect = 0;
			var optionKey = '';
			var optionValue = '';
			var hasCounts = false;
			if (arguments[8] != null) {
				hasCounts = true;
				// alert ('counts array: ' + countsArrayName);
			}
			for (i = 0; i < arrChildOptionsOutput.length; i++) {
				if (ctlSelectedChild && ctlSelectedChild.value != '' && arrChildOptionsOutput[i][0] == ctlSelectedChild.value) {
					intItemToSelect = i + 2		// add 2 to account for the 0-based array and the 'Choose...' option
				}

				optionKey = arrChildOptionsOutput[i][0];
				optionValue = arrChildOptionsOutput[i][1];								

				if (hasCounts) {
					optionValue = optionValue + ' (' + eval(countsArrayName)[optionKey] + ')'					
				}
				// CAMPER
				ctlChild.options[i + 2] = new Option(optionValue, optionValue, false, false);
			}

			// all options rendered - select the correct option
			ctlChild.options[intItemToSelect].selected = true;

		}
	}

	// Fire the onChange event explicitly on the child to cascade changes.
	if (ctlChild.onchange) ctlChild.onchange();
}

function validateMulti (multi, cbo)
{
	var anySelected;
	var allSelected;
	
	if (multi.options.length == 0) {
		anySelected = false;
		allSelected = false;
	}
	else {
		anySelected = false;
		allSelected = true;

		for (iLoop = 0; iLoop < multi.options.length; iLoop++) {
			if (multi.options[iLoop].selected) {
				anySelected = true;
			}
			else {
				allSelected = false;
			}
		}
	}
	
	// resolve the state of the cbo based on the contents of the multi.
	if (allSelected && !cbo.checked) {
		cbo.checked = true;
	}
	else if (!allSelected && cbo.checked) {
		cbo.checked = false;
	}
}

function getBitArray (arrIn)
{
	return g (arrIn);
}

function g (arrIn)
{
	var arrOut = new Array();
	
	for (iLoop = 0; iLoop < arrIn.length; iLoop++) {
		arrOut[arrIn[iLoop]] = 1;
	}
	
	return (arrOut);
}

function numberorder(a, b)
{
	return a - b;
}