function populate(objForm,selectIndex)
{
	timeA = new Date(objForm.year.options[objForm.year.selectedIndex].text, objForm.month.options[objForm.month.selectedIndex].value,1);
	timeDifference = timeA - 86400000;
	timeB = new Date(timeDifference);
	var daysInMonth = timeB.getDate();
	for (var i = 0; i < objForm.day.length; i++)
	{
		objForm.day.options[0] = null;
	}
	for (var i = 0; i < daysInMonth; i++)
	{
		objForm.day.options[i] = new Option(i+1);
	}
	document.objForm.day.options[0].selected = true;
}

function addResource(source, target, placing)
{
	var sourceLength = Number(source.length);
	var targetLength = Number(target.length);
	
	if ((source.selectedIndex == -1 && placing != 2) || (sourceLength == 2 && source.options[1].value == "dummy"))
	{
		return false;
	}
	
	if (targetLength == 2 && target.options[1].value == "dummy")
	{
		target.remove(0);
		target.remove(1);
		targetLength = 0;
	}
	
	if (placing == 2) // Flytt alle
	{
		for (i=0;i<sourceLength;i++)
		{
			var txt = source.options[0].text;
			var val = source.options[0].value;
			source.remove(0);
			target.options[targetLength++] = new Option(txt, val);
		}
	}
	else
	{
		// Legg objektene som flyttes i target
		var movecount = 0; // Teller for antall ressurser som flyttes
		
		for (var i=0;i<sourceLength;i++)
		{
			if (source.options[i].selected)
			{
				optVal = source.options[i].value;
				optTxt = source.options[i].text;
				target.options[targetLength+movecount] = new Option(optTxt, optVal);
				target.options[targetLength+movecount].selected = 1;
				movecount++;
			}
		}
		
		// Fjern objektene som flyttes fra source
		for (var i=sourceLength-1;i>=0;i--)
		{
			if (source.options[i].selected)
			{
				source.remove(i);
			}
		}
	}
	
	if (source.length == 0)
	{
		source.options[0] = new Option("Ingen ressurser");
		source.options[1] = new Option("", "dummy");
	}
	
	source.focus();
}

function moveResource(move, resources)
{
	var a = resources.selectedIndex;
	var b = a+(move);
	
	if (b >= 0 && resources.options[b] != null)
	{
		var iTxt = resources.options[b].text;
		var iVal = resources.options[b].value;
		resources.options[b] = new Option(resources.options[a].text, resources.options[a].value);
		resources.options[b].selected = 1;
		resources.options[a] = new Option(iTxt, iVal);
		resources.options[a].selected = 0;
	}
}

function selectAll(field)
{
	var rLength = field.length;
	
	if (rLength != 2 || field.options[1].value != "dummy")
	{
		for (i=0;i<rLength;i++)
		{
			field.options[i].selected = 1;
		}
	}
}
