function _ObtenerSugerencia(argComboBox) {
	try {
		if ((window.event.toElement != null) && (window.event.toElement.className == "sugerencia")) {
			var pos = window.event.offsetY-45;
			var i=1;
				
			while (pos > i*13) {
				i = i + 1;
			}  	
		}
		
		if (arrSugerencias[i-1] == null) return null;

		argComboBox.selectedIndex = arrSugerencias[i-1];								 
		return argComboBox.options(arrSugerencias[i-1]);
		
	}catch(e) {
		return null;
	}

}

var _cli_X;
var _cli_Y;
var _pro_X;
var _pro_Y;
var _tar_X;
var _tar_Y;

function AbrirComboBox(textBox, comboBox) {  	
	
var positionBox = textBox.getBoundingClientRect();
		
	try {
	textBox.style.display = 'none'; 
	comboBox.style.display = '';  
	
	comboBox.style.position = "absolute";
	
	if (positionBox.top == 0 ) {
		tope = textBox.attributes("tope").value;
		izquierda = textBox.attributes("izquierda").value;
	}else {
		textBox.setAttribute('tope', positionBox.top -2 + _cuerpo.scrollTop);
		textBox.setAttribute('izquierda', positionBox.left - 2 + _cuerpo.scrollLeft);	 
	
		tope = positionBox.top -2 + _cuerpo.scrollTop;
		izquierda = positionBox.left - 2 + _cuerpo.scrollLeft;		
	}	
	
	comboBox.style.top = tope;
	comboBox.style.left = izquierda;
		
	var ancho = textBox.clientWidth+3;
	comboBox.style.width = '';
	
	if (comboBox.clientWidth < ancho) {
		comboBox.style.width = ancho;	
	}
	
	
	
	comboBox.focus();  
	
	}catch(e){}
	//window.event.cancelBubble = true;
	//return false;
	
	
}

function Mensaje(mensaje)
{
  alert(mensaje);
}

var primeraVes
primeraVes = 0

function CerrarComboBox1(textComboId, textBox, comboBox,buscadorTabla) {
		if (buscadorTabla.style.display == "none") {
			comboBox.style.display = 'none'; 
			textBox.style.display = '';
			textBox.value = comboBox(comboBox.selectedIndex).innerText;    
			textBox.title = comboBox(comboBox.selectedIndex).innerText;
			
		if (textBox.AutoPostBack == "True") __doPostBack(textComboId, "seleccion");
		}  	
		primeraVes = 0;	
		
		if ((textComboId == "txtActividad") && (document.getElementById("chkRework") != null)) {
			document.getElementById("chkRework").checked = comboBox.options(comboBox.selectedIndex).ReWork;
			
		}
		
		if (textComboId == "txtTipoSolicitud") {			
			_CargarDatosComboTareas(__usaTareas,__esIngles,__Pais,__esIndice,__pagina);			
			
		}
		
		//window.event.cancelBubble = true;
}

function CerrarComboBox(textComboId, textBox, comboBox,buscadorTabla) {
var sugerencia;
			
	if (primeraVes == 1)
	{
		if (buscadorTabla.style.display == "none") {
			comboBox.style.display = 'none'; 
			textBox.style.display = '';
			
			sugerencia = _ObtenerSugerencia(comboBox);
			if (sugerencia != null) {
				textBox.value = sugerencia.text;    
				textBox.title = sugerencia.text;
			}else {
				textBox.value = comboBox(comboBox.selectedIndex).innerText;    
				textBox.title = comboBox(comboBox.selectedIndex).innerText;
			}
			
			
		if (textBox.AutoPostBack == "True") __doPostBack(textComboId, "seleccion");
		}  		
		primeraVes = 0;
	}
	else
	{primeraVes = 1;}
	//window.event.cancelBubble = true;
}

function CerrarBuscador(textComboId,textBox, comboBox, buscadorTabla, sugerenciaTabla, buscadorTextBox) {	
	buscadorTabla.style.display = 'none'; 
	buscadorTextBox.value = '';
	sugerenciaTabla.style.display = 'none'; 
	primeraVes = 1;
	
	
	
	CerrarComboBox(textComboId,textBox, comboBox, buscadorTabla)	
}

function CerrarBuscador2(textComboId,textBox, comboBox, buscadorTabla,sugerenciaTabla, buscadorTextBox) {	
	buscadorTabla.style.display = 'none'; 
	buscadorTextBox.value = '';
	sugerenciaTabla.style.display = 'none'; 
	primeraVes = 1;
	CerrarComboBox(textComboId,textBox, comboBox, buscadorTabla)	
}

function AbrirBuscador(buscadorTabla, buscadorTextBox, sugerenciaTabla, comboBox) {
  var positionBox = comboBox.getBoundingClientRect();	
	
	if	((event.keyCode == 13) || (event.keyCode == 9)) return;

	//posiciono el buscador por sugerencia
	sugerenciaTabla.style.top = positionBox.top + 15 + _cuerpo.scrollTop;
	sugerenciaTabla.style.left = positionBox.left - 4 + _cuerpo.scrollLeft;
	sugerenciaTabla.style.display = "";		
	sugerenciaTabla.style.width = comboBox.clientWidth + 3;
	
  buscadorTabla.style.top = positionBox.top - 47 + _cuerpo.scrollTop;;
  buscadorTabla.style.left = positionBox.left - 2 + _cuerpo.scrollLeft;
  buscadorTabla.style.display = "";		
  buscadorTextBox.focus();	  
  buscadorTabla.style.width = comboBox.clientWidth;
  if ((event.keyCode >= 49 && event.keyCode <= 57) || (event.keyCode >= 65 && event.keyCode <= 90)) {
	//if (event.keyCode >= 65 && event.keyCode <= 90) {
	//	buscadorTextBox.value   = buscadorTextBox.value + String.fromCharCode(event.keyCode + 32)
	//}else	{
	//	buscadorTextBox.value   = buscadorTextBox.value + String.fromCharCode(event.keyCode)
	//}
  }    
  BuscarEnCombo(buscadorTextBox.value, comboBox,sugerenciaTabla, comboBox.options.length);
}

function Buscar(buscador,textBox,comboBox,buscadorTabla,cantidadElementos) {
	//if (window.event.keyCode==13) {
	//	CerrarBuscador2(textBox, comboBox, buscador);		
	//}
	BuscarEnCombo(buscador.value, comboBox ,buscadorTabla,comboBox.options.length);			
			
}

function  BuscarEnCombo (palabra, comboBox,buscadorTabla, cantidadElementos) {
	var i, posicionActual;
	var largo, datoCombo;
		
	//window.event.cancelBubble = "True";	
	largo = palabra.length;
			
	if (comboBox.parentElement.parentElement.parentElement.parentElement.parentElement.attributes.MostrarCodigos == null) { 
		mostrarCodigos = true; 
	}else {
		mostrarCodigos = (comboBox.parentElement.parentElement.parentElement.parentElement.parentElement.attributes.MostrarCodigos.value.toUpperCase() == "TRUE");
	}
	
	// Busca sugerencias	
	BuscarSugerencias(buscadorTabla, comboBox, palabra, mostrarCodigos);
		
	for (i=0;i<cantidadElementos;i++) {				
		datoCombo = comboBox.options(i).text;
		idCombo = comboBox.options(i).value;
		
		if ((datoCombo.toUpperCase().indexOf(palabra.toUpperCase()) != -1) ||
			(idCombo.toUpperCase().indexOf(palabra.toUpperCase()) != -1))
	    {	    	
			comboBox.options(i).selected="True";
			return;							
	    }       	

	}
}

var arrSugerencias; 

function BuscarSugerencias(argSugerenciaTabla, argComboBox, argPalabra, argMostrarCodigos){
	var i;
	var datoCombo;
	var idCombo;
	var lista = argSugerenciaTabla.firstChild.firstChild.firstChild.firstChild;
	var j=0;
	
	lista.value = "";
	    
	arrSugerencias = new Array();
	    
    for (i=0; i<argComboBox.length; i++) {				
		datoCombo = argComboBox.options(i).text;
		idCombo = argComboBox.options(i).value;
			    
	    if ((datoCombo.toUpperCase().indexOf(argPalabra.toUpperCase()) != -1) ||
			(idCombo.toUpperCase().indexOf(argPalabra.toUpperCase()) != -1))
	    {
			if (!argMostrarCodigos) {
				lista.value = lista.value + datoCombo; 
			}else {
				lista.value = lista.value + idCombo + " - " + datoCombo; 
			}
			arrSugerencias[j] = i;
			j = j + 1;
			if (j == 10) {
				return;				
			}else {
				lista.value = lista.value + "\n";
			};
	    }   


	}
        
}