// JJBM, 12/06/2007, sugerir.js

var sugerirInfo = true
var sugerirTexto = null
var sugerirMsk = 0xFFF

/*
	2^0	1	1	1	catálogo principal
	2^1	2	2	2	catálogo auxiliar
	2^2	4	4	4	autor
	2^3	8	8	10	editor
	2^4	16	10	20	colección
	2^5	32	20	40	materia
	2^6	64	40	100	población
*/

function ProcesarSeleccion(p) {
	var t = sugerirTexto, s = "", e = t.value, i = e.length
	while(i--)
		if( e.charAt(i) == ' ' )
			break
	t.value = t.value.substr( 0, i+1 )
	t.focus()
	t.value += ProcesarObtenerPalabra( p ) + ' '
}

function ProcesarObtenerPalabra(s) {
	return s.split(';')[0]
}

function ProcesarFormatearInfo( s ) {
	if(!sugerirInfo)
		return ""

	var v = s.split(';'), t1, t2
	if( v.length < 3 )
		return ""
	s = "<table border='0' cellspacing='0' style='border-right: 1px solid black'>"
	s+= "<tr>"
	s+= "<td align='right' title='" + v[1] + " ocurrencias'>&nbsp;&nbsp;" + v[1] + "</td>"

	t1= "<td width='12px' align='center' title='TEXTO' style='border-left: 1px solid gray; font-size: 10px'>"
	t2= "</td>"
	tN = t1.replace(/TEXTO/,"") + "&nbsp;" + t2

	var m = parseInt(v[2])
	if( m & 1 )	s+= t1.replace(/TEXTO/,"Aparece en el catálogo principal") + "<font color=green><b>D</b></font>" + t2
	else		s+= tN
	if( m & 2 )	s+= t1.replace(/TEXTO/,"Aparece en el catálogo secundario") + "L" + t2
	else		s+= tN
	if( m & 4 )	s+= t1.replace(/TEXTO/,"Aparece en los autores") + "A" + t2
	else		s+= tN
	if( m & 8 )	s+= t1.replace(/TEXTO/,"Aparece en las editoriales") + "E" + t2
	else		s+= tN
	if( m & 16)	s+= t1.replace(/TEXTO/,"Aparece en las colecciones") + "C" + t2
	else		s+= tN
	if( m & 32)	s+= t1.replace(/TEXTO/,"Aparece en las materias") + "M" + t2
	else		s+= tN
	if( m & 64)	s+= t1.replace(/TEXTO/,"Aparece en las provincias") + "P" + t2
	else		s+= tN

	s+= "</tr>"
	s+= "</table>"

	return s
}

function ProcesarTecla(o) {
	var s = "", e = o.value, i = e.length
	if( i > 0 )
		while(i--)
			if( e.charAt(i) == ' ' )
				break
			else
				s = e.charAt(i) + s
	if( s.length <= 0 ) {
		ddl.Ocultar()
		return
	}
	ddl.prefijo = s
	ddl.Seleccionar = ProcesarSeleccion
	ddl.ObtenerPalabra = ProcesarObtenerPalabra
	ddl.FormatearInfo = ProcesarFormatearInfo
	luajax.BuscarPalabrasPorPrefijoMsk( s, sugerirMsk, ddl.ActualizarLista )
}

function PosicionAbsolutaLeft(o) {
	var p = 0
	while( o != null ) {
		p += o.offsetLeft
		o = o.offsetParent
	}
	return p
}

function PosicionAbsolutaTop(o) {
	var p = 0
	while( o != null ) {
		p += o.offsetTop
		o = o.offsetParent
	}
	return p
}

