
function swapItems (theSource, theDestination){
	var source = document.getElementById(theSource);
	var destination = document.getElementById(theDestination);
	
	// Add items to the destination
    for (var i = 0; i < source.length; i++)	{
        if (source.options[i].selected == true)	{
            destination.options[destination.length] = new Option(source.options[i].text, source.options[i].value);			
        }
    }

	// Remove items from the source
    for (var i = (source.length - 1); i >= 0; i--)	{
        if (source.options[i].selected)	{
            source.options[i] = null;
        }
    }
}

//the arguments in this function are varied, add as many select list element id's as you wish to be selected
function selectAllItems() {		
	for(var i=0; i<arguments.length; i++)  {
		var List1 = document.getElementById(arguments[i]);
		if(List1) {			
			for(i2=0;i2<List1.options.length;i2++) {			
				List1.options[i2].selected = true;			
			}
		}
	}	
}

//basically refresh the page (reload itself or specified url in args)
function loadCurrentPage(url) {
	if(!url)
		document.forms[0].action = window.location.href;	
	else
		document.forms[0].action = url;	
	window.document.forms[0].submit();
}

function deleteItem(theSource,theSource2,doublecheck){
	var source = document.getElementById(theSource);	
	if(theSource2)
		var secondSource = document.getElementById(theSource2);	
	var goahead = true;	
	var deleted = new Array();
	// Remove items from the source
	if(doublecheck==true) {
		if(!confirm("Are you sure you wish to delete the selected items?")) 
			goahead = false;		 
	}
	
	if(goahead) {
		var b=0;
		for (var i = (source.length - 1); i >= 0; i--)	{
			if (source.options[i].selected)	{
				deleted[b] = source.options[i];
				source.options[i] = null;
				b++;
			}
		}
		//now delete what is in the secondSource if it was given
		if(theSource2) {
			for (var i = (secondSource.length - 1); i >= 0; i--)	{
				for(var a = (deleted.length - 1); a >= 0; a--) {
					if (secondSource.options[i].value==deleted[a].value)	{
						secondSource.options[i] = null;
						break;
					}
				}
			}
		}
	}
}
