<script type="text/javascript">
function Move_Select(objSourceElement, objTargetElement)
{
var aryTempSourceOptions = new Array();
var aryTempTargetOptions = new Array();
var x = 0;
//looping through source element to find selected options
for (var i = 0; i < objSourceElement.length; i++) {
if (objSourceElement.options[i].selected) {
//need to move this option to target element
var intTargetLen = objTargetElement.length++;
objTargetElement.options[intTargetLen].text = objSourceElement.options[i].text;
objTargetElement.options[intTargetLen].value = objSourceElement.options[i].value;
}else {
//storing options that stay to recreate select element
var objTempValues = new Object();
objTempValues.text = objSourceElement.options[i].text;
objTempValues.value = objSourceElement.options[i].value;
aryTempSourceOptions[x] = objTempValues;
x++;
}
}
//sorting and refilling target list
for (var i = 0; i < objTargetElement.length; i++) {
var objTempValues = new Object();
objTempValues.text = objTargetElement.options[i].text;
objTempValues.value = objTargetElement.options[i].value;
aryTempTargetOptions[i] = objTempValues;
}
aryTempTargetOptions.sort(sortByText);
for (var i = 0; i < objTargetElement.length; i++) {
objTargetElement.options[i].text = aryTempTargetOptions[i].text;
objTargetElement.options[i].value = aryTempTargetOptions[i].value;
objTargetElement.options[i].selected = false;
}
//resetting length of source
objSourceElement.length = aryTempSourceOptions.length;
//looping through temp array to recreate source select element
for (var i = 0; i < aryTempSourceOptions.length; i++) {
objSourceElement.options[i].text = aryTempSourceOptions[i].text;
objSourceElement.options[i].value = aryTempSourceOptions[i].value;
objSourceElement.options[i].selected = false;
}
}
function sortByText(a, b)
{
if (a.text < b.text) {return -1}
if (a.text > b.text) {return 1}
return 0;
}
function selectAll(objTargetElement)
{
for (var i = 0; i < objTargetElement.length; i++) {
objTargetElement.options[i].selected = true;
}
return false;
}
function seleccionar(obj) {
a = new Array();
elem=document.getElementById(obj).options;
for(i=0;i<elem.length;i++)
{
//elem[i].selected=true;
//alert(elem[i].value);
a[i] = elem[i].value
}
//elem[0].value = implode(a);
//elem[0].selected= true;
//a = new Array(0,1,2,3,4,5,6,7,8,9);
return implode(a);
}
function implode(array){
var imploded=array[0];
for (i=1; i<array.length; i++)imploded += '+' + array[i];
return imploded
}
function llenardatos_select(LI,origen,destino)
{
var datos = LI.split("+");
for (i=0; i < datos.length; i++)
{
//alert (lineainv[i]);
document.getElementById(origen).value = datos[i];
Move_Select(document.getElementById(origen),document.getElementById(destino))
}
}function Move_Select(objSourceElement, objTargetElement)
{
var aryTempSourceOptions = new Array();
var aryTempTargetOptions = new Array();
var x = 0;
//looping through source element to find selected options
for (var i = 0; i < objSourceElement.length; i++) {
if (objSourceElement.options[i].selected) {
//need to move this option to target element
var intTargetLen = objTargetElement.length++;
objTargetElement.options[intTargetLen].text = objSourceElement.options[i].text;
objTargetElement.options[intTargetLen].value = objSourceElement.options[i].value;
}else {
//storing options that stay to recreate select element
var objTempValues = new Object();
objTempValues.text = objSourceElement.options[i].text;
objTempValues.value = objSourceElement.options[i].value;
aryTempSourceOptions[x] = objTempValues;
x++;
}
}
//sorting and refilling target list
for (var i = 0; i < objTargetElement.length; i++) {
var objTempValues = new Object();
objTempValues.text = objTargetElement.options[i].text;
objTempValues.value = objTargetElement.options[i].value;
aryTempTargetOptions[i] = objTempValues;
}
aryTempTargetOptions.sort(sortByText);
for (var i = 0; i < objTargetElement.length; i++) {
objTargetElement.options[i].text = aryTempTargetOptions[i].text;
objTargetElement.options[i].value = aryTempTargetOptions[i].value;
objTargetElement.options[i].selected = false;
}
//resetting length of source
objSourceElement.length = aryTempSourceOptions.length;
//looping through temp array to recreate source select element
for (var i = 0; i < aryTempSourceOptions.length; i++) {
objSourceElement.options[i].text = aryTempSourceOptions[i].text;
objSourceElement.options[i].value = aryTempSourceOptions[i].value;
objSourceElement.options[i].selected = false;
}
}
function sortByText(a, b)
{
if (a.text < b.text) {return -1}
if (a.text > b.text) {return 1}
return 0;
}
function selectAll(objTargetElement)
{
for (var i = 0; i < objTargetElement.length; i++) {
objTargetElement.options[i].selected = true;
}
return false;
}
function seleccionar(obj) {
a = new Array();
elem=document.getElementById(obj).options;
for(i=0;i<elem.length;i++)
{
//elem[i].selected=true;
//alert(elem[i].value);
a[i] = elem[i].value
}
//elem[0].value = implode(a);
//elem[0].selected= true;
//a = new Array(0,1,2,3,4,5,6,7,8,9);
return implode(a);
}
function implode(array){
var imploded=array[0];
for (i=1; i<array.length; i++)imploded += '+' + array[i];
return imploded
}
function llenardatos_select(LI,origen,destino)
{
var datos = LI.split("+");
for (i=0; i < datos.length; i++)
{
//alert (lineainv[i]);
document.getElementById(origen).value = datos[i];
Move_Select(document.getElementById(origen),document.getElementById(destino))
}
}
</script>