	function populateList(oSelectMain, oSelectChild){
		deleteListItems(oSelectChild);
		idMainSelect = oSelectMain.options[oSelectMain.selectedIndex].value;
		eval("ArrayList = "+oSelectChild.name);
		j = 1;		
		for(var i = 0;i < ArrayList.length;i++){
			listObj = ArrayList[i];
			if(listObj.idParentItem==idMainSelect || idMainSelect==0){
				oSelectChild.options[j++] = new Option(listObj.idName, listObj.idItemList); 
			}		
		}
		//If oSelectChild has a Child list, populate Child List
		eval("var IdChildList = "+oSelectChild.name+"_childId");
		if(IdChildList > 0){			
			populateChildList(oSelectChild, IdChildList);
		}
	}
	function populateChildList(oSelectMain, IdList){
		eval("oSelectChild = document.form1.List_"+IdList);
		deleteListItems(oSelectChild);
		eval("ArrayList = "+oSelectChild.name);
		j = 1;		
		for(var i = 1;i < ArrayList.length;i++){
			listObj = ArrayList[i];			
			if(findItem(oSelectMain, listObj.idParentItem)){
				oSelectChild.options[j++] = new Option(listObj.idName, listObj.idItemList); 
			}		
		}
		//If oSelectChild has a Child list, populate Child List
		eval("var IdChildList = "+oSelectChild.name+"_childId");
		if(IdChildList > 0){			
			populateChildList(oSelectChild.name, IdChildList);
		}
	}

	function findItem(oSelect, IdItem){
		ln = oSelect.options.length;
		var status = false;
		var i = 0;
		while(i < ln && status == false){
			status = (oSelect.options[i++].value == IdItem);
		}
		return status;
	}

	function findItemPosition(oSelect, IdItem){
		ln = oSelect.options.length;
		var pos = -1;
		var i = 0;
		while(i < ln && pos == -1){
			pos = oSelect.options[i].value==IdItem?i:-1;
			i++;
		}
		return pos;
	}

	function deleteListItems(oSelect){
		ln = oSelect.options.length - 1;
		for(var i = ln;i >=0;i--){
			oSelect.options[i] = null;
		}
	}

	function deleteListItem(oSelect, IdItem){
		pos = findItemPosition(oSelect, IdItem);
		if(pos!=-1){
			oSelect.options[pos] = null;
		}
	}
	

	function addItem(i, name, value){
		oSelect = document.form1.selectedLists;
		oSelect.options[i] = new Option(name, value);		
	}

	function addOption(oSelect, name, value){
		oSelect.options[oSelect.options.length] = new Option(name, value);
		/*
		//Este codigo solo funcionó en IE
		var oOption = document.createElement("OPTION");
		oOption.text=name;
		oOption.value=value;
		oSelect.add(oOption);
		*/
	}

	function SelectAllList(oSelect){
		for(var i = 0;i < oSelect.length;i++){
			oSelect.options[i].selected = true;
		}
	}
	
	function checkCurrentSearch(IdSearch){
		if(document.form1.currentSearch.value!="0"){
			eval("searchList = document.form1.searchLists_"+document.form1.currentSearch.value);
			eval("currentSearch = document.form1.searchBox_"+document.form1.currentSearch.value);
			if(currentSearch.checked){
				if(getCriteria(searchList.value)){
					getSearch(IdSearch);					
					return true;
				}else{return false;}				
			}else{
				getSearch(IdSearch);
				return true;
			}
		}else{
			getSearch(IdSearch);
			return true;
		}
		return true;
	}

	function activateCurrentSearch(IdSearch){
		if(parseInt(document.form1.idSearch.value) == parseInt(IdSearch)){
			//alert(true)
			document.form1.setSearch.checked=true;
		}
	}

	function getCriteria(listas){
		array = listas.split(',');	
		var searchCriteria = '';
		for(i = 0; i < (array.length-1); i++){
			eval("oSelect = document.form1.List_"+array[i]);
			if(oSelect.value == 0){
				alert(oSelect.options[0].text);	
				oSelect.focus();
				return false;
			}else{
				searchCriteria = searchCriteria+array[i]+"-"+oSelect.value+",";	
			}
		}
		saveSearchCriteria(document.form1.currentSearch.value, searchCriteria);
		return true;
	}
	
	function recoverSearchCriteria(IdSearch, listas){
		var criteria = document.form1.vinculedSearchs.options[findItemPosition(document.form1.vinculedSearchs, IdSearch)].text;
		//alert("listas: "+listas);
		//arrayList = listas.split(',');	
		arrayCriteria = criteria.split(',');	
		for(i = 0; i < (arrayCriteria.length-1); i++){
			criteria = arrayCriteria[i].split("-");
			eval("oSelect = document.form1.List_"+criteria[0]);
			oSelect.value = criteria[1];
		}
	}
	
	function dropElements(oSelect1, oSelect2){
		lnt = oSelect1.options.length;
		for(i = 0; i < lnt ; i++){
			deleteListItem(oSelect2, oSelect1.options[i].value);
		}
	}
	
	function orderSelectedLists(){
		oSelect = document.form1.selectedLists;
		for(i = 0; i < (oSelect.options.length-1); i++){
			for(j = 0; j < (oSelect.options.length-1); j++){
				A = oSelect.options[j].text.split(",");
				B = oSelect.options[j+1].text.split(",");
				if(compareXY(parseInt(A[0]), parseInt(B[0]), parseInt(A[1]), parseInt(B[1])) < 0){
					valueTemp = oSelect.options[j+1].value;			
					textTemp = oSelect.options[j+1].text;
					oSelect.options[j+1].value = oSelect.options[j].value;
					oSelect.options[j+1].text = oSelect.options[j].text;
					oSelect.options[j].value = valueTemp;
					oSelect.options[j].text = textTemp;
				}	
			}
		}
	}
	
	function compareXY(Ax, Bx, Ay, By){
		Xcmp = (Bx <= Ax);	
		Ycmp = (By <= Ay);	
		Res = (Xcmp&&Ycmp)?-1:1;
		return Res;
	}
	
	function captureSelectedLists(){
		orderSelectedLists();
		oSelect = document.form1.selectedLists;
		for(i = 0; i < oSelect.options.length; i++){
			oSelect.options[i].value = oSelect.options[i].value+","+oSelect.options[i].text;
		}
		SelectAllList(oSelect);
	}

	function reOrganizeSelectedLists(){
		oSelect = document.form1.selectedLists;
		for(i = 0; i < oSelect.options.length; i++){
			eval("var oLayer = dd.elements.Layer"+oSelect.options[i].value);
			xy = oSelect.options[i].text.split(",");
			oLayer.moveTo(parseInt(xy[0]), parseInt(xy[1])); 
		}
		SelectAllList(oSelect);
	}
