function ListItemChange(ArrObj, HiddenName, ListaSrc, ListaDst, Adding, HasBGColor, HasFontColor, XtraSrcTxt, XtraDstTxt){
	var Aux, Aux2;
	var AddedOne = false;
	var arroffset, auxoffset;
	var auxposoffset = new Number;
	var ItemCount;
	var newitemindex;
	var i, kk;
	var j = new Number;
	var k = new Number;

	// ***********************************************************************
	// Lo saque porque cuando entrabas en RO el control no se seleccionaba 
	// ***********************************************************************
	/*if(ListaSrc.disabled || ListaDst.disabled){
		return
	}*/
	// ***********************************************************************
	i = 0;
	ItemCount = 0;
	while (i < ListaSrc.length){
		if (ListaSrc.options[i].selected==true){
			// Tomar posición del item a agregar
			//j = 0;
			auxposoffset = 0;
			if(HasBGColor)
				auxposoffset++;
			if(HasFontColor)
				auxposoffset++;
			//for (j = 0; j < ArrObj.length && ArrObj[j] != ListaSrc.options[i].value; j += 2 + auxposoffset){}
			
			newitemindex = ListaSrc.options[i].dbindex
			// Recorrer items ya agregados
			list2length = ListaDst.length
			newitempos = list2length
			//kk = 0
			for (j = 0; j < list2length; j++){
				// Ver en qué posición está el item
				if (Math.abs(ListaDst.options[j].dbindex) > Math.abs(newitemindex)) {
					newitempos = j;
					break;
				}
			}

			var NewOption = new Option(ListaSrc.options[i].text, ListaSrc.options[i].value);
			if(HasBGColor || HasFontColor){
				NewOption.style.backgroundColor = ListaSrc.options[i].style.backgroundColor;
				NewOption.style.color = ListaSrc.options[i].style.color;
			}
			AddAttribute(NewOption, 'dbindex', newitemindex);
			
			ListaDst.options.add(NewOption, newitempos);
			
			// Dejar preparada para pisar una opcion nueva donde corresponde
			/*for (k = list2length; k > newitempos; k--){
				ListaDst.options[k] = new Option(ListaDst.options[k-1].text, ListaDst.options[k-1].value);
				auxoffset = 0;
				if(HasBGColor){
					ListaDst.options[k].style.backgroundColor = ListaDst.options[k-1].style.backgroundColor;
					if(HasFontColor){
						auxoffset = 1;
					}
				}
				if(HasFontColor){
					ListaDst.options[k].style.color = ListaDst.options[k-1].style.color;
				}
			}
			// Piso el valor de la opcion creada con el correspondiente
			ListaDst.options[newitempos] = new Option(ListaSrc.options[i].text, ListaSrc.options[i].value);
			
			// Macheo por id la opcion que se pasa y busco en el array el color que le corresponde
			for(arroffset=0; arroffset < ArrObj.length; arroffset += 2 + auxposoffset){
				//alert(ArrObj[arroffset] + " (" + ArrObj[arroffset+2] + "): " + ListaSrc.options[i].value);
				if(ArrObj[arroffset] == ListaSrc.options[i].value && (HasBGColor || HasFontColor)){
					auxoffset = 0;
					if(HasBGColor){
						ListaDst.options[newitempos].style.backgroundColor = ArrObj[arroffset + 2];
						if(HasFontColor){
							auxoffset = 1;
						}
					}
					if(HasFontColor){
						ListaDst.options[newitempos].style.color = ArrObj[arroffset + 2 + auxoffset];
					}
				}
			}*/
			
			AddedOne = true;
			
			// Elimino el item de la lista
			ListaSrc.options[i] = null;
		}else{
			i++;
		}
	}
	if(AddedOne){
		Aux = ''
		if(Adding){
			// Si estoy agregando
			for(i=0;i < ListaDst.options.length;i++){
				if(Aux.length > 0){
					Aux = Aux + ', ';
				}
				Aux = Aux + ListaDst.options[i].value;
			}
		}else{
			// Si estoy quitando
			for(i=0;i < ListaSrc.options.length;i++){
				if(Aux.length > 0){
					Aux = Aux + ', ';
				}
				Aux = Aux + ListaSrc.options[i].value;
			}
		}
		document.all(HiddenName).value = Aux;
	}
	SetListSize(ListaSrc, 10);
	SetListSize(ListaDst, 10);

	if(XtraSrcTxt != undefined){
		XtraSrcTxt.innerHTML = ListaSrc.options.length;
	}

	if(XtraDstTxt != undefined){
		XtraDstTxt.innerHTML = ListaDst.options.length;
	}
}

function SetListSize(LstObj, Size){
	LstObj.size = Size;
	if(LstObj.options.length > 10){
		LstObj.size = LstObj.options.length;
	}
}

function FullListChange(ArrObj, HiddenName, ListSrc, ListDest, AddAll, HasBGColor, HasFontColor, XtraSrcTxt, XtraDstTxt){
	var auxoffset, coloroffset, ObjOffset;

	if(ListSrc.disabled || ListDest.disabled){
		return
	}
	tope = ListSrc.options.length
	// Vacio la lista Source
	for (i=0;i < tope;i++){
		ListSrc.options[0] = null
	}
	tope = ListDest.options.length
	// Vacio la lista Destino
	for (i=0;i < tope;i++){
		ListDest.options[0] = null
	}
	// Guardo el valor del hidden
	var Aux = ''//document.all('" & _Values.ClientID & "').value
	
	// Lleno la lista Destino con todos los valores de los arrays
	ObjOffset = 0;
	for (i=0;i < ArrObj.length;i++){
		ListDest.options[ObjOffset] = new Option(ArrObj[i + 1], ArrObj[i]);
		AddAttribute(ListDest.options[ObjOffset], 'dbindex', ObjOffset);

		coloroffset = 0;
		auxoffset = 1;
		if(HasBGColor){
			ListDest.options[ObjOffset].style.backgroundColor = ArrObj[i + 2];
			auxoffset += 1;
			coloroffset += 1;
		}
		if(HasFontColor){
			auxoffset += 1;
			ListDest.options[ObjOffset].style.color = ArrObj[i + 2 + coloroffset];
		}
		
		// Si se esta agregando todos guardo los valores
		if(AddAll){
			// Agrego valores al hidden
			if(Aux.length > 0){
				Aux = Aux + ', '
			}
			Aux = Aux + ArrObj[i]
		}else{
			// Si se estan eliminando todos no guardo nada
			Aux = ''
		}
		i += auxoffset;
		ObjOffset++;
	}
	document.all(HiddenName).value = Aux;

	SetListSize(ListSrc, 10);
	SetListSize(ListDest, 10);

	if(XtraSrcTxt != undefined){
		XtraSrcTxt.innerHTML = ListSrc.options.length;
	}

	if(XtraDstTxt != undefined){
		XtraDstTxt.innerHTML = ListDest.options.length;
	}
}

function RequiredMultipleList(Obj){
	if(Obj.options.length > 0){
		return true
	}else{
		return false
	}
}

function RequiredCheckboxList(Obj, Max){
	var i;
	var HasChecked = false;

	for(i=0;i < Max;i++){
		if(document.all(Obj.id + "_" + i).checked){
			HasChecked = true;
			break;
		}
	}

	return HasChecked
}

function CheckHidden(ChkObj, HidObj, CheckedValue, UnCheckedValue){
	if(ChkObj.checked){
		document.all(HidObj).value = CheckedValue;
	}else{
		document.all(HidObj).value = UnCheckedValue;
	}
}

function CheckVal(oTxt, Format){
	var Valor = oTxt.value;

	if(event.keyCode >= 48 && event.keyCode <= 57 || event.keyCode >= 96 && event.keyCode <= 105){
		switch(Format.toLowerCase()){
			case('dmyyhms'):
				var Temp = Valor.split(' ');
				var Exp1 = FormatWithSeparator(Temp[0], 3, '/', oTxt.maxLength);
				var Exp2 = '';

				if(Temp.length > 1){
					Exp2 = ' ' + FormatWithSeparator(Temp[1], 3, ':', oTxt.maxLength);
				}

				oTxt.value = Exp1 + Exp2;
			break;

			case('dmyyhm'):
				var Temp = Valor.split(' ');
				var Exp1 = FormatWithSeparator(Temp[0], 3, '/', oTxt.maxLength);
				var Exp2 = '';

				if(Temp.length > 1){
					Exp2 = ' ' + FormatWithSeparator(Temp[1], 2, ':', oTxt.maxLength);
				}

				oTxt.value = Exp1 + Exp2;
			break;

			case('dmyy'):
				oTxt.value = FormatWithSeparator(Valor, 3, '/', oTxt.maxLength);
			break;

			case('myy'):
				oTxt.value = FormatWithSeparator(Valor, 2, '/', oTxt.maxLength);
			break;

			case('hm'):
				oTxt.value = FormatWithSeparator(Valor, 2, ':', oTxt.maxLength);
			break;

			case('hms'):
				oTxt.value = FormatWithSeparator(Valor, 3, ':', oTxt.maxLength)
			break;
		}
	}
}

function FormatWithSeparator(Valor, CantSep, Sep, maxLength){
	var Index1 = Valor.indexOf(Sep);
	var Index2 = Valor.indexOf(Sep, Index1 + 1);
	var Long = Valor.length;

	if(Index1 == 1){
		Valor = "0" + Valor;
	}

	if(Index1 == -1 || Index1 == 2){
		if(Long >= 3 && Valor.charAt(2) != Sep && Index1 != Long - 1){
			Valor = Valor.substr(0,2) + Sep + Valor.substr(2, Valor.length);
		}
	}

	if(CantSep > 2){
		if(Index2 == 4 && Valor.length != maxLength){
			Valor = Valor.substring(0, Index1 + 1) + '0' + Valor.substring(Index1 + 1, Long);
		}

		if(Long >= 6 && Valor.charAt(5) != Sep && Index2 == -1){
			Valor = Valor.substring(0, 5) + Sep + Valor.substring(5, Long);
		}
	}

	if(Valor.length > maxLength){
		Valor = Valor.substring(0, maxLength);
	}

	return Valor;
}

function AddAttribute(oDestino, Nombre, Valor){
	var nnm = oDestino.attributes;
	var namedItem = document.createAttribute(Nombre);

	namedItem.value = Valor;
	nnm.setNamedItem(namedItem);
}