
function InsertInSortedSelect( text, value, selectField, select )
{
	if ( selectField )
	{
		if ( selectField.length == 0 ) // No items
		{
			selectField.options[ selectField.length ] = new Option( text, value, false, select );
		}
		else
		if ( selectField.options[ selectField.length - 1 ].text.toUpperCase() < text.toUpperCase() ) // Last item
		{
			selectField.options[ selectField.length ] = new Option( text, value, false, select );
		}
		else
		{
			var index = 0;
			while ( text.toUpperCase() > selectField.options[index].text.toUpperCase() && index < selectField.length - 1 )
			{
				index++;
			}
//			if ( selectField.options[index + 1 ].text.toUpperCase() != text.toUpperCase() )    // if item allready exists
//			{
				for ( var i = selectField.length; i > index; i-- )
				{
					selectField.options[i] = new Option( selectField.options[i-1].text, selectField.options[i-1].value, false, false );
				}
				selectField.options[index] = new Option( text, value, false, select );
//			}
		}
	}
}

function InsertNumberInSortedSelect( number, value, selectField, select )
{
	if ( selectField )
	{
		if ( selectField.length == 0 ) // No items
		{
			selectField.options[ selectField.length ] = new Option( number, value, false, select );
		}
		else
		if ( parseFloat(selectField.options[ selectField.length - 1 ].text) < parseFloat(number) ) // Last item
		{
			selectField.options[ selectField.length ] = new Option( number, value, false, select );
		}
		else
		{
			var index = 0;
			while ( parseFloat(number) > parseFloat(selectField.options[index].text) && index < selectField.length - 1 )
			{
				index++;
			}
			for ( var i = selectField.length; i > index; i-- )
			{
				selectField.options[i] = new Option( selectField.options[i-1].text, selectField.options[i-1].value, false, false );
			}
			selectField.options[index] = new Option( number, value, false, select );
		}
	}
}

function UpdateTextInSelect( text, value, selectField )
{
	var index = 0;
	while ( index < selectField.length )
	{
		if ( selectField.options[index].value == value )
		{
			selectField.options[index].text = text;
		}
		index++;
	}
}

function DeleteFromSelect( value, selectField )
{
	var index = 0;
	while ( index < selectField.length )
	{
		if ( selectField.options[index].value == value )
		{
			selectField.remove( index );
		}
		else
		{
			index++;
		}
	}
}

