function list_getvalue(list,onlyselected,separator)
{
	var result = "";
	if(separator == undefined)
		separator = ";";

	for(var index=0;index < list.length;index++)
	{
		if(onlyselected)
		{
			if(list.options[index].selected)
				result += list.options[index].value + separator;
		}
		else
			result += list.options[index].value + separator;
	}

	if(result != "")
		result = result.substr(0,result.length-1);

	return result;
}

function list_gettext(list,onlyselected,separator)
{
	var result = "";

	for(var index=0;index < list.length;index++)
	{
		if(onlyselected)
		{
			if(list.options[index].selected)
				result += list.options[index].text + separator;
		}
		else
			result += list.options[index].text + separator;
	}

	if(result != "")
		result = result.substr(0,result.length-1);

	return result;
}

function list_inlist(list,onlyselected,value)
{
	var result = false;
	var index = 0;
	while((index < list.length) && (!result))
	{
		if( (onlyselected) && (list.options[index].selected) )
		{
			if(list.options[index].value == value)
				result = true;
		}
		else
			if(list.options[index].value == value)
				result = true;

		index++;
	}
	return result;
}

function list_add(list,value,text)
{
	var index = list.length;
	list.length++;
	list.options[index].value = value;
	list.options[index].text = text;
}

function list_sortadd(list,value,text)
{
	var index = 0;
	var c = 0;

	while((c < list.length) && (list.options[c].value < value))
		c++;

	list.length++;
	for(index=list.length-1;index > c;index--)
	{
		list.options[index].value = list.options[index-1].value;
		list.options[index].text = list.options[index-1].text;
	}
	
	list.options[c].value = value;
	list.options[c].text = text;
}

function list_sortaddtext(list,value,text)
{
	var index = 0;
	var c = 0;

	while((c < list.length) && (list.options[c].text < text))
		c++;

	list.length++;
	for(index=list.length-1;index > c;index--)
	{
		list.options[index].value = list.options[index-1].value;
		list.options[index].text = list.options[index-1].text;
	}
	
	list.options[c].value = value;
	list.options[c].text = text;
}

function list_getnum(list)
{
	return list.length;
}

function list_getselnum(list)
{
	var result = 0;

	for(var index=0;index < list.length;index++)
		if(list.options[index].selected)
			result++;

	return result;
}

function list_del(list,onlyselected)
{
	if(onlyselected)
	{
		var index = 0;
		while(index < list.length)
		{
			if(list.options[index].selected)
			{
				for(var c=index;c < list.length-1;c++)
				{
					list.options[c].value = list.options[c+1].value;
					list.options[c].text = list.options[c+1].text;
					if(list.options[c+1].selected)
						list.selectedIndex = c;
					else
						list.selectedIndex = -1;

					list.options[c].selected = list.options[c+1].selected;
				}

				list.options[list.length-1] = null;
			}
			else
				index++;
		}
	}
	else
	{
		for(var index=0;index < list.length;index++)
			list.options[index] = null;
		list.length = 0;
	}
}

function list_select(list)
{
	for(var index=0;index < list.length;index++)
		list.options[index].selected = true;
}

function list_selectvalue(list,value)
{
	for(var index=0;index < list.length;index++)
		if(list.options[index].value == value)
			list.options[index].selected = true;
}

function list_moveup_option(list,index)
{
	if(index > 0)
	{
		var value = list.options[index-1].value;
		var text = list.options[index-1].text;
		list.options[index-1].value = list.options[index].value;
		list.options[index-1].text = list.options[index].text;
		list.options[index].value = value;
		list.options[index].text= text;
		list.selectedIndex = index-1;
	}
}

function list_movedown_option(list,index)
{
	if(index < list.length-1)
	{
		var value = list.options[index+1].value;
		var text = list.options[index+1].text;
		list.options[index+1].value = list.options[index].value;
		list.options[index+1].text = list.options[index].text;
		list.options[index].value = value;
		list.options[index].text= text;
		list.selectedIndex = index+1;
	}
}

//==========================================================================================================
// Desc: atmasolja az egyik listabol az elemeket egy masikba.Ha onlyselected erteke igaz , akkor csak
//		 azokat masolja at , melyek ki vannak jelolve.
//
//==========================================================================================================
function list_copy(src,dest,onlyselected)
{
	d=dest.length;
	for(c=0;c<src.length;c++)
		if((!onlyselected) || (onlyselected && src.options[c].selected))
		{
			if(dest.options[d])
			{
				dest.options[d].text=src.options[c].text;
				dest.options[d].value=src.options[c].value;
			}
			else
			{
				dest.options[d] = new Option(src.options[c].text);
				dest.options[d] = new Option(src.options[c].text,src.options[c].value);
			}
			d++;
		}
}

//==========================================================================================================
// Desc: atmazgatja az egyik listabol az elemeket egy masikba.Ha onlyselected erteke igaz , akkor csak
//		 azokat mozgatja at , melyek ki vannak jelolve.
//
//==========================================================================================================
function list_move(src,dest,onlyselected)
{
	list_copy(src,dest,onlyselected);

	for(c=src.length-1;c>=0;c--)
		if((!onlyselected) || (onlyselected && src.options[c].selected))
			src.options[c] = null;
}
