var arrOldValues;
var select_changed;

function SelectAllList(CONTROL)
{
	for(var i = 0;i < CONTROL.length;i++)
	{
		CONTROL.options[i].selected = true;
	}
}

function DeselectAllList(CONTROL)
{
	for(var i = 0;i < CONTROL.length;i++)
	{
		CONTROL.options[i].selected = false;
	}
}

function FillListValues(CONTROL)
{
	var arrNewValues;
	var strTemp = GetSelectValues(CONTROL);
	arrNewValues = strTemp.split(",");
	for(var i=0;i<arrNewValues.length-1;i++)
	{
		if(arrNewValues[i]==1)
		{
			intNewPos = i;
		}
	}

	for(var i=0;i<arrOldValues.length-1;i++)
	{
		if(arrOldValues[i]==1 && i != intNewPos)
		{
			CONTROL.options[i].selected= true;
		}
		else if(arrOldValues[i]==0 && i != intNewPos)
		{
			CONTROL.options[i].selected= false;
		}
	}

	if(arrOldValues[intNewPos]==1)
	{
		CONTROL.options[intNewPos].selected= false;
	}
	select_changed=1;
}


function GetSelectValues(CONTROL)
{
	var strTemp = "";
	for(var i = 0;i < CONTROL.length;i++)
	{
		if(CONTROL.options[i].selected == true)
		{
			strTemp += "1,";
		}
		else
		{
			strTemp += "0,";
		}
	}
	return strTemp;
}

function GetCurrentListValues(CONTROL)
{
	var strValues = "";
	strValues = GetSelectValues(CONTROL);
	arrOldValues = strValues.split(",");
	select_changed=0;
}

function LastOption(CONTROL)
{
	num_selected=0;
	for(var i = 0;i < CONTROL.length;i++)
	{
		if(CONTROL.options[i].selected == true)
			num_selected++;
	}
	if(select_changed!=0 || num_selected!=1 || arrOldValues[CONTROL.selectedIndex]== undefined)
		return;
	if(arrOldValues[CONTROL.selectedIndex]== 1)
	{
		CONTROL.options[CONTROL.selectedIndex].selected = false;
	}
	else
	{
		CONTROL.options[CONTROL.selectedIndex].selected = true;
	}
}