/*****************************
* General
******************************/

function read_obj(opcion)
{
	if (document.getElementById)
		obj = document.getElementById(opcion)
	else
		obj=document.all[opcion]
	return obj
}

function pon_color_opcion_menu(opcion, color_fondo, color_texto,quita)
{
	if (celda_sel != opcion) {		
		var obj=read_obj(opcion)
		if (!obj) return
		obj.bgColor=color_fondo
		obj=read_obj(opcion+"_txt")
		if (!obj) return
		obj.color=color_texto
	}
	if (quita==true){
		var obj=read_obj(opcion)
		if (!obj) return
		obj.bgColor=color_fondo
		obj=read_obj(opcion+"_txt")
		if (!obj) return
		obj.color=color_texto
	}
}
function pon_color_opcion_menu2(opcion, color_fondo, color_texto)
{
		var obj=read_obj(opcion)
		if (!obj) return
		obj.bgColor=color_fondo
		obj=read_obj(opcion+"_txt")
		if (!obj) return
		obj.color=color_texto
}
function lee_offset_menu(obj, dir)
{
	if (!obj) return(0)
	return((dir?obj.offsetTop:obj.offsetLeft)+lee_offset_menu(obj.offsetParent, dir))
}

function lee_offset_opcion_menu(opcion, dir)
{
	return(lee_offset_menu(read_obj(opcion), dir));
}

/*****************************
* Menú desplegable
******************************/

mes_des.Registry = []
mes_des.aniLen = 250
mes_des.hideDelay = 1000
mes_des.minCPUResolution = 10
// constructor
function mes_des(id, dir, table, padre, left, top)
{
this.ie = document.all ? 1 : 0
this.ns4 = document.layers ? 1 : 0
this.dom = document.getElementById ? 1 : 0
if (this.ie || this.ns4 || this.dom) {
this.id = id
this.dir = dir
this.orientacion = dir == "left" || dir == "right" ? "h" : "v"
this.dirType = dir == "right" || dir == "down" ? "-" : "+"
this.hideTimer = false
this.padre = read_obj(padre)
this.tabla = read_obj(table)
this.aniTimer = false
this.open = false
this.over = false
this.startTime = 0
this.left=left
this.top=top
this.gRef = "mes_des_"+id
eval(this.gRef+"=this")
mes_des.Registry[id] = this
var d = document
var strCSS = '<style type="text/css">';
strCSS += '#' + this.id + '_con { visibility:hidden; '
strCSS += 'left:' + left + 'px; '
strCSS += 'top:' + top + 'px; '
strCSS += 'overflow:hidden; z-index:10000; }'
strCSS += '#' + this.id + '_con, #' + this.id + '_cnt { position:absolute; '
strCSS += 'width:' + 0 + 'px; '
strCSS += 'height:' + 0 + 'px; '
strCSS += 'clip:rect(0 ' + 0 + ' ' + 0 + ' 0); '
strCSS += '}'
strCSS += '</style>'
d.write(strCSS)
this.load()
}
}
mes_des.prototype.load = function() {
var d = document
var lyrId1 = this.id + "_con"
var lyrId2 = this.id + "_cnt"
var obj1 = this.dom ? d.getElementById(lyrId1) : this.ie ? d.all[lyrId1] : d.layers[lyrId1]
if (obj1) var obj2 = this.ns4 ? obj1.layers[lyrId2] : this.ie ? d.all[lyrId2] : d.getElementById(lyrId2)
var temp
if (!obj1 || !obj2) window.setTimeout(this.gRef + ".load()", 100)
else {
this.contenedor = obj1
this.menu = obj2
this.style = this.ns4 ? this.menu : this.menu.style


this.dim=300
this.homePos = eval("0" + this.dirType + this.dim)
this.outPos = 0
this.aceleracion = (this.outPos - this.homePos) / mes_des.aniLen / mes_des.aniLen 
// set event handlers.
if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
this.menu.onmouseover = new Function("mes_des.abre_menu('" + this.id + "')")
this.menu.onmouseout = new Function("mes_des.cierra_menu('" + this.id + "')")
//set initial state
this.cierra_slide()
}
}
mes_des.abre_menu = function(id)
{
var reg = mes_des.Registry
var obj = mes_des.Registry[id]
var p, p2
if (obj.contenedor) {

// Dimension
if (obj.tabla)
{
p=obj.tabla.offsetWidth
p2=obj.tabla.offsetHeight

obj.dim = obj.orientacion == "h" ? p : p2
obj.homePos = eval("0" + obj.dirType + obj.dim)
obj.outPos = 0
obj.aceleracion = (obj.outPos - obj.homePos) / mes_des.aniLen / mes_des.aniLen 

obj.menu.style.width = this.ns4 ? p : p + "px"
obj.menu.style.height = this.ns4 ? p2 : p2 + "px"
obj.menu.style.clip = 'rect(0 ' + p + ' ' + p2 + ' 0)'
obj.contenedor.style.width = this.ns4 ? p : p + "px"
obj.contenedor.style.height = this.ns4 ? p2 : p2 + "px"
obj.contenedor.style.clip = 'rect(0 ' + p + ' ' + p2 + ' 0)'
obj.style.width = this.ns4 ? p : p + "px"
obj.style.height = this.ns4 ? p2 : p2 + "px"
obj.style.clip = 'rect(0 ' + p + ' ' + p2 + ' 0)'
if ((obj.dir=="down" || obj.dir=="up") && obj.tabla.width<obj.padre.offsetWidth) obj.tabla.width=obj.padre.offsetWidth
}

// Posicion
if (obj.padre)
{
p=lee_offset_menu(obj.padre, 0)+obj.left
if ((obj.dir=="down" || obj.dir=="up")) p+=(obj.padre.offsetWidth-obj.contenedor.offsetWidth)
if (obj.dir=="right") p+=obj.padre.offsetWidth
if (obj.dir=="left" && obj.tabla) p-=obj.contenedor.offsetWidth
obj.contenedor.style.left = this.ns4 ? p : p + "px"
p=lee_offset_menu(obj.padre, 1)+obj.top
if (obj.dir=="down") p+=obj.padre.offsetHeight
if (obj.dir=="up") p-=obj.tabla.offsetHeight
if (obj.dir=="left") p-=(obj.tabla.offsetHeight-obj.padre.offsetHeight)/2
obj.contenedor.style.top = this.ns4 ? p : p + "px"
}


obj.over = true
for (menu in reg) if (id != menu) mes_des.hide(menu)
if (obj.hideTimer) { reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer) }
if (!obj.open && !obj.aniTimer) reg[id].abre_slide(true)
}
}
mes_des.cierra_menu = function(id)
{
var obj = mes_des.Registry[id]
if (obj.contenedor) {
if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
obj.hideTimer = window.setTimeout("mes_des.hide('" + id + "')", mes_des.hideDelay);
}
}
mes_des.cierra_todo = function()
{
var reg = mes_des.Registry
for (menu in reg) {
mes_des.hide(menu);
if (menu.hideTimer) window.clearTimeout(menu.hideTimer);
}
}
mes_des.hide = function(id)
{
var obj = mes_des.Registry[id]
obj.over = false
if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
obj.hideTimer = 0
if (obj.open && !obj.aniTimer) obj.abre_slide(false)
}
mes_des.prototype.abre_slide = function(open) {
this[open ? "onactivate" : "ondeactivate"]()
this.open = open
if (open) this.pon_visibilidad(true)
this.startTime = (new Date()).getTime() 
this.aniTimer = window.setInterval(this.gRef + ".slide()", mes_des.minCPUResolution)
}
mes_des.prototype.slide = function() {
var elapsed = (new Date()).getTime() - this.startTime
if (elapsed > mes_des.aniLen) this.cierra_slide()
else {
var d = Math.round(Math.pow(mes_des.aniLen-elapsed, 2) * this.aceleracion)
if (this.open && this.dirType == "-") d = -d
else if (this.open && this.dirType == "+") d = -d
else if (!this.open && this.dirType == "-") d = -this.dim + d
else d = this.dim + d
this.mueve(d)
}
}
mes_des.prototype.cierra_slide = function() {
this.aniTimer = window.clearTimeout(this.aniTimer)
this.mueve(this.open ? this.outPos : this.homePos)
if (!this.open) this.pon_visibilidad(false)
if ((this.open && !this.over) || (!this.open && this.over)) {
this.abre_slide(this.over)
}
}
mes_des.prototype.pon_visibilidad = function(bShow) { 
var s = this.ns4 ? this.contenedor : this.contenedor.style
s.visibility = bShow ? "visible" : "hidden"
}
mes_des.prototype.mueve = function(p) { 
this.style[this.orientacion == "h" ? "left" : "top"] = this.ns4 ? p : p + "px"
}
mes_des.prototype.lee_posicion = function(c) {
return parseInt(this.style[c])
}
mes_des.prototype.onactivate = function() { }
mes_des.prototype.ondeactivate = function() { }