function loadThesaurusItemsFromIds()
{
	if(document.getElementById("thesaurus_ids").value != "")
	{
		var id_arr = document.getElementById("thesaurus_ids").value.split(",");
		
		for(i=0; i<id_arr.length; i++)
		{
			for(j=0; j<document.thesaurus_form.chk.length; j++)
			{
				if(document.thesaurus_form.chk[j].value == id_arr[i])
				{
					document.thesaurus_form.chk[j].checked = true;
				}
			}
		}
	}
	
	getThesaurusIds();
}

function getThesaurusIds()
{
	document.getElementById("thesaurus_ids").value = "";
	
	clearThesaurusBox();
	
	var id_arr = new Array();
	
	for(i=0; i<document.thesaurus_form.chk.length; i++)
	{
		if(document.thesaurus_form.chk[i].checked)
		{
			id_arr[id_arr.length] = document.thesaurus_form.chk[i].value;
			
			document.getElementById("txt_" + document.thesaurus_form.chk[i].value).style.color = "#FF0000";
		}
		else
		{
			document.getElementById("txt_" + document.thesaurus_form.chk[i].value).style.color = "#FEFEFE";
		}
	}
	
	for(i=0; i< id_arr.length; i++)
	{
		populateThesaurusBox(id_arr[i]);
		
		if(document.getElementById("thesaurus_ids").value == "") document.getElementById("thesaurus_ids").value = id_arr[i];
		else document.getElementById("thesaurus_ids").value += "," + id_arr[i];
	}
}

function uncheckThesaurusItem(id)
{
	for(j=0; j<document.thesaurus_form.chk.length; j++)
	{
		if(document.thesaurus_form.chk[j].value == id)
		{
			document.thesaurus_form.chk[j].checked = false;
		}
	}
}

function removeSelectedThesaurusBoxItem()
{
	for(i=0; i<document.getElementById("thesaurus_items").options.length; i++)
	{
		if(document.getElementById("thesaurus_items").options[i].selected)
		{
			uncheckThesaurusItem(document.getElementById("thesaurus_items").options[i].value);
		}
	}
	
	getThesaurusIds();
}

function populateThesaurusBox(id)
{
	//var newitem = new Option(thesaurus_js_array[id], id, false, false);
	//document.getElementById("thesaurus_items").options.add(newitem);
	
	document.getElementById("thesaurus_items").options[document.getElementById("thesaurus_items").options.length] = new Option(thesaurus_js_array[id], id);
}

function clearThesaurusBox()
{
	document.getElementById("thesaurus_items").options.length = 0;
}

function selectAll()
{
	for(j=0; j<document.thesaurus_form.chk.length; j++)
	{
		document.thesaurus_form.chk[j].checked = true;
	}
	
	getThesaurusIds();
}

function clearAll()
{
	for(j=0; j<document.thesaurus_form.chk.length; j++)
	{
		document.thesaurus_form.chk[j].checked = false;
	}
	
	getThesaurusIds();
}
