/*
Carga combos que dependen de otros.
*/
function cargarSubItems(nombreArraySubItems, frm, nombreComboItems, nombreComboSubItems, valorDefaultSubItems, valueIgualText, insertarSeleccionar, nombreComboSubItemsDestino, OptionValueVacio) {
	var thisForm = eval(document.forms[frm]);
	var thisCmbItems = eval("document.forms['" + frm + "']." + nombreComboItems);
	var thisCmbSubItems = eval("document.forms['" + frm + "']." + nombreComboSubItems);
	var thisCmbSubItemsDestino = (nombreComboSubItemsDestino != null ? eval("document.forms['" + frm + "']." + nombreComboSubItemsDestino) : null);
	var arrSubItems = eval(nombreArraySubItems);
	var i, theValue, iPosSelComboItems, iValorPosSelComboItems;

	// Texto que va en el option que tiene de value vacío ó cero.
	nombreOptionValueVacio = "TODAS";
	if(OptionValueVacio != null && OptionValueVacio != 'TODAS')
		nombreOptionValueVacio = OptionValueVacio;
	
	if ( thisCmbItems.selectedIndex > 0 ) {
		// Inicializo el combo de productos
		thisCmbSubItems.options.length=0;

		// Cargo el valor de los options de productos
		i = 0;
		// Inserto opción de SELECCIONAR
		if ( insertarSeleccionar != null && insertarSeleccionar ) {
			thisCmbSubItems.options[i++] = new Option('-- '+nombreOptionValueVacio+' --', '');
		}
		// POSICION del option del combo Item del cual voy a levantar los options correspondientes (hijos)
		iPosSelComboItems = thisCmbItems.selectedIndex;
		// VALOR del option del combo Item
		iValorPosSelComboItems = thisCmbItems.options[iPosSelComboItems].value;
		
		if(arrSubItems[iValorPosSelComboItems])
		{
			// Recorro los elementos del array para armar el combo de SubItems
			for (theItem in arrSubItems[iValorPosSelComboItems]) {
				// El VALUE es igual al TEXT del option
				if ( valueIgualText != null && valueIgualText ) {
					theValue = arrSubItems[iValorPosSelComboItems][theItem];
				}else{
					theValue = theItem;
				}
	
				bAsignarOption = true;
				if (thisCmbSubItemsDestino != null && thisCmbSubItemsDestino.options.length > 0) {
					for(j=0; j < thisCmbSubItemsDestino.options.length; j++) {
						if (thisCmbSubItemsDestino.options[j].value == theValue) {
							bAsignarOption = false;
							break;
						}
					}
				}
				
				if (bAsignarOption) {
					// Asigno un option al combo
					thisCmbSubItems.options[i] = new Option(arrSubItems[iValorPosSelComboItems][theItem], theValue);
					// Si el valor que tiene que tomar el combo como SELECT es igual al valor que estoy recorriendo, lo pongo como SELECTED
					if ( valorDefaultSubItems == theValue && valorDefaultSubItems != '' ) {
						thisCmbSubItems.selectedIndex = i;
					}
					i++;
				}
			 }
		}else{
			// Inserto opción de SELECCIONAR
			if ( insertarSeleccionar != null && insertarSeleccionar ) {
				// Cargo el valor de los options de productos
				thisCmbSubItems.options[0] = new Option('-- '+nombreOptionValueVacio+' --', '');
			}
		}
	}else{
		// Inicializo el combo de productos
		thisCmbSubItems.options.length=0;

		// Inserto opción de SELECCIONAR
		if ( insertarSeleccionar != null && insertarSeleccionar ) {
			// Cargo el valor de los options de productos
			thisCmbSubItems.options[0] = new Option('-- '+nombreOptionValueVacio+' --', '');
		}
	}
}
