// JavaScript Document

// onclick="javascript:MoverAcimaSelect(id_select)"
// onclick="javascript:MoverAbaixoSelect(id_select)"

function MoverAcimaSelect(listField) {
	var selected;
	var moveText1;
	var moveText2;
	var moveValue1;
	var moveValue2;
	var moveId1;
	var moveId2;
	try{
	   if ( listField.length == -1) {  // If the list is empty
	   	return;
	   } else {
		  selected = listField.selectedIndex;
		  if (selected == -1) {
		  } else {  // Something is selected 
			 if ( listField.length == 0 ) {  // If there's only one in the list
			 } else {  // There's more than one in the list, rearrange the list order
				if ( selected == 0 ) {
				} else {
				   // Get the text/value of the one directly above the hightlighted entry as
				   // well as the highlighted entry; then flip them
				   moveText1 = listField[selected-1].text;
				   moveText2 = listField[selected].text;
				   moveValue1 = listField[selected-1].value;
				   moveValue2 = listField[selected].value;
				   moveId1 = listField[selected-1].id;
				   moveId2 = listField[selected].id;
				   listField[selected].text = moveText1;
				   listField[selected].value = moveValue1;
				   listField[selected].id = moveId1;
				   listField[selected-1].text = moveText2;
				   listField[selected-1].value = moveValue2;
				   listField[selected-1].id = moveId2;
				   listField.selectedIndex = selected-1; // Select the one that was selected before
				}  // Ends the check for selecting one which can be moved
			 }  // Ends the check for there only being one in the list to begin with
		  }  // Ends the check for there being something selected
	   }  // Ends the check for there being none in the list
	}catch(e){alert(e.message);}
}

//----------------------------------------------------------------------------------------
function MoverAbaixoSelect(listField) {
	var selected;
	var moveText1;
	var moveText2;
	var moveValue1;
	var moveValue2;
	var moveId1;
	var moveId2;
	try{
	   if ( listField.length == -1) {  // If the list is empty
		return;
	   } else {
		  var selected = listField.selectedIndex;
		  if (selected == -1) {
		  } else {  // Something is selected 
			 if ( listField.length == 0 ) {  // If there's only one in the list
			 } else {  // There's more than one in the list, rearrange the list order
				if ( selected == listField.length-1 ) {
				} else {
				   // Get the text/value of the one directly below the hightlighted entry as
				   // well as the highlighted entry; then flip them
				   var moveText1 = listField[selected+1].text;
				   var moveText2 = listField[selected].text;
				   var moveValue1 = listField[selected+1].value;
				   var moveValue2 = listField[selected].value;
				   var moveId1 = listField[selected+1].id;
				   var moveId2 = listField[selected].id;
				   listField[selected].text = moveText1;
				   listField[selected].value = moveValue1;
				   listField[selected].id = moveId1;
				   listField[selected+1].text = moveText2;
				   listField[selected+1].value = moveValue2;
				   listField[selected+1].id = moveId2;
				   listField.selectedIndex = selected+1; // Select the one that was selected before
				}  // Ends the check for selecting one which can be moved
			 }  // Ends the check for there only being one in the list to begin with
		  }  // Ends the check for there being something selected
	   }  // Ends the check for there being none in the list
	}catch(e){alert(e.message);}
}

