//this function is used to swap between elements

function swap(combo,index1, index2)
{
	var savedValue=combo.options[index1].value;
	var savedText=combo.options[index1].text;

	combo.options[index1].value=combo.options[index2].value;
	combo.options[index1].text=combo.options[index2].text;

	combo.options[index2].value=savedValue;
	combo.options[index2].text=savedText;
}

//moves options from one selection box (combo box) to another
//removes the all selected options from one combo box and adds them to the second combo box

function MoveElements(FromCombo,ToCombo)
{
	var to_remove_counter=0; //number of options that were removed (num selected options)

	//move selected options to right select box (to)
	for (var i=0;i<FromCombo.options.length;i++)
	{
		if (FromCombo.options[i].selected==true)
		{
			var addtext=FromCombo.options[i].text;
			var addvalue=FromCombo.options[i].value;
			ToCombo.options[ToCombo.options.length]=new Option(addtext,addvalue);
			FromCombo.options[i].selected=false;
			++to_remove_counter;
		}
		else
		{
			FromCombo.options[i-to_remove_counter].selected=false;
			FromCombo.options[i-to_remove_counter].text=FromCombo.options[i].text;
			FromCombo.options[i-to_remove_counter].value=FromCombo.options[i].value;
		}
	}

	//now cleanup the last remaining options 
	var numToLeave=FromCombo.options.length-to_remove_counter;
	for (i=FromCombo.options.length-1;i>=numToLeave;i--) 
	{ 
		FromCombo.options[i]=null;
	}
}

function MoveAllElements(FromCombo,ToCombo)
{
	var to_remove_counter=0; //number of options that were removed (num selected options)

	//move selected options to right select box (to)
	for (var i=0;i<FromCombo.options.length;i++)
	{
		
			var addtext=FromCombo.options[i].text;
			var addvalue=FromCombo.options[i].value;
			ToCombo.options[ToCombo.options.length]=new Option(addtext,addvalue);
			FromCombo.options[i].selected=false;
			++to_remove_counter;
		
	}

	//now cleanup the last remaining options 
	var numToLeave=FromCombo.options.length-to_remove_counter;
	for (i=FromCombo.options.length-1;i>=numToLeave;i--) 
	{ 
		FromCombo.options[i]=null;
	}
}
function resetcountries() {
	for (var k = 0; k < countries.length; k++) {
		libecondb.left_countries.options[k].value = countries[k].code
		libecondb.left_countries.options[k].text = countries[k].name
	}
}


function doReset() {
	libecondb.right_countries.options.length = 0
	libecondb.left_countries.options.length = countries.length
	resetcountries()


}

function doSubmit() {
	for (var i = 0; i < libecondb.right_countries.length; i++) {
		libecondb.right_countries.options[i].selected=true
	}
}


function validateentry(libecondb) {
	doSubmit()
	if (libecondb.sector.value == "nochoice") {
		alert("Please select a library sector.")
		libecondb.sector.focus()
		return false
	} else {
	if (libecondb.xindicator.value == "nochoice") {
		alert("Please select an x-indicator.")
		libecondb.xindicator.focus()
		return false
	} else {
	if (libecondb.right_countries.value == null || libecondb.right_countries.value == "") {
		alert("Please select countries.")
		libecondb.left_countries.focus()
		return false
	} else {
	if (libecondb.mapyear.value == "nochoice") {
		alert("Please select a year to display.")
		libecondb.mapyear.focus()
		return false
	} else {
	return true
		}
		}
		}
	}
	}
	