// JavaScript Document

function js_removeLastOptionFromSelect(select_id)
{
	var oSelect = document.getElementById(select_id);
	if (oSelect.length > 0)
	{
    	oSelect.remove(oSelect.length - 1);
	}
}


function js_removeAllOptionsFromSelect(select_id)
{
	var oSelect = document.getElementById(select_id);
	while (oSelect.length > 0)
	{
		oSelect.remove(oSelect.length - 1);
	}
}


function js_addLastOptionToSelect(select_id, text, value)
{
  	var oOption = document.createElement('option');
  	oOption.text = text;
  	oOption.value = value;
  	var oSelect = document.getElementById(select_id);
  	try
  	{
		oSelect.add(oOption, null); // standards compliant; doesn't work in IE
  	}
  	catch(ex)
	{
		oSelect.add(oOption); // IE only
  	}
}

function js_get_select_selected_id(id)
{
  	var oSelect = document.getElementById(id);
	var index = oSelect.selectedIndex;
	var value = oSelect[index].value;
	return value;
}

function js_set_select_selected(id, index)
{
  	var oSelect = document.getElementById(id);
	oSelect.selectedIndex = index;
}

function js_set_select_selected_value(id, value)
{
  	var oSelect = document.getElementById(id);
	for(i = 0; i< oSelect.length; i++)
	{
		if(oSelect[i].value == value)
		{
			js_set_select_selected(id, i);
			return;
		}
	}
}

