//
//	function FORM_SeleccionPorValor(control, VALOR, forcecheck)
//	function WINDOW_AbrirCentrada(WINWIDTH, WINHEIGHT, strURL, Nombre)
//	function FORM_Desactivar(FORMNAME)
//	function FORM_Activar(FORMNAME)
//	function FORM_DesactivarFormularios()
//	function FORM_ActivarFormularios()
//


// -------------------------------------------
// SELECCION POR VALOR
// -------------------------------------------
function FORM_SeleccionPorValor(control, VALOR, forcecheck)
{
	if (forcecheck == null) forcecheck = false;
	if (control != null) {
		if (typeof(control) == "object") {
			if (control.length == null) {
				control = (control.name);
			}
			else {
				control = (control[0].name);
			}
		}
		if (document["frmDatos"][control])
		{
			intTope = document["frmDatos"][control].length - 1;
			if (isNaN(intTope)) {
				if (forcecheck)
				{
					if (document["frmDatos"][control].value == VALOR) document["frmDatos"][control].checked = true;
				}
				else
				{
					if (document["frmDatos"][control].value == VALOR) document["frmDatos"][control].checked = !document["frmDatos"][control].checked;
				}
			}
			else
			{
				for (intIndiceSeleccionPorValor=0; intIndiceSeleccionPorValor <=intTope; intIndiceSeleccionPorValor++){
					if (forcecheck)
					{
						if (document["frmDatos"][control][intIndiceSeleccionPorValor].value==VALOR) document["frmDatos"][control][intIndiceSeleccionPorValor].checked = true
					}
					else
					{
						if (document["frmDatos"][control][intIndiceSeleccionPorValor].value==VALOR) document["frmDatos"][control][intIndiceSeleccionPorValor].checked = !document["frmDatos"][control][intIndiceSeleccionPorValor].checked;
					}
				}
			}
		}
	}
}


function WINDOW_AbrirCentrada(WINWIDTH, WINHEIGHT, strURL, Nombre)
{
	CentroX = (screen.availWidth / 2) - (WINWIDTH / 2);
	if (CentroX < 0){CentroX = 0}
	CentroY = ((screen.availHeight / 2) - (WINHEIGHT / 2)) - 24;
	if (CentroY < 0){CentroY = 0;}
	strParametros = 'width=' + WINWIDTH + ',height=' + WINHEIGHT + ',scrollbars=1,resizable=1,toolbar=0,status=1,menubar=0, top=' + CentroY + ',left=' + CentroX + ',alwaysRaised=yes';
	if (Nombre == undefined)
	{
		ventana = window.open(strURL,'',strParametros);
	}
	else
	{
		ventana = window.open(strURL, Nombre, strParametros);
	}
	return ventana;
}


function FORM_Desactivar(FORMNAME)
{
	var objForm = document.forms[FORMNAME];

	var numElem = objForm.elements.length;
	for (i = 0; i < numElem; i++) {
		elem = objForm.elements[i];

		if (elem.type == "checkbox") {
			elem.disabled = true;
		}
		else if (elem.type == "radio") {
			elem.disabled = true;
		}
		else if (elem.type == "select-one") {
			elem.disabled = true;
		}
		else {
			//elem.disabled = true;
			elem.readOnly = true;
			elem.style.backgroundColor = '#eeeeee';
		}
	}
}


function FORM_Activar(FORMNAME)
{
	var objForm = document.forms[FORMNAME];

	numElem = objForm.elements.length;
	for (i = 0; i < numElem; i++) {
		elem = objForm.elements[i];

		if (elem.type == "checkbox") {
			elem.disabled = false;
		}
		else if (elem.type == "radio") {
			elem.disabled = false;
		}
		else if (elem.type == "select-one") {
			elem.disabled = false;
		}
		else {
			//elem.disabled = false;
			elem.readOnly = false;
			elem.style.backgroundColor = '#fff1da';
		}
	}
}

function FORM_DesactivarFormularios()
{
	for (n = 0; n < document.forms.length; n++)
	{
		objForm = document.forms[n];
		numElem = objForm.elements.length;
		for (i = 0; i < numElem; i++) {
			objForm.elements[i].disabled = true;
		}
	}
}

function FORM_ActivarFormularios()
{
	for (n = 0; n < document.forms.length; n++)
	{
		objForm = document.forms[n];
		numElem = objForm.elements.length;
		for (i = 0; i < numElem; i++) {
			objForm.elements[i].disabled = false;
		}
	}
}


//--------------------------------------------------------------------------------------------------------
// REALIZA UN POST DEL FORM POR IFRAME
//--------------------------------------------------------------------------------------------------------
function FORM_Submit(FORMNAME, FRAMENAME, strURL)
{
	document.forms[FORMNAME].target = FRAMENAME;
	document.forms[FORMNAME].action = strURL;
	document.forms[FORMNAME].submit();
	document.forms[FORMNAME].target = '';
}

function FORM_SubmitTop(FORMNAME, strURL)
{
	FORM_Submit(FORMNAME,"_top",strURL);
}

function FORM_SubmitBlank(FORMNAME, strURL)
{
	FORM_Submit(FORMNAME,"_blank",strURL);
}

function FORM_SubmitSelf(FORMNAME, strURL)
{
	FORM_Submit(FORMNAME, "_self", strURL);
}

//--------------------------------------------------------------------------------------------------
// RECOPILA ELEMENTOS DE UN LIST BOX Y LOS GUARDA EN UNA LISTA SEPARADA POR COMAS EN UN HIDDEN
//--------------------------------------------------------------------------------------------------
function LISTBOX_RecopilarValores(control, hidden)
{
	LISTBOXCONTROL = document.getElementById(control);
	HIDDENLIST = document.getElementById(hidden);

	HIDDENLIST.value = "";
	count = LISTBOXCONTROL.length;
	for (n = 0; n < count; n++) {
		VALOR = LISTBOXCONTROL.options[n].value;

		if (HIDDENLIST.value != "") HIDDENLIST.value += ', ';
		HIDDENLIST.value += VALOR;
	}
}

//--------------------------------------------------------------------------------------------------
// TRASPASA ELEMENTOS SELECCIONADOS DE UN LIST BOX A OTRO
//--------------------------------------------------------------------------------------------------
function LISTBOX_TraspasarValoresSeleccionados(controlorigen, controldestino)
{
	LISTBOXORIG = document.getElementById(controlorigen);
	LISTBOXDEST = document.getElementById(controldestino);

	count = LISTBOXORIG.length;
	a = 0;
	b = LISTBOXDEST.length;
	while (a < count) {
		if (LISTBOXORIG.options[a].selected) {
			VALOR = LISTBOXORIG.options[a].value;
			TEXT = LISTBOXORIG.options[a].innerHTML;
			LISTBOXDEST.options[b] = new Option(TEXT, VALOR);
			b++;
			LISTBOXORIG.options[a] = null;
			a--;
			count--;
		}
		a++;
	}
}

//--------------------------------------------------------------------------------------------------
// QUITA ELEMENTOS EN EL LISTBOX DE LA IZQUIERDA QUE YA ESTEN EN LISTBOX DE LA DERECHA
//--------------------------------------------------------------------------------------------------
function LISTBOX_QuitarRepetidosIzquierda(controlizq, controlderecha)
{
	LISTBOXIZQ = document.getElementById(controlizq);
	LISTBOXDER = document.getElementById(controlderecha);

	count = LISTBOXDER.length;
	for (n = 0; n < count; n++) {
		VALOR = LISTBOXDER.options[n].value;
		numelem = LISTBOXIZQ.length;
		i = 0;
		while (i < numelem)
		{
			if (LISTBOXIZQ.options[i].value == VALOR) {
				LISTBOXIZQ.options[i] = null;
				break;
			}
			i++;
		}
	}
}

//--------------------------------------------------------------------------------------------------
// QUITA ELEMENTOS DE UN LISTBOX POR VALOR
//--------------------------------------------------------------------------------------------------
function LISTBOX_QuitarPorValor(control, valororigen)
{
	LISTBOXCONTROL = document.getElementById(control);
	count = LISTBOXCONTROL.length;

	for (n = 0; n < count; n++)
	{
		VALOR = LISTBOXCONTROL.options[n].value;

		if (VALOR==valororigen) LISTBOXCONTROL.options[n] = null;
	}
}

//--------------------------------------------------------------------------------------------------
// ELIMINA LOS ELEMENTOS SELECCIONADOS DE UN LISTBOX
//--------------------------------------------------------------------------------------------------
function LISTBOX_QuitarSeleccionados(control)
{
	LISTBOXCONTROL = document.getElementById(control);

	count = LISTBOXCONTROL.length;

	for (n = 0; n < count; n++)
	{
		if (LISTBOXCONTROL.options[n].selected)
		{
			LISTBOXCONTROL.options[n] = null;
			break;
		}
	}
}

