// Invoke listbox update
function invokeUpdateListbox( targetListboxId, category, selectedParentOption, selectedOption, site )
	{
	/* Create URL for ajax query (category and selected option) */
	url = "/objectmanager2/?cmd=get_areas_xml&category=" + category + "&selectedParentOption=" + selectedParentOption + "&selectedOption=" + selectedOption + "&site=" + site;

	/* Make ajax query AND redirect response to apropriate function */
	sendAjaxQuery(url, updateListBox, targetListboxId);
	}
// Update listbox
function updateListBox( xmlDoc, targetListboxId )
	{
	if( xmlDoc.readyState == 4 && xmlDoc.status == 200 )
		{
		/* Clear listbox */
		var targetListbox = document.getElementById(targetListboxId);
		for( var count = targetListbox.options.length-1; count >-1; count-- )
			targetListbox.options[count] = null;

		/* Get response as text */
		var xmlDocResponseStr = xmlDoc.responseXML.selectSingleNode("/xmlRoot").firstChild.nodeValue;
		var xmlDocResponseArray = xmlDocResponseStr.split(";");
		
		/* Add items to listbox */
		if( xmlDocResponseArray.length )
			{
			for( var i = 0; i < xmlDocResponseArray.length; i++ )
				{
				var temp = xmlDocResponseArray[i].split(":");
				if( temp.length == 3 )
					{
					targetListbox.options[i] = new Option(temp[0], temp[1], false, false);
					if( temp[2] == 'true' ) targetListbox.options[i].selected = true;
					}
				}
			}
		else
			targetListbox.options[0] = new Option('', '', false, false);

		xmlDoc = null;
		}
	}

// Add option to listbox
function addOption( addTo, addFrom )
	{
	if( addFrom.selectedIndex >= 0 )
		{
		txt = addFrom.options[addFrom.selectedIndex].text;
		val = addFrom.options[addFrom.selectedIndex].value;
		addFrom.options[addFrom.selectedIndex].selected = false;
		if( (val != '') && !optionExists(val, addTo) )
			{
			newOption = new Option(txt, val, false, false);
			if( addTo.length == 1 && (addTo.options[0].value == '') )
				addTo.options[0] = newOption;
			else
				addTo.options[addTo.length] = newOption;
			newOption.selected = false;
			}
		}
	}

// Check if option already exists
function optionExists( val, field )
	{
	for( var i = 0; i < field.length; i++ )
		{
		if( field.options[i].value==val )
			return true;
		}
	return false;
	}

// Remove option from listbox
function removeOption( field )
	{
	if( field.options[field.selectedIndex].value != '' )
		{
		if( field.length == 1 )
			{
			field.options[0].selected = false;
			newOption = new Option(' ','', false, false);
			field.options[0] = newOption;
			}
		else
			field.options[field.selectedIndex] = null;
		}
	else
		field.options[field.selectedIndex].selected = false;
	}

// Choose all options of listbox
function chooseAll( field )
	{
	for( i = 0; i < (field.length); i++ )
		field.options[i].selected = true;
	return true;
	}
