// copy a list into another list //
function copyList(source,target,selected)
	{
		// set counter to the first free spot in the target dropdown
		var counter = target.options.length;
		
		if(selected)
		{	
			// make sure to copy only selected options
			for(i=0 ; i<source.options.length ; i++)
			{
				if(source.options[i].selected)
				{
					var opt = new Option(source.options[i].text, source.options[i].value);
					target.options[counter] = opt;	
					counter++;
				}
			}
		}
		else
		{
			// copy all options
			for(i=0 ; i<source.options.length ; i++)
			{
				var opt = new Option(source.options[i].text, source.options[i].value);
				target.options[i] = opt;
			}
		}
	}		
	


// copy a list into another list //
function copyListNoDupp(source,target,selected)
	{
		// set counter to the first free spot in the target dropdown
		var counter = target.options.length;
	
		for(i=0 ; i<source.options.length ; i++)
		{
			if(selected)
			{	
				// make sure to copy only selected options
				if(source.options[i].selected)
				{
					// check for dupplicates
					if( containsValue(target,source.options[i].value) == false ) 
					{
						// check and replace placeholder if it is the 1st and only option present
						//if( i == 0 && target.options[i].value == -1 ) {
						//	counter = 0;
						//}				
						var opt = new Option(source.options[i].text, source.options[i].value);
						target.options[counter] = opt;	
						counter++;						
					}
				}
			}
			else
			{
				var opt = new Option(source.options[i].text, source.options[i].value);
				target.options[i] = opt;
			}
		}
	}


  // returns true if the 'target' dropdown contains the 'value' value 
  function containsValue(target,value)
	{
		for(j=0 ; j<target.options.length ; j++) 
		{
			if(target.options[j].value == value)
			{
				return true;
			}
		}
		return false;
	}


	// returns the text associated with a value in a dropdown
	function getLabel(target, value)
	{	
		for(m=0 ; m<target.options.length ; m++) 
		{
			if(target.options[m].value == value)
			{
				return target.options[m].text;
			}
		}
		return null;
	}

	// remove last element from a list //
	function clearLast(target)
	{
		if(target.options.length != 0)
		{
			target.options[target.options.length-1] = null;
		}
	}


	// remove all elements from a list //
	function clearList(target)
	{
		while(target.options.length != 0)
		{
			target.options[0] = null;
		}
	}

	// select all elements from a list //
	function selectList(target)
	{
		if (target!=null) {
		for(k=0 ; k<target.options.length ; k++)
		{
			target.options[k].selected = true;
		}
		}
	}

	function unselectList(target)
	{
		for(i=0 ; i<target.options.length ; i++)
		{
			target.options[i].selected = false;
		}
	}



	// remove selected entries from a list //
	function clearSelectedList(target)
	{
		var totalLength = target.options.length;
		var counter = 0;

		for(counter=0 ; counter<totalLength ; counter++)
		{
			if(target.options[counter].selected)
			{
				target.options[counter] = null;
				totalLength--;
				counter --;
			}
		}
	}

	// set the articles to copy to all 
	function setCopyToAll(source,target)
	{	
		copyList(source,target,false);
	}	

	// set the articles to copy to the ones selected 
	function setCopyTo(source,target)
	{
		//clearList(target);
		copyList(source,target,true);
	}

	// advanced version of the above
	function setCopyToNoDupp(source,target)
	{
		copyListNoDupp(source,target,true);
	}

	// remove all articles to copy to 
	function removeCopyAll(target)
	{
		clearList(target)
	}
	
	// remove selected articles to copy to
	function removeCopy(target)
	{
		clearSelectedList(target)
	}