addLoadEvent(FormularioEstandarIndex);
sortitems = 0; //Ordernar items para selector múltiple

function FormularioEstandarIndex()
{

}

function seleccionarTodos(iddesplegable)
{
	desplegable = document.getElementById(iddesplegable)
	
	for(var i=0; i<desplegable.options.length; i++) 
	{
		desplegable.options[i].selected = true;
	}
}


function move(fbox,tbox) 
{
	for(var i=0; i<fbox.options.length; i++) 
	{
		if(fbox.options[i].selected && fbox.options[i].value != '')
		{
			var no = new Option();
			no.value = fbox.options[i].value;
			no.text = fbox.options[i].text;
			//no.selected = true;
			tbox.options[tbox.options.length] = no;
			fbox.options[i].value = '';
			fbox.options[i].text = '';
		}
	}
	BumpUp(fbox);
	if (sortitems) SortD(tbox);
}
function BumpUp(box) {
	for(var i=0; i<box.options.length; i++) {
		if(box.options[i].value == '') {
			for(var j=i; j<box.options.length-1; j++) {
				box.options[j].value = box.options[j+1].value;
				box.options[j].text = box.options[j+1].text;
			}
			var ln = i;
			break;
		}
	}
	if(ln < box.options.length) {
		box.options.length -= 1;
		BumpUp(box);
	}
}
function SortD(box) {
	var temp_opts = new Array();
	var temp = new Object();
	for(var i=0; i<box.options.length; i++) {
		temp_opts[i] = box.options[i];
	}
	for(var x=0; x<temp_opts.length-1; x++) {
		for(var y=(x+1); y<temp_opts.length; y++) {
			if(temp_opts[x].text > temp_opts[y].text) {
				temp = temp_opts[x].text;
				temp_opts[x].text = temp_opts[y].text;
				temp_opts[y].text = temp;
				temp = temp_opts[x].value;
				temp_opts[x].value = temp_opts[y].value;
				temp_opts[y].value = temp;
			}
		}
	}
	for(var i=0; i<box.options.length; i++) {
		box.options[i].value = temp_opts[i].value;
		box.options[i].text = temp_opts[i].text;
	}
}


//-1 subir 1 bajar
function Mover(selectmultiple, inc)
{
	ar = new Array();
	mov = new Array();

	for(var i=0; i<selectmultiple.options.length; i++)
	if(selectmultiple.options[i].selected && selectmultiple.options[i].value != '')
	mov[i]= 1

	if(inc == -1)
	{
		for(var i=0; i<selectmultiple.options.length; i++)
		{
			if(mov[i]==1)
			{
				var temp = new Option();
				temp.value = selectmultiple.options[i+parseInt(inc)].value;
				temp.text = selectmultiple.options[i+parseInt(inc)].text;

				selectmultiple.options[i+parseInt(inc)].value = selectmultiple.options[i].value
				selectmultiple.options[i+parseInt(inc)].text = selectmultiple.options[i].text
				//selectmultiple.options[i+inc].selected = true
				selectmultiple.options[i] = temp
				ar[i+inc] = 1
			}
			else
			{
				ar[i+inc] = 0
			}
		}
	}
	else
	{
		for(var i=selectmultiple.options.length+1; i>=0; i--)
		{
			if(mov[i]==1)
			{
				var temp = new Option();
				temp.value = selectmultiple.options[i+parseInt(inc)].value;
				temp.text = selectmultiple.options[i+parseInt(inc)].text;

				selectmultiple.options[i+parseInt(inc)].value = selectmultiple.options[i].value
				selectmultiple.options[i+parseInt(inc)].text = selectmultiple.options[i].text
				//selectmultiple.options[i+inc].selected = true
				selectmultiple.options[i] = temp
				ar[i+inc] = 1
			}
			else
			{
				ar[i+inc] = 0
			}
		}
	}

	for(var i=0; i<ar.length; i++)
	{
		if(ar[i]==1)
		{
			selectmultiple.options[i].selected = true
		}
	}
}

function FiltrarSelectorMultiple1(idcampo)
{
    var filtro = $("#filtroselector-"+idcampo).val().toString().toLowerCase()
    
    $("#selectormultiple1-"+idcampo+" input:checkbox").each(function(i) {                
        var textoactual = $(this).parent().text().toString().toLowerCase();
        
        if(textoactual.indexOf(filtro) == -1 && filtro != "") 
           $(this).parent().hide()
        else
           $(this).parent().show()  
        
    });  
}
 