function clearList(id)
{
	var ul = $(id);
	if (ul != null)
	{
		while (ul.hasChildNodes())
		{
			ul.removeChild(ul.childNodes[0]);
		}
	}
}


function clearSelect(id)
{
	var sel = $(id);
	if (sel != null)
	{
		sel.options.length = 0;
	}
}

function addToList(id, text, link)
{
	var ul = $(id);
	if (ul != null)
	{
		var li;
		
		if (link != null)
		{
			var a = Builder.node('a', {'href': link}, [text]);
			li = Builder.node('li', {}, [a]);
		}
		else
		{
			li =  Builder.node('li', {}, [text]);
		}
		
		ul.appendChild(li);
	}
}

function addToSelect(id, key, text)
{	
	var sel = $(id);
	if (sel != null)
	{
		// select it if this is the first
		var isSelected = sel.options.length == 0 ? true : false;
		sel.options[sel.options.length] = new Option(text, key, isSelected);
	}
}


function selectValue(id, value)
{
	//alert("Searching " + id + " for " + value);
	var sel = $(id);
	if (sel != null)
	{
		var options = sel.options;
		for (var i = 0; i < options.length; i++)
		{
			if (options[i].value == value)
			{
				sel.selectedIndex = i;
				break;
			}
		}
	}	
}
